ATLAS Offline Software
RootAsciiDumperAlgHandle.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 // RootAsciiDumperAlgHandle.cxx
8 // Implementation file for class RootAsciiDumperAlgHandle
9 // Author: S.Binet<binet@cern.ch>
11 
12 // AthenaRootComps includes
14 
15 // STL includes
16 #include <sstream>
17 #include <stdio.h>
18 // to get the printing format specifiers (e.g. PRId64)
19 #define __STDC_FORMAT_MACROS
20 #include <inttypes.h>
21 
22 // linux i/o includes
23 #include <sys/stat.h>
24 #include <unistd.h>
25 #include <fcntl.h>
26 
27 // FrameWork includes
28 #include "Gaudi/Property.h"
29 
30 // SGTools
31 #include "SGTools/BuiltinsClids.h" // to put ints,... in evtstore
32 #include "SGTools/StlVectorClids.h" // to put std::vectors... in evtstore
33 
34 namespace Athena {
35 
37 // Public methods:
39 
40 // Constructors
43  ISvcLocator* pSvcLocator ) :
44  ::AthAlgorithm( name, pSvcLocator ),
45  m_ofname(""),
46  m_ofd(-1),
47  m_nentries(0),
48  m_runnbr(),
49  m_evtnbr(),
50  m_el_n(),
51  m_el_eta(),
52  m_el_jetcone_dr()
53 {
54  //
55  // Property declaration
56  //
57  //declareProperty( "Property", m_nProperty );
58 
59  declareProperty("AsciiFileName",
60  m_ofname = "d3pd.ascii",
61  "Name of the ascii file where the content of the "
62  "ROOT n-tuple file will be dumped.");
63 
64  declareProperty("RunNumber",
65  m_runnbr = SG::RVar<uint32_t>("RunNumber"),
66  "handle to the run-nbr in event (read)");
67 
68  declareProperty("EventNumber",
69  m_evtnbr = SG::RVar<uint32_t>("EventNumber"),
70  "handle to the evt-nbr in event (read)");
71 
72  declareProperty("el_n",
73  m_el_n = SG::RVar<int32_t>("el_n"),
74  "handle to the nbr of electrons in event (read)");
75 
76  declareProperty("el_eta",
77  m_el_eta = SG::RVar<std::vector<float> >("el_eta"),
78  "handle to the eta of electrons in event (read)");
79 
80  declareProperty("el_jetcone_dr",
81  m_el_jetcone_dr = SG::RVar<std::vector<std::vector<float> > >("el_jetcone_dr"),
82  "handle to the jetcone-dR of electrons in event (read)");
83 
84 
85  declareProperty("eiKey",
86  m_eiKey = "EventInfo");
87 
88 }
89 
90 // Destructor
93 {}
94 
95 // Athena Algorithm's Hooks
98 {
99  ATH_MSG_INFO ("Initializing " << name() << "...");
101  ATH_CHECK( m_el_jetcone_dr.initialize() );
102  ATH_CHECK( m_el_n.initialize() );
103  ATH_CHECK( m_el_eta.initialize() );
104  ATH_CHECK( m_evtnbr.initialize() );
105  ATH_CHECK( m_runnbr.initialize() );
106 
107  ATH_MSG_INFO("dumping data into file ["
108  << m_ofname << "]...");
109  if (m_ofname.empty()) {
110  ATH_MSG_ERROR("cannot dump data into an empty file name!");
111  return StatusCode::FAILURE;
112  }
113  m_ofd = open(m_ofname.c_str(),
114  O_WRONLY | O_CREAT | O_TRUNC,
115  S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
116 
117  if (m_ofd < 0) {
118  ATH_MSG_ERROR("problem opening file [" << m_ofname << "] with "
119  "write permissions.");
120  return StatusCode::FAILURE;
121  }
122 
123  return StatusCode::SUCCESS;
124 }
125 
127 {
128  ATH_MSG_INFO ("Finalizing " << name() << "...");
129 
130  if (m_ofd > 0) {
131  fflush(NULL);
132  if (close(m_ofd) < 0) {
133  ATH_MSG_WARNING("problem while closing [" << m_ofname << "]");
134  }
135  }
136 
137  return StatusCode::SUCCESS;
138 }
139 
141 {
142  ATH_MSG_DEBUG ("Executing " << name() << "...");
143 
145  m_nentries += 1;
146 
147  if (!m_runnbr.ptr()) {
148  ATH_MSG_WARNING("could not retrieve [" << m_runnbr.name()
149  << "] from store");
150  return StatusCode::RECOVERABLE;
151  }
152 
153  if (!m_evtnbr.ptr()) {
154  ATH_MSG_WARNING("could not retrieve [" << m_evtnbr.name()
155  << "] from store");
156  return StatusCode::RECOVERABLE;
157  }
158 
159  if (!m_el_n.ptr()) {
160  ATH_MSG_WARNING("could not retrieve [" << m_el_n.name()
161  << "] from store");
162  return StatusCode::RECOVERABLE;
163  }
164 
166  static const SG::AuxElement::Accessor<std::string> tupleName ("tupleName");
167  static const SG::AuxElement::Accessor<std::string> collectionName ("collectionName");
168  std::string collName = collectionName(*ei);
169  std::string::size_type pos = collName.rfind ("/");
170  if (pos != std::string::npos) {
171  collName.erase (0, pos+1);
172  }
173 
174  {
175  char* buf = 0;
176  int buf_sz = asprintf
177  (&buf,
178  "%03" PRId64 ".%s = %s\n"
179  "%03" PRId64 ".%s = %s\n"
180  "%03" PRId64 ".%s = %u\n"
181  "%03" PRId64 ".%s = %u\n"
182  "%03" PRId64 ".%s = %i\n",
183  nevts,
184  "collectionName",
185  collName.c_str(),
186  nevts,
187  "tupleName",
188  tupleName(*ei).c_str(),
189  nevts,
190  "RunNumber",
191  *m_runnbr,
192  nevts,
193  "EventNumber",
194  *m_evtnbr,
195  nevts,
196  "el_n",
197  *m_el_n);
198  write(m_ofd, buf, buf_sz);
199  free(buf);
200  }
201 
202  if (*m_el_n > 0) {
203  if (!m_el_eta.ptr()) {
204  ATH_MSG_WARNING("could not retrieve [" << m_el_eta.name()
205  << "] from store");
206  return StatusCode::RECOVERABLE;
207  }
208 
209  if (!m_el_jetcone_dr.ptr()) {
210  ATH_MSG_WARNING("could not retrieve [" << m_el_jetcone_dr.name()
211  << "] from store");
212  return StatusCode::RECOVERABLE;
213  }
214 
215  {
216  std::stringstream bufv;
217  for (int32_t ii = 0; ii < *m_el_n; ++ii) {
218  bufv << (*m_el_eta)[ii];
219  if (ii != (*m_el_n)-1) {
220  bufv << ", ";
221  }
222  }
223  char* buf = 0;
224  int buf_sz = asprintf
225  (&buf,
226  "%03" PRId64 ".%s = [%s]\n",
227  nevts,
228  "el_eta",
229  bufv.str().c_str());
230  write(m_ofd, buf, buf_sz);
231  free(buf);
232  }
233 
234 
235  {
236  std::stringstream bufv;
237  for (int32_t ii = 0; ii < *m_el_n; ++ii) {
238  bufv << "[";
239  for (std::size_t jj = 0, jjmax = (*m_el_jetcone_dr)[ii].size();
240  jj < jjmax;
241  ++jj) {
242  bufv << (*m_el_jetcone_dr)[ii][jj];
243  if (jj != jjmax-1) {
244  bufv << ", ";
245  }
246  }
247  bufv << "]";
248  if (ii != (*m_el_n)-1) {
249  bufv << ", ";
250  }
251  }
252  char* buf = 0;
253  int buf_sz = asprintf
254  (&buf,
255  "%03" PRId64 ".%s = [%s]\n",
256  nevts,
257  "el_jetcone_dr",
258  bufv.str().c_str());
259  write(m_ofd, buf, buf_sz);
260  free(buf);
261  }
262  }
263 
264  return StatusCode::SUCCESS;
265 }
266 
267 } //> end namespace Athena
Athena::RootAsciiDumperAlgHandle::m_eiKey
SG::ReadHandleKey< xAOD::EventInfo > m_eiKey
Definition: RootAsciiDumperAlgHandle.h:91
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
Athena::RootAsciiDumperAlgHandle::m_ofd
int m_ofd
file handle to the ASCII output file
Definition: RootAsciiDumperAlgHandle.h:71
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Athena::RootAsciiDumperAlgHandle::m_evtnbr
SG::RVar< uint32_t > m_evtnbr
event number
Definition: RootAsciiDumperAlgHandle.h:80
Athena::RootAsciiDumperAlgHandle::m_el_eta
SG::RVar< std::vector< float > > m_el_eta
eta of electrons
Definition: RootAsciiDumperAlgHandle.h:86
Athena::RootAsciiDumperAlgHandle::m_ofname
std::string m_ofname
ASCII output file name.
Definition: RootAsciiDumperAlgHandle.h:68
Athena::RootAsciiDumperAlgHandle::finalize
virtual StatusCode finalize()
Definition: RootAsciiDumperAlgHandle.cxx:126
BuiltinsClids.h
Athena::RootAsciiDumperAlgHandle::m_el_n
SG::RVar< int32_t > m_el_n
number of electrons
Definition: RootAsciiDumperAlgHandle.h:83
ReadHandle< T >
a smart pointer to an object of a given type in an IProxyDict (such as StoreGateSvc)....
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
StlVectorClids.h
Athena::RootAsciiDumperAlgHandle::m_el_jetcone_dr
SG::RVar< std::vector< std::vector< float > > > m_el_jetcone_dr
jetcone dR
Definition: RootAsciiDumperAlgHandle.h:89
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
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
python.ByteStreamConfig.write
def write
Definition: Event/ByteStreamCnvSvc/python/ByteStreamConfig.py:248
Athena::RootAsciiDumperAlgHandle::initialize
virtual StatusCode initialize()
Definition: RootAsciiDumperAlgHandle.cxx:97
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
sg-dump.nevts
nevts
Definition: sg-dump.py:146
Athena::RootAsciiDumperAlgHandle::RootAsciiDumperAlgHandle
RootAsciiDumperAlgHandle()
Default constructor:
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
Athena::RootAsciiDumperAlgHandle::m_nentries
uint64_t m_nentries
number of entries processed so-far
Definition: RootAsciiDumperAlgHandle.h:74
Athena::RootAsciiDumperAlgHandle::m_runnbr
SG::RVar< uint32_t > m_runnbr
run number
Definition: RootAsciiDumperAlgHandle.h:77
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Trk::open
@ open
Definition: BinningType.h:40
Athena::RootAsciiDumperAlgHandle::execute
virtual StatusCode execute()
Definition: RootAsciiDumperAlgHandle.cxx:140
Athena::RootAsciiDumperAlgHandle::~RootAsciiDumperAlgHandle
virtual ~RootAsciiDumperAlgHandle()
Destructor:
Definition: RootAsciiDumperAlgHandle.cxx:92
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
RootAsciiDumperAlgHandle.h