#include #include #include #include #include #include "TROOT.h" #include "TFile.h" #include "TH1D.h" #include "TH2D.h" #include "TKey.h" #include "TString.h" #include "TMath.h" #include "km3net-dataformat/online/JDAQHeader.hh" #include "JROOT/JRootFileReader.hh" #include "JROOT/JRootFileWriter.hh" #include "JSupport/JMeta.hh" #include "JCalibrate/JCalibrateToT.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" /** * \author mdejong * Auxiliary program to merge time-over-threshold data. */ int main(int argc, char **argv) { using namespace std; using namespace JPP; using namespace KM3NETDAQ; vector inputFile; string outputFile; int debug; try { JParser<> zap("Auxiliary program to merge time-over-threshold data."); zap['f'] = make_field(inputFile, "input file (output from JCalibrateToT)."); zap['o'] = make_field(outputFile, "output file (input to JFitToT).") = "merge-tot.root"; zap['d'] = make_field(debug, "debug.") = 1; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } gErrorIgnoreLevel = kError; typedef map map_type; map_type zmap; for (vector::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) { DEBUG("Processing " << *i << endl) ; TFile in(i->c_str(), "read"); TIter iter(in.GetListOfKeys()); for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) { if (TString(key->GetName()).EndsWith(_2SToT)) { TH2* h2 = dynamic_cast(key->ReadObj()); map_type::iterator p = zmap.find(h2->GetName()); if (p == zmap.end()) { DEBUG("Clone " << h2->GetName() << endl); p = zmap.insert(make_pair(h2->GetName(), (TH2*) h2->Clone())).first; } else { DEBUG("Add " << h2->GetName() << endl); p->second->Add(h2); } } } for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) { i->second->SetDirectory(0); } in.Close(); } // write file TFile out(outputFile.c_str(), "recreate"); for (map_type::iterator i = zmap.begin(); i != zmap.end(); ++i) { if (i->first.EndsWith(_2SToT)) { TH2D* h2s = (TH2D*) i->second; h2s->Write(); } } putObject(out, JMeta(argc, argv)); for (vector::const_iterator i = inputFile.begin(); i != inputFile.end(); ++i) { JMeta::copy(i->c_str(), out); for (JRootFileReader in(i->c_str()); in.hasNext(); ) { putObject(out, *in.next()); } } out.Write(); out.Close(); }