ATLAS Offline Software
RootAsciiDumperAlg.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 // RootAsciiDumperAlg.cxx
8 // Implementation file for class RootAsciiDumperAlg
9 // Author: S.Binet<binet@cern.ch>
11 
12 // AthenaRootComps includes
13 #include "RootAsciiDumperAlg.h"
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
34 
35 namespace Athena {
36 
38 // Public methods:
40 
41 // Constructors
44  ISvcLocator* pSvcLocator ) :
45  ::AthAlgorithm( name, pSvcLocator ),
46  m_ofname(""),
47  m_ofd(-1),
48  m_nentries(0),
49  m_runnbr(0),
50  m_evtnbr(0),
51  m_el_n(0),
52  m_el_eta(NULL),
53  m_el_jetcone_dr(NULL)
54 {
55  //
56  // Property declaration
57  //
58  //declareProperty( "Property", m_nProperty );
59 
60  declareProperty("AsciiFileName",
61  m_ofname = "d3pd.ascii",
62  "Name of the ascii file where the content of the "
63  "ROOT n-tuple file will be dumped.");
64 
65 }
66 
67 // Destructor
70 {}
71 
72 // Athena Algorithm's Hooks
75 {
76  ATH_MSG_INFO ("Initializing " << name() << "...");
77 
78  ATH_MSG_INFO("dumping data into file ["
79  << m_ofname << "]...");
80  if (m_ofname.empty()) {
81  ATH_MSG_ERROR("cannot dump data into an empty file name!");
82  return StatusCode::FAILURE;
83  }
84  m_ofd = open(m_ofname.c_str(),
85  O_WRONLY | O_CREAT | O_TRUNC,
86  S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
87 
88  if (m_ofd < 0) {
89  ATH_MSG_ERROR("problem opening file [" << m_ofname << "] with "
90  "write permissions.");
91  return StatusCode::FAILURE;
92  }
93 
94  return StatusCode::SUCCESS;
95 }
96 
98 {
99  ATH_MSG_INFO ("Finalizing " << name() << "...");
100 
101  if (m_ofd > 0) {
102  fflush(NULL);
103  if (close(m_ofd) < 0) {
104  ATH_MSG_WARNING("problem while closing [" << m_ofname << "]");
105  }
106  }
107 
108  return StatusCode::SUCCESS;
109 }
110 
112 {
113  ATH_MSG_DEBUG ("Executing " << name() << "...");
114 
116  m_nentries += 1;
117 
118  if (!evtStore()->retrieve(m_runnbr, "RunNumber").isSuccess()) {
119  ATH_MSG_WARNING("could not retrieve [RunNumber] from store");
120  return StatusCode::RECOVERABLE;
121  }
122 
123  if (!evtStore()->retrieve(m_evtnbr, "EventNumber").isSuccess()) {
124  ATH_MSG_WARNING("could not retrieve [EventNumber] from store");
125  return StatusCode::RECOVERABLE;
126  }
127 
128  if (!evtStore()->retrieve(m_el_n, "el_n").isSuccess()) {
129  ATH_MSG_WARNING("could not retrieve [el_n] from store");
130  return StatusCode::RECOVERABLE;
131  }
132 
133  xAOD::EventInfo* ei = nullptr;
134  if (!evtStore()->retrieve(ei, "EventInfo").isSuccess()) {
135  ATH_MSG_WARNING("could not retrieve [el_n] from store");
136  return StatusCode::RECOVERABLE;
137  }
138  static const SG::AuxElement::Accessor<std::string> tupleName ("tupleName");
139  static const SG::AuxElement::Accessor<std::string> collectionName ("collectionName");
140  std::string collName = collectionName(*ei);
141  std::string::size_type pos = collName.rfind ("/");
142  if (pos != std::string::npos) {
143  collName.erase (0, pos+1);
144  }
145 
146  {
147  char* buf = 0;
148  int buf_sz = asprintf
149  (&buf,
150  "%03" PRId64 ".%s = %s\n"
151  "%03" PRId64 ".%s = %s\n"
152  "%03" PRId64 ".%s = %u\n"
153  "%03" PRId64 ".%s = %u\n"
154  "%03" PRId64 ".%s = %i\n",
155  nevts,
156  "collectionName",
157  collName.c_str(),
158  nevts,
159  "tupleName",
160  tupleName(*ei).c_str(),
161  nevts,
162  "RunNumber",
163  *m_runnbr,
164  nevts,
165  "EventNumber",
166  *m_evtnbr,
167  nevts,
168  "el_n",
169  *m_el_n);
170  write(m_ofd, buf, buf_sz);
171  free(buf);
172  }
173 
174  if (*m_el_n > 0) {
175  if (!evtStore()->retrieve(m_el_eta, "el_eta").isSuccess()) {
176  ATH_MSG_WARNING("could not retrieve [el_eta] from store");
177  return StatusCode::RECOVERABLE;
178  }
179 
181  "el_jetcone_dr").isSuccess()) {
182  ATH_MSG_WARNING("could not retrieve [el_jetcone_dr] from store");
183  return StatusCode::RECOVERABLE;
184  }
185 
186  {
187  std::stringstream bufv;
188  for (int32_t ii = 0; ii < *m_el_n; ++ii) {
189  bufv << (*m_el_eta)[ii];
190  if (ii != (*m_el_n)-1) {
191  bufv << ", ";
192  }
193  }
194  char* buf = 0;
195  int buf_sz = asprintf
196  (&buf,
197  "%03" PRId64 ".%s = [%s]\n",
198  nevts,
199  "el_eta",
200  bufv.str().c_str());
201  write(m_ofd, buf, buf_sz);
202  free(buf);
203  }
204 
205 
206  {
207  std::stringstream bufv;
208  for (int32_t ii = 0; ii < *m_el_n; ++ii) {
209  bufv << "[";
210  for (std::size_t jj = 0, jjmax = (*m_el_jetcone_dr)[ii].size();
211  jj < jjmax;
212  ++jj) {
213  bufv << (*m_el_jetcone_dr)[ii][jj];
214  if (jj != jjmax-1) {
215  bufv << ", ";
216  }
217  }
218  bufv << "]";
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_jetcone_dr",
229  bufv.str().c_str());
230  write(m_ofd, buf, buf_sz);
231  free(buf);
232  }
233  }
234 
235  return StatusCode::SUCCESS;
236 }
237 
238 } //> end namespace Athena
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
Athena::RootAsciiDumperAlg::m_nentries
uint64_t m_nentries
number of entries processed so-far
Definition: RootAsciiDumperAlg.h:72
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:66
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
Athena::RootAsciiDumperAlg::initialize
virtual StatusCode initialize()
Definition: RootAsciiDumperAlg.cxx:74
Athena::RootAsciiDumperAlg::m_el_n
const int32_t * m_el_n
number of electrons
Definition: RootAsciiDumperAlg.h:81
BuiltinsClids.h
Athena::RootAsciiDumperAlg::execute
virtual StatusCode execute()
Definition: RootAsciiDumperAlg.cxx:111
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
Athena::RootAsciiDumperAlg::m_runnbr
const uint32_t * m_runnbr
run number
Definition: RootAsciiDumperAlg.h:75
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
RootAsciiDumperAlg.h
StlVectorClids.h
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
Athena::RootAsciiDumperAlg::m_el_eta
const std::vector< float > * m_el_eta
eta of electrons
Definition: RootAsciiDumperAlg.h:84
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::RootAsciiDumperAlg::~RootAsciiDumperAlg
virtual ~RootAsciiDumperAlg()
Destructor:
Definition: RootAsciiDumperAlg.cxx:69
Athena::RootAsciiDumperAlg::m_ofname
std::string m_ofname
ASCII output file name.
Definition: RootAsciiDumperAlg.h:66
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
sg-dump.nevts
nevts
Definition: sg-dump.py:146
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
EventInfo.h
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
xAOD::EventInfo_v1
Class describing the basic event information.
Definition: EventInfo_v1.h:43
Athena::RootAsciiDumperAlg::RootAsciiDumperAlg
RootAsciiDumperAlg()
Default constructor:
Trk::open
@ open
Definition: BinningType.h:40
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Athena::RootAsciiDumperAlg::m_evtnbr
const uint32_t * m_evtnbr
event number
Definition: RootAsciiDumperAlg.h:78
Athena::RootAsciiDumperAlg::m_ofd
int m_ofd
file handle to the ASCII output file
Definition: RootAsciiDumperAlg.h:69
Athena::RootAsciiDumperAlg::m_el_jetcone_dr
const std::vector< std::vector< float > > * m_el_jetcone_dr
jetcone dR
Definition: RootAsciiDumperAlg.h:87
Athena::RootAsciiDumperAlg::finalize
virtual StatusCode finalize()
Definition: RootAsciiDumperAlg.cxx:97