ATLAS Offline Software
Loading...
Searching...
No Matches
FormulaSvc.cxx File Reference
#include <MultiDraw/FormulaSvc.h>
#include <memory>
#include <sstream>
#include <TTree.h>
#include <TTreeFormula.h>
#include <TTreeFormulaManager.h>
#include <EventLoop/Job.h>
#include <EventLoop/StatusCode.h>
#include <EventLoop/IWorker.h>
#include <MultiDraw/Formula.h>
#include <RootCoreUtils/Assert.h>
#include <stdexcept>

Go to the source code of this file.

Functions

 ClassImp (MD::FormulaSvc) namespace MD

Function Documentation

◆ ClassImp()

ClassImp ( MD::FormulaSvc )
Author
Nils Krumnack

Definition at line 30 of file FormulaSvc.cxx.

33{
34 //
35 // legacy implementations
36 //
37
38 const std::string FormulaSvc::name = "MultiDraw";
39
40
41
42 std::string dbg (const FormulaSvc& /*obj*/, unsigned /*verbosity*/)
43 {
44 return "FormulaSvc";
45 }
46
47
48
49 void useFormulas (EL::Job& job)
50 {
51 if (!job.algsHas (FormulaSvc::name))
52 job.algsAdd (new FormulaSvc);
53 }
54
55
56
57 FormulaSvc *formulas (EL::IWorker *worker)
58 {
59 RCU_REQUIRE_SOFT (worker != 0);
60
61 FormulaSvc *const svc
62 = dynamic_cast<FormulaSvc*>(worker->getAlg (FormulaSvc::name));
63 if (svc == 0)
64 throw std::runtime_error ("Job not configured for FormulaSvc support");
65 return svc;
66 }
67
68
69
70 void FormulaSvc ::
71 testInvariant () const
72 {
73 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
74 {
75 RCU_INVARIANT (m_vars[form] != 0);
76 }
77 }
78
79
80
81 FormulaSvc ::
82 FormulaSvc ()
83 : m_tree (0)
84 {
85 RCU_NEW_INVARIANT (this);
86 }
87
88
89
90 FormulaSvc ::
91 ~FormulaSvc ()
92 {
94
95 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
96 {
97 delete m_vars[form];
98 }
99 }
100
101
102
103 const Formula *FormulaSvc ::
104 addForm (const std::string& formula)
105 {
107 RCU_REQUIRE_SOFT (!formula.empty());
108
109 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
110 {
111 if (m_vars[form]->formula() == formula)
112 return m_vars[form];
113 }
114 RCU_ASSERT (m_tree != 0);
115 std::ostringstream name;
116 name << "var" << m_vars.size();
117 m_vars.push_back (new Formula (name.str(), formula, m_tree));
118 return m_vars.back();
119 }
120
121
122
123 const char *FormulaSvc ::
124 GetName () const
125 {
126 RCU_READ_INVARIANT (this);
127 return name.c_str();
128 }
129
130
131
132 EL::StatusCode FormulaSvc ::
133 changeInput (bool /*firstFile*/)
134 {
136
137 m_tree = 0;
138
139 try
140 {
141 m_tree = wk()->tree();
142 m_tree->ResetBit (TTree::kForceRead);
143
144 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
145 m_vars[form]->reset (m_tree);
146 } catch (...)
147 {
148 m_tree = 0;
149 throw;
150 }
151
152 return EL::StatusCode::SUCCESS;
153 }
154
155
156
157 EL::StatusCode FormulaSvc ::
158 execute ()
159 {
161 if (wk()->treeEntry() != wk()->tree()->GetReadEvent())
162 wk()->tree()->LoadTree (wk()->treeEntry());
163 RCU_ASSERT (wk()->treeEntry() == wk()->tree()->GetReadEvent());
164 return EL::StatusCode::SUCCESS;
165 }
166}
#define RCU_INVARIANT(x)
Definition Assert.h:187
#define RCU_ASSERT(x)
Definition Assert.h:210
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:223
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:219
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
#define RCU_REQUIRE_SOFT(x)
Definition Assert.h:141
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
the interface for algorithms to access IWorker
Definition IWorker.h:40
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...
Definition Job.h:42
ID3PD * m_tree
Pointer to the ID3PD object used.
Vars m_vars
All booked variables.
::StatusCode StatusCode
StatusCode definition for legacy code.
AthROOTErrorHandlerSvc * svc
FormulaSvc * formulas(EL::IWorker *worker)
returns: the formula service for this worker guarantee: strong failures: formula service not configur...
void useFormulas(EL::Job &job)
effects: register the formula service for this job guarantee: strong failures: out of memory I
TChain * tree