#ifndef OACALIBRECONBASE_IVEVENTFUNCTION_HXX #define OACALIBRECONBASE_IVEVENTFUNCTION_HXX #include "ICOMETEvent.hxx" #include "ICOMETOutput.hxx" #include "EoaCalibRecon.hxx" /// A Base Class of Event Function. /// /// It is assumeed that a derived class is still a base class for /// concrete event function classes specified for /// single sub-detector (CDC, ECAL, etc) or combined detector (CyDet, StrECAL, etc). /// The purpose of this class is to make event function code structure simple and easy. class IVEventFunction { private: /// Event function identifier /// /// All characters are regarded as small letters in SetOption. /// Cannot be set by any methods but the constructor. TString fFunctionName; Bool_t fEnabled; ///< Flag to enable this class's Process(). public: IVEventFunction (const Char_t* name = ""); virtual ~IVEventFunction (){} /// Get the function name const Char_t* GetName() const { return fFunctionName; } /// Return the function name whose all characters are made lower. const Char_t* GetLowerName() const { TString lname = fFunctionName; lname.ToLower(); return lname; } /// Return the full name of this function. /// Fullname is defined as the functional name (such as "Recon") + this own name. /// Must be implemented by the derived class. /// /// May be useful, for example, in order to avoid trace name duplication /// among classes inheriting from different IVEventFunction's derived class, /// e.g. (Recon)ECAL and (CalibApply)ECAL. /// @return fFunctionName with an identifier prefix. virtual const Char_t* GetFullName() = 0; /// Set the status enabled or disabled void Enable(Bool_t enable = kTRUE){ fEnabled = enable; } /// Get the status enabled or disabled Bool_t IsEnabled() const { return fEnabled; } /// Set the log level specified for the recon function. /// /// Although this can be over-rided, by default the function name is set. virtual void SetLogLevel(const COMET::ICOMETLog::LogPriority level); /// Process an event inside the event loop. /// @return the error code that indicates some error happened when != 0. int Process(COMET::ICOMETEvent& event); /// Called by Initialize() in an upper module. virtual void Initialize(void){} /// Called by Finalize() in an upper module. virtual void Finalize(COMET::ICOMETOutput * const){} /// Called when there is a usage error. This code should print a usage /// message and then return. virtual void Usage(void){} /// Print the usage of CoreOptions static void UsageOfCoreOptions(); /// Use this method to check that all the necessary options have been set /// If so, return true. If options are missing then it is the derived /// class' task to inform the user and then return false virtual bool CheckOptions(){ return true; } /// Parse XXXXXXXX function specific options. /// /// The options specified for each event function should be in /// the form of "-O xxxxx-aaaaa=vvvvv" /// (x = the function name, a = the option argument, v = value if needed) /// The function name is fFunctionName but regardless of capital/small letter. /// /// @param option option argument "aaaaa" ("xxxxx-" are removed in advance by VGlobal) /// @param value option value "vvvvv" /// @return true when the option belongs to this function and was correctly processed. /// /// Note that some "aaaaa" common among all event functions should be /// parsed by SetCoreOption() and SetCommonOption() (See it) bool ParseSpecificOption(TString option, TString value = ""); protected: /// Initialize or prepare the field variables per event virtual void BeginOfEvent(void){} /// Delete or locally saving the field variables per event virtual void EndOfEvent(void){} /// Process an event inside Process. Must be over-ridden, /// @return the error code that indicates some error happened when != 0. virtual int ProcessCore(COMET::ICOMETEvent& event) = 0; /// Set an option and return true if it is valid. /// /// Basically the concept is the same as ICOMETEventLoopFunction. /// This is called once by the VGlobal executable loop function's SetOption(). virtual bool SetOption(TString option, TString value = ""); /// Only option globally common among all /// the derived functions. But don't overlap with SetCoreOption() called before. virtual bool SetCommonOption(TString option, TString value = ""){ return false; } private: /// Only function specific option whose argument string is common among all /// XXXXXXXX functions. /// /// For example, all functions must have "xxxxx-disable" options. bool SetCoreOption(TString option, TString value = ""); }; #endif // OACALIBRECONBASE_IVEVENTFUNCTION_HXX