File indexing completed on 2025-01-18 10:15:37
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef SRC_XRDEC_XRDECOBJCFG_HH_
0009 #define SRC_XRDEC_XRDECOBJCFG_HH_
0010
0011 #include "XrdOuc/XrdOucCRC32C.hh"
0012
0013 #include <isa-l/crc.h>
0014
0015 #include <cstdlib>
0016 #include <string>
0017 #include <vector>
0018 #include <sstream>
0019 #include <iomanip>
0020
0021 namespace XrdEc
0022 {
0023
0024
0025
0026 inline static uint32_t isal_crc32(uint32_t crc, void const *buf, size_t len)
0027 {
0028 const unsigned char* buffer = reinterpret_cast<const unsigned char*>( buf );
0029 return crc32_gzip_refl( crc, buffer, len );
0030 }
0031
0032 static const std::string ObjStr = "obj";
0033 struct ObjCfg
0034 {
0035 ObjCfg() = delete;
0036
0037 ObjCfg( const std::string &obj, uint8_t nbdata, uint8_t nbparity, uint64_t chunksize, bool usecrc32c, bool nomtfile = false ) :
0038 obj( obj ),
0039 nbchunks( nbdata + nbparity ),
0040 nbparity( nbparity ),
0041 nbdata( nbdata ),
0042 datasize( nbdata * chunksize ),
0043 chunksize( chunksize ),
0044 paritysize( nbparity * chunksize ),
0045 blksize( datasize + paritysize ),
0046 nomtfile( nomtfile )
0047 {
0048 digest = usecrc32c ? crc32c : isal_crc32;
0049 }
0050
0051 ObjCfg( const ObjCfg &objcfg ) : obj( objcfg.obj ),
0052 nbchunks( objcfg.nbchunks ),
0053 nbparity( objcfg.nbparity ),
0054 nbdata( objcfg.nbdata ),
0055 datasize( objcfg.datasize ),
0056 chunksize( objcfg.chunksize ),
0057 paritysize( objcfg.paritysize ),
0058 blksize( objcfg.blksize ),
0059 plgr( objcfg.plgr ),
0060 digest( objcfg.digest ),
0061 nomtfile( objcfg.nomtfile )
0062 {
0063 }
0064
0065 inline std::string GetDataUrl( size_t i ) const
0066 {
0067 std::string url = plgr[i] + '/' + obj;
0068 if( !dtacgi.empty() ) url += '?' + dtacgi[i];
0069 return url;
0070 }
0071
0072 inline std::string GetMetadataUrl( size_t i ) const
0073 {
0074 std::string url = plgr[i] + '/' + obj + ".mt";
0075 if( !mdtacgi.empty() ) url += '?' + mdtacgi[i];
0076 return url;
0077 }
0078
0079 inline std::string GetFileName( size_t blknb, size_t strpnb ) const
0080 {
0081 return ObjStr + '.' + std::to_string( blknb ) + '.' + std::to_string( strpnb );
0082 }
0083
0084 const std::string obj;
0085 const uint8_t nbchunks;
0086 const uint8_t nbparity;
0087 const uint8_t nbdata;
0088 const uint64_t datasize;
0089 const uint64_t chunksize;
0090 const uint64_t paritysize;
0091 const uint64_t blksize;
0092 std::vector<std::string> plgr;
0093 std::vector<std::string> dtacgi;
0094 std::vector<std::string> mdtacgi;
0095
0096 uint32_t (*digest)(uint32_t, void const*, size_t);
0097
0098 bool nomtfile;
0099 };
0100 }
0101
0102
0103 #endif