CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
cms::DDCMSDetElementCreator Class Reference
Inheritance diagram for cms::DDCMSDetElementCreator:

Classes

struct  Count
 
struct  Data
 

Public Member Functions

 DDCMSDetElementCreator (dd4hep::Detector &)
 
int operator() (dd4hep::PlacedVolume volume, int level) override
 Callback to output PlacedVolume information of an single Placement. More...
 
int process (dd4hep::PlacedVolume volume, int level, bool recursive) override
 Callback to output PlacedVolume information of an entire Placement. More...
 
 ~DDCMSDetElementCreator () override
 

Private Types

using Counters = std::map< dd4hep::DetElement, Count >
 
using Detectors = std::map< std::string, dd4hep::DetElement >
 
using LeafCount = std::map< std::pair< dd4hep::DetElement, int >, std::pair< int, int > >
 
using VolumeStack = std::vector< Data >
 

Private Member Functions

dd4hep::DetElement addSubdetector (const std::string &nam, dd4hep::PlacedVolume volume, bool valid)
 
dd4hep::DetElement createElement (const char *debugTag, dd4hep::PlacedVolume volume, int id)
 
void createTopLevelDetectors (dd4hep::PlacedVolume volume)
 

Private Attributes

std::map< dd4hep::PlacedVolume, std::pair< int, int > > m_allPlacements
 
Counters m_counters
 
dd4hep::DetElement m_currentDetector
 
dd4hep::SensitiveDetector m_currentSensitive
 
dd4hep::Detector & m_description
 
LeafCount m_leafCount
 
dd4hep::Atom m_silicon
 
VolumeStack m_stack
 
Detectors m_subdetectors
 
dd4hep::DetElement m_tracker
 

Detailed Description

Definition at line 19 of file DDCMSDetElementCreator.cc.

Member Typedef Documentation

using cms::DDCMSDetElementCreator::Counters = std::map<dd4hep::DetElement, Count>
private

Definition at line 65 of file DDCMSDetElementCreator.cc.

using cms::DDCMSDetElementCreator::Detectors = std::map<std::string, dd4hep::DetElement>
private

Definition at line 64 of file DDCMSDetElementCreator.cc.

using cms::DDCMSDetElementCreator::LeafCount = std::map<std::pair<dd4hep::DetElement, int>, std::pair<int, int> >
private

Definition at line 66 of file DDCMSDetElementCreator.cc.

using cms::DDCMSDetElementCreator::VolumeStack = std::vector<Data>
private

Definition at line 67 of file DDCMSDetElementCreator.cc.

Constructor & Destructor Documentation

DDCMSDetElementCreator::DDCMSDetElementCreator ( dd4hep::Detector &  desc)

Definition at line 95 of file DDCMSDetElementCreator.cc.

References m_description, m_silicon, and m_stack.

Referenced by createObject().

96  : m_description( desc )
97 {
98  dd4hep::DetectorHelper helper( m_description );
99  m_silicon = helper.element( "SI" );
100  if( !m_silicon.isValid()) {
101  except( "DDCMSDetElementCreator",
102  "++ Failed to extract SILICON from the element table." );
103  }
104  m_stack.reserve(32);
105 }
Definition: helper.py:1
DDCMSDetElementCreator::~DDCMSDetElementCreator ( )
override

Create ID Descriptors and readout configurations

Definition at line 107 of file DDCMSDetElementCreator.cc.

References bits, EnergyCorrector::c, DEBUG, cms::DDCMSDetElementCreator::Count::elements, f, callgraph::fields, MessageLogger_cfi::INFO, checklumidiff::l, m_allPlacements, m_counters, m_description, m_leafCount, AlCaHLTBitMon_ParallelJobs::p, lumiQueryAPI::q, sd, cms::DDCMSDetElementCreator::Count::sensitives, str, AlCaHLTBitMon_QueryRunRegistry::string, pileupDistInMC::total, simpleEdmComparison::totalCount, g4SimHits_cfi::Volume, and cms::DDCMSDetElementCreator::Count::volumes.

