CMS 3D CMS Logo

ListIds.cc
Go to the documentation of this file.
1 #include <string>
2 #include <vector>
3 #include <iostream>
4 #include <algorithm>
5 
15 
27 
28 static bool dddGetStringRaw(const DDFilteredView &view, const std::string &name, std::string &value) {
29  DDValue parameter(name);
30  std::vector<const DDsvalues_type *> result;
31  view.specificsV(result);
32  for (std::vector<const DDsvalues_type *>::iterator it = result.begin(); it != result.end(); ++it) {
33  if (DDfetch(*it, parameter)) {
34  if (parameter.strings().size() == 1) {
35  value = parameter.strings().front();
36  return true;
37  } else {
38  return false;
39  }
40  }
41  }
42  return false;
43 }
44 
45 /*
46 static inline
47 double dddGetDouble(const std::string & s, const DDFilteredView & view) {
48  std::string value;
49  if (dddGetStringRaw(view, s, value))
50  return double(::atof(value.c_str()));
51  else
52  return NAN;
53 }
54 */
55 
56 static inline std::string dddGetString(const std::string &s, const DDFilteredView &view) {
58  if (dddGetStringRaw(view, s, value))
59  return value;
60  else
61  return std::string();
62 }
63 
64 static inline std::ostream &operator<<(std::ostream &out, const math::XYZVector &v) {
65  return out << "(" << v.rho() << ", " << v.z() << ", " << v.phi() << ")";
66 }
67 
68 class ListIds : public edm::one::EDAnalyzer<> {
69 public:
70  ListIds(const edm::ParameterSet &);
71  ~ListIds() override;
72 
73 private:
74  void analyze(const edm::Event &, const edm::EventSetup &) override;
75  void beginJob() override {}
76  void endJob() override;
77  // List of material names used to select specific detectors.
78  // Names are matched literally, w/o any usage of regexp.
79  // Names should also be specified with the correct namespace,
80  // otherwise the matching will fail.
82  std::vector<std::string> materials_;
83 };
84 
86  : printMaterial_(pset.getUntrackedParameter<bool>("printMaterial")),
87  materials_(pset.getUntrackedParameter<std::vector<std::string> >("materials")) {}
88 
90 
92  std::cout << "______________________________ DDD ______________________________" << std::endl;
94  setup.get<IdealGeometryRecord>().get(hDdd);
95 
96  std::string attribute = "TkDDDStructure";
97  CmsTrackerStringToEnum theCmsTrackerStringToEnum;
99  DDFilteredView fv(*hDdd, filter);
100  if (theCmsTrackerStringToEnum.type(dddGetString(attribute, fv)) != GeometricDet::Tracker) {
101  fv.firstChild();
102  if (theCmsTrackerStringToEnum.type(dddGetString(attribute, fv)) != GeometricDet::Tracker)
103  throw cms::Exception("Configuration") << "The first child of the DDFilteredView is not what is expected \n"
104  << dddGetString(attribute, fv);
105  }
106 
107  std::cout << std::fixed << std::setprecision(3);
108  bool printAnyMaterial = (std::find(materials_.begin(), materials_.end(), "ANY") != materials_.end());
109  do {
110  // print the full hierarchy of all elements whose material
111  // has been specified by the user. An empty list of
112  // materials will print no elements. The special
113  // keyword ANY (in any location of the vector)
114  // will select all elements.
115  if (printAnyMaterial ||
116  (std::find(materials_.begin(), materials_.end(), fv.logicalPart().material().name().fullname()) !=
117  materials_.end())) {
118  // start from 2 to skip the leading /OCMS[0]/CMSE[1] part
119  const DDGeoHistory &history = fv.geoHistory();
120  std::cout << '/';
121  for (unsigned int h = 2; h < history.size(); ++h) {
122  std::cout << '/' << history[h].logicalPart().name().ns() << ":" << history[h].logicalPart().name().name() << '['
123  << history[h].copyno() << ']';
124  }
125  if (printMaterial_)
126  std::cout << " Material: |" << fv.logicalPart().material().name() << "|";
127  // DD3Vector and DDTranslation are the same type as math::XYZVector
128  math::XYZVector position = fv.translation() / 10.; // mm -> cm
129  std::cout << "\t" << position << std::endl;
130  }
131  } while (fv.next());
132  std::cout << std::endl;
133 
134  std::cout << "______________________________ std::vector<GeomDet*> from TrackerGeometry::dets() "
135  "______________________________"
136  << std::endl;
138  setup.get<TrackerDigiGeometryRecord>().get(hGeo);
139 
140  std::cout << std::fixed << std::setprecision(3);
141  auto const &dets = hGeo->dets();
142  for (unsigned int i = 0; i < dets.size(); ++i) {
143  const GeomDet &det = *dets[i];
144 
145  // Surface::PositionType is a typedef for Point3DBase<float,GlobalTag> a.k.a. GlobalPoint
146  const Surface::PositionType &p = det.position();
147  math::XYZVector position(p.x(), p.y(), p.z());
148 
149  std::cout << det.subDetector() << '\t' << det.geographicalId().det() << '\t' << det.geographicalId().subdetId()
150  << '\t' << det.geographicalId().rawId() << "\t" << position;
151  const std::vector<const GeomDet *> &parts = det.components();
152  if (!parts.empty()) {
153  std::cout << "\t[" << parts[0]->geographicalId().rawId();
154  for (unsigned int j = 1; j < parts.size(); ++j)
155  std::cout << '\t' << parts[j]->geographicalId().rawId();
156  std::cout << ']';
157  }
158  std::cout << std::endl;
159  }
160 }
161 
163 
164 //-------------------------------------------------------------------------
165 // define as a plugin
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: ListIds.cc:91
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
static bool dddGetStringRaw(const DDFilteredView &view, const std::string &name, std::string &value)
Definition: ListIds.cc:28
const N & name() const
Definition: DDBase.h:74
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
bool printMaterial_
Definition: ListIds.cc:81
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
T y() const
Definition: PV3DBase.h:63
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:81
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const Surface::PositionType & position() const
The position (origin of the R.F.)
Definition: GeomDet.h:48
bool next()
set current node to the next node in the filtered tree
T z() const
Definition: PV3DBase.h:64
const std::string fullname() const
Definition: DDName.h:43
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
static std::ostream & operator<<(std::ostream &out, const math::XYZVector &v)
Definition: ListIds.cc:64
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
void endJob() override
Definition: ListIds.cc:162
static std::string dddGetString(const std::string &s, const DDFilteredView &view)
Definition: ListIds.cc:56
Definition: value.py:1
const std::vector< std::string > & strings() const
a reference to the std::string-valued values stored in the given instance of DDValue ...
Definition: DDValue.h:61
std::vector< DDExpandedNode > DDGeoHistory
Geometrical &#39;path&#39; of the current node up to the root-node.
virtual std::vector< const GeomDet * > components() const
Returns direct components, if any.
Definition: GeomDet.h:88
XYZVectorD XYZVector
spatial vector with cartesian internal representation
Definition: Vector3D.h:30
std::vector< std::string > materials_
Definition: ListIds.cc:82
static int position[264][3]
Definition: ReadPGInfo.cc:509
T get() const
Definition: EventSetup.h:71
bool firstChild()
set the current node to the first child ...
void specificsV(std::vector< const DDsvalues_type * > &result) const
User specific data attached to the current node.
ListIds(const edm::ParameterSet &)
Definition: ListIds.cc:85
const DDTranslation & translation() const
The absolute translation of the current node.
virtual SubDetector subDetector() const
Which subdetector.
Definition: GeomDet.cc:44
T x() const
Definition: PV3DBase.h:62
void beginJob() override
Definition: ListIds.cc:75
const DDMaterial & material(void) const
Returns a reference object of the material this LogicalPart is made of.
GeometricDet::GeometricEnumType type(std::string const &) const
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39
~ListIds() override
Definition: ListIds.cc:89