Jpp 20.0.0-195-g190c9e876
the software that should make you happy
Loading...
Searching...
No Matches
JRootTypewriter.cc
Go to the documentation of this file.
1#include <string>
2#include <iostream>
3
4#include "TObject.h"
5#include "TFile.h"
6#include "TError.h"
7#include "TKey.h"
8#include "TClass.h"
9#include "TTree.h"
10#include "TString.h"
11#include "TRegexp.h"
12
13#include "JROOT/JRootClass.hh"
15
16#include "JSupport/JLimit.hh"
17
18#include "Jeep/JParser.hh"
19#include "Jeep/JMessage.hh"
20
21
22/**
23 * Example application to test printing of objects using ROOT dictionary.
24 */
25int main(int argc, char **argv)
26{
27 using namespace std;
28 using namespace JPP;
29
30 string inputFile;
31 string target;
32 JLimit numberOfEvents;
33 int debug;
34
35 try {
36
37 JParser<> zap;
38
39 zap['f'] = make_field(inputFile);
40 zap['T'] = make_field(target, "name of target to be read");
41 zap['n'] = make_field(numberOfEvents, "number of events, if applicable") = 1;
42 zap['d'] = make_field(debug) = 1;
43
44 zap(argc, argv);
45 }
46 catch(const exception &error) {
47 FATAL(error.what() << endl);
48 }
49
50 gErrorIgnoreLevel = kError;
51
52
53 TFile* in = TFile::Open(inputFile.c_str());
54
55 if (in == NULL || !in->IsOpen()) {
56 FATAL("Error opening file " << inputFile << endl);
57 }
58
59 const TRegexp regexp(target.c_str());
60
61 JRootTypewriter printer;
62
63 TIter iter(in->GetListOfKeys());
64
65 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
66
67 const TString tag(key->GetName());
68
69 DEBUG("Key: " << tag << " match = " << tag.Contains(regexp) << endl);
70
71 // option match
72
73 if (tag.Contains(regexp) && TClass::GetClass(key->GetClassName())->IsTObject()) {
74
75 TClass* cs = TClass::GetClass(key->GetClassName());
76
77 if (cs != NULL) {
78
79 DEBUG("TClass " << cs->GetName() << endl);
80 DEBUG("TKey::ReadObjectAny(..)" << endl);
81
82 void* ps = key->ReadObjectAny(cs);
83
84 if (cs == TTree::Class()) {
85
86 TTree* ts = (TTree*) ps;
87
88 DEBUG("TTree " << ts->GetName() << endl);
89
91
92 for (TIter next(ts->GetListOfBranches()); TBranch* p1 = dynamic_cast<TBranch*>(next()); ) {
93 ls.push_back(JBranchClass(p1));
94 }
95
96 // set branch addresses afterwards
97
98 for (auto& tp : ls) {
99 ts->GetBranch(tp.getName())->SetAddress(tp.getAddress());
100 }
101
102 for (Long64_t i = numberOfEvents.getLowerLimit(); i < ts->GetEntries() && i != numberOfEvents.getUpperLimit(); ++i) {
103
104 cout << ts->GetName() << "[" << i << "]:" << endl;
105
106 DEBUG("TTree::GetEvent(" << i << ")" << endl);
107
108 ts->GetEvent(i);
109
110 for (auto& tp : ls) {
111 printer(cout,tp);
112 }
113 }
114
115 } else {
116
117 printer(cout, cs->GetStreamerInfo(), (const char*) ps);
118 }
119 }
120 }
121 }
122}
TPaveText * p1
Auxiliaries for defining the range of iterations of objects.
General purpose messaging.
#define DEBUG(A)
Message macros.
Definition JMessage.hh:62
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:74
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
Example application to test printing of objects using ROOT dictionary.
Utility class to parse command line options.
Definition JParser.hh:1698
T getLowerLimit() const
Get lower limit.
Definition JRange.hh:202
T getUpperLimit() const
Get upper limit.
Definition JRange.hh:213
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Target.
Definition JHead.hh:300
ROOT readable class for TBranch.
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
Auxiliary data structure to list files in directory.