34{
35 void AlgCFlow ::
36 testInvariant () const
37 {
38 if (m_hist != 0)
39 {
42 RCU_INVARIANT (m_formulas.size() == std::size_t (m_hist->GetNbinsX()));
46 }
47 if (m_hist2)
48 {
51 } else
53 }
54
55
56
57 AlgCFlow ::
58 AlgCFlow ()
59 : m_hist (0), m_hist2 (0), m_formSvc (0)
60 {
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
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);
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));
90 m_back.push_back (form);
91
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
111 }
112
113
114
117 {
120 return EL::StatusCode::SUCCESS;
121 }
122
123
124
126 initialize ()
127 {
129
130 try
131 {
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
139 }
140 m_hist2 = dynamic_cast<TH1*>(m_hist->Clone ());
142 wk()->addOutput (m_hist2);
143 } catch (...)
144 {
146 throw;
147 }
148 return EL::StatusCode::SUCCESS;
149 }
150
151
152
154 execute ()
155 {
157
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:
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
174 break;
175 case 1:
176 ndim = 1;
177 if (
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)
189 {
190 for (std::size_t form = 0, end = m_formulas.size(); form != end; ++ form)
191 {
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)
201 else
203 }
204
206 m_hist2->Fill (m_axis[form], m_values[form]);
207 }
208 }
209 return EL::StatusCode::SUCCESS;
210 }
211}
#define RCU_CHANGE_INVARIANT(x)
#define RCU_NEW_INVARIANT(x)
#define RCU_REQUIRE_SOFT(x)
#define ATH_MSG_ERROR(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.