CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/CondFormats/HcalObjects/interface/HcalCondObjectContainer.h

Go to the documentation of this file.
00001 #ifndef HcalCondObjectContainer_h
00002 #define HcalCondObjectContainer_h
00003 
00004 
00005 #include <iostream>
00006 #include <vector>
00007 #include "DataFormats/DetId/interface/DetId.h"
00008 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00009 #include "FWCore/Utilities/interface/Exception.h"
00010 #include <cstdlib>
00011 
00012 template<class Item>
00013 class HcalCondObjectContainer
00014 {
00015  public:
00016   // default constructor
00017   HcalCondObjectContainer();
00018 
00019   // destructor:
00020   virtual ~HcalCondObjectContainer();
00021 
00022   // get the object back
00023   const Item* getValues(DetId fId) const;
00024 
00025   // does the object exist ?
00026   const bool exists(DetId fId) const;
00027 
00028   // set the object/fill it in:
00029   bool addValues(const Item& myItem, bool h2mode_=false);
00030 
00031   // list of available channels:
00032   std::vector<DetId> getAllChannels() const;
00033 
00034   virtual std::string myname() const {return (std::string)"Hcal Undefined";}
00035 
00036   // setting types for easier work for getAllContainers()
00037   typedef std::pair< std::string, std::vector<Item> > tHcalCont;
00038   typedef std::vector< tHcalCont > tAllContWithNames;
00039 
00040   const tAllContWithNames getAllContainers() const{
00041     tAllContWithNames allContainers;
00042     allContainers.push_back(tHcalCont("HB",HBcontainer));
00043     allContainers.push_back(tHcalCont("HE",HEcontainer));
00044     allContainers.push_back(tHcalCont("HO",HOcontainer));
00045     allContainers.push_back(tHcalCont("HF",HFcontainer));
00046     allContainers.push_back(tHcalCont("HT",HTcontainer));
00047     allContainers.push_back(tHcalCont("ZDC",ZDCcontainer));
00048     allContainers.push_back(tHcalCont("CALIB",CALIBcontainer));
00049     allContainers.push_back(tHcalCont("CASTOR",CASTORcontainer));
00050     return allContainers;
00051   }
00052 
00053  private:
00054   void initContainer(int container, bool h2mode_ = false);
00055 
00056   //  bool m_h2mode;
00057 
00058   std::vector<Item> HBcontainer;
00059   std::vector<Item> HEcontainer;
00060   std::vector<Item> HOcontainer;
00061   std::vector<Item> HFcontainer;
00062   std::vector<Item> HTcontainer;
00063   std::vector<Item> ZDCcontainer;
00064   std::vector<Item> CALIBcontainer;
00065   std::vector<Item> CASTORcontainer;
00066 };
00067 
00068 
00069 template<class Item>
00070 HcalCondObjectContainer<Item>::HcalCondObjectContainer()
00071 //: m_h2mode(false)
00072 {
00073 }
00074 
00075 template<class Item>
00076 HcalCondObjectContainer<Item>::~HcalCondObjectContainer()
00077 {
00078 }
00079 
00080 template<class Item> void
00081 HcalCondObjectContainer<Item>::initContainer(int container, bool h2mode_)
00082 {
00083   //  if (!m_h2mode) m_h2mode = h2mode_;
00084 
00085   Item emptyItem;
00086 
00087   switch (container) 
00088     {
00089     case HcalGenericDetId::HcalGenBarrel: 
00090       for (int i=0; i<(2*HcalGenericDetId::HBhalf); i++) HBcontainer.push_back(emptyItem); break;
00091     case HcalGenericDetId::HcalGenEndcap: 
00092       if (!h2mode_) for (int i=0; i<(2*HcalGenericDetId::HEhalf); i++) HEcontainer.push_back(emptyItem); 
00093       else for (int i=0; i<(2*HcalGenericDetId::HEhalfh2mode); i++) HEcontainer.push_back(emptyItem); 
00094       break;
00095     case HcalGenericDetId::HcalGenOuter: 
00096       for (int i=0; i<(2*HcalGenericDetId::HOhalf); i++) HOcontainer.push_back(emptyItem); break;
00097     case HcalGenericDetId::HcalGenForward: 
00098       for (int i=0; i<(2*HcalGenericDetId::HFhalf); i++) HFcontainer.push_back(emptyItem); break;
00099     case HcalGenericDetId::HcalGenTriggerTower: 
00100       for (int i=0; i<(2*HcalGenericDetId::HThalf); i++) HTcontainer.push_back(emptyItem); break;
00101     case HcalGenericDetId::HcalGenZDC: 
00102       for (int i=0; i<(2*HcalGenericDetId::ZDChalf); i++) ZDCcontainer.push_back(emptyItem); break;
00103     case HcalGenericDetId::HcalGenCalibration: 
00104       for (int i=0; i<(2*HcalGenericDetId::CALIBhalf); i++) CALIBcontainer.push_back(emptyItem); break;
00105     case HcalGenericDetId::HcalGenCastor: 
00106       for (int i=0; i<(2*HcalGenericDetId::CASTORhalf); i++) CASTORcontainer.push_back(emptyItem); break;
00107     default: break;
00108     }
00109 }
00110 
00111 
00112 template<class Item> const Item*
00113 HcalCondObjectContainer<Item>::getValues(DetId fId) const
00114 {
00115   HcalGenericDetId myId(fId);
00116   bool h2mode_ = (HEcontainer.size()==(2*HcalGenericDetId::HEhalfh2mode));
00117 
00118   int index = myId.hashedId(h2mode_);
00119   //  std::cout << "::::: getting values at index " << index  << ", DetId " << myId << std::endl;
00120   unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
00121 
00122   const Item* cell = NULL;
00123   if (index >= 0)
00124     switch (myId.genericSubdet() ) {
00125     case HcalGenericDetId::HcalGenBarrel: 
00126       if (index1 < HBcontainer.size()) 
00127         cell = &(HBcontainer.at(index1) );  
00128       break;
00129     case HcalGenericDetId::HcalGenEndcap: 
00130       if (index1 < HEcontainer.size()) 
00131         cell = &(HEcontainer.at(index1) ); 
00132       break;
00133     case HcalGenericDetId::HcalGenOuter: 
00134       if (index1 < HOcontainer.size())
00135         cell = &(HOcontainer.at(index1) ); 
00136       break;
00137     case HcalGenericDetId::HcalGenForward:
00138       if (index1 < HFcontainer.size()) 
00139         cell = &(HFcontainer.at(index1) ); 
00140       break;
00141     case HcalGenericDetId::HcalGenTriggerTower: 
00142       if (index1 < HTcontainer.size()) 
00143         cell = &(HTcontainer.at(index1) ); 
00144       break;
00145     case HcalGenericDetId::HcalGenZDC:    
00146       if (index1 < ZDCcontainer.size()) 
00147         cell = &(ZDCcontainer.at(index1) ); 
00148       break;
00149     case HcalGenericDetId::HcalGenCastor:
00150       if (index1 < CASTORcontainer.size()) 
00151         cell = &(CASTORcontainer.at(index1) ); 
00152       break;
00153     case HcalGenericDetId::HcalGenCalibration:
00154       if (index1 < CALIBcontainer.size())
00155         cell = &(CALIBcontainer.at(index1) ); 
00156       break;
00157     default: break;
00158     }
00159   
00160   //  Item emptyItem;
00161   //  if (cell->rawId() == emptyItem.rawId() ) 
00162   if ((!cell) || (cell->rawId() != fId ) )
00163     throw cms::Exception ("Conditions not found") 
00164       << "Unavailable Conditions of type " << myname() << " for cell " << myId;
00165   return cell;
00166 }
00167 
00168 template<class Item> const bool
00169 HcalCondObjectContainer<Item>::exists(DetId fId) const
00170 {
00171   HcalGenericDetId myId(fId);
00172   bool h2mode_ = (HEcontainer.size()==(2*HcalGenericDetId::HEhalfh2mode));
00173 
00174   int index = myId.hashedId(h2mode_);
00175   if (index < 0) return false;
00176   unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
00177   const Item* cell = NULL;
00178   switch (myId.genericSubdet() ) {
00179   case HcalGenericDetId::HcalGenBarrel: 
00180     if (index1 < HBcontainer.size()) cell = &(HBcontainer.at(index1) );  
00181     break;
00182   case HcalGenericDetId::HcalGenEndcap: 
00183     if (index1 < HEcontainer.size()) cell = &(HEcontainer.at(index1) );  
00184     break;
00185   case HcalGenericDetId::HcalGenOuter: 
00186     if (index1 < HOcontainer.size()) cell = &(HOcontainer.at(index1) );  
00187     break;
00188   case HcalGenericDetId::HcalGenForward: 
00189     if (index1 < HFcontainer.size()) cell = &(HFcontainer.at(index1) );  
00190     break;
00191   case HcalGenericDetId::HcalGenTriggerTower: 
00192     if (index1 < HTcontainer.size()) cell = &(HTcontainer.at(index1) );  
00193     break;
00194   case HcalGenericDetId::HcalGenZDC: 
00195     if (index1 < ZDCcontainer.size()) cell = &(ZDCcontainer.at(index1) );  
00196     break;
00197   case HcalGenericDetId::HcalGenCastor: 
00198     if (index1 < CASTORcontainer.size()) cell = &(CASTORcontainer.at(index1) );  
00199     break;
00200   case HcalGenericDetId::HcalGenCalibration: 
00201     if (index1 < CALIBcontainer.size()) cell = &(CALIBcontainer.at(index1) );  
00202     break;
00203   default: return false; break;
00204   }
00205   
00206   //  Item emptyItem;
00207   if (cell)
00208     //    if (cell->rawId() != emptyItem.rawId() ) 
00209     if (cell->rawId() == fId ) 
00210       return true;
00211 
00212   return false;
00213 }
00214 
00215 template<class Item> bool
00216 HcalCondObjectContainer<Item>::addValues(const Item& myItem, bool h2mode_)
00217 {
00218   unsigned long myRawId = myItem.rawId();
00219   HcalGenericDetId myId(myRawId);
00220   int index = myId.hashedId(h2mode_);
00221   bool success = false;
00222   if (index < 0) success = false;
00223   unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
00224 
00225   switch (myId.genericSubdet() ) {
00226   case HcalGenericDetId::HcalGenBarrel:
00227     if (!HBcontainer.size() ) initContainer(myId.genericSubdet() );
00228     if (index1 < HBcontainer.size())
00229       {
00230         HBcontainer.at(index1)  = myItem;
00231         success = true;
00232       }
00233     break;
00234   case HcalGenericDetId::HcalGenEndcap: 
00235     if (!HEcontainer.size() ) initContainer(myId.genericSubdet(), h2mode_ );
00236     if (index1 < HEcontainer.size())
00237       {
00238         HEcontainer.at(index1)  = myItem; 
00239         success = true;
00240       }
00241     break;
00242   case HcalGenericDetId::HcalGenOuter:  
00243     if (!HOcontainer.size() ) initContainer(myId.genericSubdet() );
00244     if (index1 < HOcontainer.size())
00245       {
00246         HOcontainer.at(index1)  = myItem; 
00247         success = true;
00248       }
00249     break;
00250   case HcalGenericDetId::HcalGenForward: 
00251     if (!HFcontainer.size() ) initContainer(myId.genericSubdet() );
00252     if (index1 < HFcontainer.size())
00253       {
00254         HFcontainer.at(index1)  = myItem;
00255         success = true;
00256       }
00257     break;
00258   case HcalGenericDetId::HcalGenTriggerTower: 
00259     if (!HTcontainer.size() ) initContainer(myId.genericSubdet() );
00260     if (index1 < HTcontainer.size())
00261       {
00262         HTcontainer.at(index1)  = myItem;
00263         success = true;
00264       }
00265     break;
00266   case HcalGenericDetId::HcalGenZDC: 
00267     if (!ZDCcontainer.size() ) initContainer(myId.genericSubdet() );
00268     if (index1 < ZDCcontainer.size())
00269       {
00270         ZDCcontainer.at(index1)  = myItem; 
00271         success = true;
00272       }
00273     break;
00274   case HcalGenericDetId::HcalGenCastor: 
00275     if (!CASTORcontainer.size() ) initContainer(myId.genericSubdet() );
00276     if (index1 < CASTORcontainer.size())
00277       {
00278         CASTORcontainer.at(index1)  = myItem; 
00279         success = true;
00280       }
00281     break;
00282   case HcalGenericDetId::HcalGenCalibration: 
00283     if (!CALIBcontainer.size() ) initContainer(myId.genericSubdet() );
00284     if (index1 < CALIBcontainer.size())
00285       {
00286         CALIBcontainer.at(index1)  = myItem;  
00287         success = true;
00288       }
00289     break;
00290   default: break;
00291   }
00292 
00293   if (!success) 
00294     throw cms::Exception ("Filling of conditions failed") 
00295       << " no valid filling possible for Conditions of type " << myname() << " for DetId " << myId;
00296   return success;
00297 }
00298 
00299 template<class Item> std::vector<DetId>
00300 HcalCondObjectContainer<Item>::getAllChannels() const
00301 {
00302   std::vector<DetId> channels;
00303   Item emptyItem;
00304   for (unsigned int i=0; i<HBcontainer.size(); i++)
00305     {
00306       if (emptyItem.rawId() != HBcontainer.at(i).rawId() )
00307         channels.push_back( DetId(HBcontainer.at(i).rawId()) );
00308     }
00309   for (unsigned int i=0; i<HEcontainer.size(); i++)
00310     {
00311       if (emptyItem.rawId() != HEcontainer.at(i).rawId() )
00312         channels.push_back( DetId(HEcontainer.at(i).rawId()) );
00313     }
00314   for (unsigned int i=0; i<HOcontainer.size(); i++)
00315     {
00316       if (emptyItem.rawId() != HOcontainer.at(i).rawId() )
00317         channels.push_back( DetId(HOcontainer.at(i).rawId()) );
00318     }
00319   for (unsigned int i=0; i<HFcontainer.size(); i++)
00320     {
00321       if (emptyItem.rawId() != HFcontainer.at(i).rawId() )
00322         channels.push_back( DetId(HFcontainer.at(i).rawId()) );
00323     }
00324   for (unsigned int i=0; i<HTcontainer.size(); i++)
00325     {
00326       if (emptyItem.rawId() != HTcontainer.at(i).rawId() )
00327         channels.push_back( DetId(HTcontainer.at(i).rawId()) );
00328     }
00329   for (unsigned int i=0; i<ZDCcontainer.size(); i++)
00330     {
00331       if (emptyItem.rawId() != ZDCcontainer.at(i).rawId() )
00332         channels.push_back( DetId(ZDCcontainer.at(i).rawId()) );
00333     }
00334   for (unsigned int i=0; i<CALIBcontainer.size(); i++)
00335     {
00336       if (emptyItem.rawId() != CALIBcontainer.at(i).rawId() )
00337         channels.push_back( DetId(CALIBcontainer.at(i).rawId()) );
00338     }
00339   for (unsigned int i=0; i<CASTORcontainer.size(); i++)
00340     {
00341       if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
00342         channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
00343     }
00344 
00345   return channels;
00346 }
00347 
00348 
00349 #endif