Project
Loading...
Searching...
No Matches
FairRootManager.cxx
Go to the documentation of this file.
1/********************************************************************************
2 * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3 * *
4 * This software is distributed under the terms of the *
5 * GNU Lesser General Public Licence (LGPL) version 3, *
6 * copied verbatim in the file "LICENSE" *
7 ********************************************************************************/
8// -------------------------------------------------------------------------
9// ----- FairRootManager source file -----
10// ----- Created 06/01/04 by M. Al-Turany/D. Bertini -----
11// -------------------------------------------------------------------------
12
13// Class FairRootManager
14// ------------------
15// Class that takes care of Root IO.
16#include "FairRootManager.h"
17
18#include "FairEventHeader.h" // for FairEventHeader
19#include "FairFileHeader.h" // for FairFileHeader
20#include "FairLink.h" // for FairLink
21#include "FairLinkManager.h" // for FairLinkManager
22#include "FairLogger.h" // for FairLogger, MESSAGE_ORIGIN
23#include "FairMonitor.h" // for FairMonitor
24#include "FairRootFileSink.h" // to enable GetOutFile()
25#include "FairRun.h" // for FairRun
26#include "FairTSBufferFunctional.h" // for FairTSBufferFunctional, etc
27#include "FairWriteoutBuffer.h" // for FairWriteoutBuffer
28
29#include <TBranch.h> // for TBranch
30#include <TClonesArray.h> // for TClonesArray
31#include <TCollection.h> // for TCollection, TIter
32#include <TFile.h> // for TFile
33#include <TFolder.h> // for TFolder
34#include <TGeoManager.h> // for TGeoManager, gGeoManager
35#include <TIterator.h> // for TIterator
36#include <TList.h> // for TList
37#include <TMCAutoLock.h>
38#include <TNamed.h> // for TNamed
39#include <TObjArray.h> // for TObjArray
40#include <TObjString.h> // for TObjString
41#include <TRefArray.h> // for TRefArray
42#include <TTree.h> // for TTree
43#include <algorithm> // for find
44#include <cassert>
45#include <cstdio>
46#include <cstring> // for strcmp
47#include <iostream> // for operator<<, basic_ostream, etc
48#include <list> // for _List_iterator, list, etc
49#include <map> // for map, _Rb_tree_iterator, etc
50#include <set> // for set, set<>::iterator
51#include <stdlib.h> // for exit
52#include <utility> // for pair
53#include <vector> // for vector
54
55using std::list;
56using std::map;
57using std::pair;
58using std::set;
59
60namespace {
61// Define mutexes per operation which modify shared data
62TMCMutex createMutex = TMCMUTEX_INITIALIZER;
63TMCMutex deleteMutex = TMCMUTEX_INITIALIZER;
64} // namespace
65
66Int_t FairRootManager::fgCounter = 0;
67std::string FairRootManager::fFolderName = "";
68std::string FairRootManager::fTreeName = "";
69
71{
72 // Returns singleton instance.
73 // ---
74 static thread_local FairRootManager instance;
75 return &instance;
76}
77
78FairRootManager::FairRootManager()
79 : TObject()
80 , fOldEntryNr(-1)
81 , fOutFolder(0)
82 , fRootFolder(0)
83 , fCurrentTime(0)
84 , fObj2(new TObject*[1000])
85 , fNObj(-1)
86 , fMap()
87 , fBranchSeqId(0)
88 , fBranchNameList(new TList())
89 , fMCTrackBranchId(-1)
90 , fTimeBasedBranchNameList(new TList())
91 , fActiveContainer()
92 , fTSBufferMap()
93 , fWriteoutBufferMap()
94 , fInputBranchMap()
95 , fTimeStamps(kFALSE)
96 , fBranchPerMap(kFALSE)
97 , fBrPerMap()
98 , fBrPerMapIter()
99 , fCurrentEntryNo(0)
100 , fTimeforEntryNo(0)
101 , fFillLastData(kFALSE)
102 , fEntryNr(0)
103 , fListFolder(0)
104 , fSource(0)
105 , fSignalChainList()
106 , fEventHeader(new FairEventHeader())
107 , fSink(nullptr)
108 , fUseFairLinks(kFALSE)
109 , fFinishRun(kFALSE)
110 , fListOfBranchesFromInput(0)
111 , fListOfBranchesFromInputIter(0)
112 , fListOfNonTimebasedBranches(new TRefArray())
113 , fListOfNonTimebasedBranchesIter(0)
114 , fId(0)
115{
116 LOG(debug) << "FairRootManager::FairRootManager: going to lock " << this;
117
118 TMCAutoLock lk(&createMutex);
119
120 // Set Id
121 fId = fgCounter;
122
123 // Increment counter
124 ++fgCounter;
125
126 lk.unlock();
127
128 LOG(debug) << "Released lock and done FairRootManager::FairRootManager in " << fId << " " << this;
129}
130
132{
133 //
134 LOG(debug) << "Enter Destructor of FairRootManager";
135
136 delete[] fObj2;
137 fBranchNameList->Delete();
138 delete fBranchNameList;
139 LOG(debug) << "Leave Destructor of FairRootManager";
140 delete fEventHeader;
141 delete fSourceChain;
142 if (fSink)
143 delete fSink;
144 if (fSource)
145 delete fSource;
146
147 // Global cleanup
148 TMCAutoLock lk(&deleteMutex);
149
150 LOG(debug) << "FairRootManager::~FairRootManager: going to lock " << fId << " " << this;
151
152 --fgCounter;
153
154 //
155 lk.unlock();
156
157 LOG(debug) << "Released lock and done FairRootManager::~FairRootManager in " << fId << " " << this;
158}
159
161{
162 // creating fSourceChain now, to give the user chance to change the tree and folder name
163 fSourceChain = new TChain(GetTreeName(), Form("/%s", GetFolderName()));
164
165 LOG(debug) << "Call the initialiazer for the FairSource in FairRootManager ";
166 if (fSource) {
167 Bool_t sourceInitBool = fSource->Init();
168 fListOfBranchesFromInput = fSourceChain->GetListOfBranches();
169 TObject* obj;
170 if (fListOfBranchesFromInput) {
171 fListOfBranchesFromInputIter = fListOfBranchesFromInput->MakeIterator();
172 while ((obj = fListOfBranchesFromInputIter->Next())) {
173 if ((fTimeBasedBranchNameList->FindObject(obj->GetName())) == 0)
174 fListOfNonTimebasedBranches->Add(obj);
175 }
176 }
177 LOG(debug) << "Source is intialized and the list of branches is created in FairRootManager ";
178 fListOfNonTimebasedBranchesIter = fListOfNonTimebasedBranches->MakeIterator();
179 return sourceInitBool;
180 }
181 return kFALSE;
182}
183
185{
186 if (fSink) {
187 fSink->InitSink();
188 }
189 return kTRUE;
190}
191
192template<typename T>
193void FairRootManager::RegisterImpl(const char* name, const char* folderName, T* obj, Bool_t toFile)
194{
196 FairMonitor::GetMonitor()->RecordRegister(name, folderName, toFile);
197
198 // Security check. If the the name is equal the folder name there are problems with reading
199 // back the data. Instead of the object inside the folder the RootManger will return a pointer
200 // to the folder. To avoid such problems we check here if both strings are equal and stop the
201 // execution with some error message if this is the case.
202 if (strcmp(name, folderName) == 0) {
203 LOG(fatal) << "The names for the object name " << name << " and the folder name " << folderName
204 << " are equal. This isn't allowed. So we stop the execution at this point. Pleae change either the "
205 "name or the folder name.";
206 }
207
208 if (toFile) {
209 obj->SetName(name);
210 if (fSink) {
211 fSink->RegisterImpl(name, folderName, obj);
212 } else {
213 LOG(fatal) << "The sink does not exist to store persistent branches.";
214 }
215 }
216 AddMemoryBranch(name, obj);
218
219 if (toFile == kFALSE) {
221 }
222}
223
224void FairRootManager::Register(const char* name, const char* folderName, TNamed* obj, Bool_t toFile)
225{
226 RegisterImpl(name, folderName, obj, toFile);
227}
228
230{
231 if (fBranchNameList->FindObject(name) == 0) {
232 fBranchNameList->AddLast(new TObjString(name));
233 // check if we are setting the MCTrack Branch
234 if (strcmp(name, "MCTrack") == 0) {
235 fMCTrackBranchId = fBranchSeqId;
236 }
237 fBranchSeqId++;
238 }
239 return fBranchSeqId;
240}
241
242void FairRootManager::Register(const char* name, const char* foldername, TCollection* obj, Bool_t toFile)
243{
244 RegisterImpl(name, foldername, obj, toFile);
245}
246
248{
249 AddMemoryBranch(name, obj);
251}
252
253TClonesArray* FairRootManager::Register(TString branchName, TString className, TString folderName, Bool_t toFile)
254{
255 FairMonitor::GetMonitor()->RecordRegister(branchName, folderName, toFile);
256
257 TClonesArray* outputArray;
258 if (fActiveContainer.find(branchName) == fActiveContainer.end()) {
259 fActiveContainer[branchName] = new TClonesArray(className);
260 outputArray = fActiveContainer[branchName];
261 Register(branchName, folderName, outputArray, toFile);
262 }
263
264 return fActiveContainer[branchName];
265}
266
267TClonesArray* FairRootManager::GetEmptyTClonesArray(TString branchName)
268{
269 if (fActiveContainer.find(branchName)
270 != fActiveContainer.end()) { // if a TClonesArray is registered in the active container
271 if (fActiveContainer[branchName] == 0) { // the address of the TClonesArray is still valid
272 std::cout << "-E- FairRootManager::GetEmptyTClonesArray: Container deleted outside FairRootManager!"
273 << std::endl;
274 } else {
275 fActiveContainer[branchName]->Delete();
276 }
277 return fActiveContainer[branchName]; // return the container
278 } else {
279 std::cout << "-E- Branch: " << branchName << " not registered!"
280 << std::endl; // error if the branch is not registered
281 }
282 return 0;
283}
284
285TClonesArray* FairRootManager::GetTClonesArray(TString branchName)
286{
287 if (fActiveContainer.find(branchName) != fActiveContainer.end()) {
288 return fActiveContainer[branchName]; // return the container
289 } else {
290 LOG(info) << "Branch: " << branchName.Data() << " not registered!";
291 }
292 // error if the branch is not registered
293 return 0;
294}
295
297{
299 if (id < fBranchSeqId) {
300 TObjString* ObjStr = static_cast<TObjString*>(fBranchNameList->At(id));
301 return ObjStr->GetString();
302 } else {
303 TString NotFound("Branch not found");
304 return NotFound;
305 }
306}
307
308Int_t FairRootManager::GetBranchId(TString const& BrName)
309{
311 TObjString* ObjStr;
312 Int_t Id = -1;
313 for (Int_t t = 0; t < fBranchNameList->GetEntries(); t++) {
314 ObjStr = static_cast<TObjString*>(fBranchNameList->TList::At(t));
315 if (BrName == ObjStr->GetString()) {
316 Id = t;
317 break;
318 }
319 }
320 return Id;
321}
322
323void FairRootManager::InitTSBuffer(TString branchName, BinaryFunctor* function)
324{
325 fTSBufferMap[branchName] = new FairTSBufferFunctional(branchName, GetInTree(), function);
326}
327
328TClonesArray* FairRootManager::GetData(TString branchName, BinaryFunctor* function, Double_t parameter)
329{
330 if (fTSBufferMap[branchName] == 0) {
331 fTSBufferMap[branchName] = new FairTSBufferFunctional(branchName, GetInTree(), function);
332 }
333 fTSBufferMap[branchName]->SetStopFunction(function);
334 return fTSBufferMap[branchName]->GetData(parameter);
335}
336
337TClonesArray* FairRootManager::GetData(TString branchName,
338 BinaryFunctor* startFunction,
339 Double_t startParameter,
340 BinaryFunctor* stopFunction,
341 Double_t stopParameter)
342{
343 if (fTSBufferMap[branchName] == 0) {
344 fTSBufferMap[branchName] = new FairTSBufferFunctional(branchName, GetInTree(), stopFunction, startFunction);
345 }
346 fTSBufferMap[branchName]->SetStopFunction(stopFunction);
347 fTSBufferMap[branchName]->SetStartFunction(startFunction);
348 return fTSBufferMap[branchName]->GetData(startParameter, stopParameter);
349}
350
352{
353 if (fTSBufferMap.count(branchName) > 0) {
354 fTSBufferMap[branchName]->Terminate();
355 }
356}
357
359{
360 for (auto& mi : fTSBufferMap) {
361 mi.second->Terminate();
362 }
363}
364
366{
367 for (auto& mi : fTSBufferMap) {
368 if (mi.second->AllDataProcessed() == kFALSE && mi.second->TimeOut() == kFALSE) {
369 return kFALSE;
370 }
371 }
372 return kTRUE;
373}
374
376{
377 if (fSink)
378 fSink->Fill();
379}
380
382{
383 // FairMonitor::GetMonitor()->StoreHistograms(); MOVED TO FairRootFileSink
384 if (fFillLastData) {
385 if (fSink)
386 fSink->Fill();
387 }
388}
389
390Int_t FairRootManager::Write(const char*, Int_t, Int_t)
391{
394 LOG(debug) << "FairRootManager::Write " << this;
395
396 if (fSink)
397 return (fSink->Write());
398
399 return 0;
400}
401
403{
405 if (fSink)
406 fSink->WriteGeometry();
407}
408
409void FairRootManager::CreateGeometryFile(const char* geofile)
410{
416 TFile* oldfile = gFile;
417 TFile* file = TFile::Open(geofile, "RECREATE");
418 file->cd();
419 gGeoManager->Write();
420 file->Close();
421 file->Delete();
422 gFile = oldfile;
423}
424
426{
427 if (fSink) {
428 fSink->WriteFolder();
429 fSink->WriteObject(fBranchNameList, "BranchList", TObject::kSingleKey);
430 fSink->WriteObject(fTimeBasedBranchNameList, "TimeBasedBranchList", TObject::kSingleKey);
431 }
432}
434{
435 if (!fSource) {
436 LOG(fatal) << "No Source available";
437 return false;
438 }
439 Bool_t Result = fSource->SpecifyRunId();
440 fSource->FillEventHeader(fEventHeader);
441 LOG(info) << "---FairRootManager::SpecifyRunId --- ";
442 return Result;
443}
445{
446 if (!fSource)
447 return 0;
448
449 fSource->Reset();
450
451 SetEntryNr(i);
452
453 if (!fSource) {
454 LOG(fatal) << "No Source available";
455 return -1;
456 }
457
458 fCurrentEntryNo = i;
459
460 Int_t readEventResult = fSource->ReadEvent(i);
461
462 fSource->FillEventHeader(fEventHeader);
463 fCurrentTime = fEventHeader->GetEventTime();
464
465 LOG(debug) << "--Event number --- " << fCurrentEntryNo << " with time ---- " << fCurrentTime;
466
467 return readEventResult;
468}
469
470void FairRootManager::ReadBranchEvent(const char* BrName, Int_t entry)
471{
472 if (!fSource)
473 return;
474 fSource->Reset();
476
477 fSource->ReadBranchEvent(BrName, entry);
478 fSource->FillEventHeader(fEventHeader);
479 fCurrentTime = fEventHeader->GetEventTime();
480}
481
483{
484 if (fSource) {
485 fSource->FillEventHeader(fEventHeader);
486 return fEventHeader->GetRunId();
487 }
488 return -1;
489}
490
491void FairRootManager::ReadBranchEvent(const char* BrName)
492{
493 if (fSource) {
494 fSource->ReadBranchEvent(BrName);
495 fSource->FillEventHeader(fEventHeader);
496 fCurrentTime = fEventHeader->GetEventTime();
497 }
498}
499
501{
502 if (fSource) {
503 TObject* Obj;
504 fListOfNonTimebasedBranchesIter->Reset();
505 while ((Obj = fListOfNonTimebasedBranchesIter->Next())) {
506 fSource->ReadBranchEvent(Obj->GetName(), Entry);
507 fSource->FillEventHeader(fEventHeader);
508 fCurrentTime = fEventHeader->GetEventTime();
509 }
510 } else {
511 return 0;
512 }
513 return 1;
514}
515
517{
518 Bool_t readentry = kFALSE;
520 return readentry;
521}
522
524{
525 fReqBrNames.emplace_back(BrName);
527 TObject* Obj = nullptr;
528 LOG(debug2) << " Try to find if the object " << BrName << " is already activated by another task or call";
530 if (fOutFolder) {
531 Obj = fOutFolder->FindObjectAny(BrName);
532 if (Obj) {
533 LOG(debug2) << "Object " << BrName << " was already activated by another task";
534 }
535 }
537 if (!Obj) {
538 LOG(debug2) << "Try to find if the object " << BrName << " is a memory branch";
539 Obj = GetMemoryBranch(BrName);
540 if (Obj) {
541 LOG(debug2) << "Object " << BrName << " is a memory branch";
542 }
543 }
545 if (fRootFolder && !Obj) {
547 LOG(debug2) << "Object " << BrName
548 << " is not a memory branch and not yet activated, try the Input Tree (Chain)";
549 Obj = fRootFolder->FindObjectAny(BrName);
550 Obj = ActivateBranch(BrName);
551 }
552 if (!Obj) {
553 Obj = ActivateBranch(BrName);
554 }
555 if (Obj != nullptr)
557 return Obj;
558}
559
561{
562 TObject* result = 0;
563
564 // std::cout << "GetCloneOfLinkData: Link " << link << std::endl;
565 Int_t fileId = link.GetFile();
566 Int_t entryNr = link.GetEntry();
567 Int_t type = link.GetType();
568 Int_t index = link.GetIndex();
569
570 Int_t oldEntryNr = GetEntryNr();
571
572 // std::cout << "OldEntryNr: " << GetEntryNr();
573
574 // std::cout << "GetLinkData: " << link << std::endl;
575
576 TTree* dataTree; // get the correct Tree
577 if (fileId < 0) {
578 dataTree = GetInTree();
579 } else if (fileId == 0) {
580 dataTree = GetInChain();
581 } else {
582 dataTree = GetSignalChainNo(fileId);
583 }
584
585 if (dataTree == 0) {
586 dataTree = GetInTree();
587 }
588
589 if (type < 0) {
590 return 0;
591 }
592
593 TBranch* dataBranch = 0;
594
595 // std::cout << "DataType: " << GetBranchName(type) << std::endl;
596
597 if (fileId < 0 && fInputBranchMap[type] != 0) {
598 dataBranch = fInputBranchMap[type];
599 } else if (fileId < 0) {
600 fInputBranchMap[type] = dataTree->GetBranch(GetBranchName(type));
601 dataBranch = fInputBranchMap[type];
602 } else {
603 dataBranch = dataTree->GetBranch(GetBranchName(type));
604 }
605
606 if (dataBranch == 0) {
607 return 0;
608 }
609
610 if (entryNr > -1) { // get the right entry (if entryNr < 0 then the current entry is taken
611 if (entryNr < dataBranch->GetEntries()) {
612 dataBranch->GetEntry(entryNr);
613 } else {
614 return 0;
615 }
616 } else { // the link entry nr is negative --> take the actual one
617
618 // std::cout << "EntryNr: " << GetEntryNr() << std::endl;
619 // dataBranch->GetEntry(GetEntryNr());
620 }
621
622 if (index < 0) { // if index is -1 then this is not a TClonesArray so only the Object is returned
623 result = GetObject(GetBranchName(type))->Clone();
624 } else {
625 TClonesArray* dataArray = static_cast<TClonesArray*>(GetObject(GetBranchName(type)));
626
627 // std::cout << "FairRootManager::GetCloneOfLinkData() dataArray size: " << dataArray->GetEntriesFast()
628 // << std::endl;
629 if (index < dataArray->GetEntriesFast()) {
630 // std::cout << "DataArray at index " << index << " has Link: " <<
631 // ((FairMultiLinkedData*)dataArray->At(index))->GetNLinks() << std::cout;
632 result = dataArray->At(index)->Clone();
633 // std::cout << "Result: " << *((FairMultiLinkedData*)result) << std::endl;
634 }
635 }
636 if (entryNr > -1) {
637 dataBranch->GetEntry(oldEntryNr); // reset the dataBranch to the original entry
638 }
639 return result;
640}
641
643{
644 TClonesArray* result = 0;
645
646 // std::cout << "GetCloneOfLinkData: Link " << link << std::endl;
647 Int_t fileId = link.GetFile();
648 Int_t entryNr = link.GetEntry();
649 Int_t type = link.GetType();
650 Int_t index = link.GetIndex();
651
652 Int_t oldEntryNr = GetEntryNr();
653
654 // std::cout << "OldEntryNr: " << GetEntryNr();
655
656 // std::cout << "GetLinkData: " << link << std::endl;
657
658 TTree* dataTree; // get the correct Tree
659 if (fileId < 0) {
660 dataTree = GetInTree();
661 } else if (fileId == 0) {
662 dataTree = GetInChain();
663 } else {
664 dataTree = GetSignalChainNo(fileId);
665 }
666
667 if (dataTree == 0) {
668 dataTree = GetInTree();
669 }
670
671 if (type < 0) {
672 return 0;
673 }
674
675 TBranch* dataBranch = 0;
676
677 // std::cout << "DataType: " << GetBranchName(type) << std::endl;
678
679 if (fileId < 0 && fInputBranchMap[type] != 0) {
680 dataBranch = fInputBranchMap[type];
681 } else if (fileId < 0) {
682 fInputBranchMap[type] = dataTree->GetBranch(GetBranchName(type));
683 dataBranch = fInputBranchMap[type];
684 } else {
685 dataBranch = dataTree->GetBranch(GetBranchName(type));
686 }
687
688 if (dataBranch == 0) {
689 return 0;
690 }
691
692 if (entryNr > -1) { // get the right entry (if entryNr < 0 then the current entry is taken
693 if (entryNr < dataBranch->GetEntries()) {
694 dataBranch->GetEntry(entryNr);
695 } else {
696 return 0;
697 }
698 } else { // the link entry nr is negative --> take the actual one
699
700 // std::cout << "EntryNr: " << GetEntryNr() << std::endl;
701 // dataBranch->GetEntry(GetEntryNr());
702 }
703
704 if (index < 0) { // if index is -1 then this is not a TClonesArray so only the Object is returned
705 result = 0;
706 } else {
707 result = static_cast<TClonesArray*>(GetObject(GetBranchName(type))->Clone());
708 }
709 if (entryNr > -1) {
710 dataBranch->GetEntry(oldEntryNr); // reset the dataBranch to the original entry
711 }
712 return result;
713}
714
715Int_t FairRootManager::CheckBranch(const char* BrName)
716{
718 if (!fBranchPerMap) {
719 CreatePerMap();
720 return CheckBranchSt(BrName);
721 } else {
722 fBrPerMapIter = fBrPerMap.find(BrName);
723 if (fBrPerMapIter != fBrPerMap.end()) {
724 return fBrPerMapIter->second;
725 } else {
726 return 0;
727 }
728 }
729}
730
732{
733 if (list == nullptr)
734 return;
735 // otherwise clear existing and add via the standard interface
736 fBranchNameList->Clear();
737 fMCTrackBranchId = -1;
738 for (Int_t t = 0; t < list->GetEntries(); t++) {
739 AddBranchToList(static_cast<TObjString*>(list->At(t))->GetString().Data());
740 }
741}
742
743void FairRootManager::SetInChain(TChain* tempChain, Int_t ident)
744{
745 if (ident <= 0)
746 fSourceChain = tempChain;
747 else
748 fSignalChainList[ident] = tempChain;
749}
750
751Double_t FairRootManager::GetEventTime() { return fCurrentTime; }
752
754{
755 for (Int_t iobj = 0; iobj <= fNObj; iobj++) {
756 if (fObj2[iobj]) {
757 LOG(info) << "FairRootManager::UpdateBranches \"" << fObj2[iobj]->GetName() << "\" (\""
758 << fObj2[iobj]->GetTitle() << "\")";
759 TString tempBranchName = fObj2[iobj]->GetName();
760 fSource->ActivateObject(&fObj2[fNObj], tempBranchName.Data());
761 }
762 }
763}
764
767TObject* FairRootManager::ActivateBranch(const char* BrName)
768{
775 fNObj++;
776 fObj2[fNObj] = GetMemoryBranch(BrName);
777 if (fObj2[fNObj]) {
778 return fObj2[fNObj];
779 }
781 LOG(debug) << "Try to find an object " << BrName << " describing the branch in the folder structure in file";
782 if (fListFolder) {
783 for (Int_t i = 0; i < fListFolder->GetEntriesFast(); i++) {
784 TFolder* fold = static_cast<TFolder*>(fListFolder->At(i));
785 fObj2[fNObj] = fold->FindObjectAny(BrName);
786 if (fObj2[fNObj]) {
787 LOG(info) << "Object " << BrName << " describing the branch in the folder structure was found";
788 break;
789 }
790 }
791 }
792
793 if (!fObj2[fNObj]) {
797 LOG(info) << " Branch: " << BrName << " not found in Tree.";
798 // Fatal(" No Branch in the tree", BrName );
799 return 0;
800 } else {
801 if (fSource)
802 fSource->ActivateObject(&fObj2[fNObj], BrName);
803 }
804
805 AddMemoryBranch(BrName, fObj2[fNObj]);
806 return fObj2[fNObj];
807}
808
809void FairRootManager::AddMemoryBranch(const char* fName, TObject* pObj)
810{
812 map<TString, TObject*>::iterator p;
813 TString BrName = fName;
814 p = fMap.find(BrName);
815 if (p != fMap.end()) {
816 } else {
817 fMap.insert(pair<TString, TObject*>(BrName, pObj));
818 }
819}
820
821Int_t FairRootManager::CheckBranchSt(const char* BrName)
822{
823 // cout <<"FairRootManager::CheckBranchSt : " << BrName << endl;
824 Int_t returnvalue = 0;
825 TObject* Obj1 = nullptr;
826
827 if (fListFolder == 0) {
828 fListFolder = new TObjArray(16);
829 }
830
831 // cout <<"FairRootManager::CheckBranchSt : " <<fRootFolder << endl;
832 if (fRootFolder) {
833 fListFolder->Add(fRootFolder);
834 Obj1 = fRootFolder->FindObjectAny(BrName);
835 }
836 if (fOutFolder && !Obj1) {
837 fListFolder->Add(fOutFolder);
838 Obj1 = fOutFolder->FindObjectAny(BrName); // Branch in output folder
839 }
840 if (!Obj1) {
841 for (Int_t i = 0; i < fListFolder->GetEntriesFast(); i++) {
842 // cout << "Search in Folder: " << i << " " << fListFolder->At(i) << endl;
843 TFolder* fold = dynamic_cast<TFolder*>(fListFolder->At(i));
844 if (fold != 0) {
845 Obj1 = fold->FindObjectAny(BrName);
846 }
847 if (Obj1) {
848 break;
849 }
850 }
851 }
852 TObject* Obj2 = nullptr;
853 Obj2 = GetMemoryBranch(BrName); // Branch in Memory
854 if (Obj1 != 0) {
855 returnvalue = 1;
856 } else if (Obj2 != 0) {
857 returnvalue = 2;
858 } else {
859 returnvalue = 0;
860 }
861
866 return returnvalue;
867}
868
869void FairRootManager::CreatePerMap()
870{
871 // cout << " FairRootManager::CreatePerMap() " << endl;
872 fBranchPerMap = kTRUE;
873 for (Int_t i = 0; i < fBranchSeqId; i++) {
874 TObjString* name = static_cast<TObjString*>(fBranchNameList->At(i));
875 // cout << " FairRootManager::CreatePerMap() Obj At " << i << " is " << name->GetString() << endl;
876 TString BrName = name->GetString();
877 fBrPerMap.insert(pair<TString, Int_t>(BrName, CheckBranchSt(BrName.Data())));
878 }
879}
880
881TObject* FairRootManager::GetMemoryBranch(const char* fName)
882{
883
884 // return fMap[BrName];
885 TString BrName = fName;
886 map<TString, TObject*>::iterator p;
887 p = fMap.find(BrName);
888
889 if (p != fMap.end()) {
890 return p->second;
891 } else {
892 return 0;
893 }
894}
895
897{
898 if (fSink)
899 fSink->WriteObject(f, "FileHeader", TObject::kSingleKey);
900}
901
903{
904 if (fSource)
905 return fSource->CheckMaxEventNo(EvtEnd);
906 return 0;
907}
908
910{
911 if (fWriteoutBufferMap[branchName] == 0) {
912 fWriteoutBufferMap[branchName] = buffer;
913 } else {
914 LOG(warn) << "Branch " << branchName.Data() << " is already registered in WriteoutBufferMap";
915 delete buffer;
916 }
917
918 return fWriteoutBufferMap[branchName];
919}
920
922{
927 for (auto& mi : fWriteoutBufferMap) {
928 if (mi.second->IsBufferingActivated())
929 fTimeBasedBranchNameList->AddLast(new TObjString(mi.first.Data()));
930 }
931}
932
934{
939 if (list != 0) {
940 fTimeBasedBranchNameList->Delete();
941 delete fTimeBasedBranchNameList;
942 fTimeBasedBranchNameList = list;
943 }
944}
945
946FairWriteoutBuffer* FairRootManager::GetWriteoutBuffer(TString branchName)
947{
948 if (fWriteoutBufferMap.count(branchName) > 0) {
949 return fWriteoutBufferMap[branchName];
950 } else {
951 return 0;
952 }
953}
954
956{
957 for (auto& mi : fWriteoutBufferMap) {
958 mi.second->WriteOutData(eventTime);
959 }
960}
961
963{
964 Bool_t dataInBuffer = kFALSE;
965 for (auto& mi : fWriteoutBufferMap) {
966 if (mi.second->GetNData() > 0) {
967 dataInBuffer = kTRUE;
968 }
969 mi.second->WriteOutAllData();
970 }
971 fFillLastData = dataInBuffer;
972}
973
975{
976 for (auto& mi : fWriteoutBufferMap) {
977 mi.second->DeleteOldData();
978 }
979}
980
981std::string FairRootManager::GetNameFromFile(const char* namekind)
982{
983 std::string default_name = "";
984
985 if (strcmp(namekind, "treename=") && strcmp(namekind, "foldername=")) {
986 LOG(fatal) << "FairRootManager, requested " << namekind << ", while only treename= and foldername= available.";
987 return default_name;
988 }
989
990 char* workdir = getenv("VMCWORKDIR");
991 if (nullptr == workdir) {
992 return default_name;
993 }
994
995 // Open file with output tree name
996 std::ifstream file(Form("%s/config/rootmanager.dat", workdir));
997 // If file does not exist -> default
998 if (!file.is_open()) {
999 return default_name;
1000 }
1001
1002 std::string line;
1003 while (std::getline(file, line)) {
1004 if (line.rfind(namekind, 0) == 0) {
1005 line.replace(0, strlen(namekind), "");
1006 file.close();
1007 return line;
1008 }
1009 }
1010
1011 file.close();
1012 return default_name;
1013}
1014
1016{
1017 if (fTreeName.length() > 0) {
1018 return Form("%s", fTreeName.c_str());
1019 }
1020
1021 std::string nameFromFile = GetNameFromFile("treename=");
1022 if (nameFromFile.length() > 0) {
1023 return Form("%s", nameFromFile.c_str());
1024 }
1025
1026 return "cbmsim";
1027}
1028
1030{
1031 if (fFolderName.length() > 0) {
1032 return Form("%s", fFolderName.c_str());
1033 }
1034
1035 std::string nameFromFile = GetNameFromFile("foldername=");
1036 if (nameFromFile.length() > 0) {
1037 return Form("%s", nameFromFile.c_str());
1038 }
1039
1040 if (!FairRun::Instance()->IsAna()) {
1041 return "cbmroot";
1042 }
1043 return "cbmout";
1044}
1045
1046void FairRootManager::EmitMemoryBranchWrongTypeWarning(const char* brname, const char* type1, const char* type2) const
1047{
1048 LOG(warn) << "Trying to read from memory branch " << brname << " with wrong type " << type1
1049 << " (expexted: " << type2 << " )";
1050}
1051
1052void FairRootManager::UpdateFileName(TString& fileName)
1053{
1054 TString tid = "_t";
1055 tid += GetInstanceId();
1056 fileName.Insert(fileName.Index(".root"), tid);
1057}
1058
1060{
1061 LOG(warning) << "FairRootManager::GetOutFile() deprecated. Use separate file to store additional data.";
1062 auto sink = GetSink();
1063 assert(sink->GetSinkType() == kFILESINK);
1064 auto rootFileSink = static_cast<FairRootFileSink*>(sink);
1065 return rootFileSink->GetRootFile();
1066}
1067
1069{
1070 LOG(warning) << "FairRootManager::GetOutTree() deprecated. Use separate file to store additional data.";
1071 auto sink = GetSink();
1072 assert(sink->GetSinkType() == kFILESINK);
1073 auto rootFileSink = static_cast<FairRootFileSink*>(sink);
1074 return rootFileSink->GetOutTree();
1075}
1076
std::ostringstream debug
ClassImp(FairRootManager)
@ kFILESINK
Definition FairSink.h:35
int32_t i
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this parameter(fixed during CTF decoding)") AddOptionRTC(defaultZOffsetOverR
std::string className
Definition Objects.cxx:33
Base class for all functors which are used in the FairTSBufferFunctional.
Double_t GetEventTime()
static FairLinkManager * Instance()
virtual void AddIgnoreType(Int_t type)
void RecordRegister(const char *name, const char *folderName, Bool_t toFile)
void RecordGetting(const char *name)
static FairMonitor * GetMonitor()
TClonesArray * GetTClonesArray(TString branchName)
static const char * GetFolderName()
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
FairWriteoutBuffer * RegisterWriteoutBuffer(TString branchName, FairWriteoutBuffer *buffer)
void UpdateListOfTimebasedBranches()
void SetEntryNr(Int_t val)
void UpdateFileName(TString &fileName)
Int_t ReadEvent(Int_t i=0)
FairSink * GetSink()
TChain * GetSignalChainNo(UInt_t i)
void CreateGeometryFile(const char *geofile)
TString GetBranchName(Int_t id)
void RegisterInputObject(const char *name, TObject *obj)
Int_t CheckMaxEventNo(Int_t EvtEnd=0)
void WriteFileHeader(FairFileHeader *f)
TObject * GetCloneOfLinkData(const FairLink link)
void TerminateTSBuffer(TString branchName)
void ReadBranchEvent(const char *BrName)
static const char * GetTreeName()
Int_t CheckBranch(const char *BrName)
void StoreWriteoutBufferData(Double_t eventTime)
static FairRootManager * Instance()
TClonesArray * GetData(TString branchName, BinaryFunctor *function, Double_t parameter)
Int_t AddBranchToList(const char *name)
Int_t ReadNonTimeBasedEventFromBranches(Int_t i=0)
TClonesArray * GetCloneOfTClonesArray(const FairLink link)
TObject * GetObject(const char *BrName)
void InitTSBuffer(TString branchName, BinaryFunctor *function)
void SetBranchNameList(TList *list)
void SetTimeBasedBranchNameList(TList *list)
Int_t GetInstanceId() const
Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
TChain * GetInChain()
Int_t GetBranchId(TString const &BrName)
Bool_t ReadNextEvent(Double_t dt)
TClonesArray * GetEmptyTClonesArray(TString branchName)
void StoreAllWriteoutBufferData()
void DeleteOldWriteoutBufferData()
void SetInChain(TChain *tempChain, Int_t ident=-1)
static FairRun * Instance()
Definition FairRun.cxx:31
virtual void Fill()=0
virtual void RegisterImpl(const char *, const char *, void *)=0
virtual void WriteFolder()=0
virtual void WriteObject(TObject *f, const char *, Int_t option=0)=0
virtual Bool_t InitSink()=0
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)=0
virtual void WriteGeometry()=0
virtual Int_t CheckMaxEventNo(Int_t=0)
Definition FairSource.h:50
virtual Bool_t SpecifyRunId()=0
virtual Int_t ReadEvent(UInt_t=0)=0
virtual void Reset()=0
virtual Bool_t Init()=0
virtual void ReadBranchEvent(const char *)
Definition FairSource.h:52
virtual void FillEventHeader(FairEventHeader *feh)
virtual Bool_t ActivateObject(TObject **, const char *)
Definition FairSource.h:43
A class to access time ordered data in a root branch.
A container class to store digi data during events.
GLuint64EXT * result
Definition glcorearb.h:5662
GLuint buffer
Definition glcorearb.h:655
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
int32_t const char int32_t line
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"