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 <AsgMessaging/MsgStreamMacros.h>
#include <stdexcept>

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 31 of file AlgCFlow.cxx.

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