ATLAS Offline Software
MonitoredAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "MonitoredAlg.h"
7 
8 #include <vector>
9 #include <cmath>
10 
11 MonitoredAlg::MonitoredAlg(const std::string& name, ISvcLocator* pSvcLocator) :
12  AthAlgorithm(name, pSvcLocator)
13 {
14 }
15 
17 {
18  // Only try to retrieve the tool if one has been set
19  if (!m_monTool.empty()) CHECK(m_monTool.retrieve());
20 
21  return StatusCode::SUCCESS;
22 }
23 
25 class Track {
26 public:
27  Track(double eta, double phi, double pt) : m_eta(eta), m_phi(phi), m_pt(pt) {}
28  double eta() const { return m_eta; }
29  double phi() const { return m_phi; }
30  double pt() const { return m_pt; }
31 private:
32  double m_eta{0}, m_phi{0}, m_pt{0};
33 };
34 
35 
37 {
38  std::vector<Track> tracks;
39 
40  // In case you want to measure the execution time
41  auto timer = Monitored::Timer("TIME_execute");
42 
43  auto count = Monitored::Scalar<int>("nTracks", 0); // explicit type
44 
45  // Access via member
46  auto eta = Monitored::Collection("eta", tracks, &Track::eta);
47 
48  // Access via function/lambda
49  auto absphi = Monitored::Collection("AbsPhi", tracks, []( const Track& t ) { return abs(t.phi()); });
50 
51  auto mon = Monitored::Group(m_monTool, count, eta, absphi, timer);
52 
53  count = 1 + (rand() % 10); // random number of tracks
54 
55  // Creating some random tracks
56  for (int i=0; i<count; ++i) {
57  tracks.push_back(Track(-3.0 + 6.0*rand()/static_cast<float>(RAND_MAX),
58  -M_PI + 2*M_PI*rand()/static_cast<float>(RAND_MAX),
59  100.0*rand()/static_cast<float>(RAND_MAX)));
60  }
61 
62  return StatusCode::SUCCESS;
63 }
64 
65 
66 
MonitoredAlg::initialize
StatusCode initialize()
Definition: MonitoredAlg.cxx:16
TrigDefs::Group
Group
Properties of a chain group.
Definition: GroupProperties.h:13
Track::m_eta
double m_eta
Definition: MonitoredAlg.cxx:32
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
xAOD::JetInput::Track
@ Track
Definition: JetContainerInfo.h:61
M_PI
#define M_PI
Definition: ActiveFraction.h:11
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
python.utils.AtlRunQueryTimer.timer
def timer(name, disabled=False)
Definition: AtlRunQueryTimer.py:86
Track::m_phi
double m_phi
Definition: MonitoredAlg.cxx:32
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
MonitoredAlg::MonitoredAlg
MonitoredAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: MonitoredAlg.cxx:11
LArG4FSStartPointFilter.rand
rand
Definition: LArG4FSStartPointFilter.py:80
lumiFormat.i
int i
Definition: lumiFormat.py:85
Track::m_pt
double m_pt
Definition: MonitoredAlg.cxx:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Track::Track
Track(double eta, double phi, double pt)
Definition: MonitoredAlg.cxx:27
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
AthAlgorithm
Definition: AthAlgorithm.h:47
Track::phi
double phi() const
Definition: MonitoredAlg.cxx:29
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:225
MonitoredAlg::execute
StatusCode execute()
Definition: MonitoredAlg.cxx:36
MonitoredAlg.h
plotBeamSpotMon.mon
mon
Definition: plotBeamSpotMon.py:67
MonitoredAlg::m_monTool
ToolHandle< GenericMonitoringTool > m_monTool
Definition: MonitoredAlg.h:22
Track::eta
double eta() const
Definition: MonitoredAlg.cxx:28
Track
Definition: TriggerChamberClusterOnTrackCreator.h:21
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
Monitored::Timer
A monitored timer.
Definition: MonitoredTimer.h:32
Track::pt
double pt() const
Definition: MonitoredAlg.cxx:30