Jpp  18.5.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMergeNB.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <string>
3 #include <vector>
4 #include <map>
5 
6 #include "Jeep/JParser.hh"
7 
8 #include "TH1.h"
9 #include "TFile.h"
10 #include "TKey.h"
11 
12 using namespace std;
13 using namespace JPP;
14 
15 int main(int argc , char** argv){
16 
17  vector<string> inputFiles;
18  string outFile;
19 
20  try {
21 
22  JParser<> zap;
23 
24  zap['f'] = make_field(inputFiles);
25  zap['o'] = make_field(outFile ) = "out.root";
26 
27  zap(argc,argv);
28  }
29  catch(const exception &error) {
30  ERROR(error.what() << endl);
31  }
32 
34  map_type zmap;
35 
36  for(vector<string>::const_iterator i = inputFiles.begin(); i != inputFiles.end(); ++i){
37  cout << " Now processing: " << *i << endl;
38  TFile in(i->c_str() , "read");
39 
40  TIter iter(in.GetListOfKeys());
41 
42  for(TKey *key; (key = (TKey*) iter.Next()) != NULL; ){
43 
44  TH1* h = dynamic_cast<TH1*>(key->ReadObj());
45 
46  if( h != NULL){
47 
48  map_type::iterator p = zmap.find(h->GetName());
49 
50  if (p == zmap.end()){
51 
52  p = zmap.insert( make_pair( h->GetName(), (TH1*) h->Clone() )).first;
53 
54  } else {
55 
56  p->second->Add(h);
57  }
58  }
59  }
60 
61  for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
62  i->second->SetDirectory(0);
63  }
64 
65  in.Close();
66  }
67 
68  TFile output(outFile.c_str() , "recreate") ;
69  for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
70 
71  TH1D* hist = (TH1D*) i->second;
72  hist->Write();
73  }
74  output.Close();
75 }
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define ERROR(A)
Definition: JMessage.hh:66
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:48
Utility class to parse command line options.
std::map< int, range_type > map_type