ATLAS Offline Software
Classes | Public Member Functions | Public Attributes | Private Types | Private Attributes | List of all members
GenericMonitoringTool Class Reference

#include <GenericMonitoringTool.h>

Inheritance diagram for GenericMonitoringTool:
Collaboration diagram for GenericMonitoringTool:

Classes

class  GenericMonitoringArray
 
class  GenericMonitoringTool
 

Public Member Functions

virtual ~GenericMonitoringTool () override
 
virtual StatusCode initialize () override
 
virtual StatusCode start () override
 
virtual StatusCode stop () override
 
void handle (const Incident &) override
 
void invokeFillers (const std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &monitoredVariables) const
 feed the fillers More...
 
StatusCode book ()
 Book histograms. More...
 
void setPath (const std::string &newPath)
 Overrride configured booking path. More...
 
const std::string & getPath () const
 
virtual const ServiceHandle< ITHistSvc > & histogramService () const
 
virtual uint32_t runNumber ()
 
virtual uint32_t lumiBlock ()
 

Public Attributes

 log = logging.getLogger(__name__)
 

Private Types

using fillerCache_t = CxxUtils::ConcurrentStrToValMap< std::vector< std::shared_ptr< Monitored::HistogramFiller > >, CxxUtils::SimpleUpdater >
 

Private Attributes

