CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/CondFormats/HcalObjects/src/HcalCovarianceMatrices.cc

Go to the documentation of this file.
00001 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00002 #include "CondFormats/HcalObjects/interface/HcalCovarianceMatrices.h"
00003 
00004 
00005 HcalCovarianceMatrices::HcalCovarianceMatrices(const HcalTopology* topo) : HcalCondObjectContainerBase(topo) 
00006 {
00007 }
00008 
00009 HcalCovarianceMatrices::~HcalCovarianceMatrices()
00010 {
00011 }
00012 
00013 void
00014 HcalCovarianceMatrices::initContainer(DetId fId)
00015 {
00016   HcalCovarianceMatrix emptyItem;
00017 
00018 
00019   if (fId.det()==DetId::Hcal) {
00020     switch (HcalSubdetector(fId.subdetId())) {
00021     case(HcalBarrel) : for (unsigned int i=0; i<sizeFor(fId); i++) HBcontainer.push_back(emptyItem); break;
00022     case(HcalEndcap) : for (unsigned int i=0; i<sizeFor(fId); i++) HEcontainer.push_back(emptyItem); break;
00023     case(HcalOuter) : for (unsigned int i=0; i<sizeFor(fId); i++) HOcontainer.push_back(emptyItem); break;
00024     case(HcalForward) : for (unsigned int i=0; i<sizeFor(fId); i++) HFcontainer.push_back(emptyItem); break;
00025     default: break;
00026     }
00027 }
00028 
00029 }
00030 
00031 
00032 const HcalCovarianceMatrix*
00033 HcalCovarianceMatrices::getValues(DetId fId, bool throwOnFail) const
00034 {
00035   unsigned int index=indexFor(fId);
00036 
00037   const HcalCovarianceMatrix* cell = NULL;
00038 
00039   if (index<0xFFFFFFFFu) {
00040     if (fId.det()==DetId::Hcal) {
00041       switch (HcalSubdetector(fId.subdetId())) {
00042       case(HcalBarrel) : if (index < HBcontainer.size()) cell = &(HBcontainer.at(index) );  
00043       case(HcalEndcap) : if (index < HEcontainer.size()) cell = &(HEcontainer.at(index) );  
00044       case(HcalForward) : if (index < HFcontainer.size()) cell = &(HFcontainer.at(index) );  
00045       case(HcalOuter) : if (index < HOcontainer.size()) cell = &(HOcontainer.at(index) );  
00046     default: break;
00047     }
00048     }
00049   }
00050   
00051   //  HcalCovarianceMatrix emptyHcalCovarianceMatrix;
00052   //  if (cell->rawId() == emptyHcalCovarianceMatrix.rawId() ) 
00053   if ((!cell) || (cell->rawId() != fId ) ) {
00054     if (throwOnFail) {
00055     throw cms::Exception ("Conditions not found") 
00056         << "Unavailable Conditions of type " << myname() << " for cell " << fId.rawId();
00057     } else {
00058       cell=0;
00059     }
00060   }
00061   return cell;
00062 }
00063 
00064 const bool
00065 HcalCovarianceMatrices::exists(DetId fId) const
00066 {
00067   const HcalCovarianceMatrix* cell = getValues(fId,false);
00068   
00069   //  HcalCovarianceMatrix emptyHcalCovarianceMatrix;
00070   if (cell)
00071     //    if (cell->rawId() != emptyHcalCovarianceMatrix.rawId() ) 
00072     if (cell->rawId() == fId ) 
00073       return true;
00074 
00075   return false;
00076 }
00077 
00078 bool
00079 HcalCovarianceMatrices::addValues(const HcalCovarianceMatrix& myHcalCovarianceMatrix)
00080 {
00081   unsigned int index=0;
00082   bool success = false;
00083   HcalCovarianceMatrix* cell=0;
00084   DetId fId(myHcalCovarianceMatrix.rawId());
00085 
00086   if (index<0xFFFFFFFu) {
00087     if (fId.det()==DetId::Hcal) {
00088       switch (HcalSubdetector(fId.subdetId())) {
00089       case(HcalBarrel) : if (!HBcontainer.size() ) initContainer(fId); 
00090         if (index < HBcontainer.size()) cell = &(HBcontainer.at(index) );  break;
00091       case(HcalEndcap) : if (!HEcontainer.size() ) initContainer(fId); 
00092         if (index < HEcontainer.size()) cell = &(HEcontainer.at(index) );  break;
00093       case(HcalForward) : if (!HFcontainer.size() ) initContainer(fId); 
00094         if (index < HFcontainer.size()) cell = &(HFcontainer.at(index) );  break; 
00095       case(HcalOuter) : if (!HOcontainer.size() ) initContainer(fId); 
00096         if (index < HOcontainer.size()) cell = &(HOcontainer.at(index) );  break;  
00097       default: break;
00098       }
00099       }
00100       }
00101   if (cell) {
00102     *cell=myHcalCovarianceMatrix;
00103         success = true;
00104       }
00105 
00106 
00107   if (!success) 
00108     throw cms::Exception ("Filling of conditions failed") 
00109       << " no valid filling possible for Conditions of type " << myname() << " for DetId " << fId.rawId();
00110   return success;
00111 }
00112 
00113 std::vector<DetId>
00114 HcalCovarianceMatrices::getAllChannels() const
00115 {
00116   std::vector<DetId> channels;
00117   HcalCovarianceMatrix emptyHcalCovarianceMatrix;
00118   for (unsigned int i=0; i<HBcontainer.size(); i++)
00119     {
00120       if (emptyHcalCovarianceMatrix.rawId() != HBcontainer.at(i).rawId() )
00121         channels.push_back( DetId(HBcontainer.at(i).rawId()) );
00122     }
00123   for (unsigned int i=0; i<HEcontainer.size(); i++)
00124     {
00125       if (emptyHcalCovarianceMatrix.rawId() != HEcontainer.at(i).rawId() )
00126         channels.push_back( DetId(HEcontainer.at(i).rawId()) );
00127     }
00128   for (unsigned int i=0; i<HOcontainer.size(); i++)
00129     {
00130       if (emptyHcalCovarianceMatrix.rawId() != HOcontainer.at(i).rawId() )
00131         channels.push_back( DetId(HOcontainer.at(i).rawId()) );
00132     }
00133   for (unsigned int i=0; i<HFcontainer.size(); i++)
00134     {
00135       if (emptyHcalCovarianceMatrix.rawId() != HFcontainer.at(i).rawId() )
00136         channels.push_back( DetId(HFcontainer.at(i).rawId()) );
00137     }
00138   return channels;
00139 }