ATLAS Offline Software
MonitoredGroup.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef AthenaMonitoringKernel_MonitoredGroup_h
6 #define AthenaMonitoringKernel_MonitoredGroup_h
7 
8 #include <functional>
9 #include <string>
10 #include <vector>
11 #include <stdexcept>
12 
13 #include "GaudiKernel/ToolHandle.h"
14 
18 
19 namespace Monitored {
54  class Group {
55  public:
65  template <typename... T>
66  Group(const ToolHandle<GenericMonitoringTool>& tool, T&&... monitoredGroup)
67  : m_tool(tool),
68  m_autoFill(true),
69  m_monitoredGroup{monitoredGroup...}
70  { }
71 
72  Group(const ToolHandle<GenericMonitoringTool>& tool, const std::vector<std::reference_wrapper<IMonitoredVariable>>& monitoredGroup)
73  : m_tool(tool),
74  m_autoFill(true),
75  m_monitoredGroup(monitoredGroup)
76  { }
77 
78  Group(const ToolHandle<GenericMonitoringTool>& tool, std::vector<std::reference_wrapper<IMonitoredVariable>>&& monitoredGroup)
79  : m_tool(tool),
80  m_autoFill(true),
81  m_monitoredGroup(std::move(monitoredGroup))
82  { }
83 
84  ~Group() {
85  if (m_autoFill) {
86  fill();
87  }
88  }
89 
100  void fill() {
101  if ( m_tool.empty() ) return;
102  setAutoFill(false);
103  m_tool->invokeFillers(m_monitoredGroup);
104  }
105 
113  void setAutoFill(bool isEnabled) { m_autoFill = isEnabled; }
114 
115  protected:
116  ToolHandle<GenericMonitoringTool> m_tool;
118  const std::vector<std::reference_wrapper<IMonitoredVariable>> m_monitoredGroup;
119  };
120 
121  template <typename... T>
122  void fill(const ToolHandle<GenericMonitoringTool>& tool, T&&... variables) {
123  if (!tool.empty()) {
124  tool->invokeFillers({std::forward<T>(variables)...});
125  }
126  }
127 
128  // Sub-namespace for internal-use functions
129  namespace detail {
131  template <typename T = int>
132  int findToolIndex( const ToolHandleArray<GenericMonitoringTool>& toolArray, const std::string& name ) {
133  auto it = std::find_if(toolArray.begin(),toolArray.end(),[&](const auto& r) {return r.name()==name;});
134  return it!=toolArray.end()
135  ? std::distance(toolArray.begin(),it)
136  : throw std::runtime_error("The tool "+name+" could not be found in the tool array.");
137  }
138  }
139 
141  template<typename V,typename std::enable_if_t<std::is_integral_v<V>>* =nullptr>
142  std::vector<V> buildToolMap(ToolHandleArray<GenericMonitoringTool> tools, const std::string& baseName, int nHist) {
143  std::vector<int> indexArray;
144  for ( int iHist=0; iHist<nHist; iHist++ ) {
145  std::string groupName = baseName + "_" + std::to_string(iHist);
146  indexArray.push_back(detail::findToolIndex(tools,groupName));
147  }
148  return indexArray;
149  }
150 
152  template<typename V,typename std::enable_if_t<!std::is_integral_v<V>>* =nullptr,typename...T>
153  std::vector<V> buildToolMap(ToolHandleArray<GenericMonitoringTool> tools, const std::string& baseName, int nHist, T... dimensions) {
154  std::vector<V> indexArray;
155  for ( int iHist=0; iHist<nHist; iHist++ ) {
156  std::string groupName = baseName + "_" + std::to_string(iHist);
157  indexArray.push_back(buildToolMap<typename V::value_type>(tools,groupName,dimensions...));
158  }
159  return indexArray;
160  }
161 
163  template<typename V,typename std::enable_if_t<std::is_integral_v<V>>* =nullptr>
164  std::map<std::string,int> buildToolMap(ToolHandleArray<GenericMonitoringTool> tools, const std::string& baseName, const std::vector<std::string>& labels) {
165  std::map<std::string,int> indexMap;
166  for ( const std::string& label : labels ) {
167  std::string groupName = baseName + "_" + label;
169  }
170  return indexMap;
171  }
172 
174  template<typename V,typename std::enable_if_t<!std::is_integral_v<V>>* =nullptr,typename...T>
175  std::map<std::string,V> buildToolMap(ToolHandleArray<GenericMonitoringTool> tools, const std::string& baseName, const std::vector<std::string>& labels, T... dimensions) {
176  std::map<std::string,V> indexMap;
177  for ( const std::string& label : labels ) {
178  std::string groupName = baseName + "_" + label;
179  indexMap[label] = buildToolMap<typename V::mapped_type>(tools,groupName,dimensions...);
180  }
181  return indexMap;
182  }
183 
184 } // namespace Monitored
185 
186 #endif /* AthenaMonitoringKernel_MonitoredGroup_h */
beamspotman.r
def r
Definition: beamspotman.py:676
Monitored::Group::m_autoFill
bool m_autoFill
Definition: MonitoredGroup.h:117
checkCoolLatestUpdate.variables
variables
Definition: checkCoolLatestUpdate.py:13
Monitored::Group::m_monitoredGroup
const std::vector< std::reference_wrapper< IMonitoredVariable > > m_monitoredGroup
Definition: MonitoredGroup.h:118
IMonitoredVariable.h
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
RunTileMonitoring.groupName
groupName
Definition: RunTileMonitoring.py:158
skel.it
it
Definition: skel.GENtoEVGEN.py:396
Monitored::Group
Group of local monitoring quantities and retain correlation when filling histograms
Definition: MonitoredGroup.h:54
detail
Definition: extract_histogram_tag.cxx:14
Monitored::Group::Group
Group(const ToolHandle< GenericMonitoringTool > &tool, T &&... monitoredGroup)
Group of monitored variables.
Definition: MonitoredGroup.h:66
GenericMonitoringTool.h
beamspotnt.labels
list labels
Definition: bin/beamspotnt.py:1447
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
Monitored::Group::m_tool
ToolHandle< GenericMonitoringTool > m_tool
Definition: MonitoredGroup.h:116
Monitored::Group::Group
Group(const ToolHandle< GenericMonitoringTool > &tool, const std::vector< std::reference_wrapper< IMonitoredVariable >> &monitoredGroup)
Definition: MonitoredGroup.h:72
Monitored::fill
void fill(const ToolHandle< GenericMonitoringTool > &tool, T &&... variables)
Definition: MonitoredGroup.h:122
HistogramFiller.h
Monitored::Group::Group
Group(const ToolHandle< GenericMonitoringTool > &tool, std::vector< std::reference_wrapper< IMonitoredVariable >> &&monitoredGroup)
Definition: MonitoredGroup.h:78
tools
Definition: DataQuality/ZLumiScripts/python/tools/__init__.py:1
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:225
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
Monitored::Group::fill
void fill()
Explicitly fill the monitoring histograms and disable autoFill.
Definition: MonitoredGroup.h:100
Monitored::detail::findToolIndex
int findToolIndex(const ToolHandleArray< GenericMonitoringTool > &toolArray, const std::string &name)
Finds the index of an element in a tool handle array by its string name.
Definition: MonitoredGroup.h:132
Monitored::Group::~Group
~Group()
Definition: MonitoredGroup.h:84
Monitored::buildToolMap
std::vector< V > buildToolMap(ToolHandleArray< GenericMonitoringTool > tools, const std::string &baseName, int nHist)
Builds an array of indices (base case)
Definition: MonitoredGroup.h:142
Monitored::Group::setAutoFill
void setAutoFill(bool isEnabled)
enables/disables filling when Monitored::Group leaves the scope
Definition: MonitoredGroup.h:113
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54