24 #include <TCollection.h>
26 #include <TGeoManager.h>
27 #include <TIterator.h>
29 #include <TObjArray.h>
44 , fListFolder(new TObjArray(16))
46 , fIsInitialized(kFALSE)
49 if (fRootFile->IsZombie()) {
50 LOG(fatal) <<
"Error opening the Input file";
52 LOG(debug) <<
"FairRootFileSink created------------";
60 , fListFolder(new TObjArray(16))
62 , fIsInitialized(kFALSE)
65 fRootFile = TFile::Open(RootFileName->Data(),
"recreate");
66 if (fRootFile->IsZombie()) {
67 LOG(fatal) <<
"Error opening the Output file";
69 LOG(debug) <<
"FairRootFileSink created------------";
77 , fListFolder(new TObjArray(16))
79 , fIsInitialized(kFALSE)
82 fRootFile = TFile::Open(RootFileName.Data(),
"recreate");
83 if (fRootFile->IsZombie()) {
84 LOG(fatal) <<
"Error opening the Input file";
86 LOG(debug) <<
"FairRootFileSink created------------";
93 if (fileName.Length() <= 5)
95 return TFile::Open(fileName.Data(),
"recreate");
100 if (fIsInitialized) {
101 LOG(info) <<
"FairRootFileSink already initialized";
104 fIsInitialized = kTRUE;
110 fOutFolder = gROOT->GetRootFolder()->AddFolder(
112 gROOT->GetListOfBrowsables()->Add(
fOutFolder);
114 LOG(info) <<
"FairRootFileSink initialized.";
116 LOG(info) <<
" - " << fRootFile->GetName();
121 void FairRootFileSink::TruncateBranchNames()
133 TCollection* lf =
fOutFolder->GetListOfFolders();
134 TIterator* iter = lf->MakeIterator();
135 TObjArray* Br = fOutTree->GetListOfBranches();
136 TIterator* BrIter = Br->MakeIterator();
141 while ((obj = iter->Next())) {
149 ffn = ffn + obj->GetName();
160 while ((BrObj = BrIter->Next())) {
161 TBranch* b =
static_cast<TBranch*
>(BrObj);
162 TruncateBranchNames(b, ffn);
173 while ((obj = iter->Next())) {
174 TString ffn =
".FairMCEventHeader";
177 while ((BrObj = BrIter->Next())) {
178 TBranch* b =
static_cast<TBranch*
>(BrObj);
179 TruncateBranchNames(b, ffn);
184 while ((obj = iter->Next())) {
185 TString ffn =
".FairEventHeader";
188 while ((BrObj = BrIter->Next())) {
189 TBranch* b =
static_cast<TBranch*
>(BrObj);
190 TruncateBranchNames(b, ffn);
198 void FairRootFileSink::TruncateBranchNames(TBranch* b, TString ffn)
207 TString nn = b->GetName();
208 LOG(debug) <<
"nn.Data before: " << nn.Data();
209 nn.ReplaceAll(ffn.Data(),
"");
210 LOG(debug) <<
"nn.Data after: " << nn.Data();
211 LOG(debug) <<
"##################";
212 b->SetName(nn.Data());
213 TObjArray* Br = b->GetListOfBranches();
214 TIterator* BrIter = Br->MakeIterator();
217 while ((BrObj = BrIter->Next())) {
218 TBranch* bb =
static_cast<TBranch*
>(BrObj);
219 TruncateBranchNames(bb, ffn);
239 f =
static_cast<TFolder*
>(
fOutFolder->FindObjectAny(folderName));
241 folder =
fOutFolder->AddFolder(folderName, folderName);
246 folder->Add((TNamed*)obj);
265 TruncateBranchNames();
275 std::unique_ptr<char, void (*)(void*)> res{abi::__cxa_demangle(name,
nullptr,
nullptr, &status), std::free};
276 return (status == 0) ? res.get() : name;
283 LOG(info) <<
"CREATING BRANCH " << iter.first;
284 auto& tinfo = iter.second->persistenttypeinfo;
289 auto cl = TClass::GetClass(tinfo);
291 LOG(fatal) <<
"No TClass found for " << tname <<
"\n";
295 if (!cl->HasDictionary()) {
296 LOG(fatal) <<
"No dictionary found for " << tname <<
"\n";
301 auto obj = iter.second->ptraddr;
303 LOG(info) <<
"Creating branch for " << iter.first.c_str() <<
" with address " << obj;
304 fOutTree->Branch(iter.first.c_str(), tname.c_str(), obj);
312 f->Write(name, option);
318 gGeoManager->Write();
326 LOG(info) <<
" No Output Tree";
342 fRootFile = fOutTree->GetCurrentFile();
344 LOG(debug) <<
"FairRootFileSink::Write to file: " << fRootFile->GetName();
348 LOG(info) <<
"No Output Tree";
359 TString workerFileName = fRootFile->GetName();
363 LOG(info) <<
"FairRootFileSink::CloneSink(). manager " << tempMan->
GetInstanceId();
FairRootFileSink(TFile *f, const char *Title="OutputRootFile")
static char * GetTreeName()
virtual void FillEventHeader(FairEventHeader *feh)
static FairMonitor * GetMonitor()
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
static FairRootManager * Instance()
ClassImp(FairEventBuilder)
virtual ~FairRootFileSink()
virtual void RegisterAny(const char *brname, const std::type_info &oi, const std::type_info &pi, void *obj)
virtual bool CreatePersistentBranchesAny()
virtual void WriteGeometry()
virtual void RegisterImpl(const char *, const char *, void *)
virtual FairSink * CloneSink()
std::string demangle(const char *name)
Int_t GetInstanceId() const
virtual void WriteFolder()
static char * GetFolderName()
void StoreHistograms(TFile *sinkFile)
void UpdateFileName(TString &fileName)
virtual Bool_t InitSink()
virtual void WriteObject(TObject *f, const char *, Int_t option=0)
virtual TFile * OpenRootFile(TString fileName="")
std::map< std::string, std::unique_ptr< TypeAddressPair const > > fPersistentBranchesMap