108 {
109  Count total;
110  stringstream str, id_str;
111 
112  printout( INFO, "DDCMSDetElementCreator", "+++++++++++++++ Summary of sensitve elements ++++++++++++++++++++++++" );
113  for( const auto& c : m_counters ) {
114  printout( INFO, "DDCMSDetElementCreator", "++ Summary: SD: %-24s %7d DetElements %7d sensitives out of %7d volumes",
115  ( c.first.name() + string(":")).c_str(), c.second.elements, c.second.sensitives, c.second.volumes );
116  total.elements += c.second.elements;
117  total.sensitives += c.second.sensitives;
118  total.volumes += c.second.volumes;
119  }
120  printout( INFO, "DDCMSDetElementCreator", "++ Summary: %-24s %7d DetElements %7d sensitives out of %7d volumes",
121  "Grand Total:", total.elements, total.sensitives, total.volumes );
122  printout( INFO, "DDCMSDetElementCreator", "+++++++++++++++ Summary of geometry depth analysis ++++++++++++++++++" );
123  int totalCount = 0, totalDepth = 0;
124  map<dd4hep::DetElement, vector<pair<int,int> > > fields;
125  for( const auto& l : m_leafCount ) {
126  dd4hep::DetElement de = l.first.first;
127  printout( INFO,"DDCMSDetElementCreator", "++ Summary: SD: %-24s system:%04X Lvl:%3d Sensitives: %6d [Max: %6d].",
128  ( de.name() + string(":")).c_str(), de.id(),
129  l.first.second, l.second.second, l.second.first );
130  fields[de].push_back( make_pair( l.first.second, l.second.first ));
131  totalDepth += l.second.second;
132  ++totalCount;
133  }
134  printout( INFO, "DDCMSDetElementCreator", "++ Summary: %-24s %d.","Total DetElements:", totalCount );
135  printout( INFO, "DDCMSDetElementCreator", "+++++++++++++++ Readout structure generation ++++++++++++++++++++++++" );
136  str << endl;
137  for( const auto& f : fields ) {
138  string roName = f.first.name() + string("Hits");
139  int num_bits = 8;
140  id_str.str("");
141  id_str << "system:" << num_bits;
142  for( const auto& q : f.second ) {
143  int bits = 0;
144  if ( q.second < 1<<0 ) bits = 1;
145  else if ( q.second < 1<<1 ) bits = 1;
146  else if ( q.second < 1<<2 ) bits = 2;
147  else if ( q.second < 1<<3 ) bits = 3;
148  else if ( q.second < 1<<4 ) bits = 4;
149  else if ( q.second < 1<<5 ) bits = 5;
150  else if ( q.second < 1<<6 ) bits = 6;
151  else if ( q.second < 1<<7 ) bits = 7;
152  else if ( q.second < 1<<8 ) bits = 8;
153  else if ( q.second < 1<<9 ) bits = 9;
154  else if ( q.second < 1<<10 ) bits = 10;
155  else if ( q.second < 1<<11 ) bits = 11;
156  else if ( q.second < 1<<12 ) bits = 12;
157  else if ( q.second < 1<<13 ) bits = 13;
158  else if ( q.second < 1<<14 ) bits = 14;
159  else if ( q.second < 1<<15 ) bits = 15;
160  bits += 1;
161  id_str << ",Lv" << q.first << ":" << bits;
162  num_bits += bits;
163  }
164  string idspec = id_str.str();
165  str << "<readout name=\"" << roName << "\">" << endl
166  << "\t<id>"
167  << idspec
168  << "</id> <!-- Number of bits: " << num_bits << " -->" << endl
169  << "</readout>" << endl;
170 
172  IDDescriptor dsc( roName, idspec );
173  m_description.addIDSpecification( dsc );
174  Readout ro( roName );
175  ro.setIDDescriptor( dsc );
176  m_description.addReadout( ro );
177  dd4hep::SensitiveDetector sd = m_description.sensitiveDetector( f.first.name());
178  sd.setHitsCollection( ro.name());
179  sd.setReadout( ro );
180  printout( INFO, "DDCMSDetElementCreator",
181  "++ Setting up readout for subdetector:%-24s id:%04X",
182  f.first.name(), f.first.id());
183  }
184  printout( INFO, "DDCMSDetElementCreator","+++++++++++++++ ID Descriptor generation ++++++++++++++++++++++++++++");
185  printout( INFO, "", str.str().c_str());
186  char volId[32];
187  for(auto& p : m_allPlacements ) {
188  dd4hep::PlacedVolume place = p.first;
189  dd4hep::Volume volume = place.volume();
190  ::snprintf( volId, sizeof(volId), "Lv%d", p.second.first );
191  printout( DEBUG,"DDCMSDetElementCreator",
192  "++ Set volid (%-24s): %-6s = %3d -> %s (%p)",
193  volume.isSensitive() ? volume.sensitiveDetector().name() : "Not Sensitive",
194  volId, p.second.second, place.name(), place.ptr());
195  place.addPhysVolID( volId, p.second.second);
196  }
197  printout( ALWAYS, "DDCMSDetElementCreator",
198  "++ Instrumented %ld subdetectors with %d DetElements %d sensitives out of %d volumes and %ld sensitive placements.",
199  fields.size(), total.elements, total.sensitives, total.volumes, m_allPlacements.size());
200 }
#define DEBUG
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
std::map< dd4hep::PlacedVolume, std::pair< int, int > > m_allPlacements
double f[11][100]
double sd
#define str(s)

