ATLAS Offline Software
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 
37 namespace 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 
52  PParameter(),
53  layout(0) {}
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 }
dqm_persistency::PParameter::disableChildren
bool disableChildren
Definition: PParameter.h:31
dqm_persistency::PParameter::GetParentRegion
PRegion * GetParentRegion(TDirectory &topdir)
Definition: dqm_persistency_impl.cxx:78
algorithm
std::string algorithm
Definition: hcg.cxx:82
get_generator_info.result
result
Definition: get_generator_info.py:21
dqm_persistency::PRegion::AddSubparameter
void AddSubparameter(PParameter &daughter)
Definition: dqm_persistency_impl.cxx:93
athena.path
path
python interpreter configuration --------------------------------------—
Definition: athena.py:128
make_coralServer_rep.opt
opt
Definition: make_coralServer_rep.py:19
dqm_persistency::PParameter::input
TObject * input
Definition: PParameter.h:26
dqm_persistency::PRegion::subparameters
std::vector< int > subparameters
Definition: PRegion.h:18
dqm_persistency::PRegion
Definition: PRegion.h:15
dqm_persistency::WriteTreeRecurse
void WriteTreeRecurse(PRegion &region, TDirectory &paramdir, PMetadata &topmap, const std::string &path)
Definition: dqm_persistency_impl.cxx:185
PAlgorithm.h
reference
Definition: hcg.cxx:437
PParameter.h
dqm_persistency::PParameter::Print
void Print(const Option_t *opt="") const
Definition: dqm_persistency_impl.cxx:60
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
dqm_persistency::PMetadata::data
std::map< std::string, std::string > data
Definition: PMetadata.h:14
python.checkMetadata.metadata
metadata
Definition: checkMetadata.py:175
ClassImp
ClassImp(xAOD::TFileChecker) namespace xAOD
Definition: TFileChecker.cxx:28
dqm_persistency::PParameter::metadata
PMetadata * metadata
Definition: PParameter.h:32
dqm_persistency::PAlgorithm::Print
void Print(const Option_t *opt="") const
Definition: dqm_persistency_impl.cxx:128
dqm_persistency::GetNode
PParameter * GetNode(TDirectory &topdir, const std::string &nodename)
Definition: dqm_persistency_impl.cxx:229
dqm_persistency::PMetadata
Definition: PMetadata.h:12
dqm_persistency::PParameter::parentRegion
int parentRegion
Definition: PParameter.h:36
lumiFormat.i
int i
Definition: lumiFormat.py:85
dqm_persistency::PRegion::Print
void Print(const Option_t *opt="") const
Definition: dqm_persistency_impl.cxx:86
dqm_persistency::PResult::status
int status
Definition: PResult.h:21
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
ParticleGun_EoverP_Config.pid
pid
Definition: ParticleGun_EoverP_Config.py:62
dqm_persistency::PAlgorithm::redThresholds
std::map< std::string, float > redThresholds
Definition: PAlgorithm.h:21
dqm_persistency::WriteTree
void WriteTree(PRegion &top_level, TDirectory &topdir, PMetadata &topmap)
Definition: dqm_persistency_impl.cxx:213
dqm_persistency::PAlgorithm::greenThresholds
std::map< std::string, float > greenThresholds
Definition: PAlgorithm.h:22
dqm_persistency::PAlgorithm
Definition: PAlgorithm.h:14
PRegion.h
dqm_persistency::PParameter::PParameter
PParameter()
Definition: dqm_persistency_impl.cxx:39
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
dqm_persistency::PRegion::PRegion
PRegion()
Definition: dqm_persistency_impl.cxx:51
PMetadata.h
dq_make_web_display.rv
def rv
Definition: dq_make_web_display.py:219
dqm_persistency::PResult::PResult
PResult()
Definition: dqm_persistency_impl.cxx:55
PResult.h
dqm_persistency::PParameter::result
PResult * result
Definition: PParameter.h:27
dqm_persistency::PRegion::GetSubparameter
PParameter * GetSubparameter(TDirectory &topdir, unsigned int i) const
Definition: dqm_persistency_impl.cxx:110
dqm_persistency::PAlgorithm::library
std::string library
Definition: PAlgorithm.h:19
dqm_persistency::PParameter::algorithm
PAlgorithm * algorithm
Definition: PParameter.h:28
dqm_persistency::PResult::Print
void Print(const Option_t *opt="") const
Definition: dqm_persistency_impl.cxx:120
dqm_persistency::PParameter::shape
TObject * shape
Definition: PParameter.h:34
dqm_persistency::PResult::results
std::vector< std::pair< std::string, float > > results
Definition: PResult.h:17
dqm_persistency::PParameter
Definition: PParameter.h:20
dqm_persistency::Print
void Print(const PParameter *param, TDirectory *topdir, Option_t *opt="")
Definition: dqm_persistency_impl.cxx:161
dqm_persistency::PResult
Definition: PResult.h:14
dqm_persistency::PMetadata::Print
void Print(const Option_t *opt="") const
Definition: dqm_persistency_impl.cxx:154
dqm_persistency::PParameter::weight
float weight
Definition: PParameter.h:30
merge.status
status
Definition: merge.py:17
dqm_persistency::PAlgorithm::parameters
std::map< std::string, std::vector< float > > parameters
Definition: PAlgorithm.h:20
dqm_persistency
Definition: PAlgorithm.h:13
dqm_persistency::PAlgorithm::name
std::string name
Definition: PAlgorithm.h:16
dqm_persistency::PParameter::name
std::string name
Definition: PParameter.h:23
PFunctions.h
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37