Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MeasurementFactory.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file 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:
58  virtual ~MeasurementFactory() { clear(); }
59 
66  void addProducer(int detID, AbsMeasurementProducer<measurement_T>* hitProd);
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