ATLAS Offline Software
Loading...
Searching...
No Matches
AlgCFlow.cxx File Reference
#include <MultiDraw/AlgCFlow.h>
#include <memory>
#include <TH1.h>
#include <TH2.h>
#include <TH3.h>
#include <TProfile.h>
#include <EventLoop/StatusCode.h>
#include <EventLoop/IWorker.h>
#include <MultiDraw/Formula.h>
#include <MultiDraw/FormulaSvc.h>
#include <RootCoreUtils/Assert.h>
#include <RootCoreUtils/ThrowMsg.h>

Go to the source code of this file.

Functions

 ClassImp (MD::AlgCFlow) namespace MD

Function Documentation

◆ ClassImp()

ClassImp ( MD::AlgCFlow )
Author
Nils Krumnack

Definition at line 29 of file AlgCFlow.cxx.

32{
33 void AlgCFlow ::
34 testInvariant () const
35 {
36 RCU_INVARIANT (this != 0);
37 if (m_hist != 0)
38 {
39 RCU_INVARIANT (m_hist->GetDirectory() == 0);
40 RCU_INVARIANT (m_hist->GetDimension() == 1);
41 RCU_INVARIANT (m_formulas.size() == std::size_t (m_hist->GetNbinsX()));
42 RCU_INVARIANT (m_formulas.size() == m_values.size());
43 RCU_INVARIANT (m_formulas.size() == m_back.size());
44 RCU_INVARIANT (m_formulas.size() == m_axis.size());
45 }
46 if (m_hist2)
47 {
48 RCU_INVARIANT (m_index.size() == m_formulas.size());
49 RCU_INVARIANT (m_formSvc != 0);
50 } else
51 RCU_INVARIANT (m_index.empty());
52 }
53
54
55
56 AlgCFlow ::
57 AlgCFlow ()
58 : m_hist (0), m_hist2 (0), m_formSvc (0)
59 {
60 RCU_NEW_INVARIANT (this);
61 }
62
63
64
65 AlgCFlow ::
66 AlgCFlow (TH1 *val_hist_swallow)
67 : m_hist (0), m_hist2 (0)
68 {
69 std::unique_ptr<TH1> hist (val_hist_swallow);
70
71 RCU_REQUIRE_SOFT (val_hist_swallow != 0);
72 RCU_REQUIRE_SOFT (val_hist_swallow->GetDimension() == 1);
73
74 for (std::size_t form = 0, end = hist->GetNbinsX();
75 form != end; ++ form)
76 {
77 const std::string label = hist->GetXaxis()->GetBinLabel(form+1);
78 const std::size_t split = label.find (':');
79
80 m_axis.push_back (hist->GetXaxis()->GetBinCenter (form+1));
81 if (split == std::string::npos)
82 {
83 m_formulas.push_back (label);
84 m_back.push_back (form - 1);
85 } else
86 {
87 m_formulas.push_back (label.substr (0, split));
88 const std::string back = label.substr (split+1);
89 m_back.push_back (form);
90
91 if (!back.empty())
92 {
93 for (std::size_t form2 = 0; form2 != form; ++ form2)
94 {
95 if (m_formulas[form2] == back)
96 m_back.back() = form2;
97 }
98 if (m_back.back() == form)
99 RCU_THROW_MSG ("unknown back formula: " + back);
100 }
101 }
102 }
103
104 m_hist = hist.release();
105 m_hist->SetDirectory (0);
106
107 m_values.resize (m_formulas.size());
108
109 RCU_NEW_INVARIANT (this);
110 }
111
112
113
114 EL::StatusCode AlgCFlow ::
115 setupJob (EL::Job& job)
116 {
118 useFormulas (job);
119 return EL::StatusCode::SUCCESS;
120 }
121
122
123
124 EL::StatusCode AlgCFlow ::
125 initialize ()
126 {
128
129 try
130 {
131 m_formSvc = formulas (wk());
132 for (std::size_t form = 0, end = m_formulas.size(); form != end; ++ form)
133 {
134 if (!m_formulas[form].empty())
135 m_index.push_back (m_formSvc->addForm (m_formulas[form]));
136 else
137 m_index.push_back (0);
138 }
139 m_hist2 = dynamic_cast<TH1*>(m_hist->Clone ());
140 RCU_ASSERT (m_hist2 != 0);
141 wk()->addOutput (m_hist2);
142 } catch (...)
143 {
144 m_index.clear ();
145 throw;
146 }
147 return EL::StatusCode::SUCCESS;
148 }
149
150
151
152 EL::StatusCode AlgCFlow ::
153 execute ()
154 {
156
157 RCU_ASSERT (m_hist2 != 0);
158
159 int ndim = 0;
160 std::size_t size = std::size_t (-1);
161 for (std::size_t form = 0; form != m_formulas.size(); ++ form)
162 {
163 if (m_index[form]) switch (m_index[form]->ndim())
164 {
165 case -1:
166 RCU_THROW_MSG ("formula not valid: " + m_formulas[form]);
167 break;
168 case 0:
169 if (m_index[form]->ndata() > 0)
170 m_values[form] = m_index[form]->value (0);
171 else
172 size = 0;
173 break;
174 case 1:
175 ndim = 1;
176 if (size > m_index[form]->ndata())
177 size = m_index[form]->ndata();
178 break;
179 default:
180 RCU_THROW_MSG ("unknown formula dimension: " + m_formulas[form]);
181 }
182 }
183
184 if (ndim == 0 && size > 1)
185 size = 1;
186 for (std::size_t iter = 0; iter != size; ++ iter)
187 {
188 for (std::size_t form = 0, end = m_formulas.size(); form != end; ++ form)
189 {
190 double weight = 1;
191
192 if (m_back[form] < form)
193 weight = m_values[m_back[form]];
194
195 if (weight != 0 && !m_formulas[form].empty())
196 {
197 if (m_index[form]->ndim() == 1)
198 weight *= m_index[form]->value (iter);
199 else
200 weight *= m_index[form]->value (0);
201 }
202
203 m_values[form] = weight;
204 m_hist2->Fill (m_axis[form], m_values[form]);
205 }
206 }
207 return EL::StatusCode::SUCCESS;
208 }
209}
#define RCU_INVARIANT(x)
Definition Assert.h:196
#define RCU_ASSERT(x)
Definition Assert.h:217
#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_THROW_MSG(message)
Definition PrintMsg.h:53
size_t size() const
Number of registered mappings.
static const Attributes_t empty
Definition Job.h:42
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:179
std::string label(const std::string &format, int i)
Definition label.h:19
return m_collEvts back().back().max_entries
::StatusCode StatusCode
StatusCode definition for legacy code.
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
size_t m_index
The index of this element within its container. Should be 0 if this object is not within a container.