REST-for-Physics  v2.3
Rare Event Searches ToolKit for Physics
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions
TRestRun Class Reference

Detailed Description

Data provider and manager in REST.

REST data, including metadata and event data, are all handled by this class A series of metadata objects is saved here after being loaded from rml/root file with sequential startup. Input file is also opened here, either being raw data file(opened with external process) or root file(opened with built- in reader). TRestRun extracts event data in the input file and wraps it into TRestEvent class, which is queried by other classes.


RESTsoft - Software for Rare Event Searches with TPCs

History of developments:

2014-june: First concept. As part of conceptualization of previous REST code (REST v2) Igor G. Irastorza

2017-Aug: Major change: added for multi-thread capability Kaixiang Ni


Definition at line 18 of file TRestRun.h.

#include <TRestRun.h>

Inheritance diagram for TRestRun:
TRestMetadata

Public Member Functions

void AddEventBranch (TRestEvent *event)
 Add an event branch in output EventTree.
 
void AddInputFileExternal (const std::string &file)
 
void AddMetadata (TRestMetadata *meta)
 add metadata object to the metadata list
 
void cd ()
 
 ClassDefOverride (TRestRun, 6)
 
void CloseFile ()
 Close both input file and output file, setting trees to nullptr also.
 
Bool_t EvaluateMetadataMember (const std::string &instr)
 It will evaluate the expression given including the data member from the corresponding metadata class type or name defined in the input string. More...
 
TString FormFormat (const TString &filenameFormat)
 Form output file name according to file info list, proc info list and run data. More...
 
TFile * FormOutputFile ()
 Create a new TFile as REST output file. Writing metadata objects into it.
 
TRestAnalysisTreeGetAnalysisTree () const
 
Long64_t GetBytesRead () const
 
int GetCurrentEntry () const
 
Double_t GetElapsedTimeSeconds () const
 
Double_t GetEndTimestamp () const
 
Long64_t GetEntries () const
 
void GetEntry (Long64_t entry)
 Calls GetEntry() for both AnalysisTree and EventTree.
 
std::vector< int > GetEventEntriesWithConditions (const std::string &, int startingIndex=0, int maxNumber=-1)
 
std::vector< int > GetEventIdsWithConditions (const std::string &, int startingIndex=0, int maxNumber=-1)
 
TTree * GetEventTree () const
 
std::vector< std::string > GetEventTypesList ()
 It returns a list of available event types inside the file.
 
TRestEventGetEventWithID (Int_t eventID, Int_t subEventID=-1, const TString &tag="")
 
TString GetExperimentName () const
 
Long64_t GetFeminosDaqTotalEvents () const
 
TRestEventProcessGetFileProcess () const
 
template<class T >
T * GetInputEvent ()
 Calling GetInputEvent<TRestGeant4Event>() will return a TRestGeant4Event*
 
TRestEventGetInputEvent () const
 Calling GetInputEvent() will return a basic TRestEvent*
 
TString GetInputEventName () const
 
TFile * GetInputFile () const
 
std::string GetInputFileName (unsigned int i) const
 
std::string GetInputFileNamePattern () const
 
std::vector< TString > GetInputFileNames () const
 
Int_t GetInputFileNumber () const
 
TRestMetadataGetMetadata (const TString &name, TFile *file=nullptr)
 
TRestMetadataGetMetadataClass (const TString &type, TFile *file=nullptr)
 
std::string GetMetadataMember (const std::string &instr)
 
std::vector< std::string > GetMetadataNames ()
 
std::vector< std::string > GetMetadataTitles ()
 
void GetNextEntry ()
 
Int_t GetNextEvent (TRestEvent *targetEvent, TRestAnalysisTree *targetTree)
 Get next event by writing event data into target event and target tree. More...
 
TRestEventGetNextEventWithConditions (const std::string &)
 Load the next event that satisfies the conditions specified by a string. More...
 
int GetNumberOfMetadata () const
 
