DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
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 //==========================================================================
11 /*
12  * MultiSegmentation.cpp
13  *
14  * Created on: Jun 28, 2013
15  * Author: Christian Grefe, CERN
16  */
17 
19 #include <DD4hep/Printout.h>
20 
21 #include <iomanip>
22 #include <stdexcept>
23 
24 namespace dd4hep {
25 
26  namespace DDSegmentation {
27 
29  MultiSegmentation::MultiSegmentation(const std::string& cellEncoding)
30  : Segmentation(cellEncoding), m_discriminator(0), m_debug(0)
31  {
32  // define type and description
33  _type = "MultiSegmentation";
34  _description = "Multi-segmenation wrapper segmentation";
35  //registerParameter<int>("debug", "Debug flag", m_debug, 0);
36  registerParameter<std::string>("key", "Diskriminating field", m_discriminatorId, "");
37  }
38 
41  : Segmentation(decode), m_discriminator(0), m_debug(0)
42  {
43  // define type and description
44  _type = "MultiSegmentation";
45  _description = "Multi-segmenation wrapper segmentation";
46  //registerParameter<int>("debug", "Debug flag", m_debug, 0);
47  registerParameter<std::string>("key", "Diskriminating field", m_discriminatorId, "");
48  }
49 
52  for(Segmentations::iterator i=m_segmentations.begin(); i!=m_segmentations.end(); ++i)
53  delete (*i).segmentation;
54  m_segmentations.clear();
55  }
56 
58  void MultiSegmentation::addSubsegmentation(long key_min, long key_max, Segmentation* entry) {
59  Entry e;
60  e.key_min = key_min;
61  e.key_max = key_max;
62  e.segmentation = entry;
63  m_segmentations.emplace_back(e);
64  }
65 
67  void MultiSegmentation::setDecoder(const BitFieldCoder* newDecoder) {
68  this->Segmentation::setDecoder(newDecoder);
69  for(Segmentations::iterator i=m_segmentations.begin(); i != m_segmentations.end(); ++i)
70  (*i).segmentation->setDecoder(newDecoder);
71  m_discriminator = &((*_decoder)[m_discriminatorId]);
72  }
73 
76  if ( m_discriminator ) {
77  long seg_id = m_discriminator->value(cID);
78  for(Segmentations::const_iterator i=m_segmentations.begin(); i != m_segmentations.end(); ++i) {
79  const Entry& e = *i;
80  if ( e.key_min<= seg_id && e.key_max >= seg_id ) {
82  if ( m_debug > 0 ) {
83  printout(ALWAYS,"MultiSegmentation","Id: %04X %s", seg_id, s->name().c_str());
84  const Parameters& pars = s->parameters();
85  for( const auto* p : pars ) {
86  printout(ALWAYS,"MultiSegmentation"," Param %s = %s",
87  p->name().c_str(), p->value().c_str());
88  }
89  }
90  return *s;
91  }
92  }
93  }
94  except("MultiSegmentation", "Invalid sub-segmentation identifier!");
95  throw std::string("Invalid sub-segmentation identifier!");
96  }
97 
100  return subsegmentation(cID).position(cID);
101  }
102 
104  CellID MultiSegmentation::cellID(const Vector3D& localPosition, const Vector3D& globalPosition, const VolumeID& vID) const {
105  return subsegmentation(vID).cellID(localPosition, globalPosition, vID);
106  }
107 
108  std::vector<double> MultiSegmentation::cellDimensions(const CellID& cID) const {
109  return subsegmentation(cID).cellDimensions(cID);
110  }
111 
112  } /* namespace DDSegmentation */
113 } /* namespace dd4hep */
dd4hep::DDSegmentation::VolumeID
uint64_t VolumeID
Definition: BitFieldCoder.h:27
dd4hep::DDSegmentation::MultiSegmentation::position
virtual Vector3D position(const CellID &cellID) const
determine the position based on the cell ID
Definition: MultiSegmentation.cpp:99
dd4hep::DDSegmentation::Vector3D
Simple container for a physics vector.
Definition: Segmentation.h:48
MultiSegmentation.h
dd4hep::DDSegmentation::BitFieldCoder
Helper class for decoding and encoding a bit field of 64bits for convenient declaration.
Definition: BitFieldCoder.h:114
dd4hep::DDSegmentation::BitFieldElement::value
FieldID value(CellID bitfield) const
calculate this field's value given an external 64 bit bitmap
Definition: BitFieldCoder.cpp:55
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:58
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:108
dd4hep::DDSegmentation::MultiSegmentation::setDecoder
virtual void setDecoder(const BitFieldCoder *decoder)
Set the underlying decoder.
Definition: MultiSegmentation.cpp:67
dd4hep::DDSegmentation::Segmentation::name
virtual const std::string & name() const
Access the segmentation name.
Definition: Segmentation.h:96
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:75
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:104
dd4hep::DDSegmentation::MultiSegmentation::m_segmentations
Segmentations m_segmentations
Sub-segmentaion container.
Definition: MultiSegmentation.h:40
dd4hep::DDSegmentation::CellID
uint64_t CellID
Definition: BitFieldCoder.h:26
dd4hep::DDSegmentation::MultiSegmentation::Entry::key_max
long key_max
Definition: MultiSegmentation.h:33
dd4hep::DDSegmentation::MultiSegmentation::~MultiSegmentation
virtual ~MultiSegmentation()
Default destructor.
Definition: MultiSegmentation.cpp:51
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:162
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:29
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:160
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:75
Printout.h
dd4hep::DDSegmentation::Segmentation::position
virtual Vector3D position(const CellID &cellID) const =0
Determine the local position based on the cell ID.