ATLAS Offline Software
Functions
CoralUtilities Namespace Reference

Functions

bool compressBlob (const char *, coral::Blob &)
 
bool writeBlobFromString (const std::string_view, coral::Blob &)
 
bool writeBlobFromJson (const nlohmann::json &, coral::Blob &)
 
bool writeBlobFromTTree (TTree *, coral::Blob &)
 
bool uncompressBlob (const coral::Blob &, std::unique_ptr< unsigned char[]> &, unsigned long &)
 
bool readBlobAsString (const coral::Blob &, std::string &)
 
bool readBlobAsJson (const coral::Blob &, nlohmann::json &)
 
bool readBlobAsTTree (const coral::Blob &, std::unique_ptr< TTree > &)
 

Function Documentation

◆ compressBlob()

bool CoralUtilities::compressBlob ( const char *  in,
coral::Blob &  out 
)

Definition at line 20 of file blobaccess.cxx.

20  {
21  uLongf comprLen = compressBound(strlen(in));
23  blob.resize(comprLen);
24  unsigned char* ptr = static_cast<unsigned char*>(blob.startingAddress());
25  compress(ptr, &comprLen, reinterpret_cast<const unsigned char*>(in), strlen(in));
26  blob.resize(comprLen);
27  out = blob;
28  return true;
29 }

◆ readBlobAsJson()

bool CoralUtilities::readBlobAsJson ( const coral::Blob &  blob,
nlohmann::json out 
)

Definition at line 94 of file blobaccess.cxx.

94  {
95  std::string str = "";
96  if(!readBlobAsString(blob, str)) return false;
97  try {
99  }
100  catch(const std::exception& e) {
101  std::cout << "ATTENTION: Cannot unpack Blob object as JSON!" << std::endl;
102  return false;
103  }
104  return true;
105 }

◆ readBlobAsString()

bool CoralUtilities::readBlobAsString ( const coral::Blob &  blob,
std::string &  out 
)

Definition at line 85 of file blobaccess.cxx.

85  {
86  std::unique_ptr<unsigned char[]> bf {};
87  uLongf len = 0;
88  if(!uncompressBlob(blob, bf, len)) return false;
89  const char* cstring = reinterpret_cast<const char*>(bf.get()); // need to cast to char*
90  out.assign(cstring, len); // copy over to C++ string
91  return true;
92 }

◆ readBlobAsTTree()

bool CoralUtilities::readBlobAsTTree ( const coral::Blob &  blob,
std::unique_ptr< TTree > &  out 
)

Definition at line 107 of file blobaccess.cxx.

107  {
108  const char* cstring = reinterpret_cast<const char*>(blob.startingAddress());
109  std::string sb;
110  sb.assign(cstring, blob.size());
111  std::vector<unsigned char> bdata = CxxUtils::base64_decode(sb);
112  TMemFile f("buffer", reinterpret_cast<char*>(bdata.data()), bdata.size());
113  TTree* t = nullptr;
114  f.GetObject("tree",t);
115  if(!t) return false;
116  t->LoadBaskets();
117  t->SetDirectory(0);
118  f.Close();
119  out.reset(t);
120  return true;
121 }

◆ uncompressBlob()

bool CoralUtilities::uncompressBlob ( const coral::Blob &  blob,
std::unique_ptr< unsigned char[]> &  out,
unsigned long &  len 
)

Definition at line 61 of file blobaccess.cxx.

61  {
62  uLongf uncompLen = 50000;
63  std::unique_ptr<unsigned char[]> uncompBuf(new unsigned char[uncompLen+1]);
64  uLongf actualLen{0};
65  while(true) {
66  actualLen = uncompLen;
67  int res(uncompress(uncompBuf.get(), &actualLen, reinterpret_cast<const unsigned char*>(blob.startingAddress()), static_cast<uLongf>(blob.size())));
68  if(res == Z_OK ) break;
69  if(res == Z_BUF_ERROR) { // double buffer if it was not big enough
70  uncompLen *= 2;
71  std::cout << "ATTENTION: Increasing buffer to " << uncompLen << std::endl;
72  uncompBuf.reset(new unsigned char[uncompLen+1]);
73  continue;
74  }
75  // something else is wrong
76  uncompBuf.reset();
77  return false;
78  }
79  uncompBuf.get()[actualLen]=0; // append 0 to terminate string
80  out = std::move(uncompBuf);
81  len = actualLen;
82  return true;
83 }

◆ writeBlobFromJson()

bool CoralUtilities::writeBlobFromJson ( const nlohmann::json in,
coral::Blob &  out 
)

Definition at line 35 of file blobaccess.cxx.

35  {
36  return writeBlobFromString(in.dump(), out);
37 }

◆ writeBlobFromString()

bool CoralUtilities::writeBlobFromString ( const std::string_view  in,
coral::Blob &  out 
)

Definition at line 31 of file blobaccess.cxx.

31  {
32  return compressBlob(in.data(), out);
33 }

◆ writeBlobFromTTree()

bool CoralUtilities::writeBlobFromTTree ( TTree *  tree,
coral::Blob &  out 
)

Definition at line 39 of file blobaccess.cxx.

39  {
40  TMemFile fout("buffer","recreate");
41  fout.cd();
42  tree->CloneTree(-1, "fast")->Write();
43  fout.Write();
44  uLongf comprLen = fout.GetSize();
45  unsigned char *buffer = new unsigned char[comprLen];
46  fout.CopyTo(buffer, comprLen);
48  blob.resize(comprLen);
49  char* ptr = reinterpret_cast<char*>(blob.startingAddress());
50  *ptr = *const_cast<char*>(CxxUtils::base64_encode(buffer, comprLen).c_str());
51  out = blob;
52  return true;
53 }
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
Amg::compress
void compress(const AmgSymMatrix(N) &covMatrix, std::vector< float > &vec)
Definition: EventPrimitivesHelpers.h:56
CoralUtilities::compressBlob
bool compressBlob(const char *, coral::Blob &)
Definition: blobaccess.cxx:20
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1054
tree
TChain * tree
Definition: tile_monitor.h:30
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
python.subdetectors.tile.Blob
Blob
Definition: tile.py:17
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
createCoolChannelIdFile.buffer
buffer
Definition: createCoolChannelIdFile.py:12
CxxUtils::base64_decode
std::vector< unsigned char > base64_decode(const std::string &)
Definition: base64.cxx:97
CoralUtilities::readBlobAsString
bool readBlobAsString(const coral::Blob &, std::string &)
Definition: blobaccess.cxx:85
dqt_zlumi_alleff_HIST.fout
fout
Definition: dqt_zlumi_alleff_HIST.py:59
calibdata.exception
exception
Definition: calibdata.py:496
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:14
CoralUtilities::uncompressBlob
bool uncompressBlob(const coral::Blob &, std::unique_ptr< unsigned char[]> &, unsigned long &)
Definition: blobaccess.cxx:61
hist_file_dump.f
f
Definition: hist_file_dump.py:135
keylayer_zslicemap.sb
sb
Definition: keylayer_zslicemap.py:192
CxxUtils::base64_encode
std::string base64_encode(const unsigned char *, unsigned int)
Definition: base64.cxx:55
str
Definition: BTagTrackIpAccessor.cxx:11
CoralUtilities::writeBlobFromString
bool writeBlobFromString(const std::string_view, coral::Blob &)
Definition: blobaccess.cxx:31
CaloCondBlobAlgs_fillNoiseFromASCII.blob
blob
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:96