ATLAS Offline Software
Loading...
Searching...
No Matches
xAODMerge.cxx File Reference
#include <cstring>
#include <vector>
#include <cstdlib>
#include <TError.h>
#include "xAODRootAccess/tools/TFileMerger.h"
#include "xAODRootAccess/tools/Message.h"
#include "xAODRootAccess/Init.h"
Include dependency graph for xAODMerge.cxx:

Go to the source code of this file.

Macros

#define R_CHECK(EXP)
 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.

Functions

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

Macro Definition Documentation

◆ R_CHECK

#define R_CHECK ( EXP)
Value:
do { \
if( ! EXP.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.

Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.

Executable replacing "hadd" for merging xAOD files in standalone mode

This executable can be used outside of Athena to conveniently merge xAOD files into a single output file. It is mainly meant to be used for merging files on the grid, or on PROOF. But it can also be used for other simple merging operations.

Author
Attila Krasznahorkay Attil.nosp@m.a.Kr.nosp@m.aszna.nosp@m.hork.nosp@m.ay@ce.nosp@m.rn.c.nosp@m.h Helper macro to return proper error codes when failing

Definition at line 27 of file xAODMerge.cxx.

27#define R_CHECK( EXP ) \
28 do { \
29 if( ! EXP.isSuccess() ) { \
30 ::Error( APP_NAME, XAOD_MESSAGE( "Failed to execute \"%s\"" ), \
31 #EXP ); \
32 return 1; \
33 } \
34 } while( 0 )

Function Documentation

◆ main()

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

Definition at line 36 of file xAODMerge.cxx.

36 {
37
38 // The name of the application:
39 const char* APP_NAME = argv[ 0 ];
40
41 // Provide usage instructions if not enough options were given:
42 if( ( argc < 3 ) ||
43 ( ! strcmp( argv[ 1 ], "-h" ) ) ||
44 ( ! strcmp( argv[ 1 ], "--help" ) ) ) {
45 ::Info( APP_NAME, " " );
46 ::Info( APP_NAME, "Usage: %s [options] outputFile inputFile1 "
47 "[inputFile2 ...]",
48 APP_NAME );
49 ::Info( APP_NAME, " " );
50 ::Info( APP_NAME, " Options:" );
51 ::Info( APP_NAME, " -s Use slow xAOD tree merging" );
52 ::Info( APP_NAME, " -b Use branch-access for slow and metadata "
53 "merging" );
54 ::Info( APP_NAME, " -v NUMBER Use a specific verbosity setting" );
55 ::Info( APP_NAME, " -m Metadata tool type to use during the merge" );
56 ::Info( APP_NAME, " -e NUMBER Number of events to merge in slow "
57 "merging mode" );
58 ::Info( APP_NAME, " " );
59 return 1;
60 }
61
62 // Initialise the environment:
64
65 // Decode the command line options:
66 bool useSlowMerge = false;
68 const char* outputName = 0;
69 std::vector< const char* > inputNames;
70 int verbosity = 0;
71 std::vector< const char* > metaDataTools;
73 for( int i = 1; i < argc; ++i ) {
74 if( ! strcmp( argv[ i ], "-s" ) ) {
75 useSlowMerge = true;
76 } else if( ! strcmp( argv[ i ], "-b" ) ) {
78 } else if( ! strcmp( argv[ i ], "-v" ) ) {
79 if( i + 1 >= argc ) {
80 ::Error( APP_NAME, "No verbosity level was provided after -v" );
81 } else {
82 const long request = strtol( argv[ i + 1 ], 0, 10 );
83 if( ( request < kMaxLong ) && ( request >= 0 ) ) {
84 verbosity = static_cast< int >( request );
85 ++i;
86 } else {
87 ::Error( APP_NAME, "Could not parse the verbosity level passed "
88 "after -v: %s", argv[ i + 1 ] );
89 ::Error( APP_NAME, "Will use the default value (0)" );
90 }
91 }
92 } else if( ! strcmp( argv[ i ], "-m" ) ) {
93 if( i + 1 >= argc ) {
94 ::Error( APP_NAME, "No tool type name provided after -m" );
95 } else {
96 metaDataTools.push_back( argv[ i + 1 ] );
97 ++i;
98 }
99 } else if( ! strcmp( argv[ i ], "-e" ) ) {
100 if( i + 1 >= argc ) {
101 ::Error( APP_NAME, "No verbosity level was provided after -e" );
102 } else {
103 const long request = strtol( argv[ i + 1 ], 0, 10 );
104 if( ( request < kMaxLong ) && ( request >= 0 ) ) {
105 entries = static_cast< ::Long64_t >( request );
106 ++i;
107 } else {
108 ::Error( APP_NAME, "Could not parse the number of entries "
109 "passed after -e: %s", argv[ i + 1 ] );
110 ::Error( APP_NAME, "Will use the default value (%i)",
111 static_cast< int >( xAOD::TFileMerger::kBigNumber ) );
112 }
113 }
114 } else if( ! outputName ) {
115 outputName = argv[ i ];
116 } else {
117 inputNames.push_back( argv[ i ] );
118 }
119 }
120
121 if( ! outputName ) {
122 ::Error( APP_NAME, "No output name provided." );
123 return 1;
124 }
125
126 // Set up the file merger object:
127 xAOD::TFileMerger merger;
128 merger.setAccessMode( mode );
129 merger.setVerbosity( verbosity );
130 R_CHECK( merger.setOutputFileName( outputName ) );
131 for( auto name : inputNames ) {
132 R_CHECK( merger.addFile( name ) );
133 }
134 for( auto typeName : metaDataTools ) {
135 R_CHECK( merger.addMetaDataTool( typeName ) );
136 }
137
138 // Execute the merge:
139 R_CHECK( merger.merge( useSlowMerge ? xAOD::TFileMerger::kSlowMerge :
141
142 return 0;
143}
@ kClassAccess
Access auxiliary data using the aux containers.
@ kBranchAccess
Access auxiliary data branch-by-branch.
Helper class for merging xAOD files.
Definition TFileMerger.h:47
StatusCode merge(EMergeMode mode=kFastMerge, ::Long64_t entries=kBigNumber)
Execute the file merge itself.
void setAccessMode(TEvent::EAuxMode mode)
Set the access mode used for slow and metadata merging.
StatusCode setOutputFileName(const std::string &name, const std::string &mode="RECREATE")
Set the name of the output file that should be created.
StatusCode addMetaDataTool(const std::string &typeName)
Add a metadata tool to be used during the merging.
static const ::Long64_t kBigNumber
Number of entries that are assumed to be never exceeded in a file.
Definition TFileMerger.h:77
void setVerbosity(int value)
Set verbosity level (meant for debugging mainly)
@ kSlowMerge
Merging is done using TEvent.
Definition TFileMerger.h:72
@ kFastMerge
Merging is done using fast TTree merge.
Definition TFileMerger.h:73
StatusCode addFile(const std::string &name, bool copyLocally=false)
Add a file to the list to be merged, by name.
double entries
Definition listroot.cxx:49
str outputName
Definition lumiFormat.py:65
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition Init.cxx:31
#define R_CHECK(EXP)
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
Definition xAODMerge.cxx:27