CMS 3D CMS Logo

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