ATLAS Offline Software
Loading...
Searching...
No Matches
INav4MomDumper.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// INav4MomDumper.cxx
8// Implementation file for class INav4MomDumper
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// FrameWork includes
21#include "Gaudi/Property.h"
22
23// NavFourMom includes
25
26// FourMomUtils includes
29
30// EventCommonAlgs includes
32
33namespace {
34 struct ToLower
35 {
36 char operator() (char c) const { return std::tolower(c); }
37 };
38}
39
41// Public methods:
43
44// Constructors
46INav4MomDumper::INav4MomDumper( const std::string& name,
47 ISvcLocator* pSvcLocator ) :
48 AthAlgorithm( name, pSvcLocator ),
49 m_outputStream ( 0 )
50{
51 //
52 // Property declaration
53 //
54 //declareProperty( "Property", m_nProperty );
55
56 std::string descr;
57
58 descr = "List of INavigable4Momentum containers one wants to dump";
59 declareProperty( "INav4Moms",
61 descr );
62 std::vector<std::string> inav4momContainersName( 0 );
63 m_inav4momContainersName.set( inav4momContainersName );
64
65 descr = "Name of the output stream where we'll dump informations from the";
66 descr += " INavigable4MomentumCollection object(s).";
67 descr += " Valid stream names are: \n";
68 descr += " - \"MsgStream\"\n";
69 descr += " - \"stderr\"\n";
70 descr += " - \"stdout\"\n";
71 descr += " - \"/path/to/some/file\".";
72
73 declareProperty( "OutputStream",
74 m_outputStreamName = "MsgStream",
75 descr );
77 this );
78}
79
80// Destructor
83{
84 ATH_MSG_DEBUG( "Calling destructor" );
85 // delete output stream
86 if ( m_outputStream &&
87 ( m_outputStream != &std::cout &&
88 m_outputStream != &std::cerr ) ) {
89 delete m_outputStream;
91 }
92}
93
94// Athena Algorithm's Hooks
97{
98 ATH_MSG_INFO( "Initializing " << name() << "..." );
99
100 ATH_MSG_INFO( "Configured to dump [" << m_inav4momContainersName.value().size()
101 << "] containers:" );
102 for ( std::vector<std::string>::const_iterator
103 itr = m_inav4momContainersName.value().begin(),
104 iEnd= m_inav4momContainersName.value().end();
105 itr != iEnd;
106 ++itr )
107 {
108 ATH_MSG_INFO( " - " << *itr );
109 }
110 ATH_MSG_INFO( "OutputStream : " << m_outputStreamName.value() );
111
112 return StatusCode::SUCCESS;
113}
114
116{
117 ATH_MSG_INFO( "Finalizing " << name() << "..." );
118 return StatusCode::SUCCESS;
119}
120
122{
123 ATH_MSG_DEBUG( "Executing " << name() << "..." );
124
125 typedef std::vector<std::string>::const_iterator ContNameIterator;
126
127 for ( ContNameIterator
128 itr = m_inav4momContainersName.value().begin(),
129 iEnd = m_inav4momContainersName.value().end();
130 itr != iEnd;
131 ++itr )
132 {
133 ATH_MSG_DEBUG( "dumping: [" << *itr << "]..." );
134
135 if ( !dump( *itr ).isSuccess() ) {
136 ATH_MSG_WARNING( "Problem while dumping [" << *itr << "] !!" );
137 continue;
138 }
139 ATH_MSG_DEBUG( "dumping: [" << *itr << "]... [OK]" );
140 }
141
142 return StatusCode::SUCCESS;
143}
144
146// Non-const methods:
148
149StatusCode
150INav4MomDumper::dump( const std::string& collName )
151{
152 typedef INavigable4MomentumCollection INav4Moms_t;
153 if ( !evtStore()->contains<INav4Moms_t>( collName ) ) {
154 ATH_MSG_WARNING( "No [" << collName
155 << "] INavigable4MomentumCollection in StoreGate !" );
156 return StatusCode::RECOVERABLE;
157 }
158
159 const INav4Moms_t * coll = 0;
160 if ( !evtStore()->retrieve( coll, collName ).isSuccess() ||
161 0 == coll )
162 {
163 ATH_MSG_WARNING( "Could not retrieve any INavigable4MomentumCollection at ["
164 << collName << "] !!" );
165 return StatusCode::RECOVERABLE;
166 }
167
168 std::ostringstream out;
169
170 const std::size_t iMax = coll->size();
171 out << "Retrieved [" << collName << "] ==> size = " << iMax << "\n";
172 if ( coll->empty() ) {
173 return StatusCode::SUCCESS;
174 }
175
176 // sorting the collection by Pt
177 typedef std::set<const INavigable4Momentum*, P4Sorters::Descending::Pt> Coll_t;
178 Coll_t inav4moms( coll->begin(), coll->end() );
179
180 FourMomUtils::dump( out, inav4moms );
181
182 if ( 0 != m_outputStream ) { (*m_outputStream) << out.str() << std::flush;
183 } else { ATH_MSG_DEBUG( out.str() );
184 }
185
186 return StatusCode::SUCCESS;
187}
188
190// Non-const methods:
192
193void INav4MomDumper::setupOutputStream( Gaudi::Details::PropertyBase& /*outputStreamName*/ )
194{
195 // reset internal state
196 if ( m_outputStream &&
197 ( m_outputStream != &std::cout && m_outputStream != &std::cerr ) ) {
198 delete m_outputStream;
199 m_outputStream = 0;
200 }
201
202 std::string streamName = m_outputStreamName.value();
203
204 // get the stream in lower case
205 std::transform( streamName.begin(), streamName.end(),
206 streamName.begin(),
207 ToLower() );
208
209 const std::string stdout = "stdout";
210 const std::string stderr = "stderr";
211 const std::string msgstream = "msgstream";
212
213 if ( streamName == msgstream ) {
214 m_outputStream = 0;
215 } else if ( streamName == stdout ) {
216 m_outputStream = &std::cout;
217 } else if ( streamName == stderr ) {
218 m_outputStream = &std::cerr;
219 } else {
220 m_outputStream = new std::ofstream( m_outputStreamName.value().c_str(),
221 std::ios::out | std::ios::trunc );
222 }
223
224 return;
225}
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
DataVector< INavigable4Momentum > INavigable4MomentumCollection
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
StringArrayProperty m_inav4momContainersName
List of INavigable4Momentum containers one wants to dump.
virtual ~INav4MomDumper()
Destructor:
std::ostream * m_outputStream
pointer to the file descriptor in case the output stream is not a "MsgStream"
StatusCode dump(const std::string &collName)
Prints out (on the configured output stream) the content of an INavigable4MomentumCollection object,...
StringProperty m_outputStreamName
Name of the output stream where we'll dump informations from the INav4MomAssocs object.
virtual StatusCode initialize()
virtual StatusCode finalize()
void setupOutputStream(Gaudi::Details::PropertyBase &outputStreamName)
Callback method to configure the output stream into which we'll dump the informations from INavigable...
INav4MomDumper()
Default constructor:
virtual StatusCode execute()
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
std::ostream & dump(std::ostream &out, const I4MomIter iBeg, const I4MomIter iEnd)
Helper to stream out a range of I4Momentum objects.
Definition P4Dumper.h:24
-event-from-file