R3BROOT
R3B analysis software
Loading...
Searching...
No Matches
R3BFileSource.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) 2019 GSI Helmholtzzentrum für Schwerionenforschung GmbH *
3 * Copyright (C) 2019-2025 Members of R3B Collaboration *
4 * *
5 * This software is distributed under the terms of the *
6 * GNU General Public Licence (GPL) version 3, *
7 * copied verbatim in the file "LICENSE". *
8 * *
9 * In applying this license GSI does not waive the privileges and immunities *
10 * granted to it by virtue of its status as an Intergovernmental Organization *
11 * or submit itself to any jurisdiction. *
12 ******************************************************************************/
13
14// -----------------------------------------------------------
15// ----- R3BFileSource -----
16// ----- Created 12/05/21 by J.L. Rodriguez-Sanchez -----
17// -----------------------------------------------------------
18
19#ifndef R3BFileSource_H
20#define R3BFileSource_H 1
21
22#include "FairSource.h"
23#include "TChain.h"
24#include "TF1.h"
25#include "TFile.h"
26#include "TFolder.h"
27#include "TMCtls.h"
28#include <fstream>
29#include <list>
30
31class FairEventHeader;
32class FairFileHeader;
33class FairMCEventHeader;
34class TString;
35class FairLogger;
36class FairRuntimeDb;
37class R3BEventHeader;
38
39class R3BFileSource : public FairSource
40{
41 public:
42 R3BFileSource(TFile* f, const char* Title = "InputRootFile", UInt_t identifier = 0);
43 R3BFileSource(const TString* RootFileName, const char* Title = "InputRootFile", UInt_t identifier = 0);
44 R3BFileSource(const TString RootFileName, const char* Title = "InputRootFile", UInt_t identifier = 0);
45
46 ~R3BFileSource() override;
47
51 static R3BFileSource* Instance();
52
53 Bool_t Init() override;
54 Int_t ReadEvent(UInt_t i = 0) override;
55 void Close() override;
56 void Reset() override;
57
58 Source_Type GetSourceType() override { return kFILE; }
59
60 void SetParUnpackers() override {}
61
62 Bool_t InitUnpackers() override { return kTRUE; }
63
64 Bool_t ReInitUnpackers() override { return kTRUE; }
65
67 Int_t CheckMaxEventNo(Int_t EvtEnd = 0) override;
69 void ReadBranchEvent(const char* BrName) override;
71 void ReadBranchEvent(const char* BrName, Int_t Entry) override;
72 void FillEventHeader(FairEventHeader* feh) override;
73
74 const TFile* GetRootFile() { return fRootFile; }
76 void AddFriend(TString FileName);
78 void AddFile(TString FileName);
79 void AddFriendsToChain();
80 void PrintFriendList();
81 Bool_t CompareBranchList(TFile* fileHandle, TString inputLevel);
82 void CheckFriendChains();
83 void CreateNewFriendChain(TString inputFile, TString inputLevel);
84 TTree* GetInTree() { return fInChain->GetTree(); }
85 TChain* GetInChain() { return fInChain; }
86 TFile* GetInFile() { return fRootFile; }
88 {
89 if (fRootFile)
90 {
91 fRootFile->Close();
92 }
93 }
94
95 void SetInTree(TTree* tempTree);
96 TObjArray* GetListOfFolders() { return fListFolder; }
98 UInt_t GetEntries() { return fNoOfEntries; }
99
100 void SetInputFile(TString name);
101
104 void SetBeamTime(Double_t beamTime, Double_t gapTime);
106 void SetEventTimeInterval(Double_t min, Double_t max);
108 void SetEventMeanTime(Double_t mean);
109 void SetEventTime();
110 Double_t GetDeltaEventTime();
111 void SetFileHeader(FairFileHeader* f) { fFileHeader = f; }
112 Double_t GetEventTime();
113
114 Bool_t ActivateObject(TObject** obj, const char* BrName) override;
115
120 void SetEvtHeaderNew(Bool_t Status) { fEvtHeaderIsNew = Status; }
121 Bool_t IsEvtHeaderNew() { return fEvtHeaderIsNew; }
122
125 void SetCheckFileLayout(Bool_t enable) { fCheckFileLayout = enable; }
126
127 void SetInputFileName(TString tstr) { fInputFileName = tstr; }
128
130#if ROOT_VERSION_CODE <= ROOT_VERSION(6, 22, 8)
131 Bool_t SpecifyRunId();
132#else
133 Bool_t SpecifyRunId() override;
134#endif
135
136 private:
137 // static pointer to this class
138 static TMCThreadLocal R3BFileSource* fSourceInstance;
140 TString fInputTitle;
142 TFile* fRootFile;
146 std::list<TString> fFriendFileList;
147 std::list<TString> fInputChainList;
148 std::map<TString, TChain*> fFriendTypeList;
149 std::map<TString, std::list<TString>*> fCheckInputBranches;
150 std::list<TString> fInputLevel;
151 std::map<TString, std::multimap<TString, TArrayI>> fRunIdInfoAll;
153 TChain* fInChain;
155 TTree* fInTree;
157 TObjArray* fListFolder;
159 FairRuntimeDb* fRtdb;
161 TFolder* fFolderOut;
163 TFolder* fFolderIn;
164 /***/
170
172 FairMCEventHeader* fMCHeader;
173
176
178 FairFileHeader* fFileHeader;
179
187
192
194 Double_t fEventTimeMin;
196 Double_t fEventTimeMax;
198 Double_t fEventTime;
200 Double_t fBeamTime;
202 Double_t fGapTime;
204 Double_t fEventMeanTime;
211
213 Int_t GetRunid(uint64_t ts);
214
216 std::ifstream fInputFile;
218
219 UInt_t fExpid;
220 std::vector<UInt_t> fRunid;
221 std::vector<uint64_t> fTimestamp;
222 uint64_t prevts, nextts;
223
226
227 ClassDefOverride(R3BFileSource, 0)
228};
229
230#endif /* R3BFileSource_H */
TFile * GetInFile()
std::map< TString, TChain * > fFriendTypeList
FairMCEventHeader * fMCHeader
MC Event header.
std::ifstream fInputFile
input file with runids
FairRuntimeDb * fRtdb
RuntimeDb.
void FillEventHeader(FairEventHeader *feh) override
std::list< TString > fInputLevel
Double_t GetEventTime()
Bool_t fEvtHeaderIsNew
This flag is true if the event header was created in this session otherwise it is false which means t...
static R3BFileSource * Instance()
static instance
Bool_t fEventTimeInMCHeader
This is true if the event time used, came from simulation.
std::list< TString > fFriendFileList
List of all files added with AddFriend.
FairFileHeader * fFileHeader
File Header.
R3BFileSource(const R3BFileSource &)
std::map< TString, std::list< TString > * > fCheckInputBranches
Int_t ReadEvent(UInt_t i=0) override
Double_t fGapTime
Time without particles in beam (gap) (ns)
R3BEventHeader * fEvtHeader
Event Header.
TFolder * fFolderOut
folder structure of output
void SetBeamTime(Double_t beamTime, Double_t gapTime)
Set the repetition time of the beam when it can interact (beamTime) and when no interaction happen (g...
Bool_t InitUnpackers() override
TFile * fRootFile
ROOT file.
void SetEventTimeInterval(Double_t min, Double_t max)
Set the min and max limit for event time in ns.
TString fInputTitle
Title of input source, could be input, background or signal.
TObjArray * fListFolder
list of folders from all input (and friends) files
Int_t CheckMaxEventNo(Int_t EvtEnd=0) override
Check the maximum event number we can run to.
UInt_t fCurrentEntryNo
for internal use, to return the same event time for the same entry
UInt_t fNoOfEntries
No of Entries in this source.
R3BFileSource(TFile *f, const char *Title="InputRootFile", UInt_t identifier=0)
Double_t GetDeltaEventTime()
void SetInTree(TTree *tempTree)
Set the input tree when running on PROOF worker.
void AddFriend(TString FileName)
Add a friend file (input) by name)
TF1 * fTimeProb
used to generate random numbers for event time;
Double_t fEventTimeMax
max time for one Event (ns)
void AddFile(TString FileName)
Add ROOT file to input, the file will be chained to already added files.
TTree * GetInTree()
std::list< TString > fInputChainList
Bool_t ActivateObject(TObject **obj, const char *BrName) override
void SetEvtHeaderNew(Bool_t Status)
Set the status of the EvtHeader.
Bool_t SpecifyRunId()
Read one event from source to find out which RunId to use.
void SetInputFile(TString name)
void SetParUnpackers() override
~R3BFileSource() override
Bool_t fCheckFileLayout
True if the file layout should be checked when adding files to a chain.
Int_t fCurrentEntryNr
Current Entry number.
UInt_t GetEntries()
Bool_t ReInitUnpackers() override
void Close() override
std::vector< uint64_t > fTimestamp
Bool_t Init() override
static TMCThreadLocal R3BFileSource * fSourceInstance
Double_t fEventTimeMin
min time for one event (ns)
Double_t fEventMeanTime
EventMean time used (P(t)=1/fEventMeanTime*Exp(-t/fEventMeanTime)
TFolder * GetBranchDescriptionFolder()
void SetCheckFileLayout(Bool_t enable)
Allow to disable the testing the file layout when adding files to a chain.
UInt_t fSourceIdentifier
Double_t fEventTime
Time of event since th start (ns)
Bool_t IsEvtHeaderNew()
std::map< TString, std::multimap< TString, TArrayI > > fRunIdInfoAll
void CreateNewFriendChain(TString inputFile, TString inputLevel)
TFolder * fFolderIn
folder structure of input
UInt_t fTimeforEntryNo
for internal use, to return the same event time for the same entry
Source_Type GetSourceType() override
TTree * fInTree
Input Tree.
TChain * GetInChain()
R3BFileSource operator=(const R3BFileSource &)
void Reset() override
void ReadBranchEvent(const char *BrName) override
Read the tree entry on one branch.
void SetFileHeader(FairFileHeader *f)
Int_t GetRunid(uint64_t ts)
GetRunid method to obtain the runid as function of timestamps.
void SetInputFileName(TString tstr)
Double_t fBeamTime
Time of particles in beam (ns)
TChain * fInChain
Input Chain.
Bool_t CompareBranchList(TFile *fileHandle, TString inputLevel)
TString fInputFileName
void SetEventMeanTime(Double_t mean)
Set the mean time for the event in ns.
Bool_t IsInitialized
Initialization flag, true if initialized.
TObjArray * GetListOfFolders()
std::vector< UInt_t > fRunid
const TFile * GetRootFile()