Int_t GetObservableID (const std::string &name)
 
TFile * GetOutputFile () const
 
TString GetOutputFileName () const
 
Int_t GetParentRunNumber () const
 
TString GetRunDescription () const
 
std::string GetRunInformation (const std::string &info)
 
Double_t GetRunLength () const
 
Int_t GetRunNumber () const
 
TString GetRunTag () const
 
TString GetRunType () const
 
TString GetRunUser () const
 
Double_t GetStartTimestamp () const
 
Int_t GetSubRunNumber () const
 
Long64_t GetTotalBytes ()
 
void HangUpEndFile ()
 
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. More...
 
void Initialize () override
 REST run class. More...
 
TFile * MergeToOutputFile (std::vector< std::string > fileFullNames, std::string outputFileName="")
 Form REST output file by merging a list of files together. More...
 
Bool_t ObservableExists (const std::string &name)
 
void OpenInputFile (const TString &filename, const std::string &mode="")
 Open the input file, read file info and the trees if it is root file. More...
 
void OpenInputFile (int i)
 Open the i th file in the file list.
 
void PassOutputFile ()
 
void PrintAllMetadata ()
 
void PrintEndDate ()
 
void PrintErrors ()
 Prints out all the warnings registered by metadata classes accessible to TRestRun, thats metadata and processes previously used in a data chain.
 
void PrintEvent () const
 
void PrintMetadata () override
 Prints the basic run information.
 
void PrintObservables ()
 
void PrintStartDate ()
 Prints the run start date and time in human format.
 
void PrintTrees () const
 
void PrintWarnings ()
 Prints out all the warnings registered by metadata classes accessible to TRestRun, thats metadata and processes previously used in a data chain.
 
void ReadFileInfo (const std::string &filename)
 Extract file info from a file, and save it in the file info list. More...
 
void ReadInputFileMetadata ()
 
void ReadInputFileTrees ()
 
void ReleaseEndFile ()
 
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 input string should be written using the following format [MetadataClass::fDataMember]. More...
 
void ResetEntry ()
 Reset file reading progress. More...
 
void SetCurrentEntry (int i)
 
void SetEndTimeStamp (Double_t timestamp)
 
void SetExtProcess (TRestEventProcess *p)
 Set external file process.
 
void SetFeminosDaqTotalEvents (Long64_t n)
 
void SetHistoricMetadataSaving (bool save)
 
void SetInputEvent (TRestEvent *event)
 Retarget input event in the tree. More...
 
void SetInputFileName (const std::string &s)
 
void SetNFilesSplit (int n)
 
void SetOutputFileName (const std::string &s)
 
void SetParentRunNumber (Int_t number)
 
void SetRunDescription (const TString &description)
 
void SetRunNumber (Int_t number)
 
void SetRunTag (const TString &tag)
 
void SetRunType (const TString &type)
 
void SetRunUser (const TString &user)
 
void SetStartTimeStamp (Double_t timestamp)
 
void SetTotalBytes (Long64_t totalBytes)
 
void SkipEventTree ()
 
 TRestRun (const std::string &filename)
 
TFile * UpdateOutputFile ()
 
Int_t Write (const char *name=nullptr, Int_t option=0, Int_t bufsize=0) override
 overwriting the write() method with fStore considered
 
void WriteWithDataBase ()
 Write this object into TFile and add a new entry in database. More...
 

Protected Member Functions

void InitFromConfigFile () override
 Initialize logic of TRestRun. More...
 

Protected Attributes

TRestAnalysisTreefAnalysisTree
 
Long64_t fBytesRead
 
int fCurrentEvent
 
Double_t fEndTime
 Event absolute ending time/date (unix timestamp)
 
Int_t fEntriesSaved
 
int fEventBranchLoc
 
int fEventIndexCounter = 0
 
TTree * fEventTree
 
TString fExperimentName
 
Long64_t fFeminosDaqTotalEvents = 0
 
