ATLAS Offline Software
Loading...
Searching...
No Matches
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
6
7//
8// includes
9//
10
12
13#include <memory>
14#include <sstream>
15#include <TTree.h>
16#include <TTreeFormula.h>
17#include <TTreeFormulaManager.h>
18#include <EventLoop/Job.h>
20#include <EventLoop/IWorker.h>
21#include <MultiDraw/Formula.h>
23
24#include <stdexcept>
25
26//
27// method implementations
28//
29
31
32namespace MD
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 RCU_INVARIANT (this != 0);
74
75 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
76 {
77 RCU_INVARIANT (m_vars[form] != 0);
78 }
79 }
80
81
82
83 FormulaSvc ::
84 FormulaSvc ()
85 : m_tree (0)
86 {
87 RCU_NEW_INVARIANT (this);
88 }
89
90
91
92 FormulaSvc ::
93 ~FormulaSvc ()
94 {
96
97 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
98 {
99 delete m_vars[form];
100 }
101 }
102
103
104
105 const Formula *FormulaSvc ::
106 addForm (const std::string& formula)
107 {
109 RCU_REQUIRE_SOFT (!formula.empty());
110
111 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
112 {
113 if (m_vars[form]->formula() == formula)
114 return m_vars[form];
115 }
116 RCU_ASSERT (m_tree != 0);
117 std::ostringstream name;
118 name << "var" << m_vars.size();
119 m_vars.push_back (new Formula (name.str(), formula, m_tree));
120 return m_vars.back();
121 }
122
123
124
125 const char *FormulaSvc ::
126 GetName () const
127 {
128 RCU_READ_INVARIANT (this);
129 return name.c_str();
130 }
131
132
133
134 EL::StatusCode FormulaSvc ::
135 changeInput (bool /*firstFile*/)
136 {
138
139 m_tree = 0;
140
141 try
142 {
143 m_tree = wk()->tree();
144 m_tree->ResetBit (TTree::kForceRead);
145
146 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
147 m_vars[form]->reset (m_tree);
148 } catch (...)
149 {
150 m_tree = 0;
151 throw;
152 }
153
154 return EL::StatusCode::SUCCESS;
155 }
156
157
158
159 EL::StatusCode FormulaSvc ::
160 execute ()
161 {
163 if (wk()->treeEntry() != wk()->tree()->GetReadEvent())
164 wk()->tree()->LoadTree (wk()->treeEntry());
165 RCU_ASSERT (wk()->treeEntry() == wk()->tree()->GetReadEvent());
166 return EL::StatusCode::SUCCESS;
167 }
168}
#define RCU_INVARIANT(x)
Definition Assert.h:189
#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
ClassImp(MD::FormulaSvc) namespace MD
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
static const std::string name
description: the name of the service
Definition FormulaSvc.h:52
::StatusCode StatusCode
StatusCode definition for legacy code.
This module provides a lot of global definitions, forward declarations and includes that are used by ...
Definition AlgCFlow.h:22
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