ATLAS Offline Software
FormulaSvc.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 // includes
15 //
16 
17 #include <MultiDraw/FormulaSvc.h>
18 
19 #include <memory>
20 #include <sstream>
21 #include <TTree.h>
22 #include <TTreeFormula.h>
23 #include <TTreeFormulaManager.h>
24 #include <EventLoop/Job.h>
25 #include <EventLoop/StatusCode.h>
26 #include <EventLoop/IWorker.h>
27 #include <MultiDraw/Formula.h>
28 #include <RootCoreUtils/Assert.h>
29 #include <RootCoreUtils/ThrowMsg.h>
30 
31 //
32 // method implementations
33 //
34 
36 
37 namespace MD
38 {
39  //
40  // legacy implementations
41  //
42 
43  const std::string FormulaSvc::name = "MultiDraw";
44 
45 
46 
47  std::string dbg (const FormulaSvc& /*obj*/, unsigned /*verbosity*/)
48  {
49  return "FormulaSvc";
50  }
51 
52 
53 
54  void useFormulas (EL::Job& job)
55  {
56  if (!job.algsHas (FormulaSvc::name))
57  job.algsAdd (new FormulaSvc);
58  }
59 
60 
61 
62  FormulaSvc *formulas (EL::IWorker *worker)
63  {
64  RCU_REQUIRE_SOFT (worker != 0);
65 
66  FormulaSvc *const svc
67  = dynamic_cast<FormulaSvc*>(worker->getAlg (FormulaSvc::name));
68  if (svc == 0)
69  RCU_THROW_MSG ("Job not configured for FormulaSvc support");
70  return svc;
71  }
72 
73 
74 
75  void FormulaSvc ::
76  testInvariant () const
77  {
78  RCU_INVARIANT (this != 0);
79 
80  for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
81  {
82  RCU_INVARIANT (m_vars[form] != 0);
83  }
84  }
85 
86 
87 
89  FormulaSvc ()
90  : m_tree (0)
91  {
92  RCU_NEW_INVARIANT (this);
93  }
94 
95 
96 
98  ~FormulaSvc ()
99  {
100  RCU_DESTROY_INVARIANT (this);
101 
102  for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
103  {
104  delete m_vars[form];
105  }
106  }
107 
108 
109 
110  const Formula *FormulaSvc ::
111  addForm (const std::string& formula)
112  {
113  RCU_CHANGE_INVARIANT (this);
114  RCU_REQUIRE_SOFT (!formula.empty());
115 
116  for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
117  {
118  if (m_vars[form]->formula() == formula)
119  return m_vars[form];
120  }
121  RCU_ASSERT (m_tree != 0);
122  std::ostringstream name;
123  name << "var" << m_vars.size();
124  m_vars.push_back (new Formula (name.str(), formula, m_tree));
125  return m_vars.back();
126  }
127 
128 
129 
130  const char *FormulaSvc ::
131  GetName () const
132  {
133  RCU_READ_INVARIANT (this);
134  return name.c_str();
135  }
136 
137 
138 
140  changeInput (bool /*firstFile*/)
141  {
142  RCU_CHANGE_INVARIANT (this);
143 
144  m_tree = 0;
145 
146  try
147  {
148  m_tree = wk()->tree();
149  m_tree->ResetBit (TTree::kForceRead);
150 
151  for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
152  m_vars[form]->reset (m_tree);
153  } catch (...)
154  {
155  m_tree = 0;
156  throw;
157  }
158 
159  return EL::StatusCode::SUCCESS;
160  }
161 
162 
163 
165  execute ()
166  {
167  RCU_CHANGE_INVARIANT (this);
168  if (wk()->treeEntry() != wk()->tree()->GetReadEvent())
169  wk()->tree()->LoadTree (wk()->treeEntry());
170  RCU_ASSERT (wk()->treeEntry() == wk()->tree()->GetReadEvent());
171  return EL::StatusCode::SUCCESS;
172  }
173 }
MD::FormulaSvc::GetName
virtual const char * GetName() const
effects: return the name of this algorithm guarantee: no-fail
EL::IWorker::getAlg
virtual EL::Algorithm * getAlg(const std::string &name) const =0
effects: returns the algorithms with the given name or NULL if there is none guarantee: strong failur...
MD
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition: AlgCFlow.h:31
MD::FormulaSvc::name
static const std::string name
description: the name of the service
Definition: FormulaSvc.h:61
Job.h
MD::FormulaSvc::~FormulaSvc
~FormulaSvc()
effects: standard destructor guarantee: no-fail
Formula.h
tree
TChain * tree
Definition: tile_monitor.h:30
MD::FormulaSvc::FormulaSvc
FormulaSvc()
effects: standard default constructor guarantee: no-fail
Assert.h
MD::dbg
std::string dbg(const FormulaSvc &obj, unsigned verbosity=0)
returns: the debugging info of this object guarantee: strong failures: out of memory II
MD::FormulaSvc::execute
virtual EL::StatusCode execute()
effects: process the next event guarantee: basic failures: algorithm dependent rationale: the virtual...
ClassImp
ClassImp(MD::FormulaSvc) namespace MD
Definition: FormulaSvc.cxx:35
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
MD::formulas
FormulaSvc * formulas(EL::IWorker *worker)
returns: the formula service for this worker guarantee: strong failures: formula service not configur...
RCU_REQUIRE_SOFT
#define RCU_REQUIRE_SOFT(x)
Definition: Assert.h:153
MD::FormulaSvc::testInvariant
void testInvariant() const
effects: test the invariant of this object guarantee: no-fail
MD::FormulaSvc::changeInput
virtual EL::StatusCode changeInput(bool firstFile)
effects: do all changes to work with a new input file, e.g.
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EL::IWorker
the interface for algorithms to access IWorker
Definition: IWorker.h:40
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
EL::Algorithm::wk
IWorker * wk() const
description: the worker that is controlling us guarantee: no-fail
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
MD::FormulaSvc::m_vars
std::vector< Formula * > m_vars
description: the list of variables used
Definition: FormulaSvc.h:131
ThrowMsg.h
MD::FormulaSvc::addForm
const Formula * addForm(const std::string &formula)
effects: add another formula returns: the formula guarantee: strong failures: out of memory II failur...
FormulaSvc.h
MD::FormulaSvc
Definition: FormulaSvc.h:54
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
MD::useFormulas
void useFormulas(EL::Job &job)
effects: register the formula service for this job guarantee: strong failures: out of memory I
StatusCode.h
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
EL::Job
Definition: Job.h:51
test_interactive_athena.job
job
Definition: test_interactive_athena.py:6
IWorker.h
RCU_ASSERT
#define RCU_ASSERT(x)
Definition: Assert.h:222
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
EL::IWorker::tree
virtual TTree * tree() const =0
description: the tree we are running on guarantee: no-fail
MD::FormulaSvc::m_tree
TTree * m_tree
description: the tree we are connected to
Definition: FormulaSvc.h:127
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233