ATLAS Offline Software
Algorithm.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 // Please feel free to contact me (krumnack@iastate.edu) for bug
11 // reports, feature suggestions, praise and complaints.
12 
13 
14 //
15 // includes
16 //
17 
18 #include <EventLoop/Algorithm.h>
19 
20 #include <EventLoop/StatusCode.h>
21 #include <EventLoop/Worker.h>
22 #include <RootCoreUtils/Assert.h>
23 #include <RootCoreUtils/ThrowMsg.h>
24 #include <TH1.h>
25 
26 #include <AsgMessaging/MsgLevel.h>
27 #include <AsgMessaging/MsgStream.h>
28 
29 //
30 // method implementations
31 //
32 
34 
35 namespace EL
36 {
37  void Algorithm ::
38  testInvariant () const
39  {
40  RCU_INVARIANT (this != 0);
41  }
42 
43 
44 
45  IWorker *Algorithm ::
46  wk () const
47  {
48  RCU_READ_INVARIANT (this);
49  return m_wk;
50  }
51 
52 
53 
54  void Algorithm ::
55  book (const TH1& hist)
56  {
57  RCU_CHANGE_INVARIANT (this);
58  wk()->addOutput (hist.Clone());
59  }
60 
61 
62 
63  TH1 *Algorithm ::
64  hist (const std::string& name) const
65  {
66  RCU_READ_INVARIANT (this);
67  return dynamic_cast<TH1*>(wk()->getOutputHist (name));
68  }
69 
70 
71 
73  Algorithm ()
74  : m_wk (0)
75  {
76  RCU_NEW_INVARIANT (this);
77  }
78 
79 
80 
82  ~Algorithm ()
83  {
84  delete m_msg;
85  }
86 
87 
88 
90  evtStore() const
91  {
92  RCU_CHANGE_INVARIANT (this);
93  if (m_evtStorePtr)
94  return m_evtStorePtr;
95  m_evtStore = asg::SgTEvent (wk()->xaodEvent(), wk()->xaodStore());
97  return m_evtStorePtr;
98  }
99 
100 
101 
102  MsgStream& Algorithm ::
103  msg () const
104  {
105  RCU_READ_INVARIANT (this);
106  if (m_msg == 0 || m_msgName != GetName())
107  {
108  delete m_msg;
109  m_msg = nullptr;
110  m_msgName = GetName();
111  std::string name;
112  if (m_msgName.empty())
113  name = "UnnamedAlgorithm";
114  else
115  name = m_msgName;
116  m_msg = new MsgStream (name);
117  m_msg->setLevel (MSG::Level (m_msgLevel));
118  }
119  return *m_msg;
120  }
121 
122 
123 
124  MsgStream& Algorithm ::
125  msg (int level) const
126  {
127  RCU_READ_INVARIANT (this);
128  MsgStream& result = msg ();
129  result << MSG::Level (level);
130  return result;
131  }
132 
133 
134 
135  bool Algorithm ::
136  msgLvl (int lvl) const
137  {
138  RCU_READ_INVARIANT (this);
139  return m_msgLevel <= lvl;
140  }
141 
142 
143 
144  void Algorithm ::
145  setMsgLevel (int level)
146  {
147  RCU_READ_INVARIANT (this);
148  if (m_msg)
149  m_msg->setLevel (MSG::Level (level));
150  m_msgLevel = level;
151  }
152 
153 
154 
156  setupJob (Job& /*job*/)
157  {
158  RCU_CHANGE_INVARIANT (this);
159  return StatusCode::SUCCESS;
160  }
161 
162 
163 
165  fileExecute ()
166  {
167  RCU_CHANGE_INVARIANT (this);
168  return StatusCode::SUCCESS;
169  }
170 
171 
172 
174  endOfFile ()
175  {
176  RCU_CHANGE_INVARIANT (this);
177  return StatusCode::SUCCESS;
178  }
179 
180 
181 
183  changeInput (bool /*firstFile*/)
184  {
185  RCU_CHANGE_INVARIANT (this);
186  return StatusCode::SUCCESS;
187  }
188 
189 
190 
192  initialize ()
193  {
194  RCU_CHANGE_INVARIANT (this);
195  return StatusCode::SUCCESS;
196  }
197 
198 
199 
202  {
203  RCU_CHANGE_INVARIANT (this);
204  return StatusCode::SUCCESS;
205  }
206 
207 
208 
210  execute ()
211  {
212  RCU_CHANGE_INVARIANT (this);
213  return StatusCode::SUCCESS;
214  }
215 
216 
217 
219  postExecute ()
220  {
221  RCU_CHANGE_INVARIANT (this);
222  return StatusCode::SUCCESS;
223  }
224 
225 
226 
228  finalize ()
229  {
230  RCU_CHANGE_INVARIANT (this);
231  return StatusCode::SUCCESS;
232  }
233 
234 
235 
237  histFinalize ()
238  {
239  RCU_CHANGE_INVARIANT (this);
240  return StatusCode::SUCCESS;
241  }
242 
243 
244 
245  bool Algorithm ::
246  hasName (const std::string& name) const
247  {
248  RCU_CHANGE_INVARIANT (this);
249  return GetName() == name;
250  }
251 
252 
253 
254  void Algorithm ::
255  sysSetupJob (Job& job)
256  {
257  RCU_CHANGE_INVARIANT (this);
258  if (setupJob (job) != StatusCode::SUCCESS)
259  RCU_THROW_MSG ("Algorithm::setupJob returned StatusCode::FAILURE");
260  }
261 
262 
263 
264  const std::string& Algorithm ::
265  name() const
266  {
267  RCU_CHANGE_INVARIANT (this);
268  m_nameCache = GetName();
269  return m_nameCache;
270  }
271 }
EL::Algorithm::sysSetupJob
void sysSetupJob(Job &job)
effects: give the algorithm a chance to intialize the job with anything this algorithm needs.
EL::Algorithm::fileExecute
virtual StatusCode fileExecute()
effects: do all the processing that needs to be done once per file
EL::Algorithm::testInvariant
void testInvariant() const
effects: test the invariant of this object guarantee: no-fail
get_generator_info.result
result
Definition: get_generator_info.py:21
EL::Algorithm::setMsgLevel
void setMsgLevel(int level)
set the message level for the message stream for this object
EL::Algorithm::execute
virtual StatusCode execute()
effects: process the next event guarantee: basic failures: algorithm dependent
plotmaker.hist
hist
Definition: plotmaker.py:148
EL::Algorithm::m_msgName
std::string m_msgName
the algorithm name for which the message stream has been instantiated
Definition: Algorithm.h:338
EL::IHistogramWorker::addOutput
virtual void addOutput(TObject *output_swallow)=0
effects: add an object to the output.
EL::Algorithm::msgLvl
bool msgLvl(int lvl) const
whether we are configured to print messages at the given level
EL::Algorithm::m_evtStorePtr
asg::SgTEvent * m_evtStorePtr
the value of evtStore
Definition: Algorithm.h:325
EL::Algorithm::postExecute
virtual StatusCode postExecute()
effects: do the post-processing for the event guarantee: basic failures: algorithm dependent rational...
EL::Algorithm::hist
TH1 * hist(const std::string &name) const
get the histogram with the given name
Assert.h
EL::Algorithm::changeInput
virtual StatusCode changeInput(bool firstFile)
effects: do all changes to work with a new input file, e.g.
EL::Algorithm::finalize
virtual StatusCode finalize()
effects: do everything that needs to be done after completing work on this worker guarantee: basic fa...
python.iconfTool.models.loaders.level
level
Definition: loaders.py:20
EL::Algorithm::m_msg
MsgStream * m_msg
the message stream, if it has been instantiated
Definition: Algorithm.h:333
EL::Algorithm::evtStore
asg::SgTEvent * evtStore() const
get the (main) event store for this algorithm
TrigConf::MSGTC::Level
Level
Definition: Trigger/TrigConfiguration/TrigConfBase/TrigConfBase/MsgStream.h:21
EL::IHistogramWorker::getOutputHist
virtual TObject * getOutputHist(const std::string &name) const =0
get the output histogram with the given name
EL::Algorithm
Definition: Algorithm.h:22
EL::Algorithm::m_nameCache
std::string m_nameCache
the cache for name
Definition: Algorithm.h:346
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Algorithm.h
EL::Algorithm::initialize
virtual StatusCode initialize()
effects: do everything that needs to be done before running the algorithm, e.g.
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
EL::Algorithm::wk
IWorker * wk() const
description: the worker that is controlling us guarantee: no-fail
EL::Algorithm::name
virtual const std::string & name() const
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
EL::Algorithm::msg
MsgStream & msg() const
messaging interface
EL::Algorithm::m_msgLevel
int m_msgLevel
the message level configured
Definition: Algorithm.h:342
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ThrowMsg.h
asg::SgTEvent
Wrapper for TEvent to make it look like StoreGate.
Definition: SgTEvent.h:44
EL::Algorithm::Algorithm
Algorithm()
effects: standard default constructor guarantee: strong failures: low level errors I
EL::Algorithm::~Algorithm
~Algorithm()
effects: standard destructor guarantee: no-fail
EL::Algorithm::m_wk
IWorker * m_wk
Definition: Algorithm.h:321
EL::Algorithm::histInitialize
virtual StatusCode histInitialize()
effects: this is a pre-initialization routine that is called before changeInput is called.
EL::Algorithm::book
void book(const TH1 &hist)
book the given histogram
MsgLevel.h
Definition of message levels and a helper function.
Worker.h
StatusCode.h
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
EL::Algorithm::hasName
virtual bool hasName(const std::string &name) const
returns: whether this algorithm has the given name guarantee: basic failures: algorithm dependent rat...
EL::Algorithm::histFinalize
virtual StatusCode histFinalize()
effects: this is a post-initialization routine that is called after finalize has been called.
EL::Algorithm::endOfFile
virtual StatusCode endOfFile()
effects: do the post-processing for each input file guarantee: basic failures: algorithm dependent ra...
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
test_interactive_athena.job
job
Definition: test_interactive_athena.py:6
EL::Algorithm::setupJob
virtual StatusCode setupJob(Job &job)
effects: give the algorithm a chance to intialize the job with anything this algorithm needs.
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
ClassImp
ClassImp(EL::Algorithm) namespace EL
Definition: Algorithm.cxx:33
EL::Algorithm::m_evtStore
asg::SgTEvent m_evtStore
when configured, the object returned by evtStore
Definition: Algorithm.h:329
MsgStream.h
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233