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 &blob, std::unique_ptr< TTree > &tree, const std::string_view name="tree")
 Interprets the coral::Blob as a TTree instance. More...
 

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  if (compress(ptr, &comprLen, reinterpret_cast<const unsigned char*>(in), strlen(in)) != Z_OK) {
26  return false;
27  }
28  blob.resize(comprLen);
29  out = blob;
30  return true;
31 }

◆ readBlobAsJson()

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

Definition at line 96 of file blobaccess.cxx.

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

◆ readBlobAsString()

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

Definition at line 87 of file blobaccess.cxx.

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

◆ readBlobAsTTree()

bool CoralUtilities::readBlobAsTTree ( const coral::Blob &  blob,
std::unique_ptr< TTree > &  tree,
const std::string_view  name = "tree" 
)

Interprets the coral::Blob as a TTree instance.

If the parsing was successful, the parsed tree pointer is assigned to an object and true is returned. Otherwise, the unique_ptr is set to nullptr with false

Parameters
blobCoral database blob to interpret
treeReference to the unique_ptr to which the TTree is interpreted
nameName of the TTree inside the memory blob

Definition at line 109 of file blobaccess.cxx.

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

◆ uncompressBlob()

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

Definition at line 63 of file blobaccess.cxx.

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

◆ writeBlobFromJson()

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

Definition at line 37 of file blobaccess.cxx.

37  {
38  return writeBlobFromString(in.dump(), out);
39 }

◆ writeBlobFromString()

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

Definition at line 33 of file blobaccess.cxx.

33  {
34  return compressBlob(in.data(), out);
35 }

◆ writeBlobFromTTree()

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

Definition at line 41 of file blobaccess.cxx.

41  {
42  TMemFile fout("buffer","recreate");
43  fout.cd();
44  tree->CloneTree(-1, "fast")->Write();
45  fout.Write();
46  uLongf comprLen = fout.GetSize();
47  unsigned char *buffer = new unsigned char[comprLen];
48  fout.CopyTo(buffer, comprLen);
50  blob.resize(comprLen);
51  char* ptr = reinterpret_cast<char*>(blob.startingAddress());
52  *ptr = *const_cast<char*>(CxxUtils::base64_encode(buffer, comprLen).c_str());
53  out = blob;
54  return true;
55 }
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:1113
tree
TChain * tree
Definition: tile_monitor.h:30
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:70
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:11
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:87
dqt_zlumi_alleff_HIST.fout
fout
Definition: dqt_zlumi_alleff_HIST.py:59
calibdata.exception
exception
Definition: calibdata.py:495
res
std::pair< std::vector< unsigned int >, bool > res
Definition: JetGroupProductTest.cxx:11
CoralUtilities::uncompressBlob
bool uncompressBlob(const coral::Blob &, std::unique_ptr< unsigned char[]> &, unsigned long &)
Definition: blobaccess.cxx:63
hist_file_dump.f
f
Definition: hist_file_dump.py:140
keylayer_zslicemap.sb
sb
Definition: keylayer_zslicemap.py:192
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
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:33
CaloCondBlobAlgs_fillNoiseFromASCII.blob
blob
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:95