ATLAS Offline Software
AlgSelect.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 // Please feel free to contact me (krumnack@iastate.edu) for bug
11 // reports, feature suggestions, praise and complaints.
12 
13 //
14 // includes
15 //
16 
18 
19 #include <TH1.h>
20 #include <EventLoop/StatusCode.h>
21 #include <EventLoop/IWorker.h>
23 #include <MultiDraw/Formula.h>
24 #include <MultiDraw/FormulaSvc.h>
25 #include <RootCoreUtils/Assert.h>
26 #include <RootCoreUtils/ThrowMsg.h>
27 
28 //
29 // method implementations
30 //
31 
33 
34 namespace EL
35 {
36  void AlgSelect ::
37  testInvariant () const
38  {
39  RCU_INVARIANT (this != 0);
40 
41  RCU_INVARIANT (!m_outputStream.empty());
42  for (std::size_t form = 0, end = m_cuts.size(); form != end; ++ form)
43  RCU_INVARIANT (!m_cuts[form].empty());
44  if (m_skim != 0)
45  {
46  RCU_INVARIANT (m_cuts.size() == m_index.size());
47  RCU_INVARIANT (m_hist != 0);
48  RCU_INVARIANT (m_formSvc != 0);
49  }
50  if (m_hist != 0)
51  {
52  RCU_INVARIANT (m_cuts.size() == std::size_t (m_hist->GetNbinsX()));
53  }
54  }
55 
56 
57 
59  AlgSelect ()
60  : m_outputStream ("output"),
61  m_hist (0), m_formSvc (0), m_skim (0)
62  {
63  RCU_NEW_INVARIANT (this);
64  }
65 
66 
67 
69  AlgSelect (const std::string& val_outputStream, const std::string& cut)
70  : m_outputStream (val_outputStream),
71  m_hist (0), m_formSvc (0), m_skim (0)
72  {
73  RCU_ASSERT (!val_outputStream.empty());
74 
75  if (!cut.empty())
76  m_cuts.push_back (cut);
77 
78  RCU_NEW_INVARIANT (this);
79  }
80 
81 
82 
83  const std::string& AlgSelect ::
84  outputStream () const
85  {
86  RCU_READ_INVARIANT (this);
87  return m_outputStream;
88  }
89 
90 
91 
92  const std::string& AlgSelect ::
93  histName () const
94  {
95  RCU_READ_INVARIANT (this);
96  return m_histName;
97  }
98 
99 
100 
101  void AlgSelect ::
102  histName (const std::string& val_histName)
103  {
104  RCU_CHANGE_INVARIANT (this);
105  m_histName = val_histName;
106  }
107 
108 
109 
110  void AlgSelect ::
111  addCut (const std::string& cut)
112  {
113  RCU_CHANGE_INVARIANT (this);
114  RCU_REQUIRE_SOFT (!cut.empty());
115  m_cuts.push_back (cut);
116  }
117 
118 
119 
121  setupJob (Job& job)
122  {
123  RCU_CHANGE_INVARIANT (this);
125  return StatusCode::SUCCESS;
126  }
127 
128 
129 
131  initialize ()
132  {
133  RCU_CHANGE_INVARIANT (this);
134 
135  try
136  {
137  m_formSvc = MD::formulas (wk());
138  if (!m_cuts.empty() && !m_histName.empty())
139  {
140  m_hist = new TH1D (m_histName.c_str(), 0, m_cuts.size(), 0, m_cuts.size());
141  wk()->addOutput (m_hist);
142  }
143  for (std::size_t form = 0, end = m_cuts.size(); form != end; ++ form)
144  {
145  m_index.push_back (m_formSvc->addForm (m_cuts[form]));
146  m_hist->GetXaxis()->SetBinLabel (1 + form, m_cuts[form].c_str());
147  }
148 
150  } catch (...)
151  {
152  m_index.clear ();
153  throw;
154  }
155  return StatusCode::SUCCESS;
156  }
157 
158 
159 
161  execute ()
162  {
163  RCU_CHANGE_INVARIANT (this);
164 
165  RCU_ASSERT (m_hist != 0);
166 
167  double weight = 1;
168  for (std::size_t form = 0; form != m_cuts.size() && weight != 0; ++ form)
169  {
170  double myweight = 1;
171  if (m_index[form]) switch (m_index[form]->ndim())
172  {
173  case -1:
174  RCU_THROW_MSG ("formula not valid: " + m_cuts[form]);
175  break;
176  case 0:
177  myweight = m_index[form]->value (0);
178  break;
179  case 1:
180  RCU_THROW_MSG ("formula is an array: " + m_cuts[form]);
181  break;
182  default:
183  RCU_THROW_MSG ("unknown formula dimension: " + m_cuts[form]);
184  }
185 
186  weight *= myweight;
187  if (m_hist && weight != 0)
188  m_hist->Fill (form);
189  }
190 
191  if (weight)
193  return StatusCode::SUCCESS;
194  }
195 }
EL::AlgSelect::initialize
virtual StatusCode initialize()
effects: do everything that needs to be done before running the algorithm, e.g.
EL::AlgSelect::addCut
void addCut(const std::string &cut)
effects: add another cut guarantee: strong failures: out of memory II requires: !cut....
AlgSelect.h
EL::AlgSelect::m_cuts
std::vector< std::string > m_cuts
description: the list of formulas used
Definition: AlgSelect.h:141
Formula.h
EL::IHistogramWorker::addOutput
virtual void addOutput(TObject *output_swallow)=0
effects: add an object to the output.
EL::AlgSelect::setupJob
virtual StatusCode setupJob(Job &job)
effects: give the algorithm a chance to intialize the job with anything this algorithm needs.
EL::AlgSelect::m_skim
NTupleSvc * m_skim
description: the skimming service we are using
Definition: AlgSelect.h:161
Assert.h
EL::AlgSelect::m_histName
std::string m_histName
description: the name of the cut-flow histogram
Definition: AlgSelect.h:145
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
EL::AlgSelect::outputStream
const std::string & outputStream() const
description: the name of the output stream guarantee: no-fail invariant: !outputStream....
NTupleSvc.h
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
EL::AlgSelect
Definition: AlgSelect.h:34
EL::AlgSelect::testInvariant
void testInvariant() const
effects: test the invariant of this object guarantee: no-fail
RCU_REQUIRE_SOFT
#define RCU_REQUIRE_SOFT(x)
Definition: Assert.h:153
EL::AlgSelect::m_formSvc
MD::FormulaSvc * m_formSvc
description: the formula service we are using
Definition: AlgSelect.h:157
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
EL::AlgSelect::m_outputStream
std::string m_outputStream
description: members directly corresponding to accessors
Definition: AlgSelect.h:137
BindingsTest.cut
cut
This script demonstrates how to call a C++ class from Python Also how to use PyROOT is shown.
Definition: BindingsTest.py:13
EL
This module defines the arguments passed from the BATCH driver to the BATCH worker.
Definition: AlgorithmWorkerData.h:24
EL::Algorithm::wk
IWorker * wk() const
description: the worker that is controlling us guarantee: no-fail
RCU_INVARIANT
#define RCU_INVARIANT(x)
Definition: Assert.h:201
ClassImp
ClassImp(EL::AlgSelect) namespace EL
Definition: AlgSelect.cxx:32
EL::AlgSelect::histName
const std::string & histName() const
description: the histogram name guarantee: no-fail / strong failures: out of memory II
EL::AlgSelect::execute
virtual StatusCode execute()
effects: process the next event guarantee: basic failures: algorithm dependent rationale: the virtual...
ThrowMsg.h
MD::FormulaSvc::addForm
const Formula * addForm(const std::string &formula)
effects: add another formula returns: the formula guarantee: strong failures: out of memory II failur...
FormulaSvc.h
EL::AlgSelect::AlgSelect
AlgSelect()
effects: standard default constructor guarantee: strong failures: out of memory II rationale: this sh...
MD::useFormulas
void useFormulas(EL::Job &job)
effects: register the formula service for this job guarantee: strong failures: out of memory I
StatusCode.h
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::AlgSelect::m_index
std::vector< const MD::Formula * > m_index
description: the indices to the formulas
Definition: AlgSelect.h:149
EL::NTupleSvc::setFilterPassed
void setFilterPassed(bool passed=true)
effects: take the current event if passed is set, otherwise perform a no-op guarantee: no-fail
test_interactive_athena.job
job
Definition: test_interactive_athena.py:6
IWorker.h
RCU_ASSERT
#define RCU_ASSERT(x)
Definition: Assert.h:222
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229
EL::AlgSelect::m_hist
TH1 * m_hist
description: the histogram we are filling
Definition: AlgSelect.h:153
EL::getNTupleSvc
NTupleSvc * getNTupleSvc(IWorker *worker, const std::string &outputStream, const std::string &treeName="")
effects: get the skimming algorithm for the given output for this worker guarantee: strong failures: ...
RCU_NEW_INVARIANT
#define RCU_NEW_INVARIANT(x)
Definition: Assert.h:233