ATLAS Offline Software
Functions
AlgHist.cxx File Reference
#include <MultiDraw/AlgHist.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::AlgHist) namespace MD
 

Function Documentation

◆ ClassImp()

ClassImp ( MD::AlgHist  )

Definition at line 35 of file AlgHist.cxx.

38 {
39  void AlgHist ::
40  testInvariant () const
41  {
42  RCU_INVARIANT (this != 0);
43  if (m_hist != 0)
44  {
45  RCU_INVARIANT (m_hist->GetDirectory() == 0);
46  RCU_INVARIANT (m_formulas.size() == m_valnum + m_cut);
47  RCU_INVARIANT (m_values.size() == m_valnum + 1);
48  }
49  switch (m_type)
50  {
51  case -1:
52  RCU_INVARIANT (m_hist == 0);
53  break;
54  case 0:
55  RCU_INVARIANT (m_hist != 0);
56  RCU_INVARIANT (m_valnum == 1);
57  break;
58  case 1:
59  RCU_INVARIANT (dynamic_cast<TProfile*>(m_hist) != 0);
60  RCU_INVARIANT (m_valnum == 2);
61  break;
62  case 2:
63  RCU_INVARIANT (dynamic_cast<TH2*>(m_hist) != 0);
64  RCU_INVARIANT (m_valnum == 2);
65  break;
66  case 3:
67  RCU_INVARIANT (dynamic_cast<TH3*>(m_hist) != 0);
68  RCU_INVARIANT (m_valnum == 3);
69  break;
70  default:
71  RCU_INVARIANT0 ("invalid type");
72  }
73  for (std::size_t form = 0, end = m_formulas.size(); form != end; ++ form)
74  RCU_INVARIANT (!m_formulas[form].empty());
75  if (m_hist2)
76  {
77  RCU_INVARIANT (m_index.size() == m_formulas.size());
78  RCU_INVARIANT (m_formSvc != 0);
79  } else
80  RCU_INVARIANT (m_index.empty());
81  }
82 
83 
84 
85  AlgHist ::
86  AlgHist ()
87  : m_hist (0), m_type (-1), m_valnum (1), m_cut (false), m_hist2 (0)
88  {
89  RCU_NEW_INVARIANT (this);
90  }
91 
92 
93 
94  AlgHist ::
95  AlgHist (TH1 *val_hist_swallow,
96  const std::string& val_value0,
97  const std::string& val_value1,
98  const std::string& val_value2,
99  const std::string& val_value3)
100  : m_hist (0), m_type (-1), m_valnum (1), m_cut (false), m_hist2 (0)
101  {
102  std::unique_ptr<TH1> hist (val_hist_swallow);
103 
104  RCU_REQUIRE_SOFT (val_hist_swallow != 0);
105  RCU_REQUIRE_SOFT (!val_value0.empty());
106 
107  m_formulas.push_back (val_value0);
108  if (!val_value1.empty())
109  m_formulas.push_back (val_value1);
110  if (!val_value2.empty())
111  m_formulas.push_back (val_value2);
112  if (!val_value3.empty())
113  m_formulas.push_back (val_value3);
114 
115  m_hist = hist.release();
116  m_hist->SetDirectory (0);
117  if (dynamic_cast<TProfile*>(m_hist) != 0)
118  {
119  m_type = 1;
120  m_valnum = 2;
121  } else if (dynamic_cast<TH2*>(m_hist) != 0)
122  {
123  m_type = 2;
124  m_valnum = 2;
125  } else if (dynamic_cast<TH3*>(m_hist) != 0)
126  {
127  m_type = 3;
128  m_valnum = 3;
129  } else
130  {
131  m_type = 0;
132  m_valnum = 1;
133  }
134  m_values.resize (m_valnum + 1, 1);
135  if (m_valnum == m_formulas.size())
136  m_cut = false;
137  else if (m_valnum+1 == m_formulas.size())
138  m_cut = true;
139  else
140  RCU_THROW_MSG ("invalid number of formulas");
141 
142  RCU_NEW_INVARIANT (this);
143  }
144 
145 
146  AlgHist ::
147  ~AlgHist ()
148  {
149  if (m_hist != nullptr) {
150  delete m_hist;
151  }
152  }
153 
154 
155 
156  EL::StatusCode AlgHist ::
157  setupJob (EL::Job& job)
158  {
159  RCU_CHANGE_INVARIANT (this);
160  useFormulas (job);
161  return EL::StatusCode::SUCCESS;
162  }
163 
164 
165 
167  initialize ()
168  {
169  RCU_CHANGE_INVARIANT (this);
170 
171  try
172  {
173  m_formSvc = formulas (wk());
174  for (std::size_t form = 0, end = m_formulas.size(); form != end; ++ form)
175  m_index.push_back (m_formSvc->addForm (m_formulas[form]));
176  m_hist2 = dynamic_cast<TH1*>(m_hist->Clone ());
177  RCU_ASSERT (m_hist2 != 0);
178  wk()->addOutput (m_hist2);
179  } catch (...)
180  {
181  m_index.clear ();
182  throw;
183  }
184  return EL::StatusCode::SUCCESS;
185  }
186 
187 
188 
190  execute ()
191  {
192  RCU_CHANGE_INVARIANT (this);
193 
194  RCU_ASSERT (m_formulas.size() == m_index.size());
195  RCU_ASSERT (m_formulas.size() <= m_values.size());
196 
197  if (m_cut && m_index.back()->ndim() == 0 &&
198  (m_values.back() = m_index.back()->value (0)) == 0)
199  return EL::StatusCode::SUCCESS;
200 
201  int ndim = 0;
202  std::size_t size = std::size_t (-1);
203  for (std::size_t form = 0; form != m_valnum; ++ form)
204  {
205  switch (m_index[form]->ndim())
206  {
207  case -1:
208  RCU_THROW_MSG ("formula not valid: " + m_formulas[form]);
209  break;
210  case 0:
211  if (m_index[form]->ndata() > 0)
212  m_values[form] = m_index[form]->value (0);
213  else
214  size = 0;
215  break;
216  case 1:
217  ndim = 1;
218  if (size > m_index[form]->ndata())
219  size = m_index[form]->ndata();
220  break;
221  default:
222  RCU_THROW_MSG ("unknown formula dimension: " + m_formulas[form]);
223  }
224  }
225 
226  if (ndim == 0 && size > 1)
227  size = 1;
228  for (std::size_t iter = 0; iter != size; ++ iter)
229  {
230  if (ndim == 1)
231  {
232  if (m_cut && m_index.back()->ndim() == 1 &&
233  (m_values.back() = m_index.back()->value (iter)) == 0)
234  continue;
235 
236  for (std::size_t form = 0; form != m_valnum; ++ form)
237  {
238  if (m_index[form]->ndim() == 1)
239  m_values[form] = m_index[form]->value (iter);
240  }
241  }
242 
243  switch (m_type)
244  {
245  case 0:
246  m_hist2->Fill (m_values[0], m_values[1]);
247  break;
248  case 1:
249  static_cast<TProfile*>(m_hist2)->Fill (m_values[0], m_values[1], m_values[2]);
250  break;
251  case 2:
252  static_cast<TH2*>(m_hist2)->Fill (m_values[0], m_values[1], m_values[2]);
253  break;
254  case 3:
255  static_cast<TH3*>(m_hist2)->Fill (m_values[0], m_values[1], m_values[2], m_values[3]);
256  break;
257  default:
258  RCU_THROW_MSG ("invalid number of values");
259  }
260  }
261  return EL::StatusCode::SUCCESS;
262  }
263 }
plotmaker.hist
hist
Definition: plotmaker.py:148
initialize
void initialize()
Definition: run_EoverP.cxx:894
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
MD::formulas
FormulaSvc * formulas(EL::IWorker *worker)
returns: the formula service for this worker guarantee: strong failures: formula service not configur...
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
m_type
TokenType m_type
the type
Definition: TProperty.cxx:44
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
RCU_REQUIRE_SOFT
#define RCU_REQUIRE_SOFT(x)
Definition: Assert.h:153
python.TrigEgammaMonitorHelper.TProfile
def TProfile(*args, **kwargs)
Definition: TrigEgammaMonitorHelper.py:81
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
RCU_INVARIANT0
#define RCU_INVARIANT0(y)
Definition: Assert.h:205
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
MD::useFormulas
void useFormulas(EL::Job &job)
effects: register the formula service for this job guarantee: strong failures: out of memory I
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
EL::Job
Definition: Job.h:51
test_interactive_athena.job
job
Definition: test_interactive_athena.py:6
RCU_ASSERT
#define RCU_ASSERT(x)
Definition: Assert.h:222
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233