ATLAS Offline Software
Functions
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 <RootCoreUtils/ThrowMsg.h>

Go to the source code of this file.

Functions

 ClassImp (MD::AlgCFlow) namespace MD
 

Function Documentation

◆ ClassImp()

ClassImp ( MD::AlgCFlow  )

Definition at line 35 of file AlgCFlow.cxx.

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