ATLAS Offline Software
Loading...
Searching...
No Matches
xAODMerge.cxx
Go to the documentation of this file.
1
12
13// System include(s):
14#include <cstring>
15#include <vector>
16#include <cstdlib>
17
18// ROOT include(s):
19#include <TError.h>
20
21// Local include(s):
24#include "xAODRootAccess/Init.h"
25
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 )
35
36int main( int argc, char* argv[] ) {
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}
#define APP_NAME
@ 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.
int main()
Definition hello.cxx:18
double entries
Definition listroot.cxx:49
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