From b51fdfb392d64af4e39ca04781f26c931427bf19 Mon Sep 17 00:00:00 2001 From: Charles Burton <cdb97@cornell.edu> Date: Mon, 21 Jan 2019 13:31:33 -0600 Subject: [PATCH] resolve MR comments 1. Cleanup boilerplate code 2. Change property declaration to new method 3. Change function names in AthMonitorCfgHelper 4. Add AOD to TestDefaults.py 5. Add override keyword to functions --- .../AthenaMonitoring/AthMonitorAlgorithm.h | 39 +++++++------- .../ExampleMonitorAlgorithm.h | 2 +- .../python/AthMonitorCfgHelper.py | 4 +- .../ExampleMonitorAlgorithm.py | 36 +++++++------ Control/AthenaMonitoring/python/__init__.py | 3 +- .../src/AthMonitorAlgorithm.cxx | 53 +++---------------- .../src/ExampleMonitorAlgorithm.cxx | 4 +- 7 files changed, 51 insertions(+), 90 deletions(-) rename Control/AthenaMonitoring/{share => python}/ExampleMonitorAlgorithm.py (82%) diff --git a/Control/AthenaMonitoring/AthenaMonitoring/AthMonitorAlgorithm.h b/Control/AthenaMonitoring/AthenaMonitoring/AthMonitorAlgorithm.h index 11c0542fb48..cdb1d6b12cd 100644 --- a/Control/AthenaMonitoring/AthenaMonitoring/AthMonitorAlgorithm.h +++ b/Control/AthenaMonitoring/AthenaMonitoring/AthMonitorAlgorithm.h @@ -52,7 +52,7 @@ public: * * @return StatusCode */ - virtual StatusCode initialize(); + virtual StatusCode initialize() override; /** @@ -61,7 +61,7 @@ public: * @param ctx event context for reentrant Athena call * @return StatusCode */ - virtual StatusCode execute(const EventContext& ctx) const; + virtual StatusCode execute(const EventContext& ctx) const override; /** @@ -125,7 +125,7 @@ public: * * @return a value in the Environment_t enumeration which matches the input string. */ - Environment_t envStringToEnum( const std::string& str ); + Environment_t envStringToEnum( const std::string& str ) const; /** @@ -141,7 +141,7 @@ public: * * @return a value in the DataType_t enumeration which matches the input string. */ - DataType_t dataTypeStringToEnum( const std::string& str ); + DataType_t dataTypeStringToEnum( const std::string& str ) const; /** @@ -261,27 +261,30 @@ public: protected: - ToolHandleArray<GenericMonitoringTool> m_tools; ///< Array of Generic Monitoring Tools - ToolHandle<Trig::ITrigDecisionTool> m_trigDecTool; ///< Tool to tell whether a specific trigger is passed - ToolHandle<ITriggerTranslatorTool> m_trigTranslator; ///< Tool to unpack trigger categories into a trigger list - ToolHandleArray<IDQFilterTool> m_DQFilterTools; ///< Array of Data Quality filter tools - ToolHandle<ILuminosityTool> m_lumiTool; ///< Tool for calculating various luminosity quantities - ToolHandle<ITrigLivefractionTool> m_liveTool; ///< Tool for calculating various live luminosity quantities + // Using the new way to declare JO properties: Gaudi::Property<int> m_myProperty {this,"MyProperty",0}; + + ToolHandleArray<GenericMonitoringTool> m_tools {this,"GMTools",{}}; ///< Array of Generic Monitoring Tools + ToolHandle<Trig::ITrigDecisionTool> m_trigDecTool {this,"TrigDecisionTool",""}; ///< Tool to tell whether a specific trigger is passed + ToolHandle<ITriggerTranslatorTool> m_trigTranslator {this,"TriggerTranslatorTool",""}; ///< Tool to unpack trigger categories into a trigger list + ToolHandleArray<IDQFilterTool> m_DQFilterTools {this,"FilterTools",{}}; ///< Array of Data Quality filter tools + + ToolHandle<ILuminosityTool> m_lumiTool {this,"lumiTool","LuminosityTool"}; ///< Tool for calculating various luminosity quantities + ToolHandle<ITrigLivefractionTool> m_liveTool {this,"liveTool","TrigLivefractionTool"}; ///< Tool for calculating various live luminosity quantities AthMonitorAlgorithm::Environment_t m_environment; ///< Instance of the Environment_t enum AthMonitorAlgorithm::DataType_t m_dataType; ///< Instance of the DataType_t enum - std::string m_environmentStr; ///< Environment string pulled from the job option and converted to enum - std::string m_dataTypeStr; ///< DataType string pulled from the job option and converted to enum + Gaudi::Property<std::string> m_environmentStr {this,"Environment","user"}; ///< Environment string pulled from the job option and converted to enum + Gaudi::Property<std::string> m_dataTypeStr {this,"DataType","userDefined"}; ///< DataType string pulled from the job option and converted to enum - std::string m_triggerChainString; ///< Trigger chain string pulled from the job option and parsed into a vector + Gaudi::Property<std::string> m_triggerChainString {this,"TriggerChain",""}; ///< Trigger chain string pulled from the job option and parsed into a vector std::vector<std::string> m_vTrigChainNames; ///< Vector of trigger chain names parsed from trigger chain string - std::string m_fileKey; + Gaudi::Property<std::string> m_fileKey {this,"FileKey",""}; ///< Internal Athena name for file bool m_hasRetrievedLumiTool; ///< Allows use of various luminosity functions - bool m_useLumi; ///< Allows use of various luminosity functions - float m_defaultLBDuration; ///< Default duration of one lumi block - int m_detailLevel; ///< Sets the level of detail used in the monitoring - SG::ReadHandleKey<xAOD::EventInfo> m_EventInfoKey; // key for retrieving EventInfo from StoreGate + Gaudi::Property<bool> m_useLumi {this,"EnableLumi",false}; ///< Allows use of various luminosity functions + Gaudi::Property<float> m_defaultLBDuration {this,"DefaultLBDuration",60.}; ///< Default duration of one lumi block + Gaudi::Property<int> m_detailLevel {this,"DetailLevel",0}; ///< Sets the level of detail used in the monitoring + SG::ReadHandleKey<xAOD::EventInfo> m_EventInfoKey {this,"EventInfoKey","EventInfo"}; ///< Key for retrieving EventInfo from StoreGate }; #endif diff --git a/Control/AthenaMonitoring/AthenaMonitoring/ExampleMonitorAlgorithm.h b/Control/AthenaMonitoring/AthenaMonitoring/ExampleMonitorAlgorithm.h index 0c6f7766270..0d959860d56 100644 --- a/Control/AthenaMonitoring/AthenaMonitoring/ExampleMonitorAlgorithm.h +++ b/Control/AthenaMonitoring/AthenaMonitoring/ExampleMonitorAlgorithm.h @@ -20,6 +20,6 @@ public: StatusCode initialize(); virtual StatusCode fillHistograms( const EventContext& ctx ) const override; private: - bool m_doRandom; + Gaudi::Property<bool> m_doRandom {this,"RandomHist",false}; }; #endif \ No newline at end of file diff --git a/Control/AthenaMonitoring/python/AthMonitorCfgHelper.py b/Control/AthenaMonitoring/python/AthMonitorCfgHelper.py index 16a4ea89337..9c8cccce5ca 100644 --- a/Control/AthenaMonitoring/python/AthMonitorCfgHelper.py +++ b/Control/AthenaMonitoring/python/AthMonitorCfgHelper.py @@ -11,7 +11,7 @@ class AthMonitorCfgHelper(object): self.monSeq = AthSequencer('AthMonSeq_' + monName) self.resobj = ComponentAccumulator() - def AddAlgorithm(self,algClassOrObj, *args, **kwargs): + def addAlgorithm(self,algClassOrObj, *args, **kwargs): from AthenaCommon.Configurable import Configurable if issubclass(algClassOrObj, Configurable): algObj = algClassOrObj(*args, **kwargs) @@ -25,7 +25,7 @@ class AthMonitorCfgHelper(object): self.monSeq += algObj return algObj - def AddGroup(self, alg, name, topPath=''): + def addGroup(self, alg, name, topPath=''): from AthenaMonitoring.GenericMonitoringTool import GenericMonitoringTool tool = GenericMonitoringTool(name) acc, histsvc = GetDQTHistSvc(self.inputFlags) diff --git a/Control/AthenaMonitoring/share/ExampleMonitorAlgorithm.py b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py similarity index 82% rename from Control/AthenaMonitoring/share/ExampleMonitorAlgorithm.py rename to Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py index bc4d4913161..88b8fffe90e 100644 --- a/Control/AthenaMonitoring/share/ExampleMonitorAlgorithm.py +++ b/Control/AthenaMonitoring/python/ExampleMonitorAlgorithm.py @@ -21,7 +21,7 @@ def ExampleMonitoringConfig(inputFlags): # The following class will make a sequence, configure algorithms, and link # them to GenericMonitoringTools from AthenaMonitoring import AthMonitorCfgHelper - helper = AthMonitorCfgHelper(inputFlags,"ExampleMonitor") + helper = AthMonitorCfgHelper(inputFlags,'ExampleAthMonitorCfg') ### STEP 2 ### @@ -31,11 +31,11 @@ def ExampleMonitoringConfig(inputFlags): # base class configuration following the inputFlags. The returned object # is the algorithm. from AthenaMonitoring.AthenaMonitoringConf import ExampleMonitorAlgorithm - exampleMonAlg = helper.AddAlgorithm(ExampleMonitorAlgorithm) + exampleMonAlg = helper.addAlgorithm(ExampleMonitorAlgorithm,'ExampleMonAlg') # You can actually make multiple instances of the same algorithm and give # them different configurations - anotherExampleMonAlg = helper.AddAlgorithm(ExampleMonitorAlgorithm) + anotherExampleMonAlg = helper.addAlgorithm(ExampleMonitorAlgorithm,'AnotherExampleMonAlg') # # If for some really obscure reason you need to instantiate an algorithm # # yourself, the AddAlgorithm method will still configure the base @@ -44,14 +44,8 @@ def ExampleMonitoringConfig(inputFlags): ### STEP 3 ### - # Edit properties of a algorithm, using inputFlags. - exampleMonAlg.FileKey = inputFlags.DQ.FileKey - exampleMonAlg.Environment = inputFlags.DQ.Environment - exampleMonAlg.DataType = inputFlags.DQ.DataType - + # Edit properties of a algorithm exampleMonAlg.TriggerChain = '' - exampleMonAlg.EnableLumi = True - ### STEP 4 ### # Add some tools. N.B. Do not use your own trigger decion tool. Use the @@ -72,21 +66,29 @@ def ExampleMonitoringConfig(inputFlags): # Add a generic monitoring tool (a "group" in old language). The returned # object here is the standard GenericMonitoringTool. - myGroup = helper.AddGroup( + myGroup = helper.addGroup( exampleMonAlg, - "ExampleMonitor", - "OneRing/" + 'ExampleMonitor', + 'OneRing/' ) + # Add a GMT for the other example monitor algorithm + anotherGroup = helper.addGroup(anotherExampleMonAlg,'ExampleMonitor') + ### STEP 5 ### # Configure histograms - myGroup.defineHistogram("lumiPerBCID;lumiPerBCID", title="Luminosity;L/BCID;Events", + myGroup.defineHistogram('lumiPerBCID;lumiPerBCID', title='Luminosity;L/BCID;Events', path='ToRuleThemAll',xbins=10,xmin=0.0,xmax=10.0) - myGroup.defineHistogram("lb;lb", title="Luminosity Block;lb;Events", + myGroup.defineHistogram('lb;lb', title='Luminosity Block;lb;Events', path='ToFindThem',xbins=1000,xmin=-0.5,xmax=999.5) - myGroup.defineHistogram("random;random", title="LB;x;Events", + myGroup.defineHistogram('random;random', title='LB;x;Events', path='ToBringThemAll',xbins=30,xmin=0,xmax=1) + + anotherGroup.defineHistogram('lbWithFilter;lbWithFilter',title='Lumi;lb;Events', + path='top',xbins=1000,xmin=-0.5,xmax=999.5) + + ### STEP 6 ### # Finalize. The return value should be a tuple of the ComponentAccumulator # and the sequence containing the created algorithms. If we haven't called @@ -116,7 +118,7 @@ if __name__=='__main__': file = 'data16_13TeV.00311321.physics_Main.recon.AOD.r9264/AOD.11038520._000001.pool.root.1' ConfigFlags.Input.Files = [nightly+file] ConfigFlags.Input.isMC = False - ConfigFlags.Output.HISTFileName = 'ExampleMonitor.root' + ConfigFlags.Output.HISTFileName = 'ExampleMonitorOutput.root' ConfigFlags.lock() # Initialize configuration object, add accumulator, merge, and run. diff --git a/Control/AthenaMonitoring/python/__init__.py b/Control/AthenaMonitoring/python/__init__.py index a97b7401395..d95762383ed 100644 --- a/Control/AthenaMonitoring/python/__init__.py +++ b/Control/AthenaMonitoring/python/__init__.py @@ -3,5 +3,4 @@ # from AthMonitorCfgHelper import AthMonitorCfgHelper -from AtlasReadyFilterTool import GetAtlasReadyFilterTool -import DQConfigFlags +from AtlasReadyFilterTool import GetAtlasReadyFilterTool \ No newline at end of file diff --git a/Control/AthenaMonitoring/src/AthMonitorAlgorithm.cxx b/Control/AthenaMonitoring/src/AthMonitorAlgorithm.cxx index a6b28b2f131..044cf89f220 100644 --- a/Control/AthenaMonitoring/src/AthMonitorAlgorithm.cxx +++ b/Control/AthenaMonitoring/src/AthMonitorAlgorithm.cxx @@ -6,41 +6,11 @@ AthMonitorAlgorithm::AthMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator ) :AthReentrantAlgorithm(name,pSvcLocator) -,m_tools(this) -,m_trigDecTool("") -,m_trigTranslator("") -,m_DQFilterTools(this) -,m_lumiTool("LuminosityTool") -,m_liveTool("TrigLivefractionTool") ,m_environment(Environment_t::user) ,m_dataType(DataType_t::userDefined) -,m_environmentStr("user") -,m_dataTypeStr("userDefined") -,m_triggerChainString("") ,m_vTrigChainNames({}) -,m_fileKey("") ,m_hasRetrievedLumiTool(false) -,m_useLumi(false) -,m_defaultLBDuration(60.) -,m_detailLevel(1) -,m_EventInfoKey("EventInfo") -{ - // The following properties are set in the python configuration and - // picked up here to be converted into the method variables. For an - // explanation of each variable, see the header. - declareProperty("GMTools",m_tools); - declareProperty("TrigDecisionTool",m_trigDecTool); - declareProperty("TriggerTranslatorTool",m_trigTranslator); - declareProperty("FilterTools",m_DQFilterTools); - declareProperty("Environment",m_environmentStr); - declareProperty("DataType",m_dataTypeStr); - declareProperty("TriggerChain",m_triggerChainString); - declareProperty("FileKey",m_fileKey); - declareProperty("EnableLumi",m_useLumi); - declareProperty("DefaultLBDuration",m_defaultLBDuration); - declareProperty("DetailLevel",m_detailLevel); - declareProperty("EventInfoKey",m_EventInfoKey); -} +{} AthMonitorAlgorithm::~AthMonitorAlgorithm() {} @@ -51,19 +21,12 @@ StatusCode AthMonitorAlgorithm::initialize() { // Retrieve the generic monitoring tools (a ToolHandleArray) if ( !m_tools.empty() ) { - sc = m_tools.retrieve(); - if ( !sc.isSuccess() ) { - ATH_MSG_ERROR("Unable to retrieve the generic monitoring tools." << endmsg); - } + ATH_CHECK( m_tools.retrieve() ); } // Retrieve the trigger decision tool if requested if ( !m_trigDecTool.empty() ) { - sc = m_trigDecTool.retrieve(); - if( !sc.isSuccess() ) { - ATH_MSG_ERROR("Unable to retrieve the TrigDecisionTool." << endmsg); - return sc; - } + ATH_CHECK( m_trigDecTool.retrieve() ); // If the trigger chain is specified, parse it into a list. if ( m_triggerChainString!="" ) { @@ -76,11 +39,7 @@ StatusCode AthMonitorAlgorithm::initialize() { // Then, retrieve the trigger translator if requested. Finally, convert // into a usable format using the unpackTriggerCategories function. if (!m_trigTranslator.empty()) { - sc = m_trigTranslator.retrieve(); - if ( !sc.isSuccess() ) { - ATH_MSG_ERROR("Unable to retrieve the TrigTranslatorTool." << endmsg); - return sc; - } + ATH_CHECK( m_trigTranslator.retrieve() ); unpackTriggerCategories(m_vTrigChainNames); } } @@ -144,7 +103,7 @@ AthMonitorAlgorithm::Environment_t AthMonitorAlgorithm::environment() const { } -AthMonitorAlgorithm::Environment_t AthMonitorAlgorithm::envStringToEnum( const std::string& str ) { +AthMonitorAlgorithm::Environment_t AthMonitorAlgorithm::envStringToEnum( const std::string& str ) const { // convert the string to all lowercase std::string lowerCaseStr = str; std::transform(lowerCaseStr.begin(), lowerCaseStr.end(), lowerCaseStr.begin(), ::tolower); @@ -177,7 +136,7 @@ AthMonitorAlgorithm::DataType_t AthMonitorAlgorithm::dataType() const { } -AthMonitorAlgorithm::DataType_t AthMonitorAlgorithm::dataTypeStringToEnum( const std::string& str ) { +AthMonitorAlgorithm::DataType_t AthMonitorAlgorithm::dataTypeStringToEnum( const std::string& str ) const { // convert the string to all lowercase std::string lowerCaseStr = str; std::transform(lowerCaseStr.begin(), lowerCaseStr.end(), lowerCaseStr.begin(), ::tolower); diff --git a/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx b/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx index 58b7784ee03..bc0167f758a 100644 --- a/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx +++ b/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx @@ -7,9 +7,7 @@ ExampleMonitorAlgorithm::ExampleMonitorAlgorithm( const std::string& name, ISvcLocator* pSvcLocator ) :AthMonitorAlgorithm(name,pSvcLocator) ,m_doRandom(false) -{ - declareProperty("RandomHist",m_doRandom); -} +{} ExampleMonitorAlgorithm::~ExampleMonitorAlgorithm() {} -- GitLab