diff --git a/Control/AthenaMonitoring/AthenaMonitoring/AthMonitorAlgorithm.h b/Control/AthenaMonitoring/AthenaMonitoring/AthMonitorAlgorithm.h index c78524baa38429e3747e360d9f1fd3c7fc5da149..59eaf244a55a7566a273bc2364a363819bea97d1 100644 --- a/Control/AthenaMonitoring/AthenaMonitoring/AthMonitorAlgorithm.h +++ b/Control/AthenaMonitoring/AthenaMonitoring/AthMonitorAlgorithm.h @@ -77,37 +77,56 @@ public: */ virtual StatusCode fillHistograms(const EventContext& ctx) const = 0; + /** @defgroup Group Filling Functions + * A group of functions which fill monitored variables in groups. + * @{ + */ + /** + * Fills a vector of variables to a group by reference. (BASE FILL) + * + * At the end of the fillHistograms routine, one should save the monitored variables + * to the group. This function wraps the process of getting the desired group by a + * call to AthMonitorAlgorithm::getGroup() and a call to Monitored::Group::fill(), + * which also disables the auto-fill feature to avoid double-filling. Note, users + * should avoid using this specific function name 'fill' in daughter classes. + * + * @param groupHandle A reference of the GenericMonitoringTool to which add variables + * @param variables Vector of monitored variables to be saved + */ + void fill( const ToolHandle<GenericMonitoringTool>& groupHandle, + std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> variables ) const; /** - * Adds variables from an event to a group by name. - * - * @param groupName The string name of the GenericMonitoringTool - * @param variables Variables desired to be saved. - * @return StatusCode + * Fills a variadic list of variables to a group by reference. Callse BASE FILL. + * + * @param groupHandle Reference to the GenericMonitoringTool + * @param variables... Variadic list of monitored variables to be saved */ template <typename... T> - void fill( const std::string& groupName, T&&... variables ) const { - fill(getGroup(groupName),std::forward<T>(variables)...); + void fill( const ToolHandle<GenericMonitoringTool>& groupHandle, T&&... variables ) const { + fill(groupHandle,{std::forward<T>(variables)...}); } + /** + * Fills a vector of variables to a group by name. Calls BASE FILL. + * + * @param groupHandle Reference to the GenericMonitoringTool + * @param variables Vector of monitored variables to be saved + */ + void fill( const std::string& groupName, + std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> variables ) const; /** - * Adds variables from an event to a group by the group's object reference. - * - * At the end of the fillHistograms routine, one should save the monitored variables - * to the group. This function wraps the process of getting the desired group by a - * call to AthMonitorAlgorithm::getGroup() and a call to Monitored::Group::fill(), - * which also disables the auto-fill feature to avoid double-filling. Note, users - * should avoid using this specific function name in daughter classes. - * - * @param groupHandle A reference of the GenericMonitoringTool to which add variables. - * @param variables Variables desired to be saved - * @return StatusCode + * Fills a variadic list of variables to a group by name. Calls BASE FILL. + * + * @param groupName The string name of the GenericMonitoringTool + * @param variables... Variadic list of monitored variables to be saved */ template <typename... T> - void fill( const ToolHandle<GenericMonitoringTool>& groupHandle, T&&... variables ) const { - Monitored::Group(groupHandle,std::forward<T>(variables)...).fill(); + void fill( const std::string& groupName, T&&... variables ) const { + fill(getGroup(groupName),{std::forward<T>(variables)...}); } + /** @} */ // end of fill group /** @@ -323,6 +342,7 @@ protected: SG::ReadHandleKey<xAOD::EventInfo> m_EventInfoKey {this,"EventInfoKey","EventInfo"}; ///< Key for retrieving EventInfo from StoreGate private: + typedef std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> MonVarVec_t; std::string m_name; }; diff --git a/Control/AthenaMonitoring/AthenaMonitoring/MonitoredGroup.h b/Control/AthenaMonitoring/AthenaMonitoring/MonitoredGroup.h index 05a29823a2d468c9734dd07c44818b3a0b7ed36f..3535ba5582c1b3c6f4bf77767a7af890eb995432 100644 --- a/Control/AthenaMonitoring/AthenaMonitoring/MonitoredGroup.h +++ b/Control/AthenaMonitoring/AthenaMonitoring/MonitoredGroup.h @@ -46,6 +46,12 @@ namespace Monitored { m_monitoredGroup{monitoredGroup...}, m_histogramsFillers(!m_tool.empty() ? m_tool->getHistogramsFillers(m_monitoredGroup) : std::vector<std::shared_ptr<Monitored::HistogramFiller>>()) { } + Group(const ToolHandle<GenericMonitoringTool>& tool, std::vector<std::reference_wrapper<IMonitoredVariable>> monitoredGroup) + : m_tool(tool), + m_autoFill(true), + m_monitoredGroup(monitoredGroup), + m_histogramsFillers(!m_tool.empty() ? m_tool->getHistogramsFillers(m_monitoredGroup) : std::vector<std::shared_ptr<Monitored::HistogramFiller>>()) { } + virtual ~Group() { if (m_autoFill) { fill(); diff --git a/Control/AthenaMonitoring/src/AthMonitorAlgorithm.cxx b/Control/AthenaMonitoring/src/AthMonitorAlgorithm.cxx index 89edbecc7dce43a6fad0ee6a2ef359b9ed9ff989..073a8a1f958e20d9b7e7459440a716b52d4474fe 100644 --- a/Control/AthenaMonitoring/src/AthMonitorAlgorithm.cxx +++ b/Control/AthenaMonitoring/src/AthMonitorAlgorithm.cxx @@ -86,6 +86,18 @@ StatusCode AthMonitorAlgorithm::execute( const EventContext& ctx ) const { } +void AthMonitorAlgorithm::fill( const ToolHandle<GenericMonitoringTool>& groupHandle, + MonVarVec_t variables ) const { + Monitored::Group(groupHandle,variables).fill(); +} + + +void AthMonitorAlgorithm::fill( const std::string& groupName, + MonVarVec_t variables ) const { + fill(getGroup(groupName),variables); +} + + SG::ReadHandle<xAOD::EventInfo> AthMonitorAlgorithm::GetEventInfo( const EventContext& ctx ) const { return SG::ReadHandle<xAOD::EventInfo>(m_EventInfoKey, ctx); } diff --git a/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx b/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx index 6fd4bcab827e4363e318b721d4b6c63721b5b05d..2c6906c43faf8cedb6b97249cea51978bf129a0b 100644 --- a/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx +++ b/Control/AthenaMonitoring/src/ExampleMonitorAlgorithm.cxx @@ -54,6 +54,11 @@ StatusCode ExampleMonitorAlgorithm::fillHistograms( const EventContext& ctx ) co // Alternative fill method. Get the group yourself, and pass it to the fill function. auto tool = getGroup("ExampleMonitor"); fill(tool,run); + + // Fill with a vector; useful in some circumstances. + std::vector<std::reference_wrapper<Monitored::IMonitoredVariable>> varVec = {lumiPerBCID,pT}; + fill("ExampleMonitor",varVec); + fill(tool,varVec); return StatusCode::SUCCESS; }