Belle II Software  release-08-01-10
MeasurementFactory.h
1 /* Copyright 2008-2010, Technische Universitaet Muenchen,
2  Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch & Tobias Schlüter
3 
4  This file is part of GENFIT.
5 
6  GENFIT is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  GENFIT is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with GENFIT. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
25 #ifndef genfit_MeasurementFactory_h
26 #define genfit_MeasurementFactory_h
27 
28 #include "MeasurementProducer.h"
29 #include "TrackCand.h"
30 
31 #include <vector>
32 #include <map>
33 
34 
35 namespace genfit {
36 
37 class AbsMeasurement;
38 
50 template <class measurement_T>
52  private:
53  std::map<int, AbsMeasurementProducer<measurement_T>*> hitProdMap_;
54 
55 
56  public:
57  MeasurementFactory() {};
58  virtual ~MeasurementFactory() { clear(); }
59 
67 
70  void clear();
71 
78  measurement_T* createOne (int detID, int index, const TrackCandHit* hit) const;
79 
91  std::vector<measurement_T*> createMany(const TrackCand& cand) const;
92 
93 };
94 
95 
96 template <class measurement_T>
98  typename std::map<int, AbsMeasurementProducer<measurement_T>*>::iterator it = hitProdMap_.find(detID);
99  if(it == hitProdMap_.end()) {
100  hitProdMap_[detID] = hitProd;
101  } else {
102  Exception exc("MeasurementFactory: detID already in use",__LINE__,__FILE__);
103  exc.setFatal();
104  std::vector<double> numbers;
105  numbers.push_back(detID);
106  exc.setNumbers("detID",numbers);
107  throw exc;
108  }
109 }
110 
111 template <class measurement_T>
113  typename std::map<int, AbsMeasurementProducer<measurement_T>*>::iterator it=hitProdMap_.begin();
114  while(it!=hitProdMap_.end()){
115  delete it->second;
116  ++it;
117  }
118  hitProdMap_.clear();
119 }
120 
121 template <class measurement_T>
122 measurement_T* MeasurementFactory<measurement_T>::createOne(int detID, int index, const TrackCandHit* hit) const {
123  typename std::map<int, AbsMeasurementProducer<measurement_T>*>::const_iterator it = hitProdMap_.find(detID);
124 
125  if(it != hitProdMap_.end()) {
126  return it->second->produce(index, hit);
127  } else {
128  Exception exc("MeasurementFactory: no hitProducer for this detID available",__LINE__,__FILE__);
129  exc.setFatal();
130  std::vector<double> numbers;
131  numbers.push_back(detID);
132  exc.setNumbers("detID", numbers);
133  throw exc;
134  }
135 }
136 
137 template <class measurement_T>
138 typename std::vector<measurement_T*> MeasurementFactory<measurement_T>::createMany(const TrackCand& cand) const {
139  typename std::vector<measurement_T*> hitVec;
140  unsigned int nHits=cand.getNHits();
141  for(unsigned int i=0;i<nHits;i++) {
142  int detID, index;
143  const TrackCandHit* hit = cand.getHit(i);
144  cand.getHit(i, detID, index);
145  hitVec.push_back( MeasurementFactory<measurement_T>::createOne(hit->getDetId(), hit->getHitId(), hit) );
146  }
147  return hitVec;
148 }
149 
150 
151 } /* End of namespace genfit */
154 #endif // genfit_MeasurementFactory_h
Abstract interface class for MeasurementProducer.
Exception class for error handling in GENFIT (provides storage for diagnostic information)
Definition: Exception.h:48
void setFatal(bool b=true)
Set fatal flag.
Definition: Exception.h:61
void setNumbers(std::string, const std::vector< double > &)
Set list of numbers with description.
Definition: Exception.cc:40
Factory object to create AbsMeasurement objects from digitized and clustered data.
std::vector< measurement_T * > createMany(const TrackCand &cand) const
Create a collection of Measurements.
void addProducer(int detID, AbsMeasurementProducer< measurement_T > *hitProd)
Register a producer module to the factory.
measurement_T * createOne(int detID, int index, const TrackCandHit *hit) const
Create a Measurement.
void clear()
Clear all hit producers.
Hit object for use in TrackCand.
Definition: TrackCandHit.h:34
Track candidate – seed values and indices.
Definition: TrackCand.h:69
Defines for I/O streams used for error and debug printing.