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