CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #include "CondFormats/HcalObjects/interface/HcalCovarianceMatrices.h"
00002 
00003 
00004 HcalCovarianceMatrices::HcalCovarianceMatrices()
00005 {
00006 }
00007 
00008 HcalCovarianceMatrices::~HcalCovarianceMatrices()
00009 {
00010 }
00011 
00012 void
00013 HcalCovarianceMatrices::initContainer(int container, bool h2mode_)
00014 {
00015   HcalCovarianceMatrix emptyHcalCovarianceMatrix;
00016 
00017   switch (container) 
00018     {
00019     case HcalGenericDetId::HcalGenBarrel: 
00020       for (int i=0; i<(2*HcalGenericDetId::HBhalf); i++) HBcontainer.push_back(emptyHcalCovarianceMatrix); break;
00021     case HcalGenericDetId::HcalGenEndcap: 
00022       if (!h2mode_) for (int i=0; i<(2*HcalGenericDetId::HEhalf); i++) HEcontainer.push_back(emptyHcalCovarianceMatrix); 
00023       else for (int i=0; i<(2*HcalGenericDetId::HEhalfh2mode); i++) HEcontainer.push_back(emptyHcalCovarianceMatrix); 
00024       break;
00025     case HcalGenericDetId::HcalGenOuter: 
00026       for (int i=0; i<(2*HcalGenericDetId::HOhalf); i++) HOcontainer.push_back(emptyHcalCovarianceMatrix); break;
00027     case HcalGenericDetId::HcalGenForward: 
00028       for (int i=0; i<(2*HcalGenericDetId::HFhalf); i++) HFcontainer.push_back(emptyHcalCovarianceMatrix); break;
00029     default: break;
00030     }
00031 }
00032 
00033 
00034 const HcalCovarianceMatrix*
00035 HcalCovarianceMatrices::getValues(DetId fId) const
00036 {
00037   HcalGenericDetId myId(fId);
00038   bool h2mode_ = (HEcontainer.size()==(2*HcalGenericDetId::HEhalfh2mode));
00039 
00040   int index = myId.hashedId(h2mode_);
00041   //  std::cout << "::::: getting values at index " << index  << ", DetId " << myId << std::endl;
00042   unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
00043 
00044   const HcalCovarianceMatrix* cell = NULL;
00045   if (index >= 0)
00046     switch (myId.genericSubdet() ) {
00047     case HcalGenericDetId::HcalGenBarrel: 
00048       if (index1 < HBcontainer.size()) 
00049         cell = &(HBcontainer.at(index1) );  
00050       break;
00051     case HcalGenericDetId::HcalGenEndcap: 
00052       if (index1 < HEcontainer.size()) 
00053         cell = &(HEcontainer.at(index1) ); 
00054       break;
00055     case HcalGenericDetId::HcalGenOuter: 
00056       if (index1 < HOcontainer.size())
00057         cell = &(HOcontainer.at(index1) ); 
00058       break;
00059     case HcalGenericDetId::HcalGenForward:
00060       if (index1 < HFcontainer.size()) 
00061         cell = &(HFcontainer.at(index1) ); 
00062       break;
00063     default: break;
00064     }
00065   
00066   //  HcalCovarianceMatrix emptyHcalCovarianceMatrix;
00067   //  if (cell->rawId() == emptyHcalCovarianceMatrix.rawId() ) 
00068   if ((!cell) || (cell->rawId() != fId ) )
00069     throw cms::Exception ("Conditions not found") 
00070       << "Unavailable Conditions of type " << myname() << " for cell " << myId;
00071   return cell;
00072 }
00073 
00074 const bool
00075 HcalCovarianceMatrices::exists(DetId fId) const
00076 {
00077   HcalGenericDetId myId(fId);
00078   bool h2mode_ = (HEcontainer.size()==(2*HcalGenericDetId::HEhalfh2mode));
00079 
00080   int index = myId.hashedId(h2mode_);
00081   if (index < 0) return false;
00082   unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
00083   const HcalCovarianceMatrix* cell = NULL;
00084   switch (myId.genericSubdet() ) {
00085   case HcalGenericDetId::HcalGenBarrel: 
00086     if (index1 < HBcontainer.size()) cell = &(HBcontainer.at(index1) );  
00087     break;
00088   case HcalGenericDetId::HcalGenEndcap: 
00089     if (index1 < HEcontainer.size()) cell = &(HEcontainer.at(index1) );  
00090     break;
00091   case HcalGenericDetId::HcalGenOuter: 
00092     if (index1 < HOcontainer.size()) cell = &(HOcontainer.at(index1) );  
00093     break;
00094   case HcalGenericDetId::HcalGenForward: 
00095     if (index1 < HFcontainer.size()) cell = &(HFcontainer.at(index1) );  
00096     break;
00097   default: return false; break;
00098   }
00099   
00100   //  HcalCovarianceMatrix emptyHcalCovarianceMatrix;
00101   if (cell)
00102     //    if (cell->rawId() != emptyHcalCovarianceMatrix.rawId() ) 
00103     if (cell->rawId() == fId ) 
00104       return true;
00105 
00106   return false;
00107 }
00108 
00109 bool
00110 HcalCovarianceMatrices::addValues(const HcalCovarianceMatrix& myHcalCovarianceMatrix, bool h2mode_)
00111 {
00112   unsigned long myRawId = myHcalCovarianceMatrix.rawId();
00113   HcalGenericDetId myId(myRawId);
00114   int index = myId.hashedId(h2mode_);
00115   bool success = false;
00116   if (index < 0) success = false;
00117   unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
00118 
00119   switch (myId.genericSubdet() ) {
00120   case HcalGenericDetId::HcalGenBarrel:
00121     if (!HBcontainer.size() ) initContainer(myId.genericSubdet() );
00122     if (index1 < HBcontainer.size())
00123       {
00124         HBcontainer.at(index1)  = myHcalCovarianceMatrix;
00125         success = true;
00126       }
00127     break;
00128   case HcalGenericDetId::HcalGenEndcap: 
00129     if (!HEcontainer.size() ) initContainer(myId.genericSubdet(), h2mode_ );
00130     if (index1 < HEcontainer.size())
00131       {
00132         HEcontainer.at(index1)  = myHcalCovarianceMatrix; 
00133         success = true;
00134       }
00135     break;
00136   case HcalGenericDetId::HcalGenOuter:  
00137     if (!HOcontainer.size() ) initContainer(myId.genericSubdet() );
00138     if (index1 < HOcontainer.size())
00139       {
00140         HOcontainer.at(index1)  = myHcalCovarianceMatrix; 
00141         success = true;
00142       }
00143     break;
00144   case HcalGenericDetId::HcalGenForward: 
00145     if (!HFcontainer.size() ) initContainer(myId.genericSubdet() );
00146     if (index1 < HFcontainer.size())
00147       {
00148         HFcontainer.at(index1)  = myHcalCovarianceMatrix;
00149         success = true;
00150       }
00151     break;
00152   default: break;
00153   }
00154 
00155   if (!success) 
00156     throw cms::Exception ("Filling of conditions failed") 
00157       << " no valid filling possible for Conditions of type " << myname() << " for DetId " << myId;
00158   return success;
00159 }
00160 
00161 std::vector<DetId>
00162 HcalCovarianceMatrices::getAllChannels() const
00163 {
00164   std::vector<DetId> channels;
00165   HcalCovarianceMatrix emptyHcalCovarianceMatrix;
00166   for (unsigned int i=0; i<HBcontainer.size(); i++)
00167     {
00168       if (emptyHcalCovarianceMatrix.rawId() != HBcontainer.at(i).rawId() )
00169         channels.push_back( DetId(HBcontainer.at(i).rawId()) );
00170     }
00171   for (unsigned int i=0; i<HEcontainer.size(); i++)
00172     {
00173       if (emptyHcalCovarianceMatrix.rawId() != HEcontainer.at(i).rawId() )
00174         channels.push_back( DetId(HEcontainer.at(i).rawId()) );
00175     }
00176   for (unsigned int i=0; i<HOcontainer.size(); i++)
00177     {
00178       if (emptyHcalCovarianceMatrix.rawId() != HOcontainer.at(i).rawId() )
00179         channels.push_back( DetId(HOcontainer.at(i).rawId()) );
00180     }
00181   for (unsigned int i=0; i<HFcontainer.size(); i++)
00182     {
00183       if (emptyHcalCovarianceMatrix.rawId() != HFcontainer.at(i).rawId() )
00184         channels.push_back( DetId(HFcontainer.at(i).rawId()) );
00185     }
00186   return channels;
00187 }