Jpp  15.0.1-rc.1-highQE
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
14 #include "JGizmo/JRootObjectID.hh"
15 #include "JGizmo/JGizmoToolkit.hh"
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  */
29 int 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)) {
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 }
Utility class to parse command line options.
Definition: JParser.hh:1500
int main(int argc, char *argv[])
Definition: Main.cc:15
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:151
then for HISTOGRAM in h0 h1
Definition: JMatrixNZ.sh:71
string outputFile
I/O formatting auxiliaries.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:63
General purpose messaging.
#define FATAL(A)
Definition: JMessage.hh:67
Utility class to parse command line options.
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.