ATLAS Offline Software
Loading...
Searching...
No Matches
xAODFileReadTest.cxx File Reference
#include <cstring>
#include <memory>
#include <vector>
#include <string>
#include <TFile.h>
#include <TError.h>
#include <TClass.h>
#include "xAODRootAccess/Init.h"
#include "xAODRootAccess/TEvent.h"
#include "xAODRootAccess/tools/Message.h"

Go to the source code of this file.

Classes

class  TEventClass
 Class used for the test. More...

Macros

#define R_CHECK(EXP)
 Helper macro.

Functions

int main (int argc, char *argv[])

Variables

static const char *const APP_NAME = "xAODFileReadTest"
 The name of the application.

Macro Definition Documentation

◆ R_CHECK

#define R_CHECK ( EXP)
Value:
do { \
const auto result = EXP; \
if( ! result.isSuccess() ) { \
Error( APP_NAME, XAOD_MESSAGE( "Failed to execute: %s" ), #EXP ); \
return 1; \
} \
} while( 0 )
#define APP_NAME
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.

Helper macro.

Definition at line 26 of file xAODFileReadTest.cxx.

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 )

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 95 of file xAODFileReadTest.cxx.

95 {
96
97 // Initialise the environment:
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;
116 for( int i = 1; i < argc; ++i ) {
117 if( ! strcmp( argv[ i ], "-m" ) ) {
118 if( i + 1 >= argc ) {
119 ::Error( APP_NAME,
120 XAOD_MESSAGE( "No access mode specified after -m" ) );
121 return 1;
122 } else {
123 const long mode = ::strtol( argv[ i + 1 ], 0, 10 );
124 auxMode = static_cast< xAOD::TEvent::EAuxMode >( mode );
125 ++i;
126 }
127 } else {
128 fileNames.push_back( argv[ i ] );
129 }
130 }
131
132 // Create the "TEvent" object used for the test:
133 TEventClass event( auxMode );
134
135 // Loop over the specified input files:
136 for( const std::string& fileName : fileNames ) {
137
138 // Open the file:
139 std::unique_ptr< TFile > ifile( TFile::Open( fileName.c_str(), "READ" ) );
140 if( ( ! ifile.get() ) || ifile->IsZombie() ) {
141 Error( APP_NAME, XAOD_MESSAGE( "Couldn't open file: %s" ),
142 fileName.c_str() );
143 return 1;
144 }
145 Info( APP_NAME, "Opened file: %s", fileName.c_str() );
146
147 // Give it to TEvent:
148 R_CHECK( event.readFrom( ifile.get() ) );
149
150 // Loop over the file's events:
151 const Long64_t entries = event.getEntries();
152 for( Long64_t entry = 0; entry < entries; ++entry ) {
153
154 // Load the event:
155 if( event.getEntry( entry ) < 0 ) {
157 XAOD_MESSAGE( "Failed to load entry %i from file: %s" ),
158 static_cast< int >( entry ), fileName.c_str() );
159 return 1;
160 }
161
162 // Load the event:
163 R_CHECK( event.loadInputObjects() );
164
165 // Tell the user where we are:
166 if( ( entry % 1000 == 0 ) || ( entry +1 == entries ) ) {
167 Info( APP_NAME, "===>>> Loaded entry %i / %i <<<===",
168 static_cast< int >( entry ), static_cast< int >( entries ) );
169 }
170 }
171 }
172
173 // Return gracefully:
174 return 0;
175}
Class used for the test.
@ kClassAccess
Access auxiliary data using the aux containers.
double entries
Definition listroot.cxx:49
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition Error.h:16
@ Info
Definition ZDCMsg.h:20
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
#define R_CHECK(EXP)
Helper macro.

Variable Documentation

◆ APP_NAME

const char* const APP_NAME = "xAODFileReadTest"
static

The name of the application.

Definition at line 23 of file xAODFileReadTest.cxx.