The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
merge.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#include "merge.C"
12#include <TError.h>
13#include <cstdlib>
14
15static int usage() {
16 ::printf( "Gaudi merge facility for ROOT tree based files.\n"
17 " Usage: \n"
18 "gaudi_merge -o <output-file> -i <input-file 1> [ -i <input-file 2> ...]\n\n"
19 "input- and output files may specify any legal (ROOT) file name.\n"
20 " -output Specify output file name.\n"
21 " -input Specify input file name.\n"
22 " -debug Switch debug flag on.\n" );
23 return 1;
24}
25
26static ErrorHandlerFunc_t s_err = nullptr;
27static void err_handler( Int_t level, Bool_t abort_bool, const char* location, const char* msg ) {
28 if ( msg && strstr( msg, "no dictionary for class" ) ) return;
29 s_err( level, abort_bool, location, msg );
30}
31
32int main( int argc, char** argv ) {
33 bool dbg = false, fixup = true;
34 vector<string> input;
35 string output;
36 for ( int i = 1; i < argc; ++i ) {
37 if ( *argv[i] == '-' ) {
38 switch ( ::toupper( *( argv[i] + 1 ) ) ) {
39 case 'N':
40 fixup = false;
41 break;
42 case 'D':
43 dbg = true;
44 break;
45 case 'O':
46 if ( i + 1 < argc ) output = argv[i + 1];
47 ++i;
48 break;
49 case 'I':
50 if ( i + 1 < argc ) input.push_back( argv[i + 1] );
51 ++i;
52 break;
53 default:
54 return usage();
55 }
56 }
57 }
58 if ( input.empty() ) {
59 ::printf( "\nERROR: No input file(s) supplied\n\n" );
60 return usage();
61 } else if ( output.empty() ) {
62 ::printf( "\nERROR: No output file supplied.\n\n" );
63 return usage();
64 }
65 gROOT->SetBatch( kTRUE );
66 s_err = SetErrorHandler( err_handler );
67 for ( size_t i = 0; i < input.size(); ++i ) {
68 const string& in = input[i];
69 bool do_fixup = fixup && ( ( i + 1 ) == input.size() );
70 //::printf("+++ Target:%s\n+++ Source file:%s Fixup:%s Dbg:%s %d %d\n",
71 // output.c_str(),in.c_str(),do_fixup ? "YES" : "NO",dbg ? "YES" : "NO",i,input.size());
72 int result = merge( output.c_str(), in.c_str(), do_fixup, dbg );
73 if ( result == MERGE_ERROR ) {
74 printf( "\nERROR: File merge failed after %ld files.\n\n", long( i + 1 ) );
75 return 1;
76 }
77 }
78 return 0;
79}
int main()
void toupper(std::string &s)
void usage(const std::string &argv0)
int merge(const char *target, const char *source, bool fixup=false, bool dbg=true)
Definition merge.C:417