Member Function Documentation

dd4hep::DetElement DDCMSDetElementCreator::addSubdetector ( const std::string &  nam,
dd4hep::PlacedVolume  volume,
bool  valid 
)
private

Definition at line 224 of file DDCMSDetElementCreator.cc.

References m_description, and m_subdetectors.

Referenced by createTopLevelDetectors().

225 {
226  auto idet = m_subdetectors.find(nam);
227  if( idet == m_subdetectors.end()) {
228  dd4hep::DetElement det( nam, m_subdetectors.size() + 1 );
229  det.setPlacement( volume );
230  if( valid ) {
231  det.placement().addPhysVolID( "system", det.id());
232  }
233  idet = m_subdetectors.insert( make_pair( nam, det)).first;
234  m_description.add( det );
235  }
236  return idet->second;
237 }
dd4hep::DetElement DDCMSDetElementCreator::createElement ( const char *  debugTag,
dd4hep::PlacedVolume  volume,
int  id 
)
private

Definition at line 203 of file DDCMSDetElementCreator.cc.

References cms::detElementName(), and dataset::name.

Referenced by process().

204 {
205  string name = detElementName( volume );
206  dd4hep::DetElement det( name, id );
207  det.setPlacement( volume );
208  return det;
209 }
std::string detElementName(dd4hep::PlacedVolume volume)
void DDCMSDetElementCreator::createTopLevelDetectors ( dd4hep::PlacedVolume  volume)
private

Definition at line 211 of file DDCMSDetElementCreator.cc.

References addSubdetector(), data, cms::detElementName(), m_currentDetector, m_stack, and m_tracker.

Referenced by process().

212 {
213  auto& data = m_stack.back();
214  if( m_stack.size() == 2 ) { // Main subssystem: tracker:Tracker
215  data.element = m_tracker = addSubdetector( cms::detElementName(volume), volume, false );
216  m_tracker->SetTitle( "compound" );
217  }
218  else if( m_stack.size() == 3 ) { // Main subsystem detector: TIB, TEC, ....
219  data.element = m_currentDetector = addSubdetector( cms::detElementName(volume), volume, true );
220  }
221 }
std::string detElementName(dd4hep::PlacedVolume volume)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
dd4hep::DetElement addSubdetector(const std::string &nam, dd4hep::PlacedVolume volume, bool valid)
int DDCMSDetElementCreator::operator() ( dd4hep::PlacedVolume  volume,
int  level 
)
override

Callback to output PlacedVolume information of an single Placement.

