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>
20
21//
22// method implementations
23//
24
26
27namespace EL
28{
29 void AlgSelect ::
30 testInvariant () const
31 {
32 RCU_INVARIANT (this != 0);
33
34 RCU_INVARIANT (!m_outputStream.empty());
35 for (std::size_t form = 0, end = m_cuts.size(); form != end; ++ form)
36 RCU_INVARIANT (!m_cuts[form].empty());
37 if (m_skim != 0)
38 {
39 RCU_INVARIANT (m_cuts.size() == m_index.size());
40 RCU_INVARIANT (m_hist != 0);
41 RCU_INVARIANT (m_formSvc != 0);
42 }
43 if (m_hist != 0)
44 {
45 RCU_INVARIANT (m_cuts.size() == std::size_t (m_hist->GetNbinsX()));
46 }
47 }
48
49
50
51 AlgSelect ::
52 AlgSelect ()
53 : m_outputStream ("output"),
54 m_hist (0), m_formSvc (0), m_skim (0)
55 {
56 RCU_NEW_INVARIANT (this);
57 }
58
59
60
61 AlgSelect ::
62 AlgSelect (const std::string& val_outputStream, const std::string& cut)
63 : m_outputStream (val_outputStream),
64 m_hist (0), m_formSvc (0), m_skim (0)
65 {
66 RCU_ASSERT (!val_outputStream.empty());
67
68 if (!cut.empty())
69 m_cuts.push_back (cut);
70
71 RCU_NEW_INVARIANT (this);
72 }
73
74
75
76 const std::string& AlgSelect ::
77 outputStream () const
78 {
79 RCU_READ_INVARIANT (this);
80 return m_outputStream;
81 }
82
83
84
85 const std::string& AlgSelect ::
86 histName () const
87 {
88 RCU_READ_INVARIANT (this);
89 return m_histName;
90 }
91
92
93
94 void AlgSelect ::
95 histName (const std::string& val_histName)
96 {
98 m_histName = val_histName;
99 }
100
101
102
103 void AlgSelect ::
104 addCut (const std::string& cut)
105 {
107 RCU_REQUIRE_SOFT (!cut.empty());
108 m_cuts.push_back (cut);
109 }
110
111
112
113 StatusCode AlgSelect ::
114 setupJob (Job& job)
115 {
117 MD::useFormulas (job);
118 return StatusCode::SUCCESS;
119 }
120
121
122
123 StatusCode AlgSelect ::
124 initialize ()
125 {
127
128 try
129 {
130 m_formSvc = MD::formulas (wk());
131 if (!m_cuts.empty() && !m_histName.empty())
132 {
133 m_hist = new TH1D (m_histName.c_str(), 0, m_cuts.size(), 0, m_cuts.size());
134 wk()->addOutput (m_hist);
135 }
136 for (std::size_t form = 0, end = m_cuts.size(); form != end; ++ form)
137 {
138 m_index.push_back (m_formSvc->addForm (m_cuts[form]));
139 m_hist->GetXaxis()->SetBinLabel (1 + form, m_cuts[form].c_str());
140 }
141
142 m_skim = getNTupleSvc (wk(), m_outputStream);
143 } catch (...)
144 {
145 m_index.clear ();
146 throw;
147 }
148 return StatusCode::SUCCESS;
149 }
150
151
152
153 StatusCode AlgSelect ::
154 execute ()
155 {
157
158 RCU_ASSERT (m_hist != 0);
159
160 double weight = 1;
161 for (std::size_t form = 0; form != m_cuts.size() && weight != 0; ++ form)
162 {
163 double myweight = 1;
164 if (m_index[form]) switch (m_index[form]->ndim())
165 {
166 case -1:
167 ATH_MSG_ERROR ("formula not valid: " << m_cuts[form]);
168 return StatusCode::FAILURE;
169 case 0:
170 myweight = m_index[form]->value (0);
171 break;
172 case 1:
173 ATH_MSG_ERROR ("formula is an array: " << m_cuts[form]);
174 return StatusCode::FAILURE;
175 default:
176 ATH_MSG_ERROR ("unknown formula dimension: " << m_cuts[form]);
177 return StatusCode::FAILURE;
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:25
#define RCU_INVARIANT(x)
Definition Assert.h:189
#define RCU_ASSERT(x)
Definition Assert.h:210
#define RCU_CHANGE_INVARIANT(x)
Definition Assert.h:219
#define RCU_NEW_INVARIANT(x)
Definition Assert.h:221
#define RCU_REQUIRE_SOFT(x)
Definition Assert.h:141
#define RCU_READ_INVARIANT(x)
Definition Assert.h:217
#define ATH_MSG_ERROR(x)
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