ServiceHandle< ITHistSvc > m_histSvc { this, "THistSvc", "THistSvc", "Histogramming svc" }
 THistSvc (do NOT fix the service type (only the name) to allow for a different implementation online. More...
 
Gaudi::Property< std::string > m_histoPath { this, "HistPath", {}, "Directory for histograms [name of parent if not set]" }
 
Gaudi::Property< std::vector< std::string > > m_histograms { this, "Histograms", {}, "Definitions of histograms", "OrderedSet<std::string>"}
 
Gaudi::Property< bool > m_explicitBooking { this, "ExplicitBooking", false, "Do not create histograms automatically in initialize but wait until the method book is called." }
 
Gaudi::Property< bool > m_failOnEmpty { this, "FailOnEmpty", true, "Fail in initialize() if no histograms defined" }
 
BooleanProperty m_useCache { this, "UseCache", true, "Cache filler lookups" }
 
BooleanProperty m_registerHandler { this, "RegisterHandler", true, "Use incident handler to make 'always book' plots (else only check once)" }
 
std::vector< std::shared_ptr< Monitored::HistogramFiller > > m_fillers
 plain list of fillers More...
 
std::vector< std::shared_ptr< Monitored::HistogramFiller > > m_alwaysCreateFillers
 fillers that need touching, usually empty More...
 
fillerCache_t m_fillerCacheMap ATLAS_THREAD_SAFE {fillerCache_t::Updater_t()}
 lookup map to speed up filler searches More...
 

Detailed Description

Definition at line 51 of file GenericMonitoringTool.h.

Member Typedef Documentation

◆ fillerCache_t

using GenericMonitoringTool::fillerCache_t = CxxUtils::ConcurrentStrToValMap<std::vector<std::shared_ptr<Monitored::HistogramFiller> >, CxxUtils::SimpleUpdater>
private

Definition at line 86 of file GenericMonitoringTool.h.

Constructor & Destructor Documentation

◆ ~GenericMonitoringTool()

GenericMonitoringTool::~GenericMonitoringTool ( )
overridevirtual

Definition at line 21 of file GenericMonitoringTool.cxx.

21 { }

Member Function Documentation

◆ book()

StatusCode GenericMonitoringTool::book ( )

Book histograms.

Definition at line 54 of file GenericMonitoringTool.cxx.

54  {
55 
56  // If no histogram path given use parent or our own name
57  if (m_histoPath.empty()) {
58  auto named = dynamic_cast<const INamedInterface*>(parent());
59  m_histoPath = named ? named->name() : name();
60  }
61 
62  // Replace dot (e.g. MyAlg.MyTool) with slash to create sub-directory
63  std::replace( m_histoPath.begin(), m_histoPath.end(), '.', '/' );
64 
65  ATH_MSG_DEBUG("Booking histograms in path: " << m_histoPath.value());
66 
67  HistogramFillerFactory factory(this, m_histoPath);
68 
69  for (const std::string& item : m_histograms) {
70  if (item.empty()) {
71  ATH_MSG_DEBUG( "Skipping empty histogram definition" );
72  continue;
73  }
74  ATH_MSG_DEBUG( "Configuring monitoring for: " << item );
76 
77  if (def.ok) {
78  std::shared_ptr<HistogramFiller> filler(factory.create(def));
79 
80  if (filler) {
81  if (def.kAlwaysCreate) {
82  if (m_registerHandler) {
83  m_alwaysCreateFillers.push_back(filler); // prepare list of fillers for handler
84  } else {
85  filler->touch(); // create now and be done with it
86  }
87  }
88  m_fillers.push_back(std::move(filler));
89  } else {
90  ATH_MSG_WARNING( "The histogram filler cannot be instantiated for: " << def.name );
91  }
92  } else {
93  ATH_MSG_ERROR( "Unparsable histogram definition: " << item );
94  return StatusCode::FAILURE;
95  }
96  ATH_MSG_DEBUG( "Monitoring for variable " << def.name << " prepared" );
97  }
98 
99  if ( m_fillers.empty() && m_failOnEmpty ) {
100  std::string hists;
101  for (const auto &h : m_histograms) hists += (h+",");
102  ATH_MSG_ERROR("No monitored variables created based on histogram definition: [" << hists <<
103  "] Remove this monitoring tool or check its configuration.");
104  return StatusCode::FAILURE;
105  }
106 
107  // are there some histograms that should always be made?
108  // then register to be notified on every event
109  if (! m_alwaysCreateFillers.empty() && m_registerHandler) {
110  ATH_MSG_DEBUG("Registering incident handler");
111  SmartIF<IIncidentSvc> incSvc{service("IncidentSvc")};
112  ATH_CHECK(incSvc.isValid());
113  incSvc->addListener(this, IncidentType::BeginEvent);
114  }
115 
116  return StatusCode::SUCCESS;
117 }

◆ getPath()

const std::string& GenericMonitoringTool::getPath ( ) const
inline

Definition at line 68 of file GenericMonitoringTool.h.

68 { return m_histoPath; }

◆ handle()

void GenericMonitoringTool::handle ( const Incident &  )
override

Definition at line 48 of file GenericMonitoringTool.cxx.

48  {
49  for (const auto& filler : m_alwaysCreateFillers) {
50  filler->touch();
51  }
52 }

◆ histogramService()

virtual const ServiceHandle<ITHistSvc>& GenericMonitoringTool::histogramService ( ) const
inlinevirtual

Definition at line 70 of file GenericMonitoringTool.h.

70 { return m_histSvc; }

◆ initialize()

StatusCode GenericMonitoringTool::initialize ( )
overridevirtual

Definition at line 23 of file GenericMonitoringTool.cxx.

23  {
24  ATH_CHECK(m_histSvc.retrieve());
25  return StatusCode::SUCCESS;
26 }

◆ invokeFillers()

void GenericMonitoringTool::invokeFillers ( const std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &  monitoredVariables) const

feed the fillers

Definition at line 164 of file GenericMonitoringTool.cxx.

164  {
165  // This is the list of fillers to consider in the invocation.
166  // If we are using the cache then this may be a proper subset of m_fillers; otherwise will just be m_fillers
167  const std::vector<std::shared_ptr<Monitored::HistogramFiller>>* fillerList{&m_fillers};
168  // pointer to list of matched fillers, if we need to update the cache (default doesn't create the vector)
169  std::vector<std::shared_ptr<Monitored::HistogramFiller>>* matchedFillerList{nullptr};
170  if (m_useCache) {
171  const auto match = m_fillerCacheMap.find(fillerKey(monitoredVariables));
172  if (match != m_fillerCacheMap.end()) {
173  fillerList = &match->second;
174  } else {
175  // make new cache entry
176  matchedFillerList = new std::vector<std::shared_ptr<Monitored::HistogramFiller>>;
177  }
178  }
179 
180  for ( auto filler: *fillerList ) {
181  const int fillerCardinality = filler->histogramVariablesNames().size() + (filler->histogramWeightName().empty() ? 0: 1) + (filler->histogramCutMaskName().empty() ? 0 : 1);
182 
183  if ( fillerCardinality == 1 ) { // simplest case, optimising this to be super fast
184  for ( auto& var: monitoredVariables ) {
185  if ( var.get().name().compare( filler->histogramVariablesNames()[0] ) == 0 ) {
186  {
187  auto guard{filler->getLock()};
188  filler->fill({&var.get()});
189  }
190  if (matchedFillerList) {
191  matchedFillerList->push_back(std::move(filler));
192  }
193  break;
194  }
195  }
196  } else { // a more complicated case, and cuts or weights
197  int matchesCount = 0;
199  for ( const auto& var: monitoredVariables ) {
200  bool matched = false;
201  for ( unsigned fillerVarIndex = 0; fillerVarIndex < filler->histogramVariablesNames().size(); ++fillerVarIndex ) {
202  if ( var.get().name().compare( filler->histogramVariablesNames()[fillerVarIndex] ) == 0 ) {
203  vars.set(fillerVarIndex, &var.get());
204  matched = true;
205  matchesCount++;
206  break;
207  }
208  }
209  if ( matchesCount == fillerCardinality ) break;
210  if ( not matched ) { // may be a weight or cut variable still
211  if ( var.get().name().compare( filler->histogramWeightName() ) == 0 ) {
212  vars.weight = &var.get();
213  matchesCount ++;
214  } else if ( var.get().name().compare( filler->histogramCutMaskName() ) == 0 ) {
215  vars.cut = &var.get();
216  matchesCount++;
217  }
218  }
219  if ( matchesCount == fillerCardinality ) break;
220  }
221  if ( matchesCount == fillerCardinality ) {
222  {
223  auto guard{filler->getLock()};
224  filler->fill( vars );
225  }
226  if (matchedFillerList) {
227  matchedFillerList->push_back(std::move(filler));
228  }
229  } else if ( ATH_UNLIKELY( msgLvl(MSG::DEBUG) && matchesCount != 0 ) ) { // something has matched, but not all, worth informing user
230  invokeFillersDebug(msg(), vars, filler, monitoredVariables);
231  }
232  }
233  }
234 
235  if (matchedFillerList) {
236  // We may hit this multiple times. If another thread has updated the cache in the meanwhile,
237  // nothing will be done here.
238  m_fillerCacheMap.emplace(fillerKey(monitoredVariables), std::move(*matchedFillerList));
239  }
240 }

◆ lumiBlock()

uint32_t GenericMonitoringTool::lumiBlock ( )
virtual

Definition at line 246 of file GenericMonitoringTool.cxx.

246  {
247  return Gaudi::Hive::currentContext().eventID().lumi_block();
248 }

◆ runNumber()

uint32_t GenericMonitoringTool::runNumber ( )
virtual

Definition at line 242 of file GenericMonitoringTool.cxx.

242  {
243  return Gaudi::Hive::currentContext().eventID().run_number();
244 }

◆ setPath()

void GenericMonitoringTool::setPath ( const std::string &  newPath)
inline

Overrride configured booking path.

Definition at line 67 of file GenericMonitoringTool.h.

67 { m_histoPath = newPath; }

◆ start()

StatusCode GenericMonitoringTool::start ( )
overridevirtual

Definition at line 28 of file GenericMonitoringTool.cxx.

28  {
29  if ( not m_explicitBooking ) {
30  ATH_MSG_DEBUG("Proceeding to histogram booking");
31  return book();
32  }
33  return StatusCode::SUCCESS;
34 }

◆ stop()

StatusCode GenericMonitoringTool::stop ( )
overridevirtual

Definition at line 36 of file GenericMonitoringTool.cxx.

36  {
37  m_alwaysCreateFillers.clear();
38  m_fillers.clear();
39  if (m_registerHandler) {
40  ATH_MSG_DEBUG("Deregistering incident handler");
41  SmartIF<IIncidentSvc> incSvc{service("IncidentSvc")};
42  ATH_CHECK(incSvc.isValid());
43  incSvc->removeListener(this, IncidentType::BeginEvent);
44  }
45  return StatusCode::SUCCESS;
46 }

Member Data Documentation

◆ ATLAS_THREAD_SAFE

fillerCache_t m_fillerCacheMap GenericMonitoringTool::ATLAS_THREAD_SAFE {fillerCache_t::Updater_t()}
mutableprivate

lookup map to speed up filler searches

Definition at line 87 of file GenericMonitoringTool.h.

◆ log

GenericMonitoringTool.log = logging.getLogger(__name__)

Definition at line 9 of file GenericMonitoringTool.py.

◆ m_alwaysCreateFillers

std::vector<std::shared_ptr<Monitored::HistogramFiller> > GenericMonitoringTool::m_alwaysCreateFillers
private

fillers that need touching, usually empty

Definition at line 85 of file GenericMonitoringTool.h.

◆ m_explicitBooking

Gaudi::Property<bool> GenericMonitoringTool::m_explicitBooking { this, "ExplicitBooking", false, "Do not create histograms automatically in initialize but wait until the method book is called." }
private

Definition at line 79 of file GenericMonitoringTool.h.

◆ m_failOnEmpty

Gaudi::Property<bool> GenericMonitoringTool::m_failOnEmpty { this, "FailOnEmpty", true, "Fail in initialize() if no histograms defined" }
private

Definition at line 80 of file GenericMonitoringTool.h.

◆ m_fillers

std::vector<std::shared_ptr<Monitored::HistogramFiller> > GenericMonitoringTool::m_fillers
private

plain list of fillers

Definition at line 84 of file GenericMonitoringTool.h.

◆ m_histograms

Gaudi::Property<std::vector<std::string> > GenericMonitoringTool::m_histograms { this, "Histograms", {}, "Definitions of histograms", "OrderedSet<std::string>"}
private

Definition at line 78 of file GenericMonitoringTool.h.

◆ m_histoPath

Gaudi::Property<std::string> GenericMonitoringTool::m_histoPath { this, "HistPath", {}, "Directory for histograms [name of parent if not set]" }
private

Definition at line 77 of file GenericMonitoringTool.h.

◆ m_histSvc

ServiceHandle<ITHistSvc> GenericMonitoringTool::m_histSvc { this, "THistSvc", "THistSvc", "Histogramming svc" }
private

THistSvc (do NOT fix the service type (only the name) to allow for a different implementation online.

Definition at line 76 of file GenericMonitoringTool.h.

◆ m_registerHandler

BooleanProperty GenericMonitoringTool::m_registerHandler { this, "RegisterHandler", true, "Use incident handler to make 'always book' plots (else only check once)" }
private

Definition at line 82 of file GenericMonitoringTool.h.

◆ m_useCache

BooleanProperty GenericMonitoringTool::m_useCache { this, "UseCache", true, "Cache filler lookups" }
private

Definition at line 81 of file GenericMonitoringTool.h.


The documentation for this class was generated from the following files:
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
GenericMonitoringTool::m_useCache
BooleanProperty m_useCache
Definition: GenericMonitoringTool.h:81
beamspotnt.var
var
Definition: bin/beamspotnt.py:1393
GenericMonitoringTool::m_histoPath
Gaudi::Property< std::string > m_histoPath
Definition: GenericMonitoringTool.h:77
parse
std::map< std::string, std::string > parse(const std::string &list)
Definition: egammaLayerRecalibTool.cxx:1113
GenericMonitoringTool::m_alwaysCreateFillers
std::vector< std::shared_ptr< Monitored::HistogramFiller > > m_alwaysCreateFillers
fillers that need touching, usually empty
Definition: GenericMonitoringTool.h:85
GenericMonitoringTool::m_histograms
Gaudi::Property< std::vector< std::string > > m_histograms
Definition: GenericMonitoringTool.h:78
Monitored::HistogramFiller::VariablesPack::cut
const Monitored::IMonitoredVariable * cut
pointer to cut mask variable, typically absent
Definition: HistogramFiller.h:113
GenericMonitoringTool::m_registerHandler
BooleanProperty m_registerHandler
Definition: GenericMonitoringTool.h:82
ATH_UNLIKELY
#define ATH_UNLIKELY(x)
Definition: AthUnlikelyMacros.h:17
GenericMonitoringTool::book
StatusCode book()
Book histograms.
Definition: GenericMonitoringTool.cxx:54
Monitored::HistogramDef
the internal class used to keep parsed Filler properties
Definition: HistogramDef.h:15
Monitored::HistogramFiller::VariablesPack::set
void set(unsigned index, const IMonitoredVariable *ptr)
sets monitored variable at the index (may need to resize vector of variables)
Definition: HistogramFiller.h:94
Monitored::HistogramDef::ok
bool ok
good declaration: parsing or copying successful
Definition: HistogramDef.h:77
GenericMonitoringTool::m_explicitBooking
Gaudi::Property< bool > m_explicitBooking
Definition: GenericMonitoringTool.h:79
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
Monitored::HistogramFiller::VariablesPack::weight
const Monitored::IMonitoredVariable * weight
pointer to weight variable, typically absent
Definition: HistogramFiller.h:112
Monitored::HistogramFiller::VariablesPack
helper class to pass variables to fillers
Definition: HistogramFiller.h:72
GenericMonitoringTool::m_failOnEmpty
Gaudi::Property< bool > m_failOnEmpty
Definition: GenericMonitoringTool.h:80
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
h
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Monitored::HistogramDef::name
std::vector< std::string > name
names of monitored variables
Definition: HistogramDef.h:16
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MakeTH3DFromTH2Ds.hists
hists
Definition: MakeTH3DFromTH2Ds.py:72
Monitored::HistogramFillerFactory
Factory of the histogram fillers.
Definition: HistogramFillerFactory.h:22
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DEBUG
#define DEBUG
Definition: page_access.h:11
Monitored::HistogramDef::kAlwaysCreate
bool kAlwaysCreate
always create this histogram, even if never filled
Definition: HistogramDef.h:52
GenericMonitoringTool::m_fillers
std::vector< std::shared_ptr< Monitored::HistogramFiller > > m_fillers
plain list of fillers
Definition: GenericMonitoringTool.h:84
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
match
bool match(std::string s1, std::string s2)
match the individual directories of two strings
Definition: hcg.cxx:356
GenericMonitoringTool::m_histSvc
ServiceHandle< ITHistSvc > m_histSvc
THistSvc (do NOT fix the service type (only the name) to allow for a different implementation online.
Definition: GenericMonitoringTool.h:76