Jpp  18.0.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMergeCalibrateToT.cc
Go to the documentation of this file.
1 
2 #include <string>
3 #include <iostream>
4 #include <iomanip>
5 #include <vector>
6 #include <map>
7 
8 #include "TROOT.h"
9 #include "TFile.h"
10 #include "TH1D.h"
11 #include "TH2D.h"
12 #include "TKey.h"
13 #include "TString.h"
14 #include "TMath.h"
15 
17 
18 #include "JROOT/JRootFileReader.hh"
19 #include "JROOT/JRootFileWriter.hh"
20 #include "JSupport/JMeta.hh"
21 
23 
24 #include "Jeep/JParser.hh"
25 #include "Jeep/JMessage.hh"
26 
27 
28 /**
29  * \author mdejong
30  * Auxiliary program to merge time-over-threshold data.
31  */
32 int main(int argc, char **argv)
33 {
34  using namespace std;
35  using namespace JPP;
36  using namespace KM3NETDAQ;
37 
38  vector<string> inputFile;
39  string outputFile;
40  int debug;
41 
42  try {
43 
44  JParser<> zap("Auxiliary program to merge time-over-threshold data.");
45 
46  zap['f'] = make_field(inputFile, "input file (output from JCalibrateToT).");
47  zap['o'] = make_field(outputFile, "output file (input to JFitToT).") = "merge-tot.root";
48  zap['d'] = make_field(debug, "debug.") = 1;
49 
50  zap(argc, argv);
51  }
52  catch(const exception &error) {
53  FATAL(error.what() << endl);
54  }
55 
56 
57  gErrorIgnoreLevel = kError;
58 
59  typedef map<TString, TH1*> map_type;
60 
61  map_type zmap;
62 
63 
64  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
65 
66  DEBUG("Processing " << *i << endl) ;
67 
68  TFile in(i->c_str(), "read");
69 
70  TIter iter(in.GetListOfKeys());
71 
72  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
73 
74  if (TString(key->GetName()).EndsWith(_2SToT)) {
75 
76  TH2* h2 = dynamic_cast<TH2*>(key->ReadObj());
77 
78  map_type::iterator p = zmap.find(h2->GetName());
79 
80  if (p == zmap.end()) {
81 
82  DEBUG("Clone " << h2->GetName() << endl);
83 
84  p = zmap.insert(make_pair(h2->GetName(), (TH2*) h2->Clone())).first;
85 
86  } else {
87 
88  DEBUG("Add " << h2->GetName() << endl);
89 
90  p->second->Add(h2);
91  }
92  }
93  }
94 
95  for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
96  i->second->SetDirectory(0);
97  }
98 
99  in.Close();
100  }
101 
102  // write file
103 
104  TFile out(outputFile.c_str(), "recreate");
105 
106  for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
107 
108  if (i->first.EndsWith(_2SToT)) {
109 
110  TH2D* h2s = (TH2D*) i->second;
111 
112  h2s->Write();
113  }
114  }
115 
116  putObject(out, JMeta(argc, argv));
117 
118  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
119 
120  JMeta::copy(i->c_str(), out);
121 
122  for (JRootFileReader<JDAQHeader> in(i->c_str()); in.hasNext(); ) {
123  putObject(out, *in.next());
124  }
125  }
126 
127  out.Write();
128  out.Close();
129 }
Auxiliary class for ROOT I/O of application specific meta data.
Definition: JMeta.hh:70
Utility class to parse command line options.
Definition: JParser.hh:1514
int main(int argc, char *argv[])
Definition: Main.cc:15
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
ROOT I/O of application specific meta data.
bool putObject(TDirectory &dir, const TObject &object)
Write object to ROOT directory.
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:162
static const char *const _2SToT
Histogram naming.
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:46
ROOT file reader.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62