All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
merge.cpp
Go to the documentation of this file.
1 #include "merge/merge.C"
2 #include "TError.h"
3 #include <cstdlib>
4 
5 static int usage() {
6  ::printf("Gaudi merge facility for ROOT tree based files.\n"
7  " Usage: \n"
8  "gaudi_merge -o <output-file> -i <input-file 1> [ -i <input-file 2> ...]\n\n"
9  "input- and output files may specify any legal (ROOT) file name.\n"
10  " -output Specify output file name.\n"
11  " -input Specify input file name.\n"
12  " -debug Switch debug flag on.\n"
13  );
14  return 1;
15 }
16 
17 static ErrorHandlerFunc_t s_err = nullptr;
18 static void err_handler(Int_t level, Bool_t abort_bool, const char *location, const char *msg)
19 {
20  if ( msg && strstr(msg,"no dictionary for class") ) return;
21  s_err(level,abort_bool, location, msg);
22 }
23 
24 int main(int argc, char** argv) {
25  bool dbg = false, fixup=true;
26  vector<string> input;
27  string output;
28  for(int i=1; i < argc; ++i) {
29  if ( *argv[i] == '-' ) {
30  switch(::toupper(*(argv[i]+1))) {
31  case 'N':
32  fixup = false;
33  break;
34  case 'D':
35  dbg = true;
36  break;
37  case 'O':
38  if ( i+1 < argc ) output = argv[i+1];
39  ++i;
40  break;
41  case 'I':
42  if ( i+1 < argc ) input.push_back(argv[i+1]);
43  ++i;
44  break;
45  default:
46  return usage();
47  }
48  }
49  }
50  if ( input.empty() ) {
51  ::printf("\nERROR: No input file(s) supplied\n\n");
52  return usage();
53  }
54  else if ( output.empty() ) {
55  ::printf("\nERROR: No output file supplied.\n\n");
56  return usage();
57  }
58  gROOT->SetBatch(kTRUE);
59  s_err = SetErrorHandler(err_handler);
60  for(size_t i=0; i<input.size();++i) {
61  const string& in = input[i];
62  bool do_fixup = fixup && ((i+1)==input.size());
63  //::printf("+++ Target:%s\n+++ Source file:%s Fixup:%s Dbg:%s %d %d\n",
64  // output.c_str(),in.c_str(),do_fixup ? "YES" : "NO",dbg ? "YES" : "NO",i,input.size());
65  int result = merge(output.c_str(),in.c_str(),do_fixup,dbg);
66  if ( result == MERGE_ERROR ) {
67  printf("\nERROR: File merge failed after %ld files.\n\n",long(i+1));
68  return 1;
69  }
70  }
71  return 0;
72 }
list argv
Definition: gaudirun.py:227
void usage(std::string argv0)
T strstr(T...args)
int main(int argc, char **argv)
Definition: merge.cpp:24
void toupper(std::string &s)