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