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
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
18
19#include <memory>
20#include <sstream>
21#include <TTree.h>
22#include <TTreeFormula.h>
23#include <TTreeFormulaManager.h>
24#include <EventLoop/Job.h>
26#include <EventLoop/IWorker.h>
27#include <MultiDraw/Formula.h>
30
31//
32// method implementations
33//
34
36
37namespace 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
88 FormulaSvc ::
89 FormulaSvc ()
90 : m_tree (0)
91 {
92 RCU_NEW_INVARIANT (this);
93 }
94
95
96
97 FormulaSvc ::
98 ~FormulaSvc ()
99 {
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 {
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
139 EL::StatusCode FormulaSvc ::
140 changeInput (bool /*firstFile*/)
141 {
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
164 EL::StatusCode FormulaSvc ::
165 execute ()
166 {
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}
#define RCU_INVARIANT(x)
Definition Assert.h:201
#define RCU_ASSERT(x)
Definition Assert.h:222
#define RCU_DESTROY_INVARIANT(x)
Definition Assert.h:235
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:231
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:233
#define RCU_REQUIRE_SOFT(x)
Definition Assert.h:153
#define RCU_READ_INVARIANT(x)
Definition Assert.h:229
ClassImp(MD::FormulaSvc) namespace MD
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
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:51
static const std::string name
description: the name of the service
Definition FormulaSvc.h:61
::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:31
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