8 #ifndef ROOTOUTFILEMANAGER_H
9 #define ROOTOUTFILEMANAGER_H
18 #include <TClonesArray.h>
23 #include <TObjString.h>
29 #include <FairMQMessage.h>
30 #include <options/FairMQProgOptions.h>
32 template<
typename DataType>
53 const std::string& treeName,
54 const std::string& branchName,
55 const std::string& className,
56 const std::string& fileOption)
78 fTree->Write(
"", TObject::kOverwrite);
94 const std::string& treeName,
95 const std::string& branchName,
96 const std::string& className =
"",
97 const std::string& fileOption =
"RECREATE",
98 bool useClonesArray =
false,
110 LOG(warn) <<
"Deactivate TClonesArray method: the data class must inherit from TObject.";
116 fFilename = config.GetValue<std::string>(
"output-file-name");
117 fTreeName = config.GetValue<std::string>(
"output-file-tree");
118 fBranchName = config.GetValue<std::string>(
"output-file-branch");
119 fClassName = config.GetValue<std::string>(
"hit-classname");
120 fFileOption = config.GetValue<std::string>(
"output-file-option");
122 fFlowMode = config.GetValue<
bool>(
"flow-mode");
124 if (!std::is_base_of<TObject, DataType>::value && fUseClonesArray) {
125 fUseClonesArray =
false;
126 LOG(warn) <<
"Deactivate TClonesArray method: the data class must inherit from TObject.";
135 for (
unsigned int i = 0; i < inputData.size(); ++i) {
136 new ((*fOutput)[i]) DataType(inputData.at(i));
140 LOG(debug) <<
"RootOutFileManager::AddToFile(vector<DataType>&): No Output array!";
145 for (
unsigned int i = 0; i < inputData.size(); ++i) {
151 fTree->Write(
"", TObject::kOverwrite);
161 for (
unsigned int i = 0; i < size; ++i) {
162 new ((*fOutput)[i]) DataType(objArr[i]);
166 LOG(debug) <<
"RootOutFileManager::AddToFile(vector<DataType>&): No Output array!";
171 fTree->Write(
"", TObject::kOverwrite);
174 std::vector<DataType> dataVector(objArr, objArr + size);
186 LOG(debug) <<
"RootOutFileManager::AddToFile(TClonesArray*): No Output array!";
190 fTree->Write(
"", TObject::kOverwrite);
193 LOG(debug) <<
"RootOutFileManager::AddToFile(TClonesArray*): TClonesArray not set as output container";
199 int inputSize = msg->GetSize();
202 numInput = inputSize /
sizeof(DataType);
204 fOutputData =
static_cast<DataType*
>(msg->GetData());
215 bool updateTree =
false;
222 LOG(info) <<
"Update tree";
225 LOG(info) <<
"Create new tree";
250 fFolder =
new TFolder(
"cbmroot",
"/cbmroot");
251 TList* branchNameList =
new TList();
252 branchNameList->AddLast(
new TObjString(
fBranchName.c_str()));
253 branchNameList->Write(
"BranchList", TObject::kSingleKey);
255 branchNameList->Delete();
256 delete branchNameList;
258 void InitTCA(
const std::string& classname);
260 std::vector<std::vector<DataType>>
GetAllObj(
const std::string& filename,
261 const std::string& treename,
262 const std::string& branchname)
266 TFile* file = TFile::Open(filename.c_str(),
"READ");
268 std::vector<std::vector<DataType>> allObj;
269 std::vector<DataType> tempObj;
274 LOG(error) <<
"Could not open file" <<
fTreeName.c_str();
282 for (Long64_t i = 0; i <
fTree->GetEntries(); i++) {
285 for (Int_t iobj = 0; iobj <
fOutput->GetEntriesFast(); ++iobj) {
286 DataType* data =
reinterpret_cast<DataType*
>(
fOutput->At(iobj));
290 tempObj.push_back(*data);
292 allObj.push_back(tempObj);
296 for (Long64_t i = 0; i <
fTree->GetEntries(); i++) {
299 tempObj.push_back(data);
301 allObj.push_back(tempObj);
304 LOG(error) <<
"Could not find tree " << treename.c_str();
313 template<
typename... Args>
325 bool updateTree =
false;
332 LOG(info) <<
"Update tree";
335 LOG(info) <<
"Create new tree";
void InitTCA(const std::string &classname)
void AddToFile(FairMQMessage *msg)
RootOutFileManager(const std::string &filename, const std::string &treeName, const std::string &branchName, const std::string &className, const std::string &fileOption)
void AddToFile(std::unique_ptr< TClonesArray > &input)
virtual ~RootOutFileManager()
RootOutFileManager operator=(const RootOutFileManager &)=delete
void SetFileProperties(const FairMQProgOptions &config)
void AddToFile(std::vector< DataType > &inputData)
void Serialize(Args &&...args)
void SetFileProperties(const std::string &filename, const std::string &treeName, const std::string &branchName, const std::string &className="", const std::string &fileOption="RECREATE", bool useClonesArray=false, bool flowMode=true)
void AddToFile(DataType *objArr, long size)
std::vector< std::vector< DataType > > GetAllObj(const std::string &filename, const std::string &treename, const std::string &branchname)
void AddToFile(TClonesArray *inputData)