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