DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ObjectPrintout.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
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 include files
15 #include "DD4hep/LCDD.h"
16 #include "DD4hep/Objects.h"
17 #include "DD4hep/Conditions.h"
19 #include "DD4hep/Printout.h"
20 
21 // C/C++ include files
22 #include <cstdarg>
23 #include <stdexcept>
24 
25 using namespace std;
26 
27 #include "TMap.h"
28 #include "TROOT.h"
29 #include "TColor.h"
30 using namespace std;
31 namespace DD4hep {
32  using namespace Geometry;
33  using Conditions::Condition;
34 
35  template <typename T> void PrintMap<T>::operator()() const {
36  Printer < T > p(lcdd, os);
37  os << "++" << endl << "++ " << text << endl << "++" << endl;
38  for (LCDD::HandleMap::const_iterator i = cont.begin(); i != cont.end(); ++i)
39  p((*i).second);
40  }
41 
42  template <> void Printer<Handle<NamedObject> >::operator()(const Handle<NamedObject>& val) const {
43  printout(INFO, "Printer", "++ %s Handle:%s %s", prefix.c_str(), val->GetName(), val->GetTitle());
44  }
45  template <> void Printer<Handle<TNamed> >::operator()(const Handle<TNamed>& val) const {
46  printout(INFO, "Printer", "++ %s Handle:%s %s", prefix.c_str(), val->GetName(), val->GetTitle());
47  }
48 
49  template <> void Printer<Constant>::operator()(const Constant& val) const {
50  printout(INFO, "Printer", "++ %s Constant:%s %s", prefix.c_str(), val->GetName(), val.toString().c_str());
51  }
52 
53  template <> void Printer<Material>::operator()(const Material& val) const {
54  printout(INFO, "Printer", "++ %s Material:%s %s", prefix.c_str(), val->GetName(), val.toString().c_str());
55  }
56 
57  template <> void Printer<VisAttr>::operator()(const VisAttr& val) const {
58  printout(INFO, "Printer", "++ %s VisAttr: %s", prefix.c_str(), val.toString().c_str());
59  }
60 
61  template <> void Printer<Readout>::operator()(const Readout& val) const {
62  printout(INFO, "Printer", "++ %s Readout: %s of type %s", prefix.c_str(), val->GetName(), val->GetTitle());
63  }
64 
65  template <> void Printer<Region>::operator()(const Region& val) const {
66  printout(INFO, "Printer", "++ %s Region: %s of type %s", prefix.c_str(), val->GetName(), val->GetTitle());
67  }
68 
69  template <> void Printer<RotationZYX>::operator()(const RotationZYX& val) const {
70  printout(INFO, "Printer", "++ %s ZYXRotation: phi: %7.3 rad theta: %7.3 rad psi: %7.3 rad", prefix.c_str(), val.Phi(),
71  val.Theta(), val.Psi());
72  }
73 
74  template <> void Printer<Position>::operator()(const Position& val) const {
75  printout(INFO, "Printer", "++ %s Position: x: %9.3 mm y: %9.3 mm z: %9.3 mm", prefix.c_str(), val.X(), val.Y(), val.Z());
76  }
77  template <> void Printer<Condition>::operator()(const Condition& val) const {
78  int flg = Condition::WITH_IOV|Condition::WITH_ADDRESS;
79  printout(INFO, "Printer", "++ %s %s", prefix.c_str(), val.str(flg).c_str());
80  }
81 #if 0
82  template <> void Printer<LimitSet>::operator()(const LimitSet& val) const {
83  const set<Limit>& o = val.limits();
84  printout(INFO, "Printer", "++ %s LimitSet: %s", prefix.c_str(), val.name());
85  val->TNamed::Print();
86  for (set<Limit>::const_iterator i = o.begin(); i != o.end(); ++i) {
87  os << "++ Limit:" << (*i).name << " " << (*i).particles << " [" << (*i).unit << "] " << (*i).content << " "
88  << (*i).value << endl;
89  }
90  }
91 
92  template <> void Printer<DetElement>::operator()(const DetElement& val) const {
93  DetElement::Object* obj = val.data<DetElement::Object>();
94  if (obj) {
95  char text[256];
96  const DetElement& sd = val;
97  PlacedVolume plc = sd.placement();
98  bool vis = plc.isValid();
99  bool env = plc.isValid();
100  bool mat = plc.isValid();
101  ::snprintf(text, sizeof(text), "ID:%-3d Combine Hits:%3s Material:%s Envelope:%s VisAttr:%s", sd.id(),
102  yes_no(sd.combineHits()), mat ? plc.material().name() : yes_no(mat),
103  env ? plc.motherVol()->GetName() : yes_no(env), yes_no(vis));
104  os << prefix << "+= DetElement: " << val.name() << " " << val.type() << endl;
105  os << prefix << "| " << text << endl;
106 
107  if (vis) {
108  VisAttr attr = plc.volume().visAttributes();
109  VisAttr::Object* v = attr.data<VisAttr::Object>();
110  TColor* col = gROOT->GetColor(v->color);
111  char text[256];
112  ::snprintf(text, sizeof(text), " RGB:%-8s [%d] %7.2f Style:%d %d ShowDaughters:%3s Visible:%3s", col->AsHexString(),
113  v->color, col->GetAlpha(), int(v->drawingStyle),
114  int(v->lineStyle), yes_no(v->showDaughters),
115  yes_no(v->visible));
116  os << prefix << "| VisAttr: " << setw(32) << left << attr.name() << text << endl;
117  }
118  if (plc.isValid()) {
119  Volume vol = plc.volume();
120  Solid s = vol.solid();
121  Material m = vol.material();
122  ::snprintf(text, sizeof(text), "Volume:%s Shape:%s Material:%s", vol->GetName(), s.isValid() ? s.name() : "Unknonw",
123  m.isValid() ? m->GetName() : "Unknown");
124  os << prefix << "+------------- " << text << endl;
125  }
126  const DetElement::Children& ch = sd.children();
127  for (DetElement::Children::const_iterator i = ch.begin(); i != ch.end(); ++i)
128  Printer < DetElement > (lcdd, os, prefix + "| ")((*i).second);
129  return;
130  }
131  }
132 #endif
133  template <> void Printer<const LCDD*>::operator()(const LCDD* const &) const {
134  //Header(lcdd.header()).fromCompact(doc,compact.child(Tag_info),Strng_t("In memory"));
135  PrintMap < Constant > (lcdd, os, lcdd->constants(), "List of Constants")();
136  //PrintMap < VisAttr > (lcdd, os, lcdd->visAttributes(), "List of Visualization attributes")();
137  //PrintMap < LimitSet > (lcdd, os, lcdd->readouts(), "List of Readouts")();
138  //PrintMap < Region > (lcdd, os, lcdd->regions(), "List of Regions")();
139  //PrintMap < DetElement > (lcdd, os, lcdd->detectors(), "List of DetElements")();
140  }
141 }
const char * name() const
Access the object name (or "" if not supported by the object)
Definition: Handle.inl:36
Handle class describing a material.
Definition: Objects.h:300
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:124
const std::set< DD4hep::Geometry::Limit > & limits() const
Accessor to limits container.
Definition: Objects.cpp:434
Helper class template to implement ASCII dumps of named objects maps.
Definition: Printout.h:274
const char * yes_no(bool value)
Helper function to print booleans in format YES/NO.
Definition: Printout.h:295
TGeoShape * s
Definition: Volumes.cpp:294
Helper class template to implement ASCII object dumps.
Definition: Printout.h:245
Handle to the implementation of the readout structure of a subdetector.
Definition: Readout.h:46
DD4hep::Geometry::DetElement DetElement
ROOT::Math::RotationZYX RotationZYX
Definition: Objects.h:98
std::string toString() const
String representation of this object.
Definition: Objects.cpp:344
std::string toString() const
String representation of this object.
Definition: Objects.cpp:237
ROOT::Math::XYZVector Position
Definition: Objects.h:75
PlacedVolume placement() const
Access to the physical volume of this detector element.
Definition: Detector.cpp:279
Solid_type< TGeoShape > Solid
Definition: Shapes.h:108
Handle class describing visualization attributes.
Definition: Objects.h:341
View * v
Definition: MultiView.cpp:30
Handle class describing a set of limits as they are used for simulation.
Definition: Objects.h:475
Handle class describing a region as used in simulation.
Definition: Objects.h:516
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
std::string toString() const
String representation of this object.
Definition: Objects.cpp:158
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111
TGeoShape TGeoMedium * m
Definition: Volumes.cpp:294
Handle class describing a constant (define) object in lcdd.
Definition: Objects.h:231