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