15#ifndef O2_MEMFILE_UTILS_H
16#define O2_MEMFILE_UTILS_H
47 inline static std::unique_ptr<TMemFile>
createTMemFile(
const T& obj,
const std::string& fName,
const std::string& optName =
"")
55 static std::unique_ptr<FileImage>
createFileImage(
const TObject& obj,
const std::string& fileName,
const std::string& objName)
58 std::unique_ptr<FileImage>
img = std::make_unique<FileImage>(memfUPtr->GetSize());
59 auto sz = memfUPtr->CopyTo(
img->data(), memfUPtr->GetSize());
68 inline static std::unique_ptr<FileImage>
createFileImage(
const T& obj,
const std::string& fileName,
const std::string& optName =
"")
77 auto tcl = TClass::GetClass(tinfo);
80 LOG(error) <<
"Could not retrieve ROOT dictionary for type " << tinfo.name();
82 clname = tcl->GetName();
90 static std::unique_ptr<TMemFile>
createTMemFile(
const TObject& rootObject,
const std::string& fName,
const std::string& objName)
92 std::unique_ptr<TMemFile> uptr;
93#if ROOT_VERSION_CODE < ROOT_VERSION(6, 18, 0)
94 uptr = std::make_unique<TMemFile>(fName.c_str(),
"RECREATE");
96 uptr = std::make_unique<TMemFile>(fName.c_str(),
"RECREATE",
"", ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose, 1024);
98 if (uptr->IsZombie()) {
101 throw std::runtime_error(std::string(
"Error opening memory file ") + fName.c_str());
103 rootObject.Write(objName.c_str());
111 static std::unique_ptr<TMemFile>
createTMemFile(
const void* obj,
const std::type_info& tinfo,
const std::string& fName,
const std::string& optName =
"")
113 std::unique_ptr<TMemFile> uptr;
114 auto tcl = TClass::GetClass(tinfo);
117 LOG(error) <<
"Could not retrieve ROOT dictionary for type " << tinfo.name();
120 clsName = tcl->GetName();
123 bool isTree = tcl->InheritsFrom(
"TTree");
124 int compressLevel = isTree ? ROOT::RCompressionSetting::EDefaults::kUseCompiledDefault : ROOT::RCompressionSetting::EDefaults::kUseGeneralPurpose;
125 Long64_t blSize = isTree ? 0LL : 1024LL;
127 std::string objName = optName.empty() ? clsName : optName;
128 std::string fileName = fName.empty() ? (objName +
".root") : fName;
129#if ROOT_VERSION_CODE < ROOT_VERSION(6, 18, 0)
130 uptr = std::make_unique<TMemFile>(fileName.c_str(),
"RECREATE");
132 uptr = std::make_unique<TMemFile>(fileName.c_str(),
"RECREATE",
"", compressLevel, blSize);
134 if (uptr->IsZombie()) {
137 throw std::runtime_error(std::string(
"Error opening memory file ") + fileName.c_str());
139 const TTree* treePtr =
nullptr;
141 treePtr =
const_cast<TTree*
>((
const TTree*)obj)->CloneTree(-1,
"");
144 uptr->WriteObjectAny(obj, clsName.c_str(), objName.c_str());
154 static std::unique_ptr<FileImage>
createFileImage(
const void* obj,
const std::type_info& tinfo,
const std::string& fileName,
const std::string& optName =
"")
157 std::unique_ptr<FileImage>
img = std::make_unique<FileImage>(memfUPtr->GetSize());
158 auto sz = memfUPtr->CopyTo(
img->data(), memfUPtr->GetSize());
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
Common utility functions.
static std::string getClassName(const T &obj)
get the class name of the object
static std::unique_ptr< FileImage > createFileImage(const void *obj, const std::type_info &tinfo, const std::string &fileName, const std::string &optName="")
ClassDefNV(MemFileHelper, 1)
static std::unique_ptr< FileImage > createFileImage(const TObject &obj, const std::string &fileName, const std::string &objName)
static std::string getClassName(const std::type_info &tinfo)
get the class name of the object
static std::unique_ptr< TMemFile > createTMemFile(const T &obj, const std::string &fName, const std::string &optName="")
dump object into the TMemFile named fileName. The stored object will be named according to the optNam...
static std::unique_ptr< TMemFile > createTMemFile(const TObject &rootObject, const std::string &fName, const std::string &objName)
dump TObject the TMemFile named fileName. The stored object will be named according to the optName or...
static std::unique_ptr< TMemFile > createTMemFile(const void *obj, const std::type_info &tinfo, const std::string &fName, const std::string &optName="")
dump object into the TMemFile named fileName. The stored object will be named according to the optNam...
std::vector< char > FileImage
static std::unique_ptr< FileImage > createFileImage(const T &obj, const std::string &fileName, const std::string &optName="")
static void trim(std::string &s)
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"