Definition at line 240 of file DDCMSDetElementCreator.cc.

References data, MillePedeFileConverter_cfg::e, cms::DDCMSDetElementCreator::Data::hasSensitive, training_settings::idx, m_allPlacements, m_currentDetector, m_leafCount, m_silicon, m_stack, SiStripPI::max, cms::DDCMSDetElementCreator::Data::sensitive, and cms::DDCMSDetElementCreator::Data::volumeCount.

241 {
242  double fracSi = volume.volume().material().fraction( m_silicon );
243  if( fracSi > 90e-2 ) {
244  Data& data = m_stack.back();
245  data.sensitive = true;
246  data.hasSensitive = true;
247  ++data.volumeCount;
248  int idx = volume->GetMotherVolume()->GetIndex( volume.ptr())+1;
249  auto& cnt = m_leafCount[make_pair( m_currentDetector, volumeLevel )];
250  cnt.first = std::max( cnt.first, idx );
251  ++cnt.second;
252  m_allPlacements[volume] = make_pair( volumeLevel, idx );
253  return 1;
254  }
255  return 0;
256 }
std::map< dd4hep::PlacedVolume, std::pair< int, int > > m_allPlacements
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
int DDCMSDetElementCreator::process ( dd4hep::PlacedVolume  volume,
int  level,
bool  recursive 
)
override

Callback to output PlacedVolume information of an entire Placement.

Complete structures if the m_stack size is > 3!

If this volume is sensitve, we must attach a sensitive detector handle

Now the cleanup kicks in....

Definition at line 259 of file DDCMSDetElementCreator.cc.

References createElement(), createTopLevelDetectors(), data, DEBUG, training_settings::idx, hcalDigis_cfi::level, m_allPlacements, m_counters, m_currentDetector, m_currentSensitive, m_description, m_leafCount, m_stack, SiStripPI::max, class-composition::parent, LaserDQM_cfg::process, sd, and dqm::qstatus::WARNING.

