DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsPrinter.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework includes
15 #include <Parsers/Parsers.h>
16 #include <DD4hep/Printout.h>
17 #include <DD4hep/ConditionsData.h>
20 
22 
23 // C/C++ include files
24 #include <sstream>
25 
26 using namespace dd4hep;
27 using namespace dd4hep::cond;
28 
29 namespace {
31  std::string str_replace(const std::string& str, const std::string& pattern, const std::string& replacement) {
32  std::string res = str;
33  for(size_t id=res.find(pattern); id != std::string::npos; id = res.find(pattern) )
34  res.replace(id,pattern.length(),replacement);
35  return res;
36  }
37 }
38 
39 
41 
48 protected:
51 public:
53  std::string prefix;
55  PrintLevel printLevel = INFO;
56 public:
58  ParamPrinter(const ParamPrinter& copy) = default;
60  ParamPrinter(ConditionsPrinter* p, PrintLevel lvl);
62  virtual ~ParamPrinter() = default;
66  virtual void operator()(const cond::AbstractMap::Params::value_type& obj) const;
67 };
68 
69 
72  : m_parent(printer), printLevel(lvl)
73 {
74 }
75 
77 void ConditionsPrinter::ParamPrinter::operator()(const AbstractMap::Params::value_type& obj) const {
78  const std::type_info& type = obj.second.typeInfo();
79  ++m_parent->numParam;
80  if ( type == typeid(std::string) ) {
81  std::string value = obj.second.get<std::string>().c_str();
82  std::size_t len = value.length();
83  if ( len > m_parent->lineLength ) {
84  value.erase(m_parent->lineLength);
85  value += "...";
86  }
87  printout(m_parent->printLevel,m_parent->name,"++ %s\t-> Param: %-16s %-8s -> %s",
88  prefix.c_str(),
89  obj.first.c_str(),
90  obj.second.dataType().c_str(),
91  value.c_str());
92  }
93  else if ( type == typeid(AbstractMap) ) {
94  const AbstractMap& d= obj.second.get<AbstractMap>();
95  printout(m_parent->printLevel,m_parent->name,"++ %s\t-> [%s] CL:%d %-8s -> %s",
96  prefix.c_str(),
97  obj.first.c_str(), d.classID,
98  obj.second.dataType().c_str(),
99  obj.second.str().c_str());
100  }
101  else {
102  std::string value = obj.second.str();
103  std::size_t len = value.length();
104  if ( len > m_parent->lineLength ) {
105  value.erase(m_parent->lineLength);
106  value += "...";
107  }
108  printout(m_parent->printLevel,m_parent->name,"++ %s\t-> [%s] %-8s -> %s",
109  prefix.c_str(),
110  obj.first.c_str(),
111  obj.second.dataType().c_str(),
112  value.c_str());
113  }
114 }
115 
117 ConditionsPrinter::ConditionsPrinter(ConditionsMap* cond_map, const std::string& pref, int flg)
118  : mapping(cond_map), m_flag(flg), name("Condition"), prefix(pref)
119 {
120  m_print = new ParamPrinter(this, printLevel);
121 }
122 
125  if ( summary ) {
126  printout(INFO,name,"++ %s +++++++++++++ Printout summary:", prefix.c_str());
127  printout(INFO,name,"++ %s Number of conditions: %8ld [ dto. empty:%ld]",
129  printout(INFO,name,"++ %s Total Number of parameters: %8ld [%7.3f Parameters/Condition]",
130  prefix.c_str(), numParam, double(numParam)/std::max(double(numCondition),1e0));
131  }
132  detail::deletePtr(m_print);
133 }
134 
138  if ( cond.isValid() ) {
139  std::string repr = cond.str(m_flag);
140  Condition::Object* ptr = cond.ptr();
141 
142  if ( repr.length() > lineLength )
143  repr = repr.substr(0,lineLength)+"...";
144  printout(this->printLevel,name, "++ %s%s", prefix.c_str(), repr.c_str());
145  std::string new_prefix = prefix;
146  new_prefix.assign(prefix.length(),' ');
147  if ( !cond.is_bound() ) {
148  printout(this->printLevel,name,"++ %s \tPath:%s Key:%16llX Type:%s (%s)",
149  new_prefix.c_str(), cond.name(), cond.key(), "<Unbound-Condition>",
150  typeName(typeid(*ptr)).c_str());
151  return 1;
152  }
153  const std::type_info& type = cond.typeInfo();
154  const OpaqueData& opaque = cond.data();
155  printout(this->printLevel,name,"++ %s \tPath:%s Key:%16llX Type:%s",
156  new_prefix.c_str(), cond.name(), cond.key(), opaque.dataType().c_str());
157  //std::string values = opaque.str();
158  //if ( values.length() > lineLength ) values = values.substr(0,130)+"...";
159  //printout(this->printLevel,name,"++ %s \tData:%s", new_prefix.c_str(), values.c_str());
160  if ( type == typeid(AbstractMap) ) {
161  const AbstractMap& data = cond.get<AbstractMap>();
162  printout(printLevel,name,"++ %s Path:%s Class:%d [%s]",
163  prefix.c_str(),
164  cond.name(),
165  data.classID,
166  cond.data().dataType().c_str());
167  ++numCondition;
168  if ( !data.params.empty() ) {
170  m_print->prefix.assign(prefix.length(),' ');
171  for_each(data.params.begin(), data.params.end(),*m_print);
172  }
173  else {
175  }
176  }
177  else if ( type == typeid(Delta) ) {
178  std::string piv;
179  std::stringstream str_tr, str_rot, str_piv;
180  const Delta& D = cond.get<Delta>();
181  if ( D.hasTranslation() ) {
182  Position copy(D.translation * (1./dd4hep::cm));
183  Parsers::toStream(copy, str_tr);
184  }
185  if ( D.hasRotation() ) {
186  Parsers::toStream(D.rotation, str_rot);
187  }
188  if ( D.hasPivot() ) {
189  Position copy(D.pivot.Vect() * (1./dd4hep::cm));
190  Parsers::toStream(copy, str_piv);
191  piv = str_replace(str_piv.str(),"\n","");
192  piv = str_replace(piv," "," , ");
193  }
194  printout(printLevel,name,"++ %s \t[%p] Typ:%s",
195  prefix.c_str(), cond.ptr(),
196  typeName(typeid(*ptr)).c_str());
197  printout(printLevel,name,"++ %s \tData(%11s-%8s-%5s): [%s [cm], %s [rad], %s [cm]]",
198  prefix.c_str(),
199  D.hasTranslation() ? "Translation" : "",
200  D.hasRotation() ? "Rotation(Phi,Theta,Psi)" : "",
201  D.hasPivot() ? "Pivot" : "",
202  str_replace(str_tr.str(),"\n","").c_str(),
203  str_replace(str_rot.str(),"\n","").c_str(),
204  piv.c_str()
205  );
206  }
207  else if ( type == typeid(AlignmentData) ) {
208  std::string piv;
209  std::stringstream str_tr, str_rot, str_piv;
210  const Delta& D = cond.get<AlignmentData>().delta;
211  if ( D.hasTranslation() ) Parsers::toStream(D.translation, str_tr);
212  if ( D.hasRotation() ) Parsers::toStream(D.rotation, str_rot);
213  if ( D.hasPivot() ) {
214  Parsers::toStream(D.pivot, str_piv);
215  piv = str_replace(str_piv.str(),"\n","");
216  piv = str_replace(piv," "," , ");
217  }
218 
219  printout(printLevel,name,"++ %s \t[%p] Typ:%s",
220  prefix.c_str(), cond.ptr(),
221  typeName(typeid(*ptr)).c_str());
222  printout(printLevel,name,"++ %s \tData(%11s-%8s-%5s): [%s, %s, %s]",
223  prefix.c_str(),
224  D.hasTranslation() ? "Translation" : "",
225  D.hasRotation() ? "Rotation(Phi,Theta,Psi)" : "",
226  D.hasPivot() ? "Pivot" : "",
227  str_replace(str_tr.str(),"\n","").c_str(),
228  str_replace(str_rot.str(),"\n","").c_str(),
229  piv.c_str()
230  );
231  }
232  else if ( type == typeid(std::string) ) {
233  std::string value = cond.get<std::string>().c_str();
234  std::size_t len = value.length();
235  if ( len > lineLength ) {
236  value = value.substr(0,lineLength);
237  value += "...";
238  value = str_replace(value,"\n","");
239  }
240  printout(printLevel,name,"++ %s \tString [%s]: %s",
241  prefix.c_str(),
242  cond.data().dataType().c_str(),
243  value.c_str());
244  }
245  else {
246  std::string value = cond.str();
247  std::size_t len = value.length();
248  if ( len > lineLength ) {
249  value = value.substr(0,lineLength);
250  value += "...";
251  value = str_replace(value,"\n","");
252  }
253  printout(printLevel,name,"++ %s \t[%s]: %s",
254  prefix.c_str(),
255  cond.data().dataType().c_str(),
256  value.c_str());
257  }
258  return 1;
259  }
260  return 0;
261 }
262 
264 int ConditionsPrinter::operator()(DetElement de, int level) const {
265  if ( mapping ) {
266  std::vector<Condition> conditions;
267  conditionsCollector(*mapping,conditions)(de,level);
268  printout(this->printLevel, name, "++ %s %-3ld Conditions for DE %s",
269  prefix.c_str(), conditions.size(), de.path().c_str());
270  for( auto cond : conditions )
271  (*this)(cond);
272  return int(conditions.size());
273  }
274  except(name,"Failed to dump conditions for DetElement:%s [No slice availible]",
275  de.path().c_str());
276  return 0;
277 }
dd4hep::DetElement::path
const std::string & path() const
Path of the detector element (not necessarily identical to placement path!)
Definition: DetElement.cpp:158
dd4hep::cond::ConditionsPrinter::ParamPrinter
friend class ParamPrinter
Definition: ConditionsPrinter.h:41
cond
AlignmentCondition::Object * cond
Definition: AlignmentsCalculator.cpp:68
dd4hep::cond::ConditionsPrinter::numEmptyCondition
size_t numEmptyCondition
Counter: number of empty conditions.
Definition: ConditionsPrinter.h:68
dd4hep::cond::ConditionsPrinter::numCondition
size_t numCondition
Counter: number of conditions.
Definition: ConditionsPrinter.h:66
dd4hep::cond::AbstractMap::classID
int classID
Definition: ConditionsData.h:59
ConditionsInterna.h
dd4hep::cond::ConditionsPrinter::m_print
ParamPrinter * m_print
Sub-printer.
Definition: ConditionsPrinter.h:45
dd4hep::cond::ConditionsPrinter::~ConditionsPrinter
virtual ~ConditionsPrinter()
Default destructor.
Definition: ConditionsPrinter.cpp:124
dd4hep::cond::conditionsCollector
ConditionsCollector< typename std::remove_reference< T >::type > conditionsCollector(ConditionsMap &m, T &&conditions)
Creator utility function for ConditionsCollector objects.
Definition: ConditionsProcessor.h:150
dd4hep::Delta::rotation
RotationZYX rotation
Definition: AlignmentData.h:43
delta
const Delta * delta
Definition: AlignmentsCalculator.cpp:67
dd4hep::cond::ConditionsPrinter::prefix
std::string prefix
Printout prefix.
Definition: ConditionsPrinter.h:58
ConditionsData.h
dd4hep::cond::ConditionsPrinter::lineLength
size_t lineLength
Line length.
Definition: ConditionsPrinter.h:62
dd4hep::cond::ConditionsPrinter::m_flag
int m_flag
Printout processing and customization flag.
Definition: ConditionsPrinter.h:51
dd4hep::Delta::hasRotation
bool hasRotation() const
Access flags: Check if the delta operation contains a rotation.
Definition: AlignmentData.h:85
dd4hep::cond::ConditionsPrinter::mapping
ConditionsMap * mapping
Conditionsmap to resolve things.
Definition: ConditionsPrinter.h:47
dd4hep::cond::ConditionsPrinter::ParamPrinter::operator()
virtual void operator()(const cond::AbstractMap::Params::value_type &obj) const
Callback to output conditions information.
Definition: ConditionsPrinter.cpp:77
dd4hep::Delta
Class describing an condition to re-adjust an alignment.
Definition: AlignmentData.h:38
dd4hep::Delta::hasPivot
bool hasPivot() const
Access flags: Check if the delta operation contains a pivot.
Definition: AlignmentData.h:87
dd4hep::Condition
Main condition object handle.
Definition: Conditions.h:51
dd4hep::cond
Namespace for implementation details of the AIDA detector description toolkit.
Definition: ConditionsCleanup.h:23
dd4hep::cond::ConditionsPrinter::numParam
size_t numParam
Counter: number of parameters.
Definition: ConditionsPrinter.h:64
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
ConditionsPrinter.h
dd4hep::Delta::translation
Position translation
Definition: AlignmentData.h:41
dd4hep::cond::ConditionsPrinter::ParamPrinter::prefix
std::string prefix
Prefix to tag print statements.
Definition: ConditionsPrinter.cpp:53
dd4hep::cond::ConditionsPrinter::ParamPrinter::operator=
ParamPrinter & operator=(const ParamPrinter &copy)=default
Assignment operator.
dd4hep::Delta::pivot
Pivot pivot
Definition: AlignmentData.h:42
dd4hep::Parsers::toStream
std::ostream & toStream(const Property &result, std::ostream &os)
Definition: ComponentProperties.cpp:191
dd4hep::OpaqueData
Class describing an opaque data block.
Definition: OpaqueData.h:39
dd4hep::cond::ConditionsPrinter::summary
bool summary
Flag to print summary.
Definition: ConditionsPrinter.h:70
dd4hep::cond::ConditionsPrinter::printLevel
PrintLevel printLevel
Printout level.
Definition: ConditionsPrinter.h:60
dd4hep::AlignmentData
Derived condition data-object definition.
Definition: AlignmentData.h:98
dd4hep::cond::AbstractMap::get
const T & get(const std::string &item) const
Simplify access to mapped item of the parameter list (const access)
Definition: ConditionsData.h:113
dd4hep::cond::ConditionsPrinter::ParamPrinter
DDDB Conditions data dumper helper to output parameter maps.
Definition: ConditionsPrinter.cpp:47
dd4hep::Delta::hasTranslation
bool hasTranslation() const
Access flags: Check if the delta operation contains a translation.
Definition: AlignmentData.h:83
dd4hep::cond::ConditionsPrinter::ParamPrinter::ParamPrinter
ParamPrinter(const ParamPrinter &copy)=default
Copy constructor.
dd4hep::detail::ConditionObject
The data class behind a conditions handle.
Definition: ConditionsInterna.h:68
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
dd4hep::cond::ConditionsPrinter::name
std::string name
Printer name. Want to know who is printing what.
Definition: ConditionsPrinter.h:56
dd4hep::cond::ConditionsPrinter::operator()
virtual int operator()(DetElement de, int level) const
Callback to output conditions information of an entire DetElement.
Definition: ConditionsPrinter.cpp:264
mapping
ConditionsMap & mapping
Definition: AlignmentsCalculator.cpp:82
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::OpaqueData::dataType
const std::string & dataType() const
Access type name of the condition data block.
Definition: OpaqueData.cpp:50
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::cond::ConditionsPrinter::ParamPrinter::printLevel
PrintLevel printLevel
Used printout level.
Definition: ConditionsPrinter.cpp:55
dd4hep::cond::ConditionsPrinter::ParamPrinter::m_parent
ConditionsPrinter * m_parent
Parent object.
Definition: ConditionsPrinter.cpp:50
dd4hep::cond::AbstractMap::params
Params params
Definition: ConditionsData.h:58
Printout.h
dd4hep::cond::ConditionsPrinter
Generic Conditions data dumper.
Definition: ConditionsPrinter.h:38
dd4hep::ConditionsMap
ConditionsMap class.
Definition: ConditionsMap.h:59
dd4hep::cond::ConditionsPrinter::ParamPrinter::~ParamPrinter
virtual ~ParamPrinter()=default
Default destructor.
ConditionsProcessor.h
dd4hep::cond::AbstractMap
Conditions data block. Internaly maps other objects to abstract data blocks.
Definition: ConditionsData.h:49