#ifndef TAnalysisModuleBase_hxx_seen #define TAnalysisModuleBase_hxx_seen #include #include #include #include #include #include #include "IoaAnalysisUtils.hxx" namespace COMET { class IAnalysisModuleBase; OA_EXCEPTION(EAnalysisModuleBase,EoaAnalysis); OA_EXCEPTION(EUndefinedTreeType,EAnalysisModuleBase); OA_EXCEPTION(EAnalysisFailure,EAnalysisModuleBase); }; /// A base class for classes which specify how to set up an Analysis format /// output tree, and fill it. These classes will be read in and run by the /// oaAnalysis package software, namely by IAnalysisLoop. The classes must be /// accompanied by tests to check that they work, and runtime tests to see if /// they are appropriate for the input root files being used. /// /// A note on naming of data members in analysis modules classes and their /// sub-classes: /// /// The names of members belonging to the modules themselves all /// start with an 'f', to indicate that they are fields in the /// classes. These names are used in coding up the modules, so it is /// better that they follow the convention. /// /// The members of storages sub-classes to the modules, which get /// saved in TTrees within TClonesArrays, DO NOT get an 'f' at the /// beginning, because they represent names that get used directly /// in analysis macros. This was always implemented consistently. /// /// The modules themselves get saved in the output files, including /// their data members (except those with a comment with an /// exclamation mark "//!" after them, which tells ROOT not to /// save them). These can be accessed in the analysis macros, /// but since they are explicitly members of the module /// classes, it is consistent to have them start with 'f' too. class COMET::IAnalysisModuleBase : public TNamed { using TNamed::Print; // just to reduce errors saying this gets hidden public: IAnalysisModuleBase(); virtual ~IAnalysisModuleBase(); protected: enum EType {kHeader = 0, kTruth, kRecon, kLowLevel, kNTypes}; public: /// Returns the type of tree, header, truth, or recon. /// This is overridden in the derived base classes such as /// IAnalysisReconModuleBase, so users do not need to override /// it explicitly virtual EType GetTreeType() const = 0; /// Returns the name of the directory which the output of a /// particular module will be saved in. std::string const GetDirectoryName() const; /// Sets whether the module is enabled. This only refer to modules /// which have been included for consideration by being instantiated /// in IAnalysisLoop.cxx or similar. virtual void SetEnabled(Bool_t yesorno = kTRUE){ fIsEnabled = yesorno; } /// Disables the module. Is called when an exception is thrown inside /// the module. virtual void SetDisabled(){ SetEnabled(kFALSE); } /// Sets whether the module should call IsFullEventWorthSaving() function /// for each event, to decide if the full oaEvent info for that event should /// be saved in the output virtual void SetUsedForPreselection(Bool_t yesorno = kTRUE){ fIsUsedForPreselection = yesorno; } /// Whether the module is enable or not. virtual Bool_t IsEnabled() const { return fIsEnabled; } /// Is the module is enabled by default. Default is to enable module. To /// set to disable override this method in the derived module. virtual Bool_t IsEnabledByDefault() const {return kTRUE;} /// Whether the module should call IsFullEventWorthSaving() function /// for each event, to decide if the full oaEvent info for that event should /// be saved in the output virtual Bool_t IsUsedForPreselection() const { return fIsUsedForPreselection; } /// Prints a simple message describing the module. Should be overridden /// for more detail virtual void Print(); /// Is called after the first event is loaded in. /// This is a good time to save persistent quantities in the module's /// data members, which will be retrievable from the oaAnalysis output /// file. /// Not intended for filling in the tree with the first event, as /// Process() will also be called. virtual Bool_t ProcessFirstEvent(COMET::ICOMETEvent&) = 0; void Initialize(TTree *tree); /// Gets the run and event IDs and calls FillTree with the /// event, and then actually calls fOutputTree->Fill. virtual bool Process(COMET::ICOMETEvent& event); /// Whether the module thinks it is worth saving the entire /// oaEvent event tree entry for this event. /// oaAnalysis can be used for event pre-selection in this way. /// Activated with the --oaEvent-preselection= command- /// line argument virtual bool IsFullEventWorthSaving(COMET::ICOMETEvent& event); /// ROOT output parameters, usually no need to touch Int_t GetBufferSize(){ return fBufferSize; } /// ROOT output parameters, usually no need to touch void SetBufferSize(Int_t buffersize){ fBufferSize = buffersize; } /// ROOT output parameters, usually no need to touch Int_t GetSplitLevel(){ return fSplitLevel; } /// ROOT output parameters, usually no need to touch void SetSplitLevel(Int_t splitlevel){ fSplitLevel = splitlevel; } std::string const GetDescription() const { return fDescription; } std::string const GetCVSTagName() const { return fCVSTagName; } std::string const GetCVSID() const { return fCVSID; } /// The output tree TTree const * GetOutputTree() const { return fOutputTree; } /// A function that allows the module to be configured from an external /// class without any dependencies. /// Should be overridden with a function that responds to the string /// option, and returns kTRUE if configuration succedded. /// Used in IAnalysisLoop.cxx (and RunOAAnalysis.exe) for options of the /// form: -O ITruthTrajectoriesModule=SaveAll virtual Bool_t Configure(std::string &option); void SetInputDirectory(std::string dir){ fInputDirectory = dir; } protected: /// Initialize Module, override if necessary virtual void InitializeModule(){}; /// Initialize Branches. Don't do anything else in this function virtual void InitializeBranches() = 0; /// Fill all the stuff that goes in the output tree. Return /// true if everything went well. Otherwise, the module /// may be disabled! (return definition changed Apr 2009!) virtual bool FillTree(COMET::ICOMETEvent&) = 0; Bool_t fIsEnabled; Bool_t fIsUsedForPreselection; TTree *fOutputTree; /// Buffer Size for TBranch. Has a default value that /// can be changed per module. Int_t fBufferSize; // Buffer Size for TBranch. Int_t fSplitLevel; ///< Split Level for TBranch. std::string fDescription; ///< A longish descrition of the analysis std::string fCVSTagName; ///< Defined if an official tagged version std::string fCVSID; ///< Defined if an official tagged version /////////////////////////////////////////////////////////////////// // Default Tree Entries Int_t fRunID; Int_t fSubrunID; Int_t fEventID; Int_t fPreselected; std::string fInputDirectory; ///< An input directory where analysis modules can search for extra files. private: ClassDef(IAnalysisModuleBase,1); }; #endif