ATLAS Offline Software
Loading...
Searching...
No Matches
I4MomDumper.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5*/
6
7// I4MomDumper.cxx
8// Implementation file for class I4MomDumper
9// Author: S.Binet<binet@cern.ch>
11
12
13// STL includes
14#include <sstream>
15#include <ostream>
16#include <fstream>
17#include <iomanip>
18#include <set>
19
20#include <array>
21
22// FrameWork includes
23#include "Gaudi/Property.h"
24
25// NavFourMom includes
27
28// FourMomUtils includes
30
31// EventCommonAlgs includes
32#include "I4MomDumper.h"
33
34static const std::array<std::string, I4MomDumper::Display::Size> s_display
35= { { "EEtaPhiM",
36 "IPtCotThPhiM",
37 "PtEtaPhiM",
38 "PxPyPzE" } };
39
40namespace {
41 struct ToLower
42 {
43 char operator() (char c) const { return std::tolower(c); }
44 };
45
46}
47
49// Public methods:
51
52// Constructors
54I4MomDumper::I4MomDumper( const std::string& name,
55 ISvcLocator* pSvcLocator ) :
56 AthAlgorithm( name, pSvcLocator ),
57 m_display ( Display::PxPyPzE ),
58 m_outputStream ( 0 )
59{
60 //
61 // Property declaration
62 //
63 //declareProperty( "Property", m_nProperty );
64
65 std::string descr;
66
67 descr = "List of INavigable4Momentum containers one wants to dump";
68 declareProperty( "INav4Moms",
70 descr );
71 std::vector<std::string> i4momContainersName( 0 );
72 m_i4momContainersName.set( i4momContainersName );
73
74 declareProperty( "Display",
75 m_displayName = "pxpypze",
76 "Tells how one wants the I4Momentum objects to be displayed"
77 " ie: eetaphim|iptcotthphim|ptetaphim|pxpypze" );
78 m_displayName.declareUpdateHandler( &I4MomDumper::setupDisplay, this );
79
80 descr = "Name of the output stream where we'll dump informations from the";
81 descr += " INavigable4MomentumCollection object(s).";
82 descr += " Valid stream names are: \n";
83 descr += " - \"MsgStream\"\n";
84 descr += " - \"stderr\"\n";
85 descr += " - \"stdout\"\n";
86 descr += " - \"/path/to/some/file\".";
87
88 declareProperty( "OutputStream",
89 m_outputStreamName = "MsgStream",
90 descr );
92 this );
93}
94
95// Destructor
98{
99 ATH_MSG_DEBUG( "Calling destructor" );
100 // delete output stream
101 if ( m_outputStream &&
102 ( m_outputStream != &std::cout &&
103 m_outputStream != &std::cerr ) ) {
104 delete m_outputStream;
105 m_outputStream = 0;
106 }
107}
108
109// Athena Algorithm's Hooks
112{
113 ATH_MSG_INFO( "Initializing " << name() << "..." );
114
115 ATH_MSG_INFO( "Configured to dump [" << m_i4momContainersName.value().size()
116 << "] containers:" );
117 for ( std::vector<std::string>::const_iterator
118 itr = m_i4momContainersName.value().begin(),
119 iEnd= m_i4momContainersName.value().end();
120 itr != iEnd;
121 ++itr )
122 {
123 ATH_MSG_INFO( " - " << *itr );
124 }
125 ATH_MSG_INFO( "Display : [" << s_display[m_display] << "]\n"
126 << "OutputStream : " << m_outputStreamName.value() );
127
128 return StatusCode::SUCCESS;
129}
130
132{
133 ATH_MSG_INFO( "Finalizing " << name() << "..." );
134 return StatusCode::SUCCESS;
135}
136
138{
139 ATH_MSG_DEBUG( "Executing " << name() << "..." );
140
141 typedef std::vector<std::string>::const_iterator ContNameIterator;
142
143 for ( ContNameIterator
144 itr = m_i4momContainersName.value().begin(),
145 iEnd = m_i4momContainersName.value().end();
146 itr != iEnd;
147 ++itr )
148 {
149 ATH_MSG_DEBUG( "dumping: [" << *itr << "]..." );
150
151 if ( !dump( *itr ).isSuccess() ) {
152 ATH_MSG_WARNING( "Problem while dumping [" << *itr << "] !!" );
153 continue;
154 }
155 ATH_MSG_DEBUG( "dumping: [" << *itr << "]... [OK]" );
156 }
157
158 return StatusCode::SUCCESS;
159}
160
162// Non-const methods:
164
165StatusCode
166I4MomDumper::dump( const std::string& collName )
167{
168 typedef INavigable4MomentumCollection I4Moms_t;
169 if ( !evtStore()->contains<I4Moms_t>( collName ) ) {
170 ATH_MSG_WARNING( "No [" << collName
171 << "] I4MomentumContainer in StoreGate !" );
172 return StatusCode::RECOVERABLE;
173 }
174
175 const I4Moms_t * coll = 0;
176 if ( !evtStore()->retrieve( coll, collName ).isSuccess() ||
177 0 == coll )
178 {
179 ATH_MSG_WARNING( "Could not retrieve any I4MomentumContainer at ["
180 << collName << "] !!" );
181 return StatusCode::RECOVERABLE;
182 }
183
184 std::ostringstream out;
185
186 const std::size_t iMax = coll->size();
187 out << "Retrieved [" << collName << "] ==> size = " << iMax << "\n";
188 if ( coll->empty() ) {
189 return StatusCode::SUCCESS;
190 }
191
192 // sorting the collection by Pt
193 typedef std::set<const I4Momentum*, P4Sorters::Descending::Pt> Coll_t;
194 Coll_t i4moms( coll->begin(), coll->end() );
195
196 if ( m_display == Display::EEtaPhiM ) {
197 out << "[e,eta,phi,m] ="
198 << std::right << std::scientific << std::setprecision(8);
199 for ( Coll_t::const_iterator itr = i4moms.begin(),
200 iEnd = i4moms.end();
201 itr != iEnd;
202 ++itr ) {
203 out << std::setw(16) << (*itr)->e()
204 << std::setw(16) << (*itr)->eta()
205 << std::setw(16) << (*itr)->phi()
206 << std::setw(16) << (*itr)->m()
207 << "\n";
208 }
209
210 } else if ( m_display == Display::IPtCotThPhiM ) {
211 out << "[ipt,cotTh,phi,m] ="
212 << std::right << std::scientific << std::setprecision(8);
213 for ( Coll_t::const_iterator itr = i4moms.begin(),
214 iEnd = i4moms.end();
215 itr != iEnd;
216 ++itr ) {
217 out << std::setw(16) << (*itr)->iPt()
218 << std::setw(16) << (*itr)->cotTh()
219 << std::setw(16) << (*itr)->phi()
220 << std::setw(16) << (*itr)->m()
221 << "\n";
222 }
223
224 } else if ( m_display == Display::PtEtaPhiM ) {
225 out << "[pt,eta,phi,m] ="
226 << std::right << std::scientific << std::setprecision(8);
227 for ( Coll_t::const_iterator itr = i4moms.begin(),
228 iEnd = i4moms.end();
229 itr != iEnd;
230 ++itr ) {
231 out << std::setw(16) << (*itr)->pt()
232 << std::setw(16) << (*itr)->eta()
233 << std::setw(16) << (*itr)->phi()
234 << std::setw(16) << (*itr)->m()
235 << "\n";
236 }
237 } else {
238 out << "[px,py,pz,e] ="
239 << std::right << std::scientific << std::setprecision(8);
240 for ( Coll_t::const_iterator itr = i4moms.begin(),
241 iEnd = i4moms.end();
242 itr != iEnd;
243 ++itr ) {
244 out << std::setw(16) << (*itr)->px()
245 << std::setw(16) << (*itr)->py()
246 << std::setw(16) << (*itr)->pz()
247 << std::setw(16) << (*itr)->e()
248 << "\n";
249 }
250 }
251 out << "\n";
252
253 if ( 0 != m_outputStream ) { (*m_outputStream) << out.str() << std::flush;
254 } else { ATH_MSG_DEBUG( out.str() );
255 }
256
257 return StatusCode::SUCCESS;
258}
259
260// Protected methods:
262
264// Const methods:
266
268// Non-const methods:
270
271void I4MomDumper::setupDisplay( Gaudi::Details::PropertyBase& /*displayName*/ )
272{
273 std::string& display = const_cast<std::string&>(m_displayName.value());
274
275 // get the stream in lower case
276 std::transform( display.begin(), display.end(),
277 display.begin(),
278 ToLower() );
279
280 if ( display == "eetaphim" ) { m_display = Display::EEtaPhiM;
281 } else if ( display == "iptcotthphim" ) { m_display = Display::IPtCotThPhiM;
282 } else if ( display == "ptetaphim" ) { m_display = Display::PtEtaPhiM;
283 } else if ( display == "pxpypze" ) { m_display = Display::PxPyPzE;
284 } else {
285 ATH_MSG_WARNING( "Unknown value for display [" << m_displayName.value() << "] !!\n"
286 << " => will use [pxpypxe] instead..." );
287 display = "pxpypze";
289 }
290
291 return;
292}
293
294void I4MomDumper::setupOutputStream( Gaudi::Details::PropertyBase& /*outputStreamName*/ )
295{
296 // reset internal state
297 if ( m_outputStream &&
298 ( m_outputStream != &std::cout && m_outputStream != &std::cerr ) ) {
299 delete m_outputStream;
300 m_outputStream = 0;
301 }
302
303 std::string streamName = m_outputStreamName.value();
304
305 // get the stream in lower case
306 std::transform( streamName.begin(), streamName.end(),
307 streamName.begin(),
308 ToLower() );
309
310 const std::string stdout = "stdout";
311 const std::string stderr = "stderr";
312 const std::string msgstream = "msgstream";
313
314 if ( streamName == msgstream ) {
315 m_outputStream = 0;
316 } else if ( streamName == stdout ) {
317 m_outputStream = &std::cout;
318 } else if ( streamName == stderr ) {
319 m_outputStream = &std::cerr;
320 } else {
321 m_outputStream = new std::ofstream( m_outputStreamName.value().c_str(),
322 std::ios::out | std::ios::trunc );
323 }
324
325 return;
326}
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static const std::array< std::string, I4MomDumper::Display::Size > s_display
DataVector< INavigable4Momentum > INavigable4MomentumCollection
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Display::Type m_display
its value translated into integer
void setupOutputStream(Gaudi::Details::PropertyBase &outputStreamName)
Callback method to configure the output stream into which we'll dump the informations from I4Momentum...
virtual ~I4MomDumper()
Destructor:
virtual StatusCode execute()
void setupDisplay(Gaudi::Details::PropertyBase &display)
Callback method to configure the display property which will tell how to dump the informations from I...
StringArrayProperty m_i4momContainersName
List of INavigable4Momentum containers one wants to dump.
Definition I4MomDumper.h:97
virtual StatusCode finalize()
StringProperty m_outputStreamName
Name of the output stream where we'll dump informations from the I4Assocs object.
I4MomDumper()
Default constructor:
virtual StatusCode initialize()
StatusCode dump(const std::string &collName)
Prints out (on the configured output stream) the content of an INavigable4MomentumCollection object,...
std::ostream * m_outputStream
pointer to the file descriptor in case the output stream is not a "MsgStream"
StringProperty m_displayName
switch for the type of printout (pxpypze/eetaphim/...)
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
-event-from-file