Jpp  18.0.0-rc.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JStack1D.cc File Reference

Auxiliary program to make stack of ROOT histograms. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TROOT.h"
#include "TFile.h"
#include "TObject.h"
#include "TKey.h"
#include "TH1.h"
#include "THStack.h"
#include "TString.h"
#include "TRegexp.h"
#include "JGizmo/JRootObjectID.hh"
#include "JGizmo/JGizmoToolkit.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Auxiliary program to make stack of ROOT histograms.

The option -f corresponds to <file name>:<object name>.

Author
mdejong

Definition in file JStack1D.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 29 of file JStack1D.cc.

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 }
Utility class to parse command line options.
Definition: JParser.hh:1514
#define MAKE_CSTRING(A)
Make C-string.
Definition: JPrint.hh:136
string outputFile
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1989
#define ERROR(A)
Definition: JMessage.hh:66
#define FATAL(A)
Definition: JMessage.hh:67
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
int debug
debug level
#define DEBUG(A)
Message macros.
Definition: JMessage.hh:62