File indexing completed on 2025-01-18 09:13:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef DDSEGMENTATION_SEGMENTATION_H
0020 #define DDSEGMENTATION_SEGMENTATION_H
0021
0022 #include <DD4hep/detail/SegmentationsInterna.h>
0023 #include <DDSegmentation/BitFieldCoder.h>
0024 #include <DDSegmentation/SegmentationParameter.h>
0025
0026 #include <map>
0027 #include <utility>
0028 #include <set>
0029 #include <string>
0030 #include <vector>
0031
0032 namespace dd4hep {
0033 namespace DDSegmentation {
0034
0035 typedef SegmentationParameter* Parameter;
0036 typedef std::vector<Parameter> Parameters;
0037 typedef TypedSegmentationParameter<int>* IntParameter;
0038 typedef TypedSegmentationParameter<float>* FloatParameter;
0039 typedef TypedSegmentationParameter<double>* DoubleParameter;
0040 typedef TypedSegmentationParameter<std::string>* StringParameter;
0041 typedef TypedSegmentationParameter<std::vector<int> >* IntVecParameter;
0042 typedef TypedSegmentationParameter<std::vector<float> >* FloatVecParameter;
0043 typedef TypedSegmentationParameter<std::vector<double> >* DoubleVecParameter;
0044 typedef TypedSegmentationParameter<std::vector<std::string> >* StringVecParameter;
0045 typedef SegmentationParameter::UnitType UnitType;
0046
0047
0048 struct Vector3D {
0049
0050 Vector3D(double x_val = 0., double y_val = 0., double z_val = 0.) :
0051 X(x_val), Y(y_val), Z(z_val) {
0052 }
0053
0054 template<typename T> Vector3D(const T& v) {
0055 X = v.x();
0056 Y = v.y();
0057 Z = v.Z();
0058 }
0059
0060 double x() const {
0061 return X;
0062 }
0063
0064 double y() const {
0065 return Y;
0066 }
0067
0068 double z() const {
0069 return Z;
0070 }
0071 double X, Y, Z;
0072 };
0073
0074
0075 class Segmentation {
0076 public:
0077
0078 virtual ~Segmentation();
0079
0080
0081 virtual void addSubsegmentation(long key_min, long key_max, Segmentation* entry);
0082
0083 virtual Vector3D position(const CellID& cellID) const = 0;
0084
0085 virtual CellID cellID(const Vector3D& localPosition, const Vector3D& globalPosition,
0086 const VolumeID& volumeID) const = 0;
0087
0088 virtual VolumeID volumeID(const CellID& cellID) const;
0089
0090 virtual void neighbours(const CellID& cellID, std::set<CellID>& neighbours) const;
0091
0092 virtual std::string fieldDescription() const {
0093 return _decoder->fieldDescription();
0094 }
0095
0096 virtual const std::string& name() const {
0097 return _name;
0098 }
0099
0100 virtual void setName(const std::string& value) {
0101 _name = value;
0102 }
0103
0104 virtual const std::string& type() const {
0105 return _type;
0106 }
0107
0108 virtual const std::string& description() const {
0109 return _description;
0110 }
0111
0112 virtual const BitFieldCoder* decoder() const {
0113 return _decoder;
0114 }
0115
0116 virtual void setDecoder(const BitFieldCoder* decoder);
0117
0118 virtual Parameter parameter(const std::string& parameterName) const;
0119
0120 virtual Parameters parameters() const;
0121
0122 virtual void setParameters(const Parameters& parameters);
0123
0124
0125
0126
0127
0128
0129 virtual std::vector<double> cellDimensions(const CellID& cellID) const;
0130
0131 protected:
0132
0133 Segmentation(const std::string& cellEncoding = "");
0134
0135 Segmentation(const BitFieldCoder* decoder);
0136
0137
0138 template<typename TYPE> void registerParameter(const std::string& nam, const std::string& desc,
0139 TYPE& param, const TYPE& defaultVal, UnitType unitTyp = SegmentationParameter::NoUnit,
0140 bool isOpt = false) {
0141 _parameters[nam] = new TypedSegmentationParameter<TYPE>(nam,desc,param,defaultVal,unitTyp,isOpt);
0142 }
0143
0144 void registerIdentifier(const std::string& nam, const std::string& desc, std::string& ident,
0145 const std::string& defaultVal);
0146
0147
0148 static double binToPosition(FieldID bin, double cellSize, double offset = 0.);
0149
0150 static int positionToBin(double position, double cellSize, double offset = 0.);
0151
0152
0153 static double binToPosition(FieldID bin, std::vector<double> const& cellBoundaries, double offset = 0.);
0154
0155 static int positionToBin(double position, std::vector<double> const& cellBoundaries, double offset = 0.);
0156
0157
0158 std::string _name;
0159
0160 std::string _type;
0161
0162 std::string _description;
0163
0164 std::map<std::string, Parameter> _parameters;
0165
0166 std::map<std::string, StringParameter> _indexIdentifiers;
0167
0168 const BitFieldCoder* _decoder = 0;
0169
0170 bool _ownsDecoder = false;
0171 private:
0172
0173 Segmentation(const Segmentation&);
0174 };
0175
0176 }
0177 }
0178 #endif