ATLAS Offline Software
Loading...
Searching...
No Matches
dqm_persistency_impl.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
11#include "TDirectory.h"
12#include "TProcessID.h"
13#include <string>
14#include <iostream>
15
16//Get rid of Root macros that confuse Doxygen
20//Get rid of Root macros that confuse Doxygen
24//Get rid of Root macros that confuse Doxygen
28//Get rid of Root macros that confuse Doxygen
32//Get rid of Root macros that confuse Doxygen
36
37namespace dqm_persistency {
38
40 name(""),
41 input(0),
42 result(0),
43 algorithm(0),
44 reference(0),
45 weight(1),
46 disableChildren(false),
47 metadata(0),
48 shape(0),
49 parentRegion(-2) {}
50
54
56 resultobj(0),
57 status(),
58 timestamp() {}
59
60 void PParameter::Print(Option_t*) const {
61 std::cout << "Parameter " << name << "\n"
62 << " Input " << input << "\n"
63 << " Results " << result
64 << std::endl;
65 if (result) result->Print();
66 std::cout << " Algorithm " << algorithm << "\n";
67 if (algorithm) algorithm->Print();
68 std::cout << " Reference " << reference << "\n"
69 << " Weight " << weight << "\n"
70 << " disableChildren " << disableChildren << "\n"
71 << " metadata " << metadata << "\n";
72 if (metadata) metadata->Print();
73 std::cout << " shape " << shape << "\n"
74 << " parent region " << parentRegion
75 << std::endl;
76 }
77
78 PRegion* PParameter::GetParentRegion(TDirectory& topdir) {
79 if (parentRegion == -2) { return 0; }
80 if (parentRegion == -1) {
81 return dynamic_cast<PRegion*>(GetNode(topdir, -1));
82 }
83 return dynamic_cast<PRegion*>(GetNode(topdir, parentRegion));
84 }
85
86 void PRegion::Print(Option_t* opt) const {
87 std::cout << "Region " << name << std::endl;
89 std::cout << "# daughter parameters: " << subparameters.size()
90 << std::endl;
91 }
92
94 int uid = TProcessID::AssignID(&daughter);
95 if (!(TProcessID::GetPID()->GetObjectWithID(uid))) {
96 TProcessID::GetPID()->PutObjectWithID(&daughter);
97 }
98 subparameters.push_back(uid);
99 if (name != "top_level") {
100 uid = TProcessID::AssignID(this);
101 if (!(TProcessID::GetPID()->GetObjectWithID(uid))) {
102 TProcessID::GetPID()->PutObjectWithID(this);
103 }
104 daughter.parentRegion = uid;
105 } else {
106 daughter.parentRegion = -1;
107 }
108 }
109
110 PParameter* PRegion::GetSubparameter(TDirectory& topdir, unsigned int i) const {
111 if (i >= subparameters.size()) {
112 std::cerr << "ERROR: attempt to access invalid subparameter " << i
113 << std::endl
114 << " valid values are in [0," << subparameters.size()
115 << ")" << std::endl;
116 }
117 return GetNode(topdir, subparameters[i]);
118 }
119
120 void PResult::Print(Option_t*) const {
121 std::cout << " Status: " << status << std::endl;
122 for (std::vector<std::pair<std::string, float> >::const_iterator ri = results.begin();
123 ri != results.end(); ++ri) {
124 std::cout << " " << ri->first << " " << ri->second << std::endl;
125 }
126 }
127
128 void PAlgorithm::Print(Option_t*) const {
129 std::cout << " Algorithm name " << name << "\n"
130 << " library " << library << "\n"
131 << " parameters: " << "\n";
132 for (std::map<std::string, std::vector<float> >::const_iterator pit = parameters.begin();
133 pit != parameters.end(); ++pit) {
134 //std::cout << " " << pit->first << " " << pit->second << "\n";
135 std::cout << " " << pit->first << " ";
136 for (std::vector<float>::const_iterator p2it = pit->second.begin();
137 p2it != pit->second.end(); ++p2it) {
138 std::cout << *p2it << " ";
139 }
140 std::cout << std::endl;
141 }
142 std::cout << " Green thresholds: " << "\n";
143 for (std::map<std::string, float>::const_iterator thit = greenThresholds.begin();
144 thit != greenThresholds.end(); ++thit) {
145 std::cout << " " << thit->first << " " << thit->second << std::endl;
146 }
147 std::cout << " Red thresholds: " << "\n";
148 for (std::map<std::string, float>::const_iterator thit = redThresholds.begin();
149 thit != redThresholds.end(); ++thit) {
150 std::cout << " " << thit->first << " " << thit->second << std::endl;
151 }
152 }
153
154 void PMetadata::Print(Option_t*) const {
155 for (std::map<std::string, std::string >::const_iterator pit = data.begin();
156 pit != data.end(); ++pit) {
157 std::cout << " " << pit->first << " " << pit->second << "\n";
158 }
159 }
160
161 void Print(const PParameter* param, TDirectory* topdir,
162 Option_t* opt) {
163 param->Print();
164 const PRegion* region = dynamic_cast<const PRegion*>(param);
165 if (region) {
166 TString option = opt; option.ToLower();
167 if (option.Contains("r")) {
168 for (unsigned int i = 0; i < region->subparameters.size(); i++) {
169 std::cout << "Subparameter " << region->subparameters[i] << std::endl;
170 const PParameter* subparam = region->GetSubparameter(*topdir, i);
171 if (subparam) {
172 Print(subparam, topdir, opt);
173 } else {
174 std::cerr << "ERROR: can't find subparameter "
175 << region->subparameters[i]
176 << " from top-level directory "
177 << topdir->GetPath()
178 << std::endl;
179 }
180 }
181 }
182 }
183 }
184
185 void WriteTreeRecurse(PRegion& region, TDirectory& paramdir,
186 PMetadata& topmap, const std::string& path) {
187 TProcessID* pid = TProcessID::GetPID();
188 for (unsigned int i = 0; i < region.subparameters.size(); i++) {
189 int subparam = region.subparameters[i];
190 TObject* subobj = pid->GetObjectWithID(subparam);
191 PParameter* pparam = dynamic_cast<PParameter*>(subobj);
192 if (!pparam) {
193 std::cerr << "ERROR: can't retrieve parameter " << subparam
194 << std::endl;
195 continue;
196 }
197 std::string uid = std::to_string(subparam);
198 if (path == "") {
199 topmap.data[pparam->name] = uid;
200 } else {
201 topmap.data[path + "/" + pparam->name] = uid;
202 }
203 paramdir.WriteTObject(subobj, uid.c_str());
204 PRegion* preg = dynamic_cast<PRegion*>(subobj);
205 if (preg) {
206 std::string daughterpath = (path != "") ? (path+"/"+preg->name) : (preg->name) ;
207 WriteTreeRecurse(*preg, paramdir, topmap, daughterpath);
208 }
209 }
210 }
211
212 // The tree has to be fully loaded with TProcessID available for all elements!
213 void WriteTree(PRegion& top_level, TDirectory& topdir, PMetadata& topmap) {
214 TDirectory* paramdir = topdir.GetDirectory("Parameters");
215 if (!paramdir) {
216 paramdir = topdir.mkdir("Parameters");
217 if (!paramdir) {
218 std::cerr << "ERROR: can't make Parameters subdirectory for storage"
219 << std::endl;
220 return;
221 }
222 }
223 WriteTreeRecurse(top_level, *paramdir, topmap, "");
224 topmap.data["top_level"] = std::to_string(top_level.GetUniqueID());
225 topdir.WriteTObject(&top_level, "top_level");
226 topdir.WriteTObject(&topmap, "object_map");
227 }
228
229 PParameter* GetNode(TDirectory& topdir, const std::string& nodename) {
230 PParameter* rv(0);
231 if (nodename == "top_level") {
232 rv = dynamic_cast<PParameter*>(topdir.Get("top_level"));
233 return rv;
234 }
235 PMetadata* pmd = dynamic_cast<PMetadata*>(topdir.Get("object_map"));
236 if (pmd) {
237 std::string key = pmd->data[nodename];
238 if (key == "") {
239 std::cerr << "ERROR: can't find node " << nodename << " in object_map"
240 << std::endl;
241 return 0;
242 } else {
243 rv = dynamic_cast<PParameter*>(topdir.Get(("Parameters/" + key).c_str()));
244 if (rv) { rv->SetUniqueID(rv->GetUniqueID() & 0xffffff); }
245 return rv;
246 }
247 } else {
248 std::cerr << "ERROR: can't retrieve object_map from file!" << std::endl;
249 return 0;
250 }
251 }
252
253 PParameter* GetNode(TDirectory& topdir, int key) {
254 if (key == -1) {
255 return dynamic_cast<PParameter*>(topdir.Get("top_level"));
256 }
257 PParameter* rv = dynamic_cast<PParameter*>(topdir.Get(("Parameters/" + std::to_string(key)).c_str()));
258 if (rv) { rv->SetUniqueID(rv->GetUniqueID() & 0xffffff); }
259 return rv;
260 }
261}
ClassImp(xAOD::Experimental::RFileChecker) namespace xAOD
void Print(const Option_t *opt="") const
std::map< std::string, float > greenThresholds
Definition PAlgorithm.h:22
std::map< std::string, float > redThresholds
Definition PAlgorithm.h:21
std::map< std::string, std::vector< float > > parameters
Definition PAlgorithm.h:20
std::map< std::string, std::string > data
Definition PMetadata.h:14
void Print(const Option_t *opt="") const
void Print(const Option_t *opt="") const
PRegion * GetParentRegion(TDirectory &topdir)
void AddSubparameter(PParameter &daughter)
std::vector< int > subparameters
Definition PRegion.h:20
PParameter * GetSubparameter(TDirectory &topdir, unsigned int i) const
void Print(const Option_t *opt="") const
std::vector< std::pair< std::string, float > > results
Definition PResult.h:19
void Print(const Option_t *opt="") const
PParameter * GetNode(TDirectory &topdir, const std::string &nodename)
void WriteTreeRecurse(PRegion &region, TDirectory &paramdir, PMetadata &topmap, const std::string &path)
void Print(const PParameter *param, TDirectory *topdir, Option_t *opt="")
void WriteTree(PRegion &top_level, TDirectory &topdir, PMetadata &topmap)