11 #include <TBranchElement.h>
12 #include <TBranchObject.h>
14 #include <TDirectory.h>
16 #include <TLeafObject.h>
17 #include <TObjArray.h>
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
25 #include <boost/algorithm/string.hpp>
26 #pragma GCC diagnostic pop
53 std::ostringstream temp;
97 file = TFile::Open(
filename.c_str(),
"RECREATE", title.c_str());
104 tree->SetMaxTreeSize(900000000000LL);
105 gROOT->cd(currdir.c_str());
116 gROOT->cd(currdir.c_str());
120 file = TFile::Open(
filename.c_str(),
"UPDATE", title.c_str());
126 tree =
new TTree(
TreeName.c_str(), title.c_str());
127 gROOT->cd(currdir.c_str());
141 topNode->
write(
this);
160 TBranch* thisBranch =
tree->GetBranch(path.c_str());
166 tree->Branch(path.c_str(), (*data)->ClassName(),
167 data, buffersize, splitlevel);
171 thisBranch->SetAddress(data);
218 std::cout <<
"PHNodeIOManager reading " <<
filename << std::endl;
222 std::cout <<
"PHNodeIOManager writing " <<
filename << std::endl;
229 std::cout <<
"\n\nList of selected objects to read:" << std::endl;
230 std::map<std::string, bool>::const_iterator classiter;
233 std::cout << classiter->first <<
" is set to " << classiter->second << std::endl;
249 #if ROOT_VERSION_CODE >= ROOT_VERSION(3, 01, 5)
250 TBranchElement* be =
dynamic_cast<TBranchElement*
>(branch);
255 return be->GetClassName();
259 TBranchObject* bo =
dynamic_cast<TBranchObject*
>(branch);
264 TLeafObject* leaf =
static_cast<TLeafObject*
>(branch->GetLeaf(branch->GetName()));
266 return leaf->GetTypeName();
268 std::cout <<
PHWHERE <<
"Fatal error, dynamic cast of TBranchObject failed" << std::endl;
280 "Tree not initialized.");
291 TFile* file_ptr = gFile;
296 if ((bytesRead =
tree->GetEvent(requestedEvent)))
307 gROOT->cd(currdir.c_str());
315 std::cout <<
PHWHERE <<
"Error: Input TTree corrupt, exiting now" << std::endl;
326 std::map<std::string, TBranch*>::const_iterator
p =
fBranches.find(objectName);
330 TBranch* branch = p->second;
333 return branch->GetEvent(requestedEvent);
339 "Unknown object name");
351 std::cout <<
PHWHERE <<
"filename was never set" << std::endl;
355 std::cout <<
PHWHERE <<
"TFile " <<
filename <<
" NULL pointer" << std::endl;
364 std::cout <<
PHWHERE <<
"PHNodeIOManager::reconstructNodeTree : Root Tree "
365 <<
TreeName <<
" not found in file " <<
file->GetName() << std::endl;
372 std::ostringstream nname;
375 tree->SetName(nname.str().c_str());
378 std::map<std::string, bool>::const_iterator
it;
380 if (
tree->GetNbranches() > 0)
384 tree->SetBranchStatus((it->first).c_str(),
385 static_cast<bool>(it->second));
390 TObjArray* branchArray =
tree->GetListOfBranches();
406 for (i = 0; i < (size_t)(branchArray->GetEntriesFast()); i++)
409 std::vector<std::string> splitvec;
410 boost::split(splitvec, branchname, boost::is_any_of(delimeters));
411 for (
size_t ia = 1; ia < splitvec.size() - 1; ia++)
413 if (!nodeIter.
cd(splitvec[ia]))
416 nodeIter.
cd(splitvec[ia]);
419 TBranch* thisBranch = (TBranch*) ((*branchArray)[
i]);
422 if (thisBranch->TestBit(kDoNotProcess))
432 TClass* thisClass = gROOT->GetClass(branchClassName.c_str());
436 std::cout <<
PHWHERE << std::endl;
437 std::cout <<
"Missing Class: " << branchClassName << std::endl;
438 std::cout <<
"Did you forget to load the shared library which contains "
439 << branchClassName <<
"?" << std::endl;
443 assert(thisClass !=
nullptr);
449 TObject* newTObject =
static_cast<TObject*
>(thisClass->New());
451 nodeIter.
addNode(newIODataNode);
455 TObject* oldobject = newIODataNode->
getData();
457 if (oldclass != branchClassName)
459 std::cout <<
"You only have to worry if you get this message when reading parallel files"
461 <<
"if you get this when opening the 2nd, 3rd,... file" << std::endl
462 <<
"It looks like your objects are not of the same version in these files" << std::endl;
463 std::cout <<
PHWHERE <<
"Found object " << oldobject->ClassName()
464 <<
" in node tree but the file "
465 <<
filename <<
" contains a " << branchClassName
466 <<
" object. The object will be replaced without harming you" << std::endl;
467 std::cout <<
"CAVEAT: If you use local copies of pointers to data nodes" << std::endl
468 <<
"instead of searching the node tree you are in trouble now" << std::endl;
469 delete newIODataNode;
470 TObject* newTObject =
static_cast<TObject*
>(thisClass->New());
472 nodeIter.
addNode(newIODataNode);
476 if (thisClass->InheritsFrom(
"PHObject"))
482 std::cout <<
PHWHERE << branchClassName.c_str()
483 <<
" inherits neither from PHTable nor from PHObject"
484 <<
" setting type to PHObject" << std::endl;
487 thisBranch->SetAddress(&(newIODataNode->
data));
488 for (j = 1; j < splitvec.size() - 1; j++)
503 std::map<std::string, bool>::const_iterator
it;
507 tree->SetBranchStatus((it->first).c_str(),
508 static_cast<bool>(it->second));
516 std::map<std::string, TBranch*>::const_iterator
p =
fBranches.find(objectName);
544 if (
file)
return file->GetBytesWritten();
555 std::map<std::string, TBranch*>*
566 TTree* treetmp =
static_cast<TTree*
>(
file->Get(
TreeName.c_str()));
569 TObjArray* branchArray = treetmp->GetListOfBranches();
570 for (
size_t i = 0;
i < (size_t)(branchArray->GetEntriesFast());
i++)
572 TBranch* thisBranch = (TBranch*) ((*branchArray)[
i]);
580 <<
" on file " <<
filename << std::endl;
596 std::vector<std::string> splitvec;
597 boost::split(splitvec, fBranche.first, boost::is_any_of(delimeters));
598 if (splitvec.back() == nodename)