CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/CondFormats/HcalObjects/src/HcalCholeskyMatrices.cc

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