//////////////////////////////////////////////////////////////////// // // This processor outputs the events into a T tree containing // DS::Entry instances and a runT tree containing DS::Run instances. // The name of the file can be specified at the command line, in // the ratdb and in the macro. // // Author: Stan Seibert // P G Jones - contact person // // REVISION HISTORY: // 2014-04-26 : P Jones - refactor, add doxygen. // 2016-10-19 : M Stringer - Changes to how MCTracks are accessed (PR #1508). // 2017-04-26: J Dunger - add end of job meta informatio // 2018-01-11: N Barros - Change file opening logic to allow to specify a file suffix // 2018-01-12: N Barros - Moved file creation to BeginOfRun to make sure that // a file is always created, even if it is empty // //////////////////////////////////////////////////////////////////// #ifndef __RATOutROOTProc___ #define __RATOutROOTProc___ #include #include #include class TFile; class TTree; namespace RAT { class OutROOTProc : public Processor { public: // Constructor, initialises pointers to NULL OutROOTProc(); // Destructor, close file and finalise ~OutROOTProc(); // Called when a procset string is set on the command line // // The options are, // `file name` which sets the name of a file to create and write to // `updatefile name` which sets the name of a file to update to // // param: parameter or command // value: value to set // Throws ParamUnknown if the param is not file or updatefile void SetS( const std::string& param, const std::string& value ); // Called when a procset int is set on the command line // // The options are, // `autosave value` which sets the maximum interval between points in run at which all // the baskets are closed and written to disk individually. // `autoflush value` which sets the maximum interval between points in run at which // a new key is written in the output root file and all data are output. // See comments in the ROOT routine TTree.cxx // // param: parameter or command // value: value to set // Throws ParamUnknown if the param is not autosave or autoflush // Throws ParamInvalid if the autosave value is negative void SetI( const std::string& param, const int value ); // Begin of run, load from the database // // run: Data structure for the run void BeginOfRun( DS::Run& run ); // New event, write it out // // run: Data structure for the run // ds: Data structure for the event Processor::Result DSEvent( DS::Run& run, DS::Entry& ds ); // End of run, write out the run // // run: Data structure for the run void EndOfRun( DS::Run& run ); private: // Opens the file ready to write to void OpenFile(); std::string fDBFileName; // The file name as loaded from the ratdb, the default std::string fOverrideFileName; // The file name as set from the macro std::string fFileNameSuffix; // suffix to be applied between the file name and the extension TFile* fFile; // The file to write to TTree* fDSTree; // The dsTree to write DS::Entry instances to TTree* fRunTree; // The runTree to write DS::Run instances to DS::Entry* fDSBranch; // The branch in the dsTree DS::Run* fRunBranch; // The branch in the runTree int fAutoSave; // Number to pass to ROOT to indicate when to autosave int fAutoFlush; // Number to pass to ROOT to indicate when to autoflush bool fUpdate; // Update the file if true, overwrite if false MetaHelper fMetaHelper; // to count the events going by each run, written to meta data at the end }; } // namespace RAT #endif