TRestEventProcessfFileProcess
 
bool fFromRML = false
 
bool fHangUpEndFile = false
 
TRestEventfInputEvent
 
TFile * fInputFile
 
TString fInputFileName
 
std::vector< TString > fInputFileNames
 
std::vector< TRestMetadata * > fInputMetadata
 
std::vector< TRestMetadata * > fMetadata
 
Int_t fNFilesSplit
 
TFile * fOutputFile
 
TString fOutputFileName
 
bool fOverwrite
 
Int_t fParentRunNumber
 It can be used as parent number of subrun number.
 
TString fRunClassName
 
TString fRunDescription
 
Int_t fRunNumber
 
TString fRunTag
 
TString fRunType
 
TString fRunUser
 
bool fSaveHistoricData
 
Double_t fStartTime
 Event absolute starting time/date (unix timestamp)
 
Long64_t fTotalBytes
 

Private Member Functions

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 input string. More...
 

Member Function Documentation

◆ EvaluateMetadataMember()

Bool_t TRestRun::EvaluateMetadataMember ( const std::string &  instr)

It will evaluate the expression given including the data member from the corresponding metadata class type or name defined in the input string.

The input expression should contain the metadata class type or name using the format metadata->member or metadata::fMember, where metadata might be the class name or the intrinsic name assigned to the metadata object.

Examples:

run->EvaluateMetadataMember("TRestDetectorSetup->fDetectorPressure == 4");
run->EvaluateMetadataMember("sc->fMinValues[1] == 3" );

Both, :: and -> are allowed to separate class and the data member.

Returns
The result of the evaluated expression. If the input string is empty it will return true.

Definition at line 1768 of file TRestRun.cxx.

◆ FormFormat()

TString TRestRun::FormFormat ( const TString &  FilenameFormat)

Form output file name according to file info list, proc info list and run data.

It will replace the fields in output file name surrounded by "[]". The file info list is created by TRestRun::ReadFileInfo(), the proc info list is created by TRestProcessRunner::ReadProcInfo(), the run data is from TRestRun's datamember(fRunNumber,fRunType, etc) e.g. we can set output file name like:

Run[fRunNumber]_Proc_[LastProcess].root

and generates:

Run00000_T2018-01-01_08:00:00_Proc_sAna.root

Definition at line 940 of file TRestRun.cxx.

◆ GetNextEvent()

Int_t TRestRun::GetNextEvent ( TRestEvent targetEvent,
TRestAnalysisTree targetTree 
)

Get next event by writing event data into target event and target tree.

returns 0 if success, returns -1 if failed, e.g. end of file writing event data into target event calls the method TRestEvent::CloneTo() writing observable data into target analysistree calls memcpy It requires same branch structure, but we didn't verify it here.

Definition at line 796 of file TRestRun.cxx.

◆ GetNextEventWithConditions()

TRestEvent * TRestRun::GetNextEventWithConditions ( const std::string &  cuts)

Load the next event that satisfies the conditions specified by a string.

Parameters
conditionsstring specifying conditions, supporting multiple conditions separated by ":", allowed symbols include "<", "<=", ">", ">=", "=", "==". For example "A>=2.2:B==4".
Returns
TRestEvent

Definition at line 1525 of file TRestRun.cxx.

◆ ImportMetadata()

void TRestRun::ImportMetadata ( const TString &  File,
const TString &  name,
const TString &  type,
Bool_t  store 
)

Open the root file and import the metadata of the given name.

The metadata class can be recovered to the same condition as when it is saved.

Definition at line 1298 of file TRestRun.cxx.

◆ InitFromConfigFile()

void TRestRun::InitFromConfigFile ( )
overrideprotectedvirtual

Initialize logic of TRestRun.

