ATLAS Offline Software
Loading...
Searching...
No Matches
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
6
7//
8// includes
9//
10
12
13#include <TH1.h>
15#include <EventLoop/IWorker.h>
17#include <MultiDraw/Formula.h>
21
22//
23// method implementations
24//
25
27
28namespace EL
29{
30 void AlgSelect ::
31 testInvariant () const
32 {
33 RCU_INVARIANT (this != 0);
34
35 RCU_INVARIANT (!m_outputStream.empty());
36 for (std::size_t form = 0, end = m_cuts.size(); form != end; ++ form)
37 RCU_INVARIANT (!m_cuts[form].empty());
38 if (m_skim != 0)
39 {
40 RCU_INVARIANT (m_cuts.size() == m_index.size());
41 RCU_INVARIANT (m_hist != 0);
42 RCU_INVARIANT (m_formSvc != 0);
43 }
44 if (m_hist != 0)
45 {
46 RCU_INVARIANT (m_cuts.size() == std::size_t (m_hist->GetNbinsX()));
47 }
48 }
49
50
51
52 AlgSelect ::
53 AlgSelect ()
54 : m_outputStream ("output"),
55 m_hist (0), m_formSvc (0), m_skim (0)
56 {
57 RCU_NEW_INVARIANT (this);
58 }
59
60
61
62 AlgSelect ::
63 AlgSelect (const std::string& val_outputStream, const std::string& cut)
64 : m_outputStream (val_outputStream),
65 m_hist (0), m_formSvc (0), m_skim (0)
66 {
67 RCU_ASSERT (!val_outputStream.empty());
68
69 if (!cut.empty())
70 m_cuts.push_back (cut);
71
72 RCU_NEW_INVARIANT (this);
73 }
74
75
76
77 const std::string& AlgSelect ::
78 outputStream () const
79 {
80 RCU_READ_INVARIANT (this);
81 return m_outputStream;
82 }
83
84
85
86 const std::string& AlgSelect ::
87 histName () const
88 {
89 RCU_READ_INVARIANT (this);
90 return m_histName;
91 }
92
93
94
95 void AlgSelect ::
96 histName (const std::string& val_histName)
97 {
99 m_histName = val_histName;
100 }
101
102
103
104 void AlgSelect ::
105 addCut (const std::string& cut)
106 {
108 RCU_REQUIRE_SOFT (!cut.empty());
109 m_cuts.push_back (cut);
110 }
111
112
113
114 StatusCode AlgSelect ::
115 setupJob (Job& job)
116 {
118 MD::useFormulas (job);
119 return StatusCode::SUCCESS;
120 }
121
122
123
124 StatusCode AlgSelect ::
125 initialize ()
126 {
128
129 try
130 {
131 m_formSvc = MD::formulas (wk());
132 if (!m_cuts.empty() && !m_histName.empty())
133 {
134 m_hist = new TH1D (m_histName.c_str(), 0, m_cuts.size(), 0, m_cuts.size());
135 wk()->addOutput (m_hist);
136 }
137 for (std::size_t form = 0, end = m_cuts.size(); form != end; ++ form)
138 {
139 m_index.push_back (m_formSvc->addForm (m_cuts[form]));
140 m_hist->GetXaxis()->SetBinLabel (1 + form, m_cuts[form].c_str());
141 }
142
143 m_skim = getNTupleSvc (wk(), m_outputStream);
144 } catch (...)
145 {
146 m_index.clear ();
147 throw;
148 }
149 return StatusCode::SUCCESS;
150 }
151
152
153
154 StatusCode AlgSelect ::
155 execute ()
156 {
158
159 RCU_ASSERT (m_hist != 0);
160
161 double weight = 1;
162 for (std::size_t form = 0; form != m_cuts.size() && weight != 0; ++ form)
163 {
164 double myweight = 1;
165 if (m_index[form]) switch (m_index[form]->ndim())
166 {
167 case -1:
168 RCU_THROW_MSG ("formula not valid: " + m_cuts[form]);
169 break;
170 case 0:
171 myweight = m_index[form]->value (0);
172 break;
173 case 1:
174 RCU_THROW_MSG ("formula is an array: " + m_cuts[form]);
175 break;
176 default:
177 RCU_THROW_MSG ("unknown formula dimension: " + m_cuts[form]);
178 }
179
180 weight *= myweight;
181 if (m_hist && weight != 0)
182 m_hist->Fill (form);
183 }
184
185 if (weight)
186 m_skim->setFilterPassed ();
187 return StatusCode::SUCCESS;
188 }
189}
ClassImp(EL::AlgSelect) namespace EL
Definition AlgSelect.cxx:26
#define RCU_INVARIANT(x)
Definition Assert.h:196
#define RCU_ASSERT(x)
Definition Assert.h:217
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:226
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:228
#define RCU_REQUIRE_SOFT(x)
Definition Assert.h:148
#define RCU_READ_INVARIANT(x)
Definition Assert.h:224
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:53
static const Attributes_t empty
This module defines the arguments passed from the BATCH driver to the BATCH worker.
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: ...
::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