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

Detailed Description

Running the processes efficiently with fantastic display.

This class implements REST's main functionality - process running. multi- thread is enabled here which improves efficiency. Pause menu and progress bar is also provided which makes the work easier!


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 28 of file TRestProcessRunner.h.

#include <TRestProcessRunner.h>

Inheritance diagram for TRestProcessRunner:
TRestMetadata

Public Member Functions

void BeginOfInit ()
 Reads information from rml config file. More...
 
 ClassDefOverride (TRestProcessRunner, 7)
 
void ConfigOutputFile ()
 Forming an output file. More...
 
void EndOfInit ()
 Ending of the startup procedure. More...
 
void FillThreadEventFunc (TRestThread *t)
 Calling back the FillEvent() method in TRestThread. More...
 
Long64_t GetFileSplitSize () const
 
TRestAnalysisTreeGetInputAnalysisTree ()
 
TRestEventGetInputEvent ()
 
Int_t GetNextevtFunc (TRestEvent *targetevt, TRestAnalysisTree *targettree)
 Get next event and copy it to the address of targetevt. More...
 
int GetNProcessedEvents () const
 
int GetNProcesses () const
 
int GetNThreads () const
 
TRestAnalysisTreeGetOutputAnalysisTree ()
 
TFile * GetOutputDataFile ()
 
std::string GetProcInfo (std::string infoname)
 
double GetReadingSpeed ()
 
ProcStatus GetStatus () const
 
void InitFromConfigFile () override
 To make settings from rml file. This method must be implemented in the derived class.
 
void Initialize () override
 REST run class. More...
 
TRestEventProcessInstantiateProcess (TString type, TiXmlElement *ele)
 InstantiateProcess in sequential start up. More...
 
std::string MakeProgressBar (int progress100, int length=100)
 Make a string of progress bar with given length and percentage.
 
void MergeOutputFile ()
 Calls TRestRun::MergeOutputFile() to merge the main file with process's tmp file. More...
 
void PauseMenu ()
 A pause menu providing some functions during the process. More...
 
void PrintMetadata () override
 Implemented it in the derived metadata class to print out specific metadata information. More...
 
void PrintProcessedEvents (Int_t rateE)
 Print number of events processed, file read speed, ETA and a progress bar.
 
Int_t ReadConfig (const std::string &keydeclare, TiXmlElement *e)
 method to deal with iterated child elements More...
 
void ReadProcInfo ()
 Create a process info list which used called by TRestRun::FormFormat(). More...
 
void ResetRunTimes ()
 Reset running time count to 0.
 
void RunProcess ()
 The main executer of event process. More...
 
bool UseTestRun () const
 
void WriteProcessesMetadata ()
 Write process metadata to fOutputDataFile.
 

Private Attributes

TRestAnalysisTreefAnalysisTree
 
Int_t fEventsToProcess
 
TTree * fEventTree
 
Int_t fFileCompression
 
Long64_t fFileSplitSize
 
Int_t fFirstEntry
 
Bool_t fInputAnalysisStorage
 
TRestEventfInputEvent
 
Bool_t fInputEventStorage
 
Int_t fNBranches
 
Int_t fNFilesSplit
 
Bool_t fOutputAnalysisStorage
 
TFile * fOutputDataFile
 
TString fOutputDataFileName
 the TFile pointer being used
 
TRestEventfOutputEvent
 
Bool_t fOutputEventStorage
 
Int_t fProcessedEvents
 
std::map< std::string, std::string > fProcessInfo
 
Int_t fProcessNumber
 
ProcStatus fProcStatus
 
TRestRunfRunInfo
 
Bool_t fSortOutputEvents
 
Int_t fThreadNumber
 
std::vector< TRestThread * > fThreads
 
Bool_t fUsePauseMenu
 
Bool_t fUseTestRun
 Number of files being split.
 
Bool_t fValidateObservables
 

Additional Inherited Members

Member Function Documentation

◆ BeginOfInit()

void TRestProcessRunner::BeginOfInit ( )

Reads information from rml config file.

It first checks if a friendly TRestRun object is initialized in TRestManager, if so, it reads the following configuration items:

  1. firstEntry, lastEntry, eventsToProcess. These indicates how many events we need to process.
  2. Tree branch list. can be inputAnalysis, inputEvent, outputEvent.
  3. Number of thread needed. A list TRestThread will then be instantiated.

Definition at line 114 of file TRestProcessRunner.cxx.

◆ ConfigOutputFile()

void TRestProcessRunner::ConfigOutputFile ( )

Forming an output file.

Merge all the process's file together, write TRestRun metadata, and then save process metadata to that file

Definition at line 951 of file TRestProcessRunner.cxx.

◆ EndOfInit()

void TRestProcessRunner::EndOfInit ( )

