DD4hep  1.32.0
Detector Description Toolkit for High Energy Physics
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MultiSegmentation.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 // Created: Jun 28, 2013
11 // Author: Christian Grefe, CERN
12 //
13 //==========================================================================
14 
17 #include <DD4hep/Printout.h>
18 
20 #include <string>
21 
22 namespace dd4hep {
23 
24  namespace DDSegmentation {
25 
27  MultiSegmentation::MultiSegmentation(const std::string& cellEncoding)
28  : Segmentation(cellEncoding), m_discriminator(0), m_debug(0)
29  {
30  // define type and description
31  _type = "MultiSegmentation";
32  _description = "Multi-segmenation wrapper segmentation";
33  //registerParameter<int>("debug", "Debug flag", m_debug, 0);
34  registerParameter<std::string>("key", "Diskriminating field", m_discriminatorId, "");
35  }
36 
39  : Segmentation(decode), m_discriminator(0), m_debug(0)
40  {
41  // define type and description
42  _type = "MultiSegmentation";
43  _description = "Multi-segmenation wrapper segmentation";
44  //registerParameter<int>("debug", "Debug flag", m_debug, 0);
45  registerParameter<std::string>("key", "Diskriminating field", m_discriminatorId, "");
46  }
47 
50  for(Segmentations::iterator i=m_segmentations.begin(); i!=m_segmentations.end(); ++i)
51  delete (*i).segmentation;
52  m_segmentations.clear();
53  }
54 
56  void MultiSegmentation::addSubsegmentation(long key_min, long key_max, Segmentation* entry) {
57  Entry e;
58  e.key_min = key_min;
59  e.key_max = key_max;
60  e.segmentation = entry;
61  m_segmentations.emplace_back(e);
62  }
63 
65  void MultiSegmentation::setDecoder(const BitFieldCoder* newDecoder) {
66  this->Segmentation::setDecoder(newDecoder);
67  for(Segmentations::iterator i=m_segmentations.begin(); i != m_segmentations.end(); ++i)
68  (*i).segmentation->setDecoder(newDecoder);
69  m_discriminator = &((*_decoder)[m_discriminatorId]);
70  }
71 
74  if ( m_discriminator ) {
75  long seg_id = m_discriminator->value(cID);
76  for(Segmentations::const_iterator i=m_segmentations.begin(); i != m_segmentations.end(); ++i) {
77  const Entry& e = *i;
78  if ( e.key_min<= seg_id && e.key_max >= seg_id ) {
80  if ( m_debug > 0 ) {
81  printout(ALWAYS,"MultiSegmentation","Id: %04X %s", seg_id, s->name().c_str());
82  const Parameters& pars = s->parameters();
83  for( const auto* p : pars ) {
84  printout(ALWAYS,"MultiSegmentation"," Param %s = %s",
85  p->name().c_str(), p->value().c_str());
86  }
87  }
88  return *s;
89  }
90  }
91  }
92  except("MultiSegmentation", "Invalid sub-segmentation identifier!");
93  throw std::string("Invalid sub-segmentation identifier!");
94  }
95 
98  return subsegmentation(cID).position(cID);
99  }
100 
102  CellID MultiSegmentation::cellID(const Vector3D& localPosition, const Vector3D& globalPosition, const VolumeID& vID) const {
103  return subsegmentation(vID).cellID(localPosition, globalPosition, vID);
104  }
105 
106  std::vector<double> MultiSegmentation::cellDimensions(const CellID& cID) const {
107  return subsegmentation(cID).cellDimensions(cID);
108  }
109 
110  } /* namespace DDSegmentation */
111 } /* namespace dd4hep */
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:26
dd4hep::DDSegmentation::MultiSegmentation::position
virtual Vector3D position(const CellID &cellID) const
determine the position based on the cell ID
Definition: MultiSegmentation.cpp:97
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:47
MultiSegmentation.h
dd4hep::DDSegmentation::BitFieldCoder
Helper class for decoding and encoding a bit field of 64bits for convenient declaration.
Definition: BitFieldCoder.h:113
dd4hep::DDSegmentation::BitFieldElement::value
FieldID value(CellID bitfield) const
calculate this field's value given an external 64 bit bitmap
Definition: BitFieldCoder.cpp:56
dd4hep::DDSegmentation::MultiSegmentation::Entry
Helper structure to describe a sub-segmentation entry.
Definition: MultiSegmentation.h:32
dd4hep::DDSegmentation::MultiSegmentation::addSubsegmentation
virtual void addSubsegmentation(long key_min, long key_max, Segmentation *entry)
Add subsegmentation.
Definition: MultiSegmentation.cpp:56
dd4hep::DDSegmentation::MultiSegmentation::cellDimensions
virtual std::vector< double > cellDimensions(const CellID &cellID) const
Returns a vector<double> of the cellDimensions of the given cell ID in natural order of dimensions,...
Definition: MultiSegmentation.cpp:106
dd4hep::DDSegmentation::MultiSegmentation::setDecoder
virtual void setDecoder(const BitFieldCoder *decoder)
Set the underlying decoder.
Definition: MultiSegmentation.cpp:65
dd4hep::DDSegmentation::Segmentation::name
virtual const std::string & name() const
Access the segmentation name.
Definition: Segmentation.h:95
dd4hep::DDSegmentation::MultiSegmentation::Entry::key_min
long key_min
Definition: MultiSegmentation.h:33
dd4hep::DDSegmentation::MultiSegmentation::subsegmentation
const Segmentation & subsegmentation(const CellID &cellID) const
Access subsegmentation by cell identifier.
Definition: MultiSegmentation.cpp:73
dd4hep::DDSegmentation::MultiSegmentation::Entry::segmentation
Segmentation * segmentation
Definition: MultiSegmentation.h:34
dd4hep::DDSegmentation::Segmentation::parameters
virtual Parameters parameters() const
Access to all parameters.
Definition: Segmentation.cpp:121
dd4hep::DDSegmentation::Parameters
std::vector< Parameter > Parameters
Definition: SegmentationsInterna.h:35
dd4hep::DDSegmentation::MultiSegmentation::cellID
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const
determine the cell ID based on the position
Definition: MultiSegmentation.cpp:102
dd4hep::DDSegmentation::MultiSegmentation::m_segmentations
Segmentations m_segmentations
Sub-segmentaion container.
Definition: MultiSegmentation.h:40
dd4hep::DDSegmentation::CellID
uint64_t CellID
Definition: BitFieldCoder.h:25
dd4hep::DDSegmentation::MultiSegmentation::Entry::key_max
long key_max
Definition: MultiSegmentation.h:33
dd4hep::DDSegmentation::MultiSegmentation::~MultiSegmentation
virtual ~MultiSegmentation()
Default destructor.
Definition: MultiSegmentation.cpp:49
dd4hep::DDSegmentation::Segmentation::setDecoder
virtual void setDecoder(const BitFieldCoder *decoder)
Set the underlying decoder.
Definition: Segmentation.cpp:100
dd4hep::DDSegmentation::Segmentation::_description
std::string _description
The description of the segmentation.
Definition: Segmentation.h:169
dd4hep::DDSegmentation::MultiSegmentation::m_discriminatorId
std::string m_discriminatorId
the field name used to discriminate sub-segmentations
Definition: MultiSegmentation.h:43
dd4hep::DDSegmentation::Segmentation::cellID
virtual CellID cellID(const Vector3D &localPosition, const Vector3D &globalPosition, const VolumeID &volumeID) const =0
Determine the cell ID based on the position.
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::DDSegmentation::MultiSegmentation::MultiSegmentation
MultiSegmentation(const std::string &cellEncoding="")
Default constructor passing the encoding string.
Definition: MultiSegmentation.cpp:27
dd4hep::DDSegmentation::Segmentation::cellDimensions
virtual std::vector< double > cellDimensions(const CellID &cellID) const
Returns a vector<double> of the cellDimensions of the given cell ID in natural order of dimensions,...
Definition: Segmentation.cpp:195
dd4hep::DDSegmentation::Segmentation::_type
std::string _type
The segmentation type.
Definition: Segmentation.h:167
dd4hep::DDSegmentation::MultiSegmentation::m_discriminator
const BitFieldElement * m_discriminator
Bitfield corresponding to dicriminator identifier.
Definition: MultiSegmentation.h:46
dd4hep::DDSegmentation::MultiSegmentation::m_debug
int m_debug
Debug flags.
Definition: MultiSegmentation.h:49
dd4hep::DDSegmentation::Segmentation
Base class for all segmentations.
Definition: Segmentation.h:74
Printout.h
dd4hep::DDSegmentation::Segmentation::position
virtual Vector3D position(const CellID &cellID) const =0
Determine the local position based on the cell ID.