ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
xAODRootAccess
util
xAODRNFileReadTest.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
6
// System include(s):
7
#include <cstring>
8
#include <memory>
9
#include <vector>
10
#include <string>
11
12
// ROOT include(s):
13
#include <TFile.h>
14
#include <TError.h>
15
#include <TClass.h>
16
17
// Local include(s):
18
#include "
xAODRootAccess/Init.h
"
19
#include "
xAODRootAccess/REvent.h
"
20
#include "
xAODRootAccess/tools/Message.h
"
21
23
static
const
char
*
const
APP_NAME
=
"xAODFileReadTest"
;
24
26
#define R_CHECK( EXP ) \
27
do { \
28
const auto result = EXP; \
29
if( ! result.isSuccess() ) { \
30
Error( APP_NAME, XAOD_MESSAGE( "Failed to execute: %s" ), #EXP ); \
31
return 1; \
32
} \
33
} while( 0 )
34
36
class
REventClass
:
public
xAOD::Experimental::REvent
{
37
public
:
38
// Inherit the constructor(s).
39
using
xAOD::Experimental::REvent::REvent
;
40
42
StatusCode
loadInputObjects
() {
43
// Get the event format object:
44
const
xAOD::EventFormat
* ef = this->
inputEventFormat
();
45
if
( ! ef ) {
46
return
StatusCode::FAILURE;
47
}
48
// Loop over the objects of the file:
49
for
(
const
auto
& ef_itr : *ef ) {
50
// A helper object:
51
const
xAOD::EventFormatElement
& efe = ef_itr.second;
52
// Skip auxiliary objects:
53
if
( efe.
branchName
().rfind(
"Aux."
) ==
54
( efe.
branchName
().size() - 4 ) ) {
55
continue
;
56
}
57
// And dynamic variables:
58
if
( efe.
parentName
() !=
""
) {
59
continue
;
60
}
61
// Skip auxiliary stores with non-standard names:
62
::TClass* cl = ::TClass::GetClass( efe.
className
().c_str(), kTRUE,
63
kTRUE );
64
if
( ! cl )
continue
;
65
if
( cl->InheritsFrom(
"SG::IConstAuxStore"
) ) {
66
continue
;
67
}
68
// Get the type of the branch:
69
const
std::type_info* ti = cl->GetTypeInfo();
70
if
( ! ti ) {
71
::Warning(
"REventClass::loadInputObjects"
,
72
"Couldn't find std::type_info object for type %s "
73
"(key=%s)"
, cl->GetName(), efe.
branchName
().c_str() );
74
continue
;
75
}
76
// Check if the branch exists in the file:
77
static
constexpr
bool
METADATA =
false
;
78
if
( ! this->
contains
( efe.
branchName
(), *ti, METADATA ) ) {
79
continue
;
80
}
81
// Try to load the object/container:
82
static
constexpr
bool
SILENT =
false
;
83
if
( ! this->
getInputObject
( efe.
branchName
(), *ti, SILENT, METADATA ) ) {
84
Error(
"REventClass::loadInputObjects"
,
85
XAOD_MESSAGE
(
"Couldn't load object: %s"
),
86
efe.
branchName
().c_str() );
87
return
StatusCode::FAILURE;
88
}
89
}
90
// Return gracefully:
91
return
StatusCode::SUCCESS;
92
}
93
};
// class REventClass
94
95
int
main
(
int
argc,
char
* argv[] ) {
96
97
// Initialise the environment:
98
R_CHECK
(
xAOD::Init
() );
99
100
// Provide usage instructions if not enough options were given:
101
if
( ( argc < 2 ) ||
102
( ! strcmp( argv[ 1 ],
"-h"
) ) ||
103
( ! strcmp( argv[ 1 ],
"--help"
) ) ) {
104
Info(
APP_NAME
,
"Usage: %s [options] <file1> [file2]..."
,
APP_NAME
);
105
Info(
APP_NAME
,
"Options:"
);
106
Info(
APP_NAME
,
" -m <access mode>"
);
107
Info(
APP_NAME
,
" 0: Branch access"
);
108
Info(
APP_NAME
,
" 1: Class access (default)"
);
109
Info(
APP_NAME
,
" 2: Athena access"
);
110
return
1;
111
}
112
113
// Decode the command line options:
114
std::vector< std::string > fileNames;
115
for
(
int
i = 1; i < argc; ++i ) {
116
fileNames.push_back( argv[ i ] );
117
}
118
119
// Create the "REvent" object used for the test:
120
REventClass
event;
121
122
// Loop over the specified input files:
123
for
(
const
std::string& fileName : fileNames ) {
124
125
// // Open the file:
126
Info(
APP_NAME
,
"Opening file: %s"
, fileName.c_str() );
127
128
// Give it to Event:
129
130
// Call readFrom to setup REvent for reading
131
R_CHECK
( event.readFrom( fileName ) );
132
133
// Loop over the file's events:
134
const
Long64_t
entries
=
event
.getEntries();
135
for
( Long64_t entry = 0; entry <
entries
; ++entry ) {
136
137
// Load the event:
138
if
( event.getEntry( entry ) < 0 ) {
139
Error(
APP_NAME
,
140
XAOD_MESSAGE
(
"Failed to load entry %i from file: %s"
),
141
static_cast<
int
>
( entry ), fileName.c_str() );
142
return
1;
143
}
144
145
// Load the event:
146
R_CHECK
( event.loadInputObjects() );
147
148
// Tell the user where we are:
149
if
( ( entry % 1000 == 0 ) || ( entry +1 ==
entries
) ) {
150
Info(
APP_NAME
,
"===>>> Loaded entry %i / %i <<<==="
,
151
static_cast<
int
>
( entry ),
static_cast<
int
>
(
entries
) );
152
}
153
}
154
}
155
156
// Return gracefully:
157
return
0;
158
}
APP_NAME
#define APP_NAME
Definition
BoostedXbbTag.cxx:25
Message.h
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition
Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
Init.h
REvent.h
REventClass
Class used for the test.
Definition
xAODRNFileReadTest.cxx:36
REventClass::loadInputObjects
StatusCode loadInputObjects()
Function loading all interface objects of the event.
Definition
xAODRNFileReadTest.cxx:42
xAOD::EventFormatElement
Class describing one branch of the ROOT file.
Definition
EventFormatElement.h:35
xAOD::EventFormatElement::branchName
const std::string & branchName() const
Get the branch/key name.
Definition
EventFormatElement.cxx:30
xAOD::EventFormatElement::parentName
const std::string & parentName() const
Get the name of the parent auxiliary object.
Definition
EventFormatElement.cxx:42
xAOD::EventFormatElement::className
const std::string & className() const
Get the class name of this branch/key.
Definition
EventFormatElement.cxx:36
xAOD::Event::inputEventFormat
const EventFormat * inputEventFormat() const
Get information about the input objects.
Definition
EventCore.cxx:235
xAOD::Event::contains
bool contains(const std::string &key)
Function checking if an object is available from the store.
xAOD::Event::getInputObject
const void * getInputObject(SG::sgkey_t key, const std::type_info &ti, bool silent) override
Function for retrieving an input object in a non-template way.
Definition
EventTVirtualEvent.cxx:162
xAOD::Experimental::REvent
Tool for accessing xAOD files outside of Athena, version RNTuple.
Definition
REvent.h:33
xAOD::Experimental::REvent::REvent
REvent()
Default constructor.
Definition
REvent.cxx:144
main
int main()
Definition
hello.cxx:18
entries
double entries
Definition
listroot.cxx:49
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition
Init.cxx:31
xAOD::EventFormat
EventFormat_v1 EventFormat
Definition of the current event format version.
Definition
EventFormat.h:16
R_CHECK
#define R_CHECK(EXP)
Helper macro.
Definition
xAODRNFileReadTest.cxx:26
Generated on
for ATLAS Offline Software by
1.17.0