ATLAS Offline Software
INav4MomDumper.cxx
Go to the documentation of this file.
1 
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
27 #include "FourMomUtils/P4Dumper.h"
29 
30 // EventCommonAlgs includes
32 
33 namespace {
34  struct ToLower
35  {
36  char operator() (char c) const { return std::tolower(c); }
37  };
38 }
39 
41 // Public methods:
43 
44 // Constructors
46 INav4MomDumper::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;
90  m_outputStream = 0;
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 
149 StatusCode
150 INav4MomDumper::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 
193 void 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 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
INav4MomDumper::m_inav4momContainersName
StringArrayProperty m_inav4momContainersName
List of INavigable4Momentum containers one wants to dump.
Definition: INav4MomDumper.h:80
INav4MomDumper::execute
virtual StatusCode execute()
Definition: INav4MomDumper.cxx:121
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
FullCPAlgorithmsTest_eljob.flush
flush
Definition: FullCPAlgorithmsTest_eljob.py:186
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
INav4MomDumper::m_outputStream
std::ostream * m_outputStream
pointer to the file descriptor in case the output stream is not a "MsgStream"
Definition: INav4MomDumper.h:90
P4DescendingSorters.h
INav4MomDumper::finalize
virtual StatusCode finalize()
Definition: INav4MomDumper.cxx:115
get_generator_info.stdout
stdout
Definition: get_generator_info.py:40
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
INav4MomDumper.h
get_generator_info.stderr
stderr
Definition: get_generator_info.py:40
P4Dumper.h
INav4MomDumper::initialize
virtual StatusCode initialize()
Definition: INav4MomDumper.cxx:96
INav4MomDumper::~INav4MomDumper
virtual ~INav4MomDumper()
Destructor:
Definition: INav4MomDumper.cxx:82
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
INav4MomDumper::INav4MomDumper
INav4MomDumper()
Default constructor:
INav4MomDumper::setupOutputStream
void setupOutputStream(Gaudi::Details::PropertyBase &outputStreamName)
Callback method to configure the output stream into which we'll dump the informations from INavigable...
Definition: INav4MomDumper.cxx:193
INav4MomDumper::dump
StatusCode dump(const std::string &collName)
Prints out (on the configured output stream) the content of an INavigable4MomentumCollection object,...
Definition: INav4MomDumper.cxx:150
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
tolower
void tolower(std::string &s)
Definition: AthenaSummarySvc.cxx:111
INavigable4MomentumCollection.h
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
python.TransformConfig.descr
descr
print "%s.properties()" % self.__name__
Definition: TransformConfig.py:360
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
INav4MomDumper::m_outputStreamName
StringProperty m_outputStreamName
Name of the output stream where we'll dump informations from the INav4MomAssocs object.
Definition: INav4MomDumper.h:86
AthenaPoolExample_Copy.streamName
string streamName
Definition: AthenaPoolExample_Copy.py:39
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
FourMomUtils::dump
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
python.compressB64.c
def c
Definition: compressB64.py:93