Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMergeCalibrateToT.cc File Reference
#include <string>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include "TROOT.h"
#include "TFile.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TKey.h"
#include "TString.h"
#include "TMath.h"
#include "JROOT/JRootFileReader.hh"
#include "JSupport/JMeta.hh"
#include "JCalibrate/JCalibrateToT.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

int main ( int  argc,
char **  argv 
)
Author
mdejong Auxiliary program to merge time-over-threshold data.

Definition at line 28 of file JMergeCalibrateToT.cc.

29 {
30  using namespace std;
31  using namespace JPP;
32 
33  vector<string> inputFile;
34  string outputFile;
35  int debug;
36 
37  try {
38 
39  JParser<> zap("Auxiliary program to merge time-over-threshold data.");
40 
41  zap['f'] = make_field(inputFile, "input file (output from JCalibrateToT).");
42  zap['o'] = make_field(outputFile, "output file (input to JFitToT).") = "merge-tot.root";
43  zap['d'] = make_field(debug, "debug.") = 1;
44 
45  zap(argc, argv);
46  }
47  catch(const exception &error) {
48  FATAL(error.what() << endl);
49  }
50 
51 
52  typedef map<TString, TH1*> map_type;
53 
54  map_type zmap;
55 
56 
57  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
58 
59  DEBUG("Processing " << *i << endl) ;
60 
61  TFile in(i->c_str(), "read");
62 
63  TIter iter(in.GetListOfKeys());
64 
65  for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
66 
67  TH2* h2 = dynamic_cast<TH2*>(key->ReadObj());
68 
69  if (h2 != NULL) {
70 
71  map_type::iterator p = zmap.find(h2->GetName());
72 
73  if (p == zmap.end()) {
74 
75  DEBUG("Clone " << h2->GetName() << endl);
76 
77  p = zmap.insert(make_pair(h2->GetName(), (TH2*) h2->Clone())).first;
78 
79  } else {
80 
81  DEBUG("Add " << h2->GetName() << endl);
82 
83  p->second->Add(h2);
84  }
85  }
86  }
87 
88  for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
89  i->second->SetDirectory(0);
90  }
91 
92  in.Close();
93  }
94 
95  // write file
96 
97  TFile out(outputFile.c_str(), "recreate");
98 
99  for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) {
100 
101  if (i->first.EndsWith(_2SToT)) {
102 
103  TH2D* h2s = (TH2D*) i->second;
104 
105  h2s->Write();
106  }
107  }
108 
109  putObject(&out, JMeta(argc, argv));
110 
111  for (vector<string>::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) {
112  JMeta::copy(i->c_str(), out);
113  }
114 
115  out.Write();
116  out.Close();
117 }
Utility class to parse command line options.
Definition: JParser.hh:1500
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
void copy(const Head &from, JHead &to)
Copy header from from to to.
Definition: JHead.cc:139
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 source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:38
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62
bool putObject(TDirectory *dir, const T &object)
Write object to ROOT directory.