ATLAS Offline Software
xAODMerge.cxx
Go to the documentation of this file.
1 
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 
36 int 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 }
TFileMerger.h
xAOD::TFileMerger::merge
StatusCode merge(EMergeMode mode=kFastMerge, ::Long64_t entries=kBigNumber)
Execute the file merge itself.
xAOD::TFileMerger::setVerbosity
void setVerbosity(int value)
Set verbosity level (meant for debugging mainly)
xAOD::TFileMerger::addFile
StatusCode addFile(const std::string &name, bool copyLocally=false)
Add a file to the list to be merged, by name.
LArCellConditions.argv
argv
Definition: LArCellConditions.py:112
xAOD::TEvent::kClassAccess
@ kClassAccess
Access auxiliary data using the aux containers.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:97
xAOD::TFileMerger::kSlowMerge
@ kSlowMerge
Merging is done using TEvent.
Definition: TFileMerger.h:72
xAOD::TFileMerger::addMetaDataTool
StatusCode addMetaDataTool(const std::string &typeName)
Add a metadata tool to be used during the merging.
lumiFormat.i
int i
Definition: lumiFormat.py:85
Message.h
APP_NAME
#define APP_NAME
Definition: BoostedXbbTag.cxx:23
Init.h
Preparation.mode
mode
Definition: Preparation.py:94
main
int main(int argc, char *argv[])
Definition: xAODMerge.cxx:36
DQHistogramMergeRegExp.argc
argc
Definition: DQHistogramMergeRegExp.py:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
R_CHECK
#define R_CHECK(EXP)
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
Definition: xAODMerge.cxx:27
covarianceTool.verbosity
verbosity
Definition: covarianceTool.py:513
xAOD::TFileMerger::setOutputFileName
StatusCode setOutputFileName(const std::string &name, const std::string &mode="RECREATE")
Set the name of the output file that should be created.
lumiFormat.outputName
string outputName
Definition: lumiFormat.py:65
xAOD::TFileMerger
Helper class for merging xAOD files.
Definition: TFileMerger.h:47
xAOD::TFileMerger::kFastMerge
@ kFastMerge
Merging is done using fast TTree merge.
Definition: TFileMerger.h:73
xAOD::TEvent::EAuxMode
EAuxMode
Auxiliary store "mode".
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:95
xAOD::TFileMerger::setAccessMode
void setAccessMode(TEvent::EAuxMode mode)
Set the access mode used for slow and metadata merging.
entries
double entries
Definition: listroot.cxx:49
ReadCalibFromCool.typeName
typeName
Definition: ReadCalibFromCool.py:477
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
xAOD::TEvent::kBranchAccess
@ kBranchAccess
Access auxiliary data branch-by-branch.
Definition: Control/xAODRootAccess/xAODRootAccess/TEvent.h:96
xAOD::TFileMerger::kBigNumber
static const ::Long64_t kBigNumber
Number of entries that are assumed to be never exceeded in a file.
Definition: TFileMerger.h:77
xAOD::Init
StatusCode Init(const char *appname)
Function initialising ROOT/PyROOT for using the ATLAS EDM.
Definition: Init.cxx:31