Referenced by Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::dumpPython(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::open(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::outputEventContent(), Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::setProcess(), and Vispa.Plugins.ConfigEditor.ConfigDataAccessor.ConfigDataAccessor::setProperty().

261  {
262  m_stack.push_back(Data(volume));
263  if ( m_stack.size() <= 3 ) {
264  createTopLevelDetectors(volume);
265  }
266  int ret = dd4hep::PlacedVolumeProcessor::process( volume, level, recursive );
267 
269  if( m_stack.size() > 3 ) {
270  // Note: short-cuts to entries in the m_stack MUST be local and
271  // initialized AFTER the call to "process"! The vector may be resized!
272  auto& data = m_stack.back();
273  auto& parent = m_stack[ m_stack.size() - 2 ];
274  auto& counts = m_counters[ m_currentDetector ];
275  if( data.sensitive ) {
277  if ( !m_currentSensitive.isValid()) {
278  dd4hep::SensitiveDetector sd = m_description.sensitiveDetector( m_currentDetector.name());
279  if( !sd.isValid()) {
280  sd = dd4hep::SensitiveDetector( m_currentDetector.name(), "tracker" );
281  m_currentDetector->flag |= DetElement::Object::HAVE_SENSITIVE_DETECTOR;
282  m_description.add( sd );
283  }
285  }
286  volume.volume().setSensitiveDetector( m_currentSensitive );
287  ++counts.sensitives;
288  }
289  ++counts.volumes;
290  bool added = false;
291  if( data.volumeCount > 0 ) {
292  parent.daughterCount += data.volumeCount;
293  parent.daughterCount += data.daughterCount;
294  data.hasSensitive = true;
295  }
296  else {
297  parent.daughterCount += data.daughterCount;
298  data.hasSensitive = ( data.daughterCount > 0 );
299  }
300 
301  if( data.hasSensitive ) {
302  // If we have sensitive elements at this level or below,
303  // we must complete the DetElement hierarchy
304  if( !data.element.isValid()) {
305  data.element = createElement( "Element", data.volume, m_currentDetector.id());
306  ++counts.elements;
307  }
308  if( !parent.element.isValid()) {
309  parent.element = createElement( "Parent ", parent.volume, m_currentDetector.id());
310  ++counts.elements;
311  }
312  printout( DEBUG, "DDCMSDetElementCreator",
313  "++ Assign detector element: %s (%p, %ld children) to %s (%p) with %ld vols",
314  data.element.name(), data.element.ptr(), data.element.children().size(),
315  parent.element.name(), parent.element.ptr(),
316  data.volumeCount );
317 
318  // Trickle up the tree only for sensitive pathes. Forget the passive rest
319  // This should automatically omit non-sensitive pathes
320  parent.hasSensitive = true;
321  parent.element.add( data.element );
322  added = true;
323  // It is simpler to collect the volumes and later assign the volids
324  // rather than checking if the volid already exists.
325  int volumeLevel = level;
326  int idx = data.volume->GetMotherVolume()->GetIndex( data.volume.ptr())+1;
327  m_allPlacements[data.volume] = make_pair( volumeLevel, idx ); // 1...n
328  // Update counters
329  auto& cnt_det = m_leafCount[make_pair( m_currentDetector, volumeLevel )];
330  cnt_det.first = std::max( cnt_det.first, idx );
331  cnt_det.second += 1;
332  }
333  if ( !added && data.element.isValid() ) {
334  printout(WARNING,"MEMORY-LEAK","Level:%3d Orpahaned DetElement:%s Daugthers:%d Parent:%s",
335  int(m_stack.size()), data.element.name(), data.volumeCount, parent.volume.name());
336  }
337  }
339  if( m_stack.size() == 3 ) {
341  m_currentDetector = DetElement();
342  ret = 0;
343  }
344  m_stack.pop_back();
345  return ret;
346 }
#define DEBUG
void createTopLevelDetectors(dd4hep::PlacedVolume volume)
dd4hep::DetElement createElement(const char *debugTag, dd4hep::PlacedVolume volume, int id)
static const int WARNING
std::map< dd4hep::PlacedVolume, std::pair< int, int > > m_allPlacements
double sd
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
dd4hep::SensitiveDetector m_currentSensitive

Member Data Documentation

std::map<dd4hep::PlacedVolume, std::pair<int,int> > cms::DDCMSDetElementCreator::m_allPlacements
private

Definition at line 69 of file DDCMSDetElementCreator.cc.

Referenced by operator()(), process(), and ~DDCMSDetElementCreator().

Counters cms::DDCMSDetElementCreator::m_counters
private

Definition at line 71 of file DDCMSDetElementCreator.cc.

Referenced by process(), and ~DDCMSDetElementCreator().

dd4hep::DetElement cms::DDCMSDetElementCreator::m_currentDetector
private

Definition at line 75 of file DDCMSDetElementCreator.cc.

Referenced by createTopLevelDetectors(), operator()(), and process().

dd4hep::SensitiveDetector cms::DDCMSDetElementCreator::m_currentSensitive
private

Definition at line 76 of file DDCMSDetElementCreator.cc.

Referenced by process().

dd4hep::Detector& cms::DDCMSDetElementCreator::m_description
private
LeafCount cms::DDCMSDetElementCreator::m_leafCount
private

Definition at line 72 of file DDCMSDetElementCreator.cc.

Referenced by operator()(), process(), and ~DDCMSDetElementCreator().

dd4hep::Atom cms::DDCMSDetElementCreator::m_silicon
private

Definition at line 78 of file DDCMSDetElementCreator.cc.

Referenced by DDCMSDetElementCreator(), and operator()().

VolumeStack cms::DDCMSDetElementCreator::m_stack
private
Detectors cms::DDCMSDetElementCreator::m_subdetectors
private

Definition at line 74 of file DDCMSDetElementCreator.cc.

Referenced by addSubdetector().

dd4hep::DetElement cms::DDCMSDetElementCreator::m_tracker
private

Definition at line 75 of file DDCMSDetElementCreator.cc.

Referenced by createTopLevelDetectors().