Project
Loading...
Searching...
No Matches
FairRootManager.h
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#ifndef FAIR_ROOT_MANAGER_H
9#define FAIR_ROOT_MANAGER_H
10
11#include "FairLogger.h"
12#include "FairSink.h"
13#include "FairSource.h"
14
15#include <Rtypes.h> // for Bool_t, Int_t, UInt_t, etc
16#include <TChain.h> // for TChain
17#include <TMCtls.h> // for multi-threading
18#include <TObject.h> // for TObject
19#include <TString.h> // for TString, operator<
20#include <map> // for map, multimap, etc
21#include <memory>
22#include <string>
23#include <type_traits> // is_pointer, remove_pointer, is_const, remove...
24#include <typeinfo>
25#include <vector>
26
27class BinaryFunctor;
28class FairEventHeader;
29class FairFileHeader;
30class FairLink;
33class TBranch;
34class TClonesArray;
35class TObjArray;
36class TCollection;
37class TFile;
38class TFolder;
39class TIterator;
40class TList;
41class TNamed;
42class TRefArray;
43class TTree;
44
53{
54 public:
56 virtual ~FairRootManager();
57 Bool_t AllDataProcessed();
59 Int_t AddBranchToList(const char* name);
66 Int_t CheckBranch(const char* BrName);
67
68 void CloseSink()
69 {
70 if (fSink) {
71 fSink->Close();
72 }
73 }
75 void CreateGeometryFile(const char* geofile);
76 void Fill();
77 void LastFill();
78 TClonesArray* GetEmptyTClonesArray(TString branchName);
79 TClonesArray* GetTClonesArray(TString branchName);
81 void UpdateBranches();
82
84 TString GetBranchName(Int_t id);
86 Int_t GetBranchId(TString const& BrName);
87
89 Int_t GetMCTrackBranchId() const { return fMCTrackBranchId; }
90
92 TList* GetBranchNameList() { return fBranchNameList; }
94 const std::vector<std::string>& GetReqBranchNames() const { return fReqBrNames; }
95
102 TObject* GetObject(const char* BrName);
103
108 template<typename T>
109 T InitObjectAs(const char* BrName);
110
112 Double_t GetEventTime();
121 TClonesArray* GetCloneOfTClonesArray(const FairLink link);
122
123 void InitTSBuffer(TString branchName, BinaryFunctor* function);
124 TClonesArray* GetData(TString branchName, BinaryFunctor* function, Double_t parameter);
125 TClonesArray* GetData(TString branchName,
126 BinaryFunctor* startFunction,
127 Double_t startParameter,
128 BinaryFunctor* stopFunction,
129 Double_t stopParameter);
130 void RegisterTSBuffer(TString branchName, FairTSBufferFunctional* functionalBuffer)
131 {
132 fTSBufferMap[branchName] = functionalBuffer;
133 }
134 void TerminateTSBuffer(TString branchName);
136 FairTSBufferFunctional* GetTSBuffer(TString branchName) { return fTSBufferMap[branchName]; }
137
139 static FairRootManager* Instance();
140
142 Int_t ReadEvent(Int_t i = 0);
144 Int_t ReadNonTimeBasedEventFromBranches(Int_t i = 0);
146 void ReadBranchEvent(const char* BrName);
148 void ReadBranchEvent(const char* BrName, Int_t entry);
149
152 Int_t GetRunId();
153
154 Bool_t ReadNextEvent(Double_t dt);
160 void Register(const char* name, const char* Foldername, TNamed* obj, Bool_t toFile);
166 void Register(const char* name, const char* Foldername, TCollection* obj, Bool_t toFile);
167
169 template<typename T>
170 void RegisterAny(const char* name, T*& obj, Bool_t toFile);
175
176 void RegisterInputObject(const char* name, TObject* obj);
177
178 TClonesArray* Register(TString branchName, TString className, TString folderName, Bool_t toFile);
185 void RunWithTimeStamps() { fTimeStamps = kTRUE; }
186
188 void SetBranchNameList(TList* list);
190 void SetTimeBasedBranchNameList(TList* list);
191
193 {
194 if (fSource)
195 fSource->FillEventHeader(feh);
196 }
197
199 void SetLastFill(Bool_t val = kTRUE) { fFillLastData = val; }
204 Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0);
206 void WriteGeometry();
210 void WriteFolder();
211
213 Int_t CheckMaxEventNo(Int_t EvtEnd = 0);
214
215 void StoreWriteoutBufferData(Double_t eventTime);
218
219 Int_t GetEntryNr() { return fEntryNr; }
220 void SetEntryNr(Int_t val) { fEntryNr = val; }
221
222 void SetUseFairLinks(Bool_t val) { fUseFairLinks = val; };
223 Bool_t GetUseFairLinks() const { return fUseFairLinks; };
224
229 /* void SetMixAllInputs(Bool_t Status) { */
230 /* fMixAllInputs=kTRUE; */
231 /* } */
232
234 void SetSource(FairSource* tempSource) { fSource = tempSource; }
235 FairSource* GetSource() { return fSource; }
236 Bool_t InitSource();
237
238 void SetSink(FairSink* tempSink) { fSink = tempSink; }
239 FairSink* GetSink() { return fSink; }
240 Bool_t InitSink();
241
242 void SetListOfFolders(TObjArray* ta) { fListFolder = ta; }
243 TChain* GetInChain() { return fSourceChain; }
244 TChain* GetSignalChainNo(UInt_t i) { return fSignalChainList[i]; }
245 TTree* GetInTree()
246 {
247 if (fSourceChain)
248 return fSourceChain->GetTree();
249 return 0;
250 }
251 const TFile* GetRootFile()
252 {
253 if (fSourceChain)
254 return fSourceChain->GetFile();
255 return 0;
256 }
257 TFile* GetInFile()
258 {
259 if (fSourceChain)
260 return fSourceChain->GetFile();
261 return 0;
262 }
263 void SetInChain(TChain* tempChain, Int_t ident = -1);
264 /* /\**Set the input tree when running on PROOF worker*\/ */
265
266 void SetFinishRun(Bool_t val = kTRUE) { fFinishRun = val; }
267 Bool_t FinishRun() { return fFinishRun; }
268
269 static void SetTreeName(const std::string& tname) { fTreeName = tname; }
270 static void SetFolderName(const std::string& tname) { fFolderName = tname; }
271
272 const static char* GetTreeName();
273 const static char* GetFolderName();
274
276 Int_t GetInstanceId() const { return fId; }
277 void UpdateFileName(TString& fileName);
278
279 // vvvvvvvvvv depracted functions, replaced by FairSink vvvvvvvvvv
281 TFile* GetOutFile();
283 TTree* GetOutTree();
284 // ^^^^^^^^^^ depracted functions, replaced by FairSink ^^^^^^^^^^
285
287 Bool_t SpecifyRunId();
288
289 private:
290 // helper struct since std::pair has problems with type_info
291 struct TypeAddressPair
292 {
293 TypeAddressPair(const std::type_info& oi, const std::type_info& pi, void* a)
294 : origtypeinfo(oi)
295 , persistenttypeinfo(pi)
296 , ptraddr(a)
297 {}
298 const std::type_info& origtypeinfo; // type_info of type addr points to
299 const std::type_info& persistenttypeinfo; // type_info of ROOT persistent branch (drops pointers)
300 void* ptraddr; // address of a pointer (pointing to origtypeinfo);
301 };
302
307 FairRootManager& operator=(const FairRootManager&);
310 TObject* ActivateBranch(const char* BrName);
311 void AddFriends();
313 void AddMemoryBranch(const char*, TObject*);
314
315 template<typename T>
316 void AddMemoryBranchAny(const char* name, T** obj);
317 template<typename T>
318 T GetMemoryBranchAny(const char* name) const;
319
320 template<typename T>
321 void RegisterImpl(const char* name, const char* Foldername, T* obj, Bool_t toFile);
322
329 Int_t CheckBranchSt(const char* BrName);
331 void CreatePerMap();
332 TObject* GetMemoryBranch(const char*);
333 // void GetRunIdInfo(TString fileName, TString inputLevel);
334
335 FairWriteoutBuffer* GetWriteoutBuffer(TString branchName);
336
337 // private helper function to emit a warning
338 void EmitMemoryBranchWrongTypeWarning(const char* brname, const char* typen1, const char* typen2) const;
339
341 Int_t fOldEntryNr;
343 TFolder* fOutFolder;
345 TFolder* fRootFolder;
347 Double_t fCurrentTime;
348 TObject** fObj2;
350 Int_t fNObj;
355 std::map<TString, TObject*> fMap;
356
358 static std::string fFolderName;
360 static std::string fTreeName;
361 static std::string GetNameFromFile(const char* namekind);
362
366 std::map<std::string, std::unique_ptr<TypeAddressPair const>> fAnyBranchMap;
368 std::vector<std::string> fPersistentBranchesAny;
369
371 Int_t fBranchSeqId;
373 TList* fBranchNameList;
375 std::vector<std::string> fReqBrNames;
376
378 Int_t fMCTrackBranchId;
379
381 TList* fTimeBasedBranchNameList;
383 std::map<TString, TClonesArray*> fActiveContainer;
385 std::map<TString, FairTSBufferFunctional*> fTSBufferMap;
386 std::map<TString, FairWriteoutBuffer*> fWriteoutBufferMap;
387 std::map<Int_t, TBranch*> fInputBranchMap;
389 Bool_t fTimeStamps;
391 Bool_t fBranchPerMap;
393 std::map<TString, Int_t> fBrPerMap;
395 std::map<TString, Int_t>::iterator fBrPerMapIter;
396
398 UInt_t fCurrentEntryNo;
400 UInt_t fTimeforEntryNo;
401 Bool_t fFillLastData;
402 Int_t fEntryNr;
403
404 TObjArray* fListFolder;
405
406 FairSource* fSource;
407
408 TChain* fSourceChain = nullptr;
409 std::map<UInt_t, TChain*> fSignalChainList;
410
411 FairEventHeader* fEventHeader;
412
413 FairSink* fSink;
414
415 Bool_t fUseFairLinks;
416 Bool_t fFinishRun;
418 TObjArray* fListOfBranchesFromInput;
420 TIterator* fListOfBranchesFromInputIter;
422 TRefArray* fListOfNonTimebasedBranches;
424 TIterator* fListOfNonTimebasedBranchesIter;
425
427 // global static data members
428 static Int_t fgCounter; // The counter of instances
429 // data members
430 Int_t fId; // This manager ID
431
432 ClassDef(FairRootManager, 12);
433};
434
435// FIXME: move to source since we can make it non-template dependent
436template<typename T>
437void FairRootManager::AddMemoryBranchAny(const char* brname, T** obj)
438{
439 if (fAnyBranchMap.find(brname) == fAnyBranchMap.end()) {
440 auto& ot = typeid(T*);
441 auto& pt = typeid(T);
442 fAnyBranchMap[brname] = std::unique_ptr<TypeAddressPair const>(new TypeAddressPair(ot, pt, (void*)obj));
443 }
444}
445
446// try to retrieve an object address from the registered branches/names
447template<typename T>
448T FairRootManager::GetMemoryBranchAny(const char* brname) const
449{
450 static_assert(std::is_pointer<T>::value, "Return type of GetMemoryBranchAny has to be a pointer");
451 using P = typename std::remove_pointer<T>::type;
452 auto iter = fAnyBranchMap.find(brname);
453 if (iter != fAnyBranchMap.end()) {
454 // verify type consistency
455 if (typeid(P).hash_code() != iter->second->origtypeinfo.hash_code()) {
456 EmitMemoryBranchWrongTypeWarning(brname, typeid(P).name(), iter->second->origtypeinfo.name());
457 return nullptr;
458 }
459 return static_cast<T>(iter->second->ptraddr);
460 }
461 return nullptr;
462}
463
464template<typename T>
465void FairRootManager::RegisterAny(const char* brname, T*& obj, bool persistence)
466{
467 AddBranchToList(brname);
468 // we are taking the address of the passed pointer
469 AddMemoryBranchAny<T>(brname, &obj);
470 if (persistence) {
471 auto& ot = typeid(T*);
472 auto& pt = typeid(T);
473 if (fSink)
474 fSink->RegisterAny(brname, ot, pt, &obj);
475 else
476 LOG(fatal) << "The sink does not exist to store persistent branches.";
477 }
478}
479
480// this function serves as a factory (or lookup) for memory managed
481// instances associated to branches
482// it returns a pointer to unmodifiable instance of T
483template<typename TPtr>
484TPtr FairRootManager::InitObjectAs(const char* brname)
485{
486 static_assert(std::is_pointer<TPtr>::value, "Return type of GetObjectAs has to be a pointer");
487 using X = typename std::remove_pointer<TPtr>::type;
488 static_assert(std::is_const<X>::value, "Return type of GetObjectAs has to be pointer to const class");
489 using T = typename std::remove_const<X>::type;
490
491 // is there already an object associated to the branch in memory??
492 // then just return
493 T** obj = GetMemoryBranchAny<T**>(brname);
494 // obj is some address/instance holding TPtr instances
495 if (obj != nullptr)
496 return *obj;
497
498 if (!fSource) {
499 return nullptr;
500 }
501
502 // it does not seem to be the case, let us create the pointer which will be initialized
503 // with the data (pointer to T)
504 T** addr = new T*;
505 // init the pointee to a default obj which we can return
506 (*addr) = new T;
507 // try to find and activate in the source
508 auto succeeded = fSource->ActivateObjectAny((void**)addr, typeid(T), brname);
509
510 if (!succeeded) {
511 delete (*addr);
512 delete addr;
513 return nullptr;
514 }
515 // add into branch list
516 AddMemoryBranchAny<T>(brname, addr);
517 // register as a **requested** branch
518 // (duplications are explicitely allowed)
519 fReqBrNames.emplace_back(brname);
520
521 // NOTE: ideally we would do proper resource management for addr and *addr
522 // since the FairRootManager becomes owner of these pointers/instances; Unfortunately this
523 // is quite a difficult task since we would have to store something like std::unique_ptr<T> in a member
524 // container which we cannot know a priori; Some solutions we could think of in the future are
525 // a) use the Destructor mechanism of ROOT::TClass since we still have the type info.
526 // b) investigate if boost::any could be of help here
527 // In any case, this problem is not very critical in the sense that FairRootManager is a singleton and hence
528 // cannot really leak memory (Assuming that the destructors of T are not doing something non-trivial).
529 return *addr;
530}
531
532#endif // FAIR_ROOT_MANAGER_H
int32_t i
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 ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder Print launch bounds used for RTC code as debugging option
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.
TClonesArray * GetTClonesArray(TString branchName)
const std::vector< std::string > & GetReqBranchNames() const
static const char * GetFolderName()
void SetSource(FairSource *tempSource)
void Register(const char *name, const char *Foldername, TNamed *obj, Bool_t toFile)
FairWriteoutBuffer * RegisterWriteoutBuffer(TString branchName, FairWriteoutBuffer *buffer)
bool CreatePersistentBranchesAny()
void SetListOfFolders(TObjArray *ta)
void SetFinishRun(Bool_t val=kTRUE)
void UpdateListOfTimebasedBranches()
void SetLastFill(Bool_t val=kTRUE)
void SetEntryNr(Int_t val)
void UpdateFileName(TString &fileName)
static void SetTreeName(const std::string &tname)
Int_t ReadEvent(Int_t i=0)
FairSink * GetSink()
void SetUseFairLinks(Bool_t val)
TChain * GetSignalChainNo(UInt_t i)
void CreateGeometryFile(const char *geofile)
TString GetBranchName(Int_t id)
void RegisterInputObject(const char *name, TObject *obj)
T InitObjectAs(const char *BrName)
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)
void RegisterTSBuffer(TString branchName, FairTSBufferFunctional *functionalBuffer)
static const char * GetTreeName()
void RegisterAny(const char *name, T *&obj, Bool_t toFile)
Bool_t GetUseFairLinks() const
TList * GetBranchNameList()
Int_t CheckBranch(const char *BrName)
FairTSBufferFunctional * GetTSBuffer(TString branchName)
static void SetFolderName(const std::string &tname)
void StoreWriteoutBufferData(Double_t eventTime)
static FairRootManager * Instance()
TClonesArray * GetData(TString branchName, BinaryFunctor *function, Double_t parameter)
Int_t AddBranchToList(const char *name)
void FillEventHeader(FairEventHeader *feh)
Int_t ReadNonTimeBasedEventFromBranches(Int_t i=0)
const TFile * GetRootFile()
Int_t GetMCTrackBranchId() const
FairSource * GetSource()
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
TChain * GetInChain()
Int_t GetBranchId(TString const &BrName)
Bool_t ReadNextEvent(Double_t dt)
void SetSink(FairSink *tempSink)
TClonesArray * GetEmptyTClonesArray(TString branchName)
void StoreAllWriteoutBufferData()
void DeleteOldWriteoutBufferData()
void SetInChain(TChain *tempChain, Int_t ident=-1)
virtual void Close()=0
virtual void RegisterAny(const char *brname, const std::type_info &oi, const std::type_info &pi, void *obj)=0
virtual Bool_t ActivateObjectAny(void **, const std::type_info &, const char *)
Definition FairSource.h:44
virtual void FillEventHeader(FairEventHeader *feh)
A class to access time ordered data in a root branch.
A container class to store digi data during events.
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
GLuint GLfloat * val
Definition glcorearb.h:1582
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
ctfTree Write()