ATLAS Offline Software
Classes | Macros | Functions
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. More...
 

Functions

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

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 )

Helper macro.

Definition at line 27 of file xAODFileReadTest.cxx.

Function Documentation

◆ main()

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

Definition at line 95 of file xAODFileReadTest.cxx.

95  {
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;
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 ) {
156  Error( APP_NAME,
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 }
R_CHECK
#define R_CHECK(EXP)
Helper macro.
Definition: xAODFileReadTest.cxx:26
get_generator_info.result
result
Definition: get_generator_info.py:21
checkxAOD.fileNames
fileNames
Definition: Tools/PyUtils/bin/checkxAOD.py:79
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition: Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
TEventClass
Class used for the test.
Definition: xAODFileReadTest.cxx:36
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:71
ZDCMsg::Info
@ Info
Definition: ZDCMsg.h:20
POOL::TEvent::readFrom
StatusCode readFrom(TFile *file)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:133
event
POOL::TEvent event(POOL::TEvent::kClassAccess)
POOL::TEvent::getEntry
int getEntry(long entry)
Definition: PhysicsAnalysis/POOLRootAccess/src/TEvent.cxx:185
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArCellNtuple.argv
argv
Definition: LArCellNtuple.py:152
Preparation.mode
mode
Definition: Preparation.py:107
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:19
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::TEvent::EAuxMode
EAuxMode
Auxiliary store "mode".
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:69
entries
double entries
Definition: listroot.cxx:49
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
LArCellNtuple.ifile
string ifile
Definition: LArCellNtuple.py:133
jobOptions.fileName
fileName
Definition: jobOptions.SuperChic_ALP2.py:39
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31