Jpp 19.3.0-rc.2
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
11#include "JROOT/JRootClass.hh"
13
14#include "JSupport/JLimit.hh"
15
16#include "Jeep/JParser.hh"
17#include "Jeep/JMessage.hh"
18
19
20/**
21 * Example application to test printing of objects using ROOT dictionary.
22 */
23int main(int argc, char **argv)
24{
25 using namespace std;
26 using namespace JPP;
27
28 string inputFile;
29 string target;
30 JLimit numberOfEvents;
31 int debug;
32
33 try {
34
35 JParser<> zap;
36
37 zap['f'] = make_field(inputFile);
38 zap['T'] = make_field(target, "name of target to be read");
39 zap['n'] = make_field(numberOfEvents, "number of events, if applicable") = 1;
40 zap['d'] = make_field(debug) = 1;
41
42 zap(argc, argv);
43 }
44 catch(const exception &error) {
45 FATAL(error.what() << endl);
46 }
47
48 gErrorIgnoreLevel = kError;
49
50
51 TFile* in = TFile::Open(inputFile.c_str());
52
53 if (in == NULL || !in->IsOpen()) {
54 FATAL("Error opening file " << inputFile << endl);
55 }
56
57 if (debug >= debug_t) {
58 for (TIter i(in->GetListOfKeys()); TKey* key = dynamic_cast<TKey*>(i.Next()); ) {
59 cout << "key: " << key->GetName() << ' ' << key->GetClassName() << endl;
60 }
61 }
62
63 TKey* key = in->GetKey(target.c_str());
64
65 if (key == NULL) {
66 FATAL("No key for " << target << endl);
67 }
68
69 JRootTypewriter printer;
70
71 TClass* cs = TClass::GetClass(key->GetClassName());
72
73 if (cs != NULL) {
74
75 void* ps = key->ReadObjectAny(cs);
76
77 if (cs == TTree::Class()) {
78
79 TTree* ts = (TTree*) ps;
80
82
83 for (TIter next(ts->GetListOfBranches()); TBranch* p1 = dynamic_cast<TBranch*>(next()); ) {
84 ls.push_back(JBranchClass(p1));
85 }
86
87 // set branch addresses afterwards
88
89 for (auto& tp : ls) {
90 ts->GetBranch(tp.getName())->SetAddress(tp.getAddress());
91 }
92
93 for (Long64_t i = numberOfEvents.getLowerLimit(); i < ts->GetEntries() && i != numberOfEvents.getUpperLimit(); ++i) {
94
95 cout << ts->GetName() << "[" << i << "]:" << endl;
96
97 ts->GetEvent(i);
98
99 for (auto& tp : ls) {
100 printer(cout,tp);
101 }
102 }
103
104 } else {
105
106 printer(cout, cs->GetStreamerInfo(), (const char*) ps);
107 }
108 }
109}
TPaveText * p1
Auxiliaries for defining the range of iterations of objects.
General purpose messaging.
#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
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 branch class.
Auxiliary class for defining the range of iterations of objects.
Definition JLimit.hh:45
Auxiliary data structure to list files in directory.