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>
24
25//
26// method implementations
27//
28
30
31namespace MD
32{
33 //
34 // legacy implementations
35 //
36
37 const std::string FormulaSvc::name = "MultiDraw";
38
39
40
41 std::string dbg (const FormulaSvc& /*obj*/, unsigned /*verbosity*/)
42 {
43 return "FormulaSvc";
44 }
45
46
47
48 void useFormulas (EL::Job& job)
49 {
50 if (!job.algsHas (FormulaSvc::name))
51 job.algsAdd (new FormulaSvc);
52 }
53
54
55
56 FormulaSvc *formulas (EL::IWorker *worker)
57 {
58 RCU_REQUIRE_SOFT (worker != 0);
59
60 FormulaSvc *const svc
61 = dynamic_cast<FormulaSvc*>(worker->getAlg (FormulaSvc::name));
62 if (svc == 0)
63 RCU_THROW_MSG ("Job not configured for FormulaSvc support");
64 return svc;
65 }
66
67
68
69 void FormulaSvc ::
70 testInvariant () const
71 {
72 RCU_INVARIANT (this != 0);
73
74 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
75 {
76 RCU_INVARIANT (m_vars[form] != 0);
77 }
78 }
79
80
81
82 FormulaSvc ::
83 FormulaSvc ()
84 : m_tree (0)
85 {
86 RCU_NEW_INVARIANT (this);
87 }
88
89
90
91 FormulaSvc ::
92 ~FormulaSvc ()
93 {
95
96 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
97 {
98 delete m_vars[form];
99 }
100 }
101
102
103
104 const Formula *FormulaSvc ::
105 addForm (const std::string& formula)
106 {
108 RCU_REQUIRE_SOFT (!formula.empty());
109
110 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
111 {
112 if (m_vars[form]->formula() == formula)
113 return m_vars[form];
114 }
115 RCU_ASSERT (m_tree != 0);
116 std::ostringstream name;
117 name << "var" << m_vars.size();
118 m_vars.push_back (new Formula (name.str(), formula, m_tree));
119 return m_vars.back();
120 }
121
122
123
124 const char *FormulaSvc ::
125 GetName () const
126 {
127 RCU_READ_INVARIANT (this);
128 return name.c_str();
129 }
130
131
132
133 EL::StatusCode FormulaSvc ::
134 changeInput (bool /*firstFile*/)
135 {
137
138 m_tree = 0;
139
140 try
141 {
142 m_tree = wk()->tree();
143 m_tree->ResetBit (TTree::kForceRead);
144
145 for (std::size_t form = 0, end = m_vars.size(); form != end; ++ form)
146 m_vars[form]->reset (m_tree);
147 } catch (...)
148 {
149 m_tree = 0;
150 throw;
151 }
152
153 return EL::StatusCode::SUCCESS;
154 }
155
156
157
158 EL::StatusCode FormulaSvc ::
159 execute ()
160 {
162 if (wk()->treeEntry() != wk()->tree()->GetReadEvent())
163 wk()->tree()->LoadTree (wk()->treeEntry());
164 RCU_ASSERT (wk()->treeEntry() == wk()->tree()->GetReadEvent());
165 return EL::StatusCode::SUCCESS;
166 }
167}
#define RCU_INVARIANT(x)
Definition Assert.h:196
#define RCU_ASSERT(x)
Definition Assert.h:217
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:230
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:226
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:228
#define RCU_REQUIRE_SOFT(x)
Definition Assert.h:148
#define RCU_READ_INVARIANT(x)
Definition Assert.h:224
ClassImp(MD::FormulaSvc) namespace MD
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:53
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