CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/CondFormats/CastorObjects/interface/CastorCondObjectContainer.h

Go to the documentation of this file.
00001 #ifndef CastorCondObjectContainer_h
00002 #define CastorCondObjectContainer_h
00003 //
00004 //Adapted for CASTOR by L. Mundim
00005 //
00006 #include <iostream>
00007 #include <vector>
00008 #include "DataFormats/DetId/interface/DetId.h"
00009 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00010 #include "FWCore/Utilities/interface/Exception.h"
00011 #include <cstdlib>
00012 
00013 template<class Item>
00014 class CastorCondObjectContainer
00015 {
00016  public:
00017   // default constructor
00018   CastorCondObjectContainer();
00019 
00020   // destructor:
00021   ~CastorCondObjectContainer();
00022 
00023   // get the object back
00024   const Item* getValues(DetId fId) const;
00025 
00026   // does the object exist ?
00027   const bool exists(DetId fId) const;
00028 
00029   // set the object/fill it in:
00030   bool addValues(const Item& myItem);
00031   //bool addValues(const Item& myItem, bool h2mode_=false);
00032 
00033   // list of available channels:
00034   std::vector<DetId> getAllChannels() const;
00035 
00036   std::string myname() const {return (std::string)"Castor Undefined";}
00037 
00038  private:
00039   //void initContainer(int container, bool h2mode_ = false);
00040   void initContainer(int container);
00041 
00042   std::vector<Item> CASTORcontainer;
00043 };
00044 
00045 
00046 template<class Item>
00047 //CastorCondObjectContainer<Item>::CastorCondObjectContainer(): m_h2mode(false)
00048 CastorCondObjectContainer<Item>::CastorCondObjectContainer()
00049 {
00050 }
00051 
00052 template<class Item>
00053 CastorCondObjectContainer<Item>::~CastorCondObjectContainer()
00054 {
00055 }
00056 
00057 template<class Item> void
00058 //CastorCondObjectContainer<Item>::initContainer(int container, bool h2mode_)
00059 CastorCondObjectContainer<Item>::initContainer(int container)
00060 {
00061   //m_h2mode = h2mode_;
00062 
00063   Item emptyItem;
00064 
00065   switch (container) 
00066     {
00067     case HcalGenericDetId::HcalGenCastor:
00068       for (int i=0; i<(2*HcalGenericDetId::CASTORhalf); i++) CASTORcontainer.push_back(emptyItem); break;
00069     default: break;
00070     }
00071 }
00072 
00073 
00074 template<class Item> const Item*
00075 CastorCondObjectContainer<Item>::getValues(DetId fId) const
00076 {
00077   HcalGenericDetId myId(fId);
00078   //int index = myId.hashedId(m_h2mode);
00079   int index = myId.hashedId();
00080   //  std::cout << "::::: getting values at index " << index  << ", DetId " << myId << std::endl;
00081   unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
00082 
00083   const Item* cell = NULL;
00084   if (index >= 0)
00085     switch (myId.genericSubdet() ) {
00086     case HcalGenericDetId::HcalGenCastor:
00087       if (index1 < CASTORcontainer.size()) 
00088         cell = &(CASTORcontainer.at(index1) ); 
00089       break;
00090     default: break;
00091     }
00092   
00093   //  Item emptyItem;
00094   //  if (cell->rawId() == emptyItem.rawId() ) 
00095   if ((!cell) || (cell->rawId() != fId ) )
00096     throw cms::Exception ("Conditions not found") 
00097       << "Unavailable Conditions of type " << myname() << " for cell " << myId;
00098   return cell;
00099 }
00100 
00101 template<class Item> const bool
00102 CastorCondObjectContainer<Item>::exists(DetId fId) const
00103 {
00104   HcalGenericDetId myId(fId);
00105   //int index = myId.hashedId(m_h2mode);
00106   int index = myId.hashedId();
00107   if (index < 0) return false;
00108   unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
00109   const Item* cell = NULL;
00110   switch (myId.genericSubdet() ) {
00111   case HcalGenericDetId::HcalGenCastor: 
00112     if (index1 < CASTORcontainer.size()) cell = &(CASTORcontainer.at(index1) );  
00113     break;
00114   default: return false; break;
00115   }
00116   
00117   //  Item emptyItem;
00118   if (cell)
00119     //    if (cell->rawId() != emptyItem.rawId() ) 
00120     if (cell->rawId() == fId ) 
00121       return true;
00122 
00123   return false;
00124 }
00125 
00126 template<class Item> bool
00127 //CastorCondObjectContainer<Item>::addValues(const Item& myItem, bool h2mode_)
00128 CastorCondObjectContainer<Item>::addValues(const Item& myItem)
00129 {
00130   unsigned long myRawId = myItem.rawId();
00131   HcalGenericDetId myId(myRawId);
00132   //int index = myId.hashedId(h2mode_);
00133   int index = myId.hashedId();
00134   bool success = false;
00135   if (index < 0) success = false;
00136   unsigned int index1 = abs(index); // b/c I'm fed up with compiler warnings about comparison betw. signed and unsigned int
00137 
00138 
00139   switch (myId.genericSubdet() ) {
00140   case HcalGenericDetId::HcalGenCastor: 
00141     if (!CASTORcontainer.size() ) initContainer(myId.genericSubdet() );
00142     if (index1 < CASTORcontainer.size())
00143       {
00144         CASTORcontainer.at(index1)  = myItem; 
00145         success = true;
00146       }
00147     break;
00148   default: break;
00149   }
00150 
00151   if (!success) 
00152     throw cms::Exception ("Filling of conditions failed") 
00153       << " no valid filling possible for Conditions of type " << myname() << " for DetId " << myId;
00154    
00155   return success;
00156 }
00157 
00158 template<class Item> std::vector<DetId>
00159 CastorCondObjectContainer<Item>::getAllChannels() const
00160 {
00161   std::vector<DetId> channels;
00162   Item emptyItem;
00163   for (unsigned int i=0; i<CASTORcontainer.size(); i++)
00164     {
00165       if (emptyItem.rawId() != CASTORcontainer.at(i).rawId() )
00166         channels.push_back( DetId(CASTORcontainer.at(i).rawId()) );
00167     }
00168 
00169   return channels;
00170 }
00171 
00172 
00173 #endif