Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JStack1D.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3#include <iomanip>
4
5#include "TROOT.h"
6#include "TFile.h"
7#include "TObject.h"
8#include "TKey.h"
9#include "TH1.h"
10#include "THStack.h"
11#include "TString.h"
12#include "TRegexp.h"
13
16
17#include "Jeep/JPrint.hh"
18#include "Jeep/JParser.hh"
19#include "Jeep/JMessage.hh"
20
21
22/**
23 * \file
24 *
25 * Auxiliary program to make stack of ROOT histograms.
26 * The option <tt>-f</tt> corresponds to <tt><file name>:<object name></tt>.
27 * \author mdejong
28 */
29int main(int argc, char **argv)
30{
31 using namespace std;
32 using namespace JPP;
33
34 vector<JRootObjectID> inputFile;
35 string outputFile;
36 int debug;
37
38 try {
39
40 JParser<> zap("Auxiliary program to make stack of ROOT histograms.");
41
42 zap['f'] = make_field(inputFile, "<input file>:<object name>");
43 zap['o'] = make_field(outputFile, "ROOT file with histogram(s)") = "stack.root";
44 zap['d'] = make_field(debug) = 0;
45
46 zap(argc, argv);
47 }
48 catch(const exception &error) {
49 FATAL(error.what() << endl);
50 }
51
52
53 THStack* hs = NULL;
54
55 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
56
57 DEBUG("Input: " << *input << endl);
58
59 TDirectory* dir = getDirectory(*input);
60
61 if (dir == NULL) {
62 ERROR("File: " << input->getFullFilename() << " not opened." << endl);
63 continue;
64 }
65
66 const TRegexp regexp(input->getObjectName());
67
68 TIter iter(dir->GetListOfKeys());
69
70 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
71
72 const TString tag(key->GetName());
73
74 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
75
76 // option match
77
78 if (tag.Contains(regexp) && isTObject(key)) {
79
80 TH1* h1 = dynamic_cast<TH1*>(key->ReadObj());
81
82 if (h1 != NULL) {
83
84 if (hs == NULL) {
85 hs = new THStack(MAKE_CSTRING(h1->GetName() << "_s"), NULL);
86 }
87
88 hs->Add(h1);
89 }
90 }
91 }
92 }
93
94 if (hs != NULL) {
95
96 TFile out(outputFile.c_str(), "recreate");
97
98 out.WriteTObject(hs);
99
100 out.Write();
101 out.Close();
102 }
103}
string outputFile
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define ERROR(A)
Definition JMessage.hh:66
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
I/O formatting auxiliaries.
#define MAKE_CSTRING(A)
Make C-string.
Definition JPrint.hh:72
int main(int argc, char **argv)
Definition JStack1D.cc:29
Utility class to parse command line options.
Definition JParser.hh:1698
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).