CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/EventFilter/EcalRawToDigi/interface/EcalRegionCabling.h

Go to the documentation of this file.
00001 #ifndef EcalRegionCabling_H
00002 #define EcalRegionCabling_H
00003 
00004 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
00005 #include "Geometry/EcalMapping/interface/ESElectronicsMapper.h"
00006 
00007 #include "DataFormats/Common/interface/LazyGetter.h"
00008 #include "DataFormats/Common/interface/RefGetter.h"
00009 #include "DataFormats/EcalRecHit/interface/EcalRecHit.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00012 
00013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00014 
00015 class EcalRegionCabling {
00016  public:
00017   EcalRegionCabling(edm::ParameterSet & conf, const EcalElectronicsMapping * m)
00018   : mapping_(m)
00019   {
00020     const edm::ParameterSet esMap = conf.getParameter<edm::ParameterSet>("esMapping");
00021     es_mapping_ = new ESElectronicsMapper(esMap);
00022   }
00023   
00024   ~EcalRegionCabling(){
00025     // this pointer is own by this object.
00026     delete es_mapping_;
00027   }
00028   const EcalElectronicsMapping * mapping() const  { return mapping_;}
00029   const ESElectronicsMapper * es_mapping() const { return es_mapping_;}
00030 
00031   template <class T>  void updateEcalRefGetterWithElementIndex(edm::RefGetter<T> & refgetter,
00032                                                                const edm::Handle< edm::LazyGetter<T> >& lazygetter,
00033                                                                const uint32_t index)const;
00034 
00035   template <class T>  void updateEcalRefGetterWithFedIndex(edm::RefGetter<T> & refgetter,
00036                                                                const edm::Handle< edm::LazyGetter<T> >& lazygetter,
00037                                                                const int index)const;
00038 
00039   template <class T> void updateEcalRefGetterWithEtaPhi(edm::RefGetter<T> & refgetter,
00040                                                         const edm::Handle< edm::LazyGetter<T> >& lazygetter,
00041                                                         const double eta,
00042                                                         const double phi)const;
00043   
00044   static uint32_t maxElementIndex() {return (FEDNumbering::MAXECALFEDID - FEDNumbering::MINECALFEDID +1);}
00045   static uint32_t maxESElementIndex() { return (FEDNumbering::MAXPreShowerFEDID - FEDNumbering::MINPreShowerFEDID +1);}
00046 
00047   static uint32_t elementIndex(const int FEDindex) {
00048     //do a test for the time being
00049     if (FEDindex > FEDNumbering::MAXECALFEDID || FEDindex < FEDNumbering::MINECALFEDID) {
00050       edm::LogError("IncorrectMapping")<<"FEDindex: "<< FEDindex
00051                                         <<" is not between: "<<(int) FEDNumbering::MINECALFEDID
00052                                         <<" and "<<(int)FEDNumbering::MAXECALFEDID;
00053       return 0;}
00054     uint32_t eI = FEDindex - FEDNumbering::MINECALFEDID;
00055     return eI; }
00056 
00057   static uint32_t esElementIndex(const int FEDindex) {
00058     //do a test for the time being
00059     if (FEDindex > FEDNumbering::MAXPreShowerFEDID || FEDindex < FEDNumbering::MINPreShowerFEDID) {
00060       edm::LogError("IncorrectMapping")<<"FEDindex: "<< FEDindex
00061                                         <<" is not between: "<<(int) FEDNumbering::MINPreShowerFEDID
00062                                         <<" and "<<(int)FEDNumbering::MAXPreShowerFEDID;
00063       return 0;}
00064     uint32_t eI = FEDindex - FEDNumbering::MINPreShowerFEDID;
00065     return eI; }
00066 
00067   static int fedIndex(const uint32_t index){ 
00068     int fI = index+FEDNumbering::MINECALFEDID; 
00069     return fI;}
00070     
00071   static int esFedIndex(const uint32_t index){ 
00072     int fI = index+FEDNumbering::MINPreShowerFEDID; 
00073     return fI;}
00074 
00075     
00076   uint32_t elementIndex(const double eta, const double phi) const{
00077     int FEDindex = mapping()->GetFED(eta,phi);
00078     return elementIndex(FEDindex); }
00079 
00080  private:
00081   const EcalElectronicsMapping * mapping_;
00082   const ESElectronicsMapper * es_mapping_;
00083 };
00084 
00085 
00086 template <class T> void EcalRegionCabling::updateEcalRefGetterWithElementIndex(edm::RefGetter<T> & refgetter, 
00087                                                                                const edm::Handle< edm::LazyGetter<T> >& lazygetter, 
00088                                                                                const uint32_t index)const{
00089   LogDebug("EcalRawToRecHit|Cabling")<<"updating a refgetter with element index: "<<index;
00090   refgetter.push_back(lazygetter, index);
00091 }
00092 
00093 
00094 template <class T> void EcalRegionCabling::updateEcalRefGetterWithFedIndex(edm::RefGetter<T> & refgetter, 
00095                                                                            const edm::Handle< edm::LazyGetter<T> >& lazygetter, 
00096                                                                            const int fedindex)const{
00097   LogDebug("EcalRawToRecHit|Cabling")<<"updating a refgetter with fed index: "<<fedindex;
00098   updateEcalRefGetterWithElementIndex(refgetter, lazygetter, elementIndex(fedindex));
00099 }
00100 
00101 
00102 template <class T> void EcalRegionCabling::updateEcalRefGetterWithEtaPhi(edm::RefGetter<T> & refgetter, 
00103                                                                          const edm::Handle< edm::LazyGetter<T> >& lazygetter, 
00104                                                                          const double eta,
00105                                                                          const double phi)const{
00106   int index = mapping()->GetFED(eta,phi);
00107   LogDebug("EcalRawToRecHit|Cabling")<<"updating a refgetter with eta: "<<eta<<" phi: "<<phi;
00108   updateEcalRefGetterWithFedIndex(refgetter, lazygetter, index);
00109 }
00110 
00111 #endif