Ending of the startup procedure.

It first sets input event as the first event in process chain, and then do a Validation of the process chain. Finally it calls ReadProcInfo() and create a process info list

Definition at line 282 of file TRestProcessRunner.cxx.

◆ FillThreadEventFunc()

void TRestProcessRunner::FillThreadEventFunc ( TRestThread t)

Calling back the FillEvent() method in TRestThread.

This method is locked by mutex. There can never be two of it running simultaneously in two threads. As a result threads will not write their files together, thus preventing segmentaion violation.

Definition at line 792 of file TRestProcessRunner.cxx.

◆ GetNextevtFunc()

Int_t TRestProcessRunner::GetNextevtFunc ( TRestEvent targetevt,
TRestAnalysisTree targettree 
)

Get next event and copy it to the address of targetevt.

If can, it will also set the observal value of targettree according to the local analysis tree.

This method is locked by mutex. There can never be two of it running simultaneously in two threads.

If there is a single thread process, the local input event will be set to the out put of this process. The targettree will not be changed.

If not, the local input event and analysis tree will be updated after calling TTree::GetEntry(). The observables in the local tree will be copyed to the targettree.

Finally the data in the input event will get cloned to the targetevt by root streamer.

If the current entry is the last entry of the input tree, or the single thread process stops to give a concret pointer as the output, the process is over. This method returns -1.

Definition at line 759 of file TRestProcessRunner.cxx.

◆ Initialize()

void TRestProcessRunner::Initialize ( )
overridevirtual

REST run class.

Setting default values of class' data member.

Reimplemented from TRestMetadata.

Definition at line 73 of file TRestProcessRunner.cxx.

◆ InstantiateProcess()

TRestEventProcess * TRestProcessRunner::InstantiateProcess ( TString  type,
TiXmlElement *  ele 
)

InstantiateProcess in sequential start up.

It instantiates a the object by the method TClass::GetClass(), giving it type name. Then it asks the process object to LoadConfigFromFile() with an xml section.

Definition at line 1049 of file TRestProcessRunner.cxx.

◆ MergeOutputFile()

void TRestProcessRunner::MergeOutputFile ( )

Calls TRestRun::MergeOutputFile() to merge the main file with process's tmp file.

After this operation, fOutputDataFile will be set to TRestRun's output file

Definition at line 1006 of file TRestProcessRunner.cxx.

◆ PauseMenu()

void TRestProcessRunner::PauseMenu ( )

A pause menu providing some functions during the process.

It can:

  1. Change verbose level
  2. Change number of events to process
  3. Push forward event by event
  4. Print the latest processed event
  5. Quit the process directly with file saved

Definition at line 554 of file TRestProcessRunner.cxx.

◆ PrintMetadata()

void TRestProcessRunner::PrintMetadata ( )
overridevirtual

Implemented it in the derived metadata class to print out specific metadata information.

Prints metadata content on screen. Usually overloaded by the derived metadata class.

Reimplemented from TRestMetadata.

Definition at line 1174 of file TRestProcessRunner.cxx.

◆ ReadConfig()

Int_t TRestProcessRunner::ReadConfig ( const std::string &  keydeclare,
TiXmlElement *  e 
)

method to deal with iterated child elements

If child element is declared as "addProcess", then multiple new process will be instantiated using sequential startup method, by calling InstantiateProcess() The processes will be added into each TRestThread instance. If the process is external process, then it will be sent to TRestRun.

Definition at line 213 of file TRestProcessRunner.cxx.

◆ ReadProcInfo()

void TRestProcessRunner::ReadProcInfo ( )

Create a process info list which used called by TRestRun::FormFormat().

Items: FirstProcess, LastProcess, ProcNumber

Definition at line 314 of file TRestProcessRunner.cxx.

◆ RunProcess()

void TRestProcessRunner::RunProcess ( )

The main executer of event process.

Things doing in this method:

  1. Call each thread to prepare their process chain, output tree and output file. The method is PrepareToProcess().
  2. Print metadata for each process
  3. Set output tree by cloning the TRestThread output tree
  4. Reset run count, modify ROOT mutex to make it support multi-thread.
  5. Call each thread to start. The threads running the processes are detatched after this calling.
  6. The main thread loops for progress bar while waiting the child threads to finish.
  7. After finished, print some information, reset ROOT mutexs.
  8. Call ConfigOutputFile() method to save the output file

!!!!!!!!!!!Important!!!!!!!!!!!!

Definition at line 342 of file TRestProcessRunner.cxx.

Field Documentation

◆ fEventTree

TTree* TRestProcessRunner::fEventTree
private

indicates the name of the first file created as output data file. The actual output file maybe changed if tree is too large

Definition at line 42 of file TRestProcessRunner.h.


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