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