Things doing in this method:

  1. Read basic parameter. This is done by calling ReadAllParameters()
  2. Initialize runnumber and input file name. They follow non-trivial logic.
  3. Construct default output file name with runNumber, runTag, etc.
  4. Loop over sections to initialize metadata
  5. Open input file(s), read the stored metadata and trees, read file name pattern to TRestDetector metadata.

Reimplemented from TRestMetadata.

Definition at line 122 of file TRestRun.cxx.

◆ Initialize()

void TRestRun::Initialize ( )
overridevirtual

REST run class.

Set variables by default during initialization.

Reimplemented from TRestMetadata.

Definition at line 71 of file TRestRun.cxx.

◆ MergeToOutputFile()

TFile * TRestRun::MergeToOutputFile ( std::vector< std::string >  fileFullNames,
std::string  outputFileName = "" 
)

Form REST output file by merging a list of files together.

If output file name is not given(=""), then it will recreate the output file according to fOutputFileName. Otherwise it will update the given file. File Merging is by calling TFileMerger. After this, it will format the merged file name. This method is used to create output file after TRestProcessRunner is finished. The metadata objects will also be written into the file.

Definition at line 985 of file TRestRun.cxx.

◆ OpenInputFile()

void TRestRun::OpenInputFile ( const TString &  filename,
const std::string &  mode = "" 
)

Open the input file, read file info and the trees if it is root file.

TRestRun will:

  1. read the file info (size, date, etc.) if it's root file from REST output, then
  2. update its class's data(version, tag, user, etc.) to the same as the one stored in the input file.
  3. link the input event and observables to the corresponding tree

Definition at line 331 of file TRestRun.cxx.

◆ ReadFileInfo()

void TRestRun::ReadFileInfo ( const std::string &  filename)

Extract file info from a file, and save it in the file info list.

Items:

  1. matched file name formats
  2. Created time and date
  3. File size and entries

Definition at line 652 of file TRestRun.cxx.

◆ ReplaceMetadataMember()

string TRestRun::ReplaceMetadataMember ( const std::string &  instr,
Int_t  precision = 0 
)
private

It will replace the data member from the corresponding metadata class type or name defined in the input string.

The input string should contain the metadata class type or name following the format string instr = "mdName::fDataMember"; or string instr = "TRestMetadataClass::fDataMember";. or the format string instr = "mdName->fDataMember";. Both, :: and -> are allowed to separate class and member of the class.

The method will work with both, metadata class or metadata name. First it will be evaluated if the metadata name is found, using the method TRestRun::GetMetadata. If not, it will try to check if the corresponding input string is giving a metadata class type, using the method TRestRun::GetMetadataClass.

Returns
The corresponding class data member value in string format.

Definition at line 1703 of file TRestRun.cxx.

◆ ReplaceMetadataMembers()

string TRestRun::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 input string should be written using the following format [MetadataClass::fDataMember].

Returns
The string with data members replaced

Definition at line 1652 of file TRestRun.cxx.

◆ ResetEntry()

void TRestRun::ResetEntry ( )

Reset file reading progress.

if input file is root file, just set current entry to be 0 if input file is external file, handled by external process, It will force the process to reload the file.

Definition at line 781 of file TRestRun.cxx.

◆ SetInputEvent()

void TRestRun::SetInputEvent ( TRestEvent event)

Retarget input event in the tree.

The input event is by default the last branch in EventTree, by calling this method, it can be retargeted to other branches corresponding to the given event.

Definition at line 1245 of file TRestRun.cxx.

◆ WriteWithDataBase()

void TRestRun::WriteWithDataBase ( )

Write this object into TFile and add a new entry in database.

level=0 : add a new run in database. run number is the next number, subrun number is 0. level=1 (default) : add a new subrun in database. run number is determined in BeginOfInit(). subrun number is the next number. if run does not exist, it will create new if "force" is true. level>=2 : add a new file in database. run number is determined in BeginOfInit(). subrun number is 0. if not exist, it will create new if "force" is true.

Definition at line 1092 of file TRestRun.cxx.


The documentation for this class was generated from the following files: