34{
35 void AlgCFlow ::
36 testInvariant () const
37 {
39 if (m_hist != 0)
40 {
43 RCU_INVARIANT (m_formulas.size() == std::size_t (m_hist->GetNbinsX()));
47 }
48 if (m_hist2)
49 {
52 } else
54 }
55
56
57
58 AlgCFlow ::
59 AlgCFlow ()
60 : m_hist (0), m_hist2 (0), m_formSvc (0)
61 {
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
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);
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));
91 m_back.push_back (form);
92
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
112 }
113
114
115
118 {
121 return EL::StatusCode::SUCCESS;
122 }
123
124
125
127 initialize ()
128 {
130
131 try
132 {
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
140 }
141 m_hist2 = dynamic_cast<TH1*>(m_hist->Clone ());
143 wk()->addOutput (m_hist2);
144 } catch (...)
145 {
147 throw;
148 }
149 return EL::StatusCode::SUCCESS;
150 }
151
152
153
155 execute ()
156 {
158
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:
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
175 break;
176 case 1:
177 ndim = 1;
178 if (
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)
190 {
191 for (std::size_t form = 0, end = m_formulas.size(); form != end; ++ form)
192 {
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)
202 else
204 }
205
207 m_hist2->Fill (m_axis[form], m_values[form]);
208 }
209 }
210 return EL::StatusCode::SUCCESS;
211 }
212}
#define RCU_CHANGE_INVARIANT(x)
#define RCU_NEW_INVARIANT(x)
#define RCU_REQUIRE_SOFT(x)
size_t size() const
Number of registered mappings.
static const Attributes_t empty
std::vector< std::string > split(const std::string &s, const std::string &t=":")
std::string label(const std::string &format, int i)
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.