2#ifndef RestCore_TRestRun
3#define RestCore_TRestRun
5#define REST_MAXIMUM_EVENTS 2E9
10#include "TRestAnalysisTree.h"
11#include "TRestEvent.h"
12#include "TRestMetadata.h"
13#include "TRestTools.h"
24 TString fRunClassName;
30 TString fRunDescription;
31 TString fExperimentName;
34 TString fInputFileName;
35 TString fOutputFileName;
42 std::vector<TRestMetadata*> fMetadata;
43 std::vector<TRestMetadata*> fInputMetadata;
46 std::vector<TString> fInputFileNames;
55 bool fSaveHistoricData;
61 int fEventIndexCounter = 0;
62 bool fHangUpEndFile =
false;
63 bool fFromRML =
false;
65 Long64_t fFeminosDaqTotalEvents = 0;
78 void OpenInputFile(
const TString& filename,
const std::string& mode =
"");
79 void AddInputFileExternal(
const std::string& file);
81 void ReadInputFileMetadata();
82 void ReadInputFileTrees();
91 if (fCurrentEvent + 1 >= GetEntries()) {
97 TString
FormFormat(
const TString& filenameFormat);
98 TFile*
MergeToOutputFile(std::vector<std::string> fileFullNames, std::string outputFileName =
"");
100 TFile* UpdateOutputFile();
102 void PassOutputFile() {
103 if (!fOutputFileOwner.
Close())
104 RESTError <<
"Failed to close the previously owned output file: " << fOutputFileOwner.Error()
106 fOutputFile = fInputFile;
107 fOutputFileName = fOutputFile->GetName();
114 void ImportMetadata(
const TString& rootFile,
const TString& name,
const TString& type, Bool_t store);
118 if (meta !=
nullptr) {
119 fMetadata.push_back(meta);
121 RESTWarning <<
"REST Warning! A null metadata wants to be added in TRestRun!" <<
RESTendl;
125 void SkipEventTree() {}
128 if (fInputFile !=
nullptr) fInputFile->cd();
134 inline Int_t GetRunNumber()
const {
return fRunNumber; }
135 inline TString GetRunType()
const {
return fRunType; }
136 inline TString GetRunUser()
const {
return fRunUser; }
137 inline TString GetRunTag()
const {
return fRunTag; }
138 inline TString GetRunDescription()
const {
return fRunDescription; }
139 Double_t GetRunLength()
const;
140 inline Double_t GetStartTimestamp()
const {
return fStartTime; }
141 inline Double_t GetEndTimestamp()
const {
return fEndTime; }
142 inline TString GetExperimentName()
const {
return fExperimentName; }
144 inline std::vector<TString> GetInputFileNames()
const {
return fInputFileNames; }
145 inline std::string GetInputFileName(
unsigned int i)
const {
146 return i < fInputFileNames.size() ? (std::string)fInputFileNames[i] :
"";
148 inline std::string GetInputFileNamePattern()
const {
return fInputFileName.Data(); }
149 inline TString GetOutputFileName()
const {
return fOutputFileName; }
150 inline TFile* GetInputFile()
const {
return fInputFile; }
151 inline TFile* GetOutputFile()
const {
return fOutputFile; }
152 inline int GetCurrentEntry()
const {
return fCurrentEvent; }
153 inline Long64_t GetBytesRead()
const {
return fBytesRead; }
154 Long64_t GetTotalBytes();
155 Long64_t GetEntries()
const;
162 return static_cast<T*
>(fInputEvent);
165 TRestEvent* GetEventWithID(Int_t eventID, Int_t subEventID = -1,
const TString& tag =
"");
166 std::vector<int> GetEventEntriesWithConditions(
const std::string&,
int startingIndex = 0,
168 std::vector<int> GetEventIdsWithConditions(
const std::string&,
int startingIndex = 0,
int maxNumber = -1);
171 std::string GetRunInformation(
const std::string& info);
172 inline Int_t GetObservableID(
const std::string& name) {
return fAnalysisTree->
GetObservableID(name); }
173 inline Bool_t ObservableExists(
const std::string& name) {
return fAnalysisTree->
ObservableExists(name); }
174 inline TString GetInputEventName()
const {
return fInputEvent->ClassName(); }
176 inline TTree* GetEventTree()
const {
return fEventTree; }
177 inline Int_t GetInputFileNumber()
const {
return fFileProcess ==
nullptr ? fInputFileNames.size() : 1; }
181 TRestMetadata* GetMetadata(
const TString& name, TFile* file =
nullptr);
182 TRestMetadata* GetMetadataClass(
const TString& type, TFile* file =
nullptr);
183 std::vector<std::string> GetMetadataNames();
184 std::vector<std::string> GetMetadataTitles();
185 inline int GetNumberOfMetadata()
const {
return fMetadata.size(); }
188 inline std::string GetMetadataMember(
const std::string& instr) {
return ReplaceMetadataMember(instr); }
194 inline void SetInputFileName(
const std::string& s) {
196 fInputFileNames = Vector_cast<std::string, TString>(
199 inline void SetOutputFileName(
const std::string& s) { fOutputFileName = s; }
201 inline void SetCurrentEntry(
int i) { fCurrentEvent = i; }
203 inline void SetRunNumber(Int_t number) { fRunNumber = number; }
205 inline void SetRunType(
const TString& type) {
207 fRunType = (TString)cleanType;
209 inline void SetRunTag(
const TString& tag) {
211 fRunTag = (TString)cleanTag;
213 inline void SetRunUser(
const TString& user) {
215 fRunUser = (TString)cleanUser;
217 inline void SetRunDescription(
const TString& description) { fRunDescription = description; }
218 inline void SetStartTimeStamp(Double_t timestamp) {
fStartTime = timestamp; }
219 inline void SetEndTimeStamp(Double_t timestamp) {
fEndTime = timestamp; }
220 inline void SetTotalBytes(Long64_t totalBytes) { fTotalBytes = totalBytes; }
221 inline void SetHistoricMetadataSaving(
bool save) { fSaveHistoricData = save; }
222 inline void SetNFilesSplit(
int n) { fNFilesSplit = n; }
223 inline void HangUpEndFile() { fHangUpEndFile =
true; }
224 inline void ReleaseEndFile() { fHangUpEndFile =
false; }
226 inline void SetFeminosDaqTotalEvents(Long64_t n) { fFeminosDaqTotalEvents = n; }
227 inline Long64_t GetFeminosDaqTotalEvents()
const {
return fFeminosDaqTotalEvents; }
234 inline void PrintAllMetadata() {
236 for (
unsigned int i = 0; i < fMetadata.size(); i++) {
237 fMetadata[i]->PrintMetadata();
240 inline void PrintTrees()
const {
241 if (fEventTree !=
nullptr) {
243 RESTcout <<
"=====EventTree=====" <<
RESTendl;
246 if (fAnalysisTree !=
nullptr) {
248 RESTcout <<
"=====AnalysisTree=====" <<
RESTendl;
249 fAnalysisTree->Print();
252 void PrintObservables() {
253 if (fAnalysisTree !=
nullptr) {
254 fAnalysisTree->PrintObservables();
258 inline void PrintEvent()
const { fInputEvent->
PrintEvent(); }
262 Int_t
Write(
const char* name =
nullptr, Int_t option = 0, Int_t bufsize = 0)
override;
266 explicit TRestRun(
const std::string& filename);
REST core data-saving helper based on TTree.
Int_t GetObservableID(const std::string &obsName)
Get the index of the specified observable.
Bool_t ObservableExists(const std::string &obsName)
Get if the specified observable exists.
A base class for any REST event process.
A base class for any REST event.
virtual void PrintEvent() const
Data provider and manager in REST.
void PrintWarnings()
Prints out all the warnings registered by metadata classes accessible to TRestRun,...
void AddEventBranch(TRestEvent *event)
Add an event branch in output EventTree.
void OpenInputFile(int i)
Open the i th file in the file list.
void CloseFile()
Close both input file and output file, setting trees to nullptr also.
TFile * FormOutputFile()
Create a new TFile as REST output file. Writing metadata objects into it.
void AddMetadata(TRestMetadata *meta)
add metadata object to the metadata list
void ResetEntry()
Reset file reading progress.
TString FormFormat(const TString &filenameFormat)
Form output file name according to file info list, proc info list and run data.
TRestEvent * GetInputEvent() const
Calling GetInputEvent() will return a basic TRestEvent*
Int_t fParentRunNumber
It can be used as parent number of subrun number.
T * GetInputEvent()
Calling GetInputEvent<TRestGeant4Event>() will return a TRestGeant4Event*
void SetInputEvent(TRestEvent *event)
Retarget input event in the tree.
std::string ReplaceMetadataMember(const std::string &instr, Int_t precision=0)
It will replace the data member from the corresponding metadata class type or name defined in the inp...
void GetEntry(Long64_t entry)
Calls GetEntry() for both AnalysisTree and EventTree.
void InitFromConfigFile() override
Initialize logic of TRestRun.
void Initialize() override
REST run class.
void PrintErrors()
Prints out all the warnings registered by metadata classes accessible to TRestRun,...
std::string ReplaceMetadataMembers(const std::string &instr, Int_t precision=8)
It will replace the data members contained inside the string given as input. The data members in the ...
void PrintMetadata() override
Prints the basic run information.
TFile * MergeToOutputFile(std::vector< std::string > fileFullNames, std::string outputFileName="")
Form REST output file by merging a list of files together.
std::vector< std::string > GetEventTypesList()
It returns a list of available event types inside the file.
void ImportMetadata(const TString &rootFile, const TString &name, const TString &type, Bool_t store)
Open the root file and import the metadata of the given name.
Bool_t EvaluateMetadataMember(const std::string &instr)
It will evaluate the expression given including the data member from the corresponding metadata class...
void SetExtProcess(TRestEventProcess *p)
Set external file process.
void PrintStartDate()
Prints the run start date and time in human format.
Double_t fStartTime
Event absolute starting time/date (unix timestamp)
void WriteWithDataBase()
Write this object into TFile and add a new entry in database.
Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0) override
overwriting the write() method with fStore considered
void ReadFileInfo(const std::string &filename)
Extract file info from a file, and save it in the file info list.
Double_t fEndTime
Event absolute ending time/date (unix timestamp)
Int_t GetNextEvent(TRestEvent *targetEvent, TRestAnalysisTree *targetTree)
Get next event by writing event data into target event and target tree.
TRestEvent * GetNextEventWithConditions(const std::string &)
Load the next event that satisfies the conditions specified by a string.
std::string RemoveWhiteSpaces(std::string in)
Returns the input string removing all white spaces.