Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JPrint1D.cc File Reference

Auxiliary program to print contents of 1D ROOT objects. More...

#include <string>
#include <iostream>
#include <iomanip>
#include <limits>
#include "TROOT.h"
#include "TFile.h"
#include "TClass.h"
#include "TKey.h"
#include "TRegexp.h"
#include "TH1.h"
#include "TGraph.h"
#include "TProfile.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 print contents of 1D ROOT objects.

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

Author
mdejong

Definition in file JPrint1D.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 29 of file JPrint1D.cc.

30{
31 using namespace std;
32 using namespace JPP;
33
34 vector<JRootObjectID> inputFile;
35 int debug;
36
37 try {
38
39 JParser<> zap("Auxiliary program to print contents of 1D ROOT objects.");
40
41 zap['f'] = make_field(inputFile, "<input file>:<object name>");
42 zap['d'] = make_field(debug) = 0;
43
44 zap(argc, argv);
45 }
46 catch(const exception &error) {
47 FATAL(error.what() << endl);
48 }
49
50
51 for (vector<JRootObjectID>::const_iterator input = inputFile.begin(); input != inputFile.end(); ++input) {
52
53 DEBUG("Input: " << *input << endl);
54
55 TDirectory* dir = getDirectory(*input);
56
57 if (dir == NULL) {
58 ERROR("File: " << input->getFullFilename() << " not opened." << endl);
59 continue;
60 }
61
62 const TRegexp regexp(input->getObjectName());
63
64 TIter iter(dir->GetListOfKeys());
65
66 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
67
68 const TString tag(key->GetName());
69
70 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
71
72 // option match
73
74 if (tag.Contains(regexp) && isTObject(key)) {
75
76 TObject* object = key->ReadObj();
77
78 try {
79
80 TH1& h1 = dynamic_cast<TH1&>(*object);
81
82 for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
83
84 cout << setw(32) << left << key->GetName() << right << ' '
85 << setw(4) << ix << ' '
86 << SCIENTIFIC(15,5) << h1.GetXaxis()->GetBinCenter (ix) << ' '
87 << SCIENTIFIC(15,5) << h1.GetBinContent(ix) << endl;
88 }
89 }
90 catch(exception&) {}
91
92 try {
93
94 TProfile& h1 = dynamic_cast<TProfile&>(*object);
95
96 for (Int_t ix = 1; ix <= h1.GetXaxis()->GetNbins(); ++ix) {
97
98 cout << setw(32) << left << key->GetName() << right << ' '
99 << setw(4) << ix << ' '
100 << SCIENTIFIC(15,5) << h1.GetXaxis()->GetBinCenter (ix) << ' '
101 << SCIENTIFIC(15,5) << h1.GetBinContent(ix) << endl;
102 }
103 }
104 catch(exception&) {}
105
106 try {
107
108 TGraph& g1 = dynamic_cast<TGraph&>(*object);
109
110 for (Int_t i = 0; i != g1.GetN(); ++i) {
111
112 cout << setw(32) << left << key->GetName() << right << ' '
113 << setw(4) << i << ' '
114 << SCIENTIFIC(15,5) << g1.GetX()[i] << ' '
115 << SCIENTIFIC(15,5) << g1.GetX()[i] << endl;
116 }
117 }
118 catch(exception&) {}
119 }
120 }
121 }
122}
#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:74
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
Double_t g1(const Double_t x)
Function.
Definition JQuantiles.cc:25
Utility class to parse command line options.
Definition JParser.hh:1698
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer.
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488