CMS 3D CMS Logo

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 
00011 template<class Item>
00012 class HcalCondObjectContainer
00013 {
00014  public:
00015   // default constructor
00016   HcalCondObjectContainer();
00017 
00018   // destructor:
00019   ~HcalCondObjectContainer();
00020 
00021   // get the object back
00022   const Item* getValues(DetId fId) const;
00023 
00024   // does the object exist ?
00025   const bool exists(DetId fId) const;
00026 
00027   // set the object/fill it in:
00028   bool addValues(const Item& myItem);
00029 
00030   // list of available channels:
00031   std::vector<DetId> getAllChannels() const;
00032 
00033 
00034  private:
00035   void initContainer(int container);
00036 
00037   std::vector<Item> HBcontainer;
00038   std::vector<Item> HEcontainer;
00039   std::vector<Item> HOcontainer;
00040   std::vector<Item> HFcontainer;
00041   std::vector<Item> HTcontainer;
00042   std::vector<Item> ZDCcontainer;
00043   std::vector<Item> CALIBcontainer;
00044   std::vector<Item> CASTORcontainer;
00045 };
00046 
00047 
00048 template<class Item>
00049 HcalCondObjectContainer<Item>::HcalCondObjectContainer()
00050 {
00051 }
00052 
00053 template<class Item>
00054 HcalCondObjectContainer<Item>::~HcalCondObjectContainer()
00055 {
00056 }
00057 
00058 template<class Item> void
00059 HcalCondObjectContainer<Item>::initContainer(int container)
00060 {
00061   Item emptyItem;
00062 
00063   switch (container) 
00064     {
00065     case HcalGenericDetId::HcalGenBarrel: for (int i=0; i<2592; i++) HBcontainer.push_back(emptyItem); break;
00066     case HcalGenericDetId::HcalGenEndcap: for (int i=0; i<2592; i++) HEcontainer.push_back(emptyItem); break;
00067     case HcalGenericDetId::HcalGenOuter: for (int i=0; i<2160; i++) HOcontainer.push_back(emptyItem); break;
00068     case HcalGenericDetId::HcalGenForward: for (int i=0; i<1728; i++) HFcontainer.push_back(emptyItem); break;
00069     case HcalGenericDetId::HcalGenTriggerTower: for (int i=0; i<4176; i++) HTcontainer.push_back(emptyItem); break;
00070     case HcalGenericDetId::HcalGenZDC: for (int i=0; i<22; i++) ZDCcontainer.push_back(emptyItem); break;
00071     case HcalGenericDetId::HcalGenCalibration: for (int i=0; i<1386; i++) CALIBcontainer.push_back(emptyItem); break;
00072     case HcalGenericDetId::HcalGenCastor: for (int i=0; i<1; i++) CASTORcontainer.push_back(emptyItem); break;
00073     default: break;
00074     }
00075 }
00076 
00077 
00078 template<class Item> const Item*
00079 HcalCondObjectContainer<Item>::getValues(DetId fId) const
00080 {
00081   HcalGenericDetId myId(fId);
00082   int index = myId.hashedId();
00083   //  std::cout << "::::: getting values at index " << index  << ", DetId " << myId << std::endl;
00084   unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
00085 
00086   const Item* cell = NULL;
00087   if (index >= 0)
00088     switch (myId.genericSubdet() ) {
00089     case HcalGenericDetId::HcalGenBarrel: 
00090       if (index1 < HBcontainer.size()) 
00091         cell = &(HBcontainer.at(index1) );  
00092       break;
00093     case HcalGenericDetId::HcalGenEndcap: 
00094       if (index1 < HEcontainer.size()) 
00095         cell = &(HEcontainer.at(index1) ); 
00096       break;
00097     case HcalGenericDetId::HcalGenOuter: 
00098       if (index1 < HOcontainer.size())
00099         cell = &(HOcontainer.at(index1) ); 
00100       break;
00101     case HcalGenericDetId::HcalGenForward:
00102       if (index1 < HFcontainer.size()) 
00103         cell = &(HFcontainer.at(index1) ); 
00104       break;
00105     case HcalGenericDetId::HcalGenTriggerTower: 
00106       if (index1 < HTcontainer.size()) 
00107         cell = &(HTcontainer.at(index1) ); 
00108       break;
00109     case HcalGenericDetId::HcalGenZDC:    
00110       if (index1 < ZDCcontainer.size()) 
00111         cell = &(ZDCcontainer.at(index1) ); 
00112       break;
00113     case HcalGenericDetId::HcalGenCastor:
00114       if (index1 < CASTORcontainer.size()) 
00115         cell = &(CASTORcontainer.at(index1) ); 
00116       break;
00117     case HcalGenericDetId::HcalGenCalibration:
00118       if (index1 < CALIBcontainer.size())
00119         cell = &(CALIBcontainer.at(index1) ); 
00120       break;
00121     default: break;
00122     }
00123   
00124   //  Item emptyItem;
00125   //  if (cell->rawId() == emptyItem.rawId() ) 
00126   if ((!cell) || (cell->rawId() != fId ) )
00127     throw cms::Exception ("Conditions not found") 
00128       << "Unavailable Conditions for cell " << myId;
00129   return cell;
00130 }
00131 
00132 template<class Item> const bool
00133 HcalCondObjectContainer<Item>::exists(DetId fId) const
00134 {
00135   HcalGenericDetId myId(fId);
00136   int index = myId.hashedId();
00137   if (index < 0) return false;
00138   unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
00139   const Item* cell = NULL;
00140   switch (myId.genericSubdet() ) {
00141   case HcalGenericDetId::HcalGenBarrel: 
00142     if (index1 < HBcontainer.size()) cell = &(HBcontainer.at(index1) );  
00143     break;
00144   case HcalGenericDetId::HcalGenEndcap: 
00145     if (index1 < HEcontainer.size()) cell = &(HEcontainer.at(index1) );  
00146     break;
00147   case HcalGenericDetId::HcalGenOuter: 
00148     if (index1 < HOcontainer.size()) cell = &(HOcontainer.at(index1) );  
00149     break;
00150   case HcalGenericDetId::HcalGenForward: 
00151     if (index1 < HFcontainer.size()) cell = &(HFcontainer.at(index1) );  
00152     break;
00153   case HcalGenericDetId::HcalGenTriggerTower: 
00154     if (index1 < HTcontainer.size()) cell = &(HTcontainer.at(index1) );  
00155     break;
00156   case HcalGenericDetId::HcalGenZDC: 
00157     if (index1 < ZDCcontainer.size()) cell = &(ZDCcontainer.at(index1) );  
00158     break;
00159   case HcalGenericDetId::HcalGenCastor: 
00160     if (index1 < CASTORcontainer.size()) cell = &(CASTORcontainer.at(index1) );  
00161     break;
00162   case HcalGenericDetId::HcalGenCalibration: 
00163     if (index1 < CALIBcontainer.size()) cell = &(CALIBcontainer.at(index1) );  
00164     break;
00165   default: return false; break;
00166   }
00167   
00168   //  Item emptyItem;
00169   if (cell)
00170     //    if (cell->rawId() != emptyItem.rawId() ) 
00171     if (cell->rawId() == fId ) 
00172       return true;
00173 
00174   return false;
00175 }
00176 
00177 template<class Item> bool
00178 HcalCondObjectContainer<Item>::addValues(const Item& myItem)
00179 {
00180   unsigned long myRawId = myItem.rawId();
00181   HcalGenericDetId myId(myRawId);
00182   int index = myId.hashedId();
00183   if (index < 0) return false;
00184   bool success = false;
00185 
00186   switch (myId.genericSubdet() ) {
00187   case HcalGenericDetId::HcalGenBarrel:
00188     if (!HBcontainer.size() ) initContainer(myId.genericSubdet() );
00189     HBcontainer.at(index)  = myItem;
00190     success = true;
00191     break;
00192   case HcalGenericDetId::HcalGenEndcap: 
00193     if (!HEcontainer.size() ) initContainer(myId.genericSubdet() );
00194     HEcontainer.at(index)  = myItem; 
00195     success = true;
00196     break;
00197   case HcalGenericDetId::HcalGenOuter:  
00198     if (!HOcontainer.size() ) initContainer(myId.genericSubdet() );
00199     HOcontainer.at(index)  = myItem; 
00200     success = true;
00201     break;
00202   case HcalGenericDetId::HcalGenForward: 
00203     if (!HFcontainer.size() ) initContainer(myId.genericSubdet() );
00204     HFcontainer.at(index)  = myItem;
00205     success = true;
00206     break;
00207   case HcalGenericDetId::HcalGenTriggerTower: 
00208     if (!HTcontainer.size() ) initContainer(myId.genericSubdet() );
00209     HTcontainer.at(index)  = myItem;
00210     success = true;
00211     break;
00212   case HcalGenericDetId::HcalGenZDC: 
00213     if (!ZDCcontainer.size() ) initContainer(myId.genericSubdet() );
00214     ZDCcontainer.at(index)  = myItem; 
00215     success = true;
00216     break;
00217   case HcalGenericDetId::HcalGenCastor: 
00218     if (!CASTORcontainer.size() ) initContainer(myId.genericSubdet() );
00219     CASTORcontainer.at(index)  = myItem; 
00220     success = true;
00221     break;
00222   case HcalGenericDetId::HcalGenCalibration: 
00223     if (!CALIBcontainer.size() ) initContainer(myId.genericSubdet() );
00224     CALIBcontainer.at(index)  = myItem;  
00225     success = true;
00226     break;
00227   default: break;
00228   }
00229 
00230   return success;
00231 }
00232 
00233 template<class Item> std::vector<DetId>
00234 HcalCondObjectContainer<Item>::getAllChannels() const
00235 {
00236   std::vector<DetId> channels;
00237   Item emptyItem;
00238   for (unsigned int i=0; i<HBcontainer.size(); i++)
00239     {
00240       if (emptyItem.rawId() != HBcontainer.at(i).rawId() )
00241         channels.push_back( DetId(HBcontainer.at(i).rawId()) );
00242     }
00243   for (unsigned int i=0; i<HEcontainer.size(); i++)
00244     {
00245       if (emptyItem.rawId() != HEcontainer.at(i).rawId() )
00246         channels.push_back( DetId(HEcontainer.at(i).rawId()) );
00247     }
00248   for (unsigned int i=0; i<HOcontainer.size(); i++)
00249     {
00250       if (emptyItem.rawId() != HOcontainer.at(i).rawId() )
00251         channels.push_back( DetId(HOcontainer.at(i).rawId()) );
00252     }
00253   for (unsigned int i=0; i<HFcontainer.size(); i++)
00254     {
00255       if (emptyItem.rawId() != HFcontainer.at(i).rawId() )
00256         channels.push_back( DetId(HFcontainer.at(i).rawId()) );
00257     }
00258   for (unsigned int i=0; i<HTcontainer.size(); i++)
00259     {
00260       if (emptyItem.rawId() != HTcontainer.at(i).rawId() )
00261         channels.push_back( DetId(HTcontainer.at(i).rawId()) );
00262     }
00263   for (unsigned int i=0; i<ZDCcontainer.size(); i++)
00264     {
00265       if (emptyItem.rawId() != ZDCcontainer.at(i).rawId() )
00266         channels.push_back( DetId(ZDCcontainer.at(i).rawId()) );
00267     }
00268   for (unsigned int i=0; i<CALIBcontainer.size(); i++)
00269     {
00270       if (emptyItem.rawId() != CALIBcontainer.at(i).rawId() )
00271         channels.push_back( DetId(CALIBcontainer.at(i).rawId()) );
00272     }
00273   for (unsigned int i=0; i<CASTORcontainer.size(); i++)
00274     {
00275       if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
00276         channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
00277     }
00278 
00279   return channels;
00280 }
00281 
00282 
00283 #endif

Generated on Tue Jun 9 17:26:34 2009 for CMSSW by  doxygen 1.5.4