00001 #include <memory>
00002 #include <iostream>
00003
00004 #include "FWCore/Framework/interface/ValidityInterval.h"
00005 #include "DataFormats/HcalDetId/interface/HcalCastorDetId.h"
00006 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00007 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00008 #include "CalibCalorimetry/CastorCalib/interface/CastorDbHardcode.h"
00009 #include "CondFormats/CastorObjects/interface/CastorPedestals.h"
00010 #include "CondFormats/CastorObjects/interface/CastorPedestalWidths.h"
00011 #include "CondFormats/CastorObjects/interface/CastorGains.h"
00012 #include "CondFormats/CastorObjects/interface/CastorGainWidths.h"
00013 #include "CondFormats/CastorObjects/interface/CastorElectronicsMap.h"
00014 #include "CondFormats/CastorObjects/interface/CastorChannelQuality.h"
00015 #include "CondFormats/CastorObjects/interface/CastorQIEData.h"
00016
00017 #include "CondFormats/DataRecord/interface/CastorPedestalsRcd.h"
00018 #include "CondFormats/DataRecord/interface/CastorPedestalWidthsRcd.h"
00019 #include "CondFormats/DataRecord/interface/CastorGainsRcd.h"
00020 #include "CondFormats/DataRecord/interface/CastorGainWidthsRcd.h"
00021 #include "CondFormats/DataRecord/interface/CastorElectronicsMapRcd.h"
00022 #include "CondFormats/DataRecord/interface/CastorChannelQualityRcd.h"
00023 #include "CondFormats/DataRecord/interface/CastorQIEDataRcd.h"
00024 #include "Geometry/ForwardGeometry/interface/CastorTopology.h"
00025 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00027
00028 #include "CastorHardcodeCalibrations.h"
00029
00030
00031
00032
00033 using namespace cms;
00034
00035 namespace {
00036
00037 std::vector<HcalGenericDetId> allCells (bool h2_mode) {
00038 static std::vector<HcalGenericDetId> result;
00039 if (result.size () <= 0) {
00040
00041 CastorTopology castortopology;
00042 HcalCastorDetId cell;
00043 HcalCastorDetId::Section section = HcalCastorDetId::EM;
00044
00045 for(int sector=1; sector<17; sector++) {
00046 for(int module=1; module<3; module++) {
00047 cell = HcalCastorDetId(section, true, sector, module);
00048 if (castortopology.valid(cell)) result.push_back(cell);
00049 cell = HcalCastorDetId(section, false, sector, module);
00050 if (castortopology.valid(cell)) result.push_back(cell);
00051 }
00052 }
00053
00054 section = HcalCastorDetId::HAD;
00055 for(int sector= 1; sector < 17; sector++){
00056 for(int module=1; module<13; module++) {
00057 cell = HcalCastorDetId(section, true, sector, module);
00058 if(castortopology.valid(cell)) result.push_back(cell);
00059 cell = HcalCastorDetId(section, false, sector, module);
00060 if(castortopology.valid(cell)) result.push_back(cell);
00061 }
00062 }
00063
00064 return result;
00065 }
00066
00067 }
00068 }
00069
00070 CastorHardcodeCalibrations::CastorHardcodeCalibrations ( const edm::ParameterSet& iConfig )
00071
00072 {
00073 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::CastorHardcodeCalibrations->...";
00074
00075 h2mode_=iConfig.getUntrackedParameter<bool>("H2Mode",false);
00076 std::vector <std::string> toGet = iConfig.getUntrackedParameter <std::vector <std::string> > ("toGet");
00077 for(std::vector <std::string>::iterator objectName = toGet.begin(); objectName != toGet.end(); ++objectName ) {
00078 bool all = *objectName == "all";
00079 if ((*objectName == "Pedestals") || all) {
00080 setWhatProduced (this, &CastorHardcodeCalibrations::producePedestals);
00081 findingRecord <CastorPedestalsRcd> ();
00082 }
00083 if ((*objectName == "PedestalWidths") || all) {
00084 setWhatProduced (this, &CastorHardcodeCalibrations::producePedestalWidths);
00085 findingRecord <CastorPedestalWidthsRcd> ();
00086 }
00087 if ((*objectName == "Gains") || all) {
00088 setWhatProduced (this, &CastorHardcodeCalibrations::produceGains);
00089 findingRecord <CastorGainsRcd> ();
00090 }
00091 if ((*objectName == "GainWidths") || all) {
00092 setWhatProduced (this, &CastorHardcodeCalibrations::produceGainWidths);
00093 findingRecord <CastorGainWidthsRcd> ();
00094 }
00095 if ((*objectName == "QIEData") || all) {
00096 setWhatProduced (this, &CastorHardcodeCalibrations::produceQIEData);
00097 findingRecord <CastorQIEDataRcd> ();
00098 }
00099 if ((*objectName == "ChannelQuality") || (*objectName == "channelQuality") || all) {
00100 setWhatProduced (this, &CastorHardcodeCalibrations::produceChannelQuality);
00101 findingRecord <CastorChannelQualityRcd> ();
00102 }
00103 if ((*objectName == "ElectronicsMap") || (*objectName == "electronicsMap") || all) {
00104 setWhatProduced (this, &CastorHardcodeCalibrations::produceElectronicsMap);
00105 findingRecord <CastorElectronicsMapRcd> ();
00106 }
00107
00108 }
00109 }
00110
00111
00112 CastorHardcodeCalibrations::~CastorHardcodeCalibrations()
00113 {
00114 }
00115
00116
00117
00118
00119
00120 void
00121 CastorHardcodeCalibrations::setIntervalFor( const edm::eventsetup::EventSetupRecordKey& iKey, const edm::IOVSyncValue& iTime, edm::ValidityInterval& oInterval ) {
00122 std::string record = iKey.name ();
00123 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::setIntervalFor-> key: " << record << " time: " << iTime.eventID() << '/' << iTime.time ().value ();
00124 oInterval = edm::ValidityInterval (edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());
00125 }
00126
00127 std::auto_ptr<CastorPedestals> CastorHardcodeCalibrations::producePedestals (const CastorPedestalsRcd&) {
00128 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::producePedestals-> ...";
00129 std::auto_ptr<CastorPedestals> result (new CastorPedestals ());
00130 std::vector <HcalGenericDetId> cells = allCells(h2mode_);
00131 for (std::vector <HcalGenericDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
00132 CastorPedestal item = CastorDbHardcode::makePedestal (*cell);
00133 result->addValue (*cell, item.getValues ());
00134 }
00135 result->sort ();
00136 return result;
00137 }
00138
00139 std::auto_ptr<CastorPedestalWidths> CastorHardcodeCalibrations::producePedestalWidths (const CastorPedestalWidthsRcd&) {
00140 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::producePedestalWidths-> ...";
00141 std::auto_ptr<CastorPedestalWidths> result (new CastorPedestalWidths ());
00142 std::vector <HcalGenericDetId> cells = allCells(h2mode_);
00143 for (std::vector <HcalGenericDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
00144 CastorPedestalWidth item = CastorDbHardcode::makePedestalWidth (*cell);
00145 result->setWidth (item);
00146 }
00147 result->sort ();
00148 return result;
00149 }
00150
00151 std::auto_ptr<CastorGains> CastorHardcodeCalibrations::produceGains (const CastorGainsRcd&) {
00152 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceGains-> ...";
00153 std::auto_ptr<CastorGains> result (new CastorGains ());
00154 std::vector <HcalGenericDetId> cells = allCells(h2mode_);
00155 for (std::vector <HcalGenericDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
00156 CastorGain item = CastorDbHardcode::makeGain (*cell);
00157 result->addValue (*cell, item.getValues ());
00158 }
00159 result->sort ();
00160 return result;
00161 }
00162
00163 std::auto_ptr<CastorGainWidths> CastorHardcodeCalibrations::produceGainWidths (const CastorGainWidthsRcd&) {
00164 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceGainWidths-> ...";
00165 std::auto_ptr<CastorGainWidths> result (new CastorGainWidths ());
00166 std::vector <HcalGenericDetId> cells = allCells(h2mode_);
00167 for (std::vector <HcalGenericDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
00168 CastorGainWidth item = CastorDbHardcode::makeGainWidth (*cell);
00169 result->addValue (*cell, item.getValues ());
00170 }
00171 result->sort ();
00172 return result;
00173 }
00174
00175 std::auto_ptr<CastorQIEData> CastorHardcodeCalibrations::produceQIEData (const CastorQIEDataRcd& rcd) {
00176 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceQIEData-> ...";
00177 std::auto_ptr<CastorQIEData> result (new CastorQIEData ());
00178 std::vector <HcalGenericDetId> cells = allCells(h2mode_);
00179 for (std::vector <HcalGenericDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
00180 CastorQIECoder coder = CastorDbHardcode::makeQIECoder (*cell);
00181 result->addCoder (*cell, coder);
00182 }
00183 result->sort ();
00184 return result;
00185 }
00186
00187 std::auto_ptr<CastorChannelQuality> CastorHardcodeCalibrations::produceChannelQuality (const CastorChannelQualityRcd& rcd) {
00188 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceChannelQuality-> ...";
00189 std::auto_ptr<CastorChannelQuality> result (new CastorChannelQuality ());
00190 std::vector <HcalGenericDetId> cells = allCells(h2mode_);
00191 for (std::vector <HcalGenericDetId>::const_iterator cell = cells.begin (); cell != cells.end (); cell++) {
00192 result->setChannel (cell->rawId (), CastorChannelQuality::GOOD);
00193 }
00194 result->sort ();
00195 return result;
00196 }
00197
00198 std::auto_ptr<CastorElectronicsMap> CastorHardcodeCalibrations::produceElectronicsMap (const CastorElectronicsMapRcd& rcd) {
00199 edm::LogInfo("HCAL") << "CastorHardcodeCalibrations::produceElectronicsMap-> ...";
00200
00201 std::auto_ptr<CastorElectronicsMap> result (new CastorElectronicsMap ());
00202 CastorDbHardcode::makeHardcodeMap(*result);
00203 return result;
00204 }
00205