Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:07

0001 #ifndef GUARD_RecoIdealGeometry_H
0002 #define GUARD_RecoIdealGeometry_H
0003 
0004 #include "CondFormats/Serialization/interface/Serializable.h"
0005 
0006 #include <vector>
0007 #include <algorithm>
0008 #include <cassert>
0009 
0010 #include <DataFormats/DetId/interface/DetId.h>
0011 
0012 /** @class 
0013  *
0014  *  @author:  Michael Case               Initial Version
0015  *  @version: 0.0
0016  *  @date:    21 May 2007
0017  * 
0018  *  Description:
0019  *  
0020  *  Users are expected to read the publicly available data members themselves
0021  *  though insert is provided for convenience when adding to this container.
0022  * 
0023  *  2009-11-19:  Removed full vector copies and instead force the use of *Start and *End methods
0024  *               which return a const_iterator for the range of elements for each "vector"
0025  *
0026  */
0027 
0028 class RecoIdealGeometry {
0029 public:
0030   RecoIdealGeometry() {}
0031   ~RecoIdealGeometry() {}
0032 
0033   bool insert(DetId id,
0034               const std::vector<double>& trans,
0035               const std::vector<double>& rot,
0036               const std::vector<double>& pars) {
0037     if (trans.size() != 3 || rot.size() != 9)
0038       return false;
0039     pDetIds.push_back(id);
0040     pNumShapeParms.push_back(pars.size());  // number of shape specific parameters.
0041     pParsIndex.push_back(pPars.size());     // start of this guys "blob"
0042     pPars.reserve(pPars.size() + trans.size() + rot.size() + pars.size());
0043     std::copy(trans.begin(), trans.end(), std::back_inserter(pPars));
0044     std::copy(rot.begin(), rot.end(), std::back_inserter(pPars));
0045     std::copy(pars.begin(), pars.end(), std::back_inserter(pPars));
0046     return true;
0047   }
0048 
0049   bool insert(DetId id,
0050               const std::vector<double>& trans,
0051               const std::vector<double>& rot,
0052               const std::vector<double>& pars,
0053               const std::vector<std::string>& spars) {
0054     if (trans.size() != 3 || rot.size() != 9)
0055       return false;
0056     pDetIds.push_back(id);
0057     pNumShapeParms.push_back(pars.size());  // number of shape specific parameters.
0058     pParsIndex.push_back(pPars.size());     // start of this guys "blob"
0059     pPars.reserve(pPars.size() + trans.size() + rot.size() + pars.size());
0060     std::copy(trans.begin(), trans.end(), std::back_inserter(pPars));
0061     std::copy(rot.begin(), rot.end(), std::back_inserter(pPars));
0062     std::copy(pars.begin(), pars.end(), std::back_inserter(pPars));
0063 
0064     sNumsParms.push_back(spars.size());
0065     sParsIndex.push_back(strPars.size());
0066     strPars.reserve(strPars.size() + spars.size());
0067     std::copy(spars.begin(), spars.end(), std::back_inserter(strPars));
0068     return true;
0069   }
0070 
0071   size_t size() {
0072     assert((pDetIds.size() == pNumShapeParms.size()) && (pNumShapeParms.size() == pParsIndex.size()));
0073     return pDetIds.size();
0074   }
0075 
0076   // HOW to use this stuff... first, get hold of the reference to the detIds like:
0077   // const std::vector<double>& myds = classofthistype.detIds()
0078   // Then iterate over the detIds using
0079   // for ( size_t it = 0 ; it < myds.size(); ++it )
0080   // and ask for the parts ...
0081   // {
0082   //   std::vector<double>::const_iterator xyzB = classofthistype.transStart(it);
0083   //   std::vector<double>::const_iterator xyzE = classofthistype.transEnd(it);
0084   // }
0085   const std::vector<DetId>& detIds() const { return pDetIds; }
0086 
0087   std::vector<double>::const_iterator tranStart(size_t ind) const { return pPars.begin() + pParsIndex[ind]; }
0088 
0089   std::vector<double>::const_iterator tranEnd(size_t ind) const { return pPars.begin() + pParsIndex[ind] + 3; }
0090 
0091   std::vector<double>::const_iterator rotStart(size_t ind) const { return pPars.begin() + pParsIndex[ind] + 3; }
0092 
0093   std::vector<double>::const_iterator rotEnd(size_t ind) const { return pPars.begin() + pParsIndex[ind] + 3 + 9; }
0094 
0095   std::vector<double>::const_iterator shapeStart(size_t ind) const { return pPars.begin() + pParsIndex[ind] + 3 + 9; }
0096 
0097   std::vector<double>::const_iterator shapeEnd(size_t ind) const {
0098     return pPars.begin() + pParsIndex[ind] + 3 + 9 + pNumShapeParms[ind];
0099   }
0100 
0101   std::vector<std::string>::const_iterator strStart(size_t ind) const { return strPars.begin() + sParsIndex[ind]; }
0102 
0103   std::vector<std::string>::const_iterator strEnd(size_t ind) const {
0104     return strPars.begin() + sParsIndex[ind] + sNumsParms[ind];
0105   }
0106 
0107 private:
0108   // translation always 3; rotation 9 for now; pars depends on shape_type.
0109   std::vector<DetId> pDetIds;
0110 
0111   std::vector<double> pPars;  // trans, rot then shape parms.
0112   // 0 for first pDetId, 3 + 9 + number of shape parameters for second & etc.
0113   // just save pPars size BEFORE adding next stuff.
0114   std::vector<int> pParsIndex;
0115   std::vector<int> pNumShapeParms;  // save the number of shape parameters.
0116 
0117   std::vector<std::string> strPars;
0118   std::vector<int> sParsIndex;
0119   std::vector<int> sNumsParms;
0120 
0121   COND_SERIALIZABLE;
0122 };
0123 
0124 #endif