BmnRoot
Loading...
Searching...
No Matches
BmnPadGenerator.cxx
Go to the documentation of this file.
1
2#include "BmnPadGenerator.h"
3
4#include <fairlogger/Logger.h>
5
6void BmnPadGenerator::LoadPTFrom(string FileName)
7{
8 LOGF(info, "LoadPTFrom start");
9 std::ifstream in(FileName, std::ios::binary);
10 if (!in) {
11 LOG(error) << "failed to open file";
12 return;
13 }
14 LOG(debug) << in.rdbuf();
15 try {
16 pt::read_json(FileName, _TreeScheme);
17 } catch (pt::ptree_error& exc) {
18 LOG(error) << "LoadPTFrom exception: " << exc.what() << std::endl;
19 return;
20 }
21 _pad = GeneratePadBranch(_TreeScheme);
22 LOGF(info, "pad tree generated");
23 return;
24}
25
27{
28 PadInfo* info = nullptr;
29 try {
30 boost::optional<string> clOpt = propTree.get_optional<string>("Class");
31 if (!clOpt)
32 return info;
33 string clName = clOpt.get();
34 TClass* cl = TClass::GetClass(clName.c_str());
35 printf("cl name %s\n", cl->GetName());
36 ROOT::NewFunc_t histNew = cl->GetNew();
37 string name = propTree.get<string>("Name");
38 string title = propTree.get<string>("Title");
39 string variable = propTree.get<string>("Variable");
40 // string selection = propTree.get<string>("Selection");
41 printf("Hist name %s\n", name.c_str());
42 vector<float> dimVec;
43 boost::optional<pt::ptree> dim = propTree.get_child("Dimensions");
44 if (dim) {
45 for (auto v = dim.get().begin(); v != dim.get().end(); v++) {
46 dimVec.push_back(stof((*v).second.data()));
47 printf("%f\n", dimVec.back());
48 }
49 } else
50 dimVec.resize(3, 0); // default 1Dim histogram
51 info = new PadInfo();
52 info->name = name;
53 info->variable = variable;
54 boost::optional<string> opt = propTree.get_optional<string>("Options");
55 if (opt) {
56 info->opt = opt.get();
57 printf("info opt %s\n", info->opt.c_str());
58 }
59 boost::optional<string> sel = propTree.get_optional<string>("Selection");
60 if (sel) {
61 info->selection = sel.get();
62 }
63 TH1* h = nullptr;
64 switch (dimVec.size()) {
65 case 3:
66 h = static_cast<TH1*>(histNew(0));
67 h->SetBins(dimVec[0], dimVec[1], dimVec[2]);
68 h->SetName(name.c_str());
69 h->SetTitle(title.c_str());
70 _HM->Add(name, h);
71 info->current = h; //_HM->H1(name);
72 break;
73 case 6:
74 h = static_cast<TH2*>(histNew(0));
75 h->SetBins(dimVec[0], dimVec[1], dimVec[2], dimVec[3], dimVec[4], dimVec[5]);
76 h->SetName(name.c_str());
77 h->SetTitle(title.c_str());
78 _HM->Add(name, h);
79 info->current = h; //_HM->H2(name);
80 break;
81 case 9:
82 h = static_cast<TH3*>(histNew(0));
83 h->SetBins(dimVec[0], dimVec[1], dimVec[2], dimVec[3], dimVec[4], dimVec[5], dimVec[6], dimVec[7],
84 dimVec[8]);
85 h->SetName(name.c_str());
86 h->SetTitle(title.c_str());
87 _HM->Add(name, h);
88 info->current = h;
89 break;
90 default:
91 throw string("Wrong dimensions!");
92 break;
93 }
94 // boost::optional<pt::ptree> axes = propTree.get_child("Dimensions");
95 info->temp = static_cast<TH1*>(info->current->Clone((name + "_temp").c_str()));
96 } catch (std::exception& ex) {
97 printf("Exception for node: %s\n", ex.what());
98 if (info) {
99 delete info;
100 info = nullptr;
101 }
102 }
103 return info;
104}
105
107{
108 BmnPadBranch* branch = nullptr;
109 try {
110 branch = new BmnPadBranch();
111 boost::optional<uint32_t> optDivX = propTree.get_optional<uint32_t>("DivX");
112 boost::optional<uint32_t> optDivY = propTree.get_optional<uint32_t>("DivY");
113 uint32_t divX = optDivX ? *optDivX : 1;
114 uint32_t divY = optDivY ? *optDivY : 1;
115 branch->SetDivXY(divX, divY);
116 printf("%d : %d \n", divX, divY);
117
118 if ((divX == 1) && (divY == 1)) {
119 PadInfo* info = GeneratePadNode(propTree);
120 branch->SetPadInfo(info);
121 } else {
122 // string name = propTree.get<string>("Name");
123 // string title = propTree.get<string>("Title");
124 // printf("title %s\n", title.c_str());
125
126 boost::optional<pt::ptree&> pads = propTree.get_child_optional("Pads");
127 if (pads) {
128 for (auto& v : pads.get()) {
129 printf("Parsing pad content: %s\n", v.second.data().c_str());
130 BmnPadBranch* b = GeneratePadBranch(v.second);
131 branch->AddBranch(b);
132 }
133 }
134 }
135
136 } catch (std::exception& ex) {
137 printf("Exception for branch: %s\n", ex.what());
138 if (branch) {
139 delete branch;
140 branch = nullptr;
141 }
142 }
143 return branch;
144}
145
147{
148 if ((!br) || (!pad)) {
149 printf("No pad data! Skipping.\n");
150 return;
151 }
152 if (PadInfo* info = br->GetPadInfo()) {
153 info->padPtr = pad;
154 } else {
155 vector<BmnPadBranch*>& bvec = br->GetBranchesRef();
156 pad->Divide(br->GetDivX(), br->GetDivY());
157 for (size_t i = 0; i < std::min((size_t)(br->GetDivX() * br->GetDivY()), bvec.size()); i++) {
158 TVirtualPad* innerPad = pad->cd(i + 1);
159 BmnPadBranch* innerBr = bvec[i];
160 PadTree2Canvas(innerBr, innerPad);
161 }
162 }
163 return;
164}
__m128 v
Definition P4_F32vec4.h:1
int i
Definition P4_F32vec4.h:22
Node of pad tree.
vector< BmnPadBranch * > & GetBranchesRef()
void SetPadInfo(PadInfo *p)
void AddBranch(BmnPadBranch *b)
void SetDivXY(uint32_t x, uint32_t y)
uint32_t GetDivX()
PadInfo * GetPadInfo()
uint32_t GetDivY()
static void PadTree2Canvas(BmnPadBranch *br, TVirtualPad *pad)
Create pad structure in the canvas from the pad tree and associate pad branch instances with the pad ...
BmnPadBranch * GeneratePadBranch(pt::ptree &PropTree)
Generate pad branch tree from the boost property tree.
PadInfo * GeneratePadNode(pt::ptree &PropTree)
void LoadPTFrom(string FileName)
Load pad tree from json config.
Storage for pad content and it's options.
Definition PadInfo.h:20
string name
Definition PadInfo.h:89
string selection
Definition PadInfo.h:91
string opt
Definition PadInfo.h:88
string variable
Definition PadInfo.h:90
TH1 * current
Definition PadInfo.h:78
TH1 * temp
Definition PadInfo.h:76
const UInt_t dim