00001
00002
00003
00004
00005
00006
00007 #include <memory>
00008 #include <iostream>
00009 #include <fstream>
00010
00011 #include "FWCore/Utilities/interface/Exception.h"
00012 #include "FWCore/ParameterSet/interface/FileInPath.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014
00015 #include "FWCore/Framework/interface/ValidityInterval.h"
00016
00017 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
00018 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00019
00020 #include "CondFormats/DataRecord/interface/HcalAllRcds.h"
00021
00022 #include "HcalTextCalibrations.h"
00023
00024
00025
00026
00027 using namespace cms;
00028
00029 HcalTextCalibrations::HcalTextCalibrations ( const edm::ParameterSet& iConfig )
00030
00031 {
00032
00033 std::vector<edm::ParameterSet> data = iConfig.getParameter<std::vector<edm::ParameterSet> >("input");
00034 std::vector<edm::ParameterSet>::iterator request = data.begin ();
00035 for (; request != data.end (); request++) {
00036 std::string objectName = request->getParameter<std::string> ("object");
00037 edm::FileInPath fp = request->getParameter<edm::FileInPath>("file");
00038 mInputs [objectName] = fp.fullPath();
00039 if (objectName == "Pedestals") {
00040 setWhatProduced (this, &HcalTextCalibrations::producePedestals);
00041 findingRecord <HcalPedestalsRcd> ();
00042 }
00043 else if (objectName == "PedestalWidths") {
00044 setWhatProduced (this, &HcalTextCalibrations::producePedestalWidths);
00045 findingRecord <HcalPedestalWidthsRcd> ();
00046 }
00047 else if (objectName == "Gains") {
00048 setWhatProduced (this, &HcalTextCalibrations::produceGains);
00049 findingRecord <HcalGainsRcd> ();
00050 }
00051 else if (objectName == "GainWidths") {
00052 setWhatProduced (this, &HcalTextCalibrations::produceGainWidths);
00053 findingRecord <HcalGainWidthsRcd> ();
00054 }
00055 else if (objectName == "QIEData") {
00056 setWhatProduced (this, &HcalTextCalibrations::produceQIEData);
00057 findingRecord <HcalQIEDataRcd> ();
00058 }
00059 else if (objectName == "ChannelQuality") {
00060 setWhatProduced (this, &HcalTextCalibrations::produceChannelQuality);
00061 findingRecord <HcalChannelQualityRcd> ();
00062 }
00063 else if (objectName == "ZSThresholds") {
00064 setWhatProduced (this, &HcalTextCalibrations::produceZSThresholds);
00065 findingRecord <HcalZSThresholdsRcd> ();
00066 }
00067 else if (objectName == "RespCorrs") {
00068 setWhatProduced (this, &HcalTextCalibrations::produceRespCorrs);
00069 findingRecord <HcalRespCorrsRcd> ();
00070 }
00071 else if (objectName == "LUTCorrs") {
00072 setWhatProduced (this, &HcalTextCalibrations::produceLUTCorrs);
00073 findingRecord <HcalLUTCorrsRcd> ();
00074 }
00075 else if (objectName == "PFCorrs") {
00076 setWhatProduced (this, &HcalTextCalibrations::producePFCorrs);
00077 findingRecord <HcalPFCorrsRcd> ();
00078 }
00079 else if (objectName == "TimeCorrs") {
00080 setWhatProduced (this, &HcalTextCalibrations::produceTimeCorrs);
00081 findingRecord <HcalTimeCorrsRcd> ();
00082 }
00083 else if (objectName == "L1TriggerObjects") {
00084 setWhatProduced (this, &HcalTextCalibrations::produceL1TriggerObjects);
00085 findingRecord <HcalL1TriggerObjectsRcd> ();
00086 }
00087 else if (objectName == "ElectronicsMap") {
00088 setWhatProduced (this, &HcalTextCalibrations::produceElectronicsMap);
00089 findingRecord <HcalElectronicsMapRcd> ();
00090 }
00091 else if (objectName == "ValidationCorrs") {
00092 setWhatProduced (this, &HcalTextCalibrations::produceValidationCorrs);
00093 findingRecord <HcalValidationCorrsRcd> ();
00094 }
00095 else if (objectName == "LutMetadata") {
00096 setWhatProduced (this, &HcalTextCalibrations::produceLutMetadata);
00097 findingRecord <HcalLutMetadataRcd> ();
00098 }
00099 else if (objectName == "DcsValues") {
00100 setWhatProduced (this, &HcalTextCalibrations::produceDcsValues);
00101 findingRecord <HcalDcsRcd> ();
00102 }
00103 else if (objectName == "DcsMap") {
00104 setWhatProduced (this, &HcalTextCalibrations::produceDcsMap);
00105 findingRecord <HcalDcsMapRcd> ();
00106 }
00107 else if (objectName == "CholeskyMatrices") {
00108 setWhatProduced (this, &HcalTextCalibrations::produceCholeskyMatrices);
00109 findingRecord <HcalCholeskyMatricesRcd> ();
00110 }
00111 else if (objectName == "CovarianceMatrices") {
00112 setWhatProduced (this, &HcalTextCalibrations::produceCovarianceMatrices);
00113 findingRecord <HcalCovarianceMatricesRcd> ();
00114 }
00115 else if (objectName == "RecoParams") {
00116 setWhatProduced (this, &HcalTextCalibrations::produceRecoParams);
00117 findingRecord <HcalRecoParamsRcd> ();
00118 }
00119 else if (objectName == "TimingParams") {
00120 setWhatProduced (this, &HcalTextCalibrations::produceTimingParams);
00121 findingRecord <HcalTimingParamsRcd> ();
00122 }
00123 else if (objectName == "LongRecoParams") {
00124 setWhatProduced (this, &HcalTextCalibrations::produceLongRecoParams);
00125 findingRecord <HcalLongRecoParamsRcd> ();
00126 }
00127 else if (objectName == "MCParams") {
00128 setWhatProduced (this, &HcalTextCalibrations::produceMCParams);
00129 findingRecord <HcalMCParamsRcd> ();
00130 }
00131 else if (objectName == "FlagHFDigiTimeParams") {
00132 setWhatProduced (this, &HcalTextCalibrations::produceFlagHFDigiTimeParams);
00133 findingRecord <HcalFlagHFDigiTimeParamsRcd> ();
00134 }
00135 else {
00136 std::cerr << "HcalTextCalibrations-> Unknown object name '" << objectName
00137 << "', known names are: "
00138 << "Pedestals PedestalWidths Gains GainWidths QIEData ChannelQuality ElectronicsMap "
00139 << "ZSThresholds RespCorrs LUTCorrs PFCorrs TimeCorrs L1TriggerObjects "
00140 << "ValidationCorrs LutMetadata DcsValues DcsMap CholeskyMatrices CovarianceMatrices "
00141 << "RecoParams LongRecoParams FlagHFDigiTimeParams MCParams "
00142 << std::endl;
00143 }
00144 }
00145
00146 }
00147
00148
00149 HcalTextCalibrations::~HcalTextCalibrations()
00150 {
00151 }
00152
00153
00154
00155
00156
00157 void
00158 HcalTextCalibrations::setIntervalFor( const edm::eventsetup::EventSetupRecordKey& iKey, const edm::IOVSyncValue& iTime, edm::ValidityInterval& oInterval ) {
00159 std::string record = iKey.name ();
00160 oInterval = edm::ValidityInterval (edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());
00161 }
00162
00163 template <class T>
00164 std::auto_ptr<T> produce_impl (const HcalTopology* topo, const std::string& fFile) {
00165 std::auto_ptr<T> result (new T (topo));
00166
00167 std::ifstream inStream (fFile.c_str ());
00168 if (!inStream.good ()) {
00169 std::cerr << "HcalTextCalibrations-> Unable to open file '" << fFile << "'" << std::endl;
00170 throw cms::Exception("FileNotFound") << "Unable to open '" << fFile << "'" << std::endl;
00171 }
00172 if (!HcalDbASCIIIO::getObject (inStream, &*result)) {
00173 std::cerr << "HcalTextCalibrations-> Can not read object from file '" << fFile << "'" << std::endl;
00174 throw cms::Exception("ReadError") << "Can not read object from file '" << fFile << "'" << std::endl;
00175 }
00176 return result;
00177 }
00178
00179 template <class T>
00180 std::auto_ptr<T> produce_impl (const std::string& fFile) {
00181 std::auto_ptr<T> result (new T ());
00182
00183 std::ifstream inStream (fFile.c_str ());
00184 if (!inStream.good ()) {
00185 std::cerr << "HcalTextCalibrations-> Unable to open file '" << fFile << "'" << std::endl;
00186 throw cms::Exception("FileNotFound") << "Unable to open '" << fFile << "'" << std::endl;
00187 }
00188 if (!HcalDbASCIIIO::getObject (inStream, &*result)) {
00189 std::cerr << "HcalTextCalibrations-> Can not read object from file '" << fFile << "'" << std::endl;
00190 throw cms::Exception("ReadError") << "Can not read object from file '" << fFile << "'" << std::endl;
00191 }
00192 return result;
00193 }
00194
00195
00196
00197 std::auto_ptr<HcalPedestals> HcalTextCalibrations::producePedestals (const HcalPedestalsRcd& rcd) {
00198 edm::ESHandle<HcalTopology> htopo;
00199 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00200 const HcalTopology* topo=&(*htopo);
00201
00202 return produce_impl<HcalPedestals> (topo,mInputs ["Pedestals"]);
00203 }
00204
00205 std::auto_ptr<HcalPedestalWidths> HcalTextCalibrations::producePedestalWidths (const HcalPedestalWidthsRcd& rcd) {
00206 edm::ESHandle<HcalTopology> htopo;
00207 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00208 const HcalTopology* topo=&(*htopo);
00209 return produce_impl<HcalPedestalWidths> (topo,mInputs ["PedestalWidths"]);
00210 }
00211
00212 std::auto_ptr<HcalGains> HcalTextCalibrations::produceGains (const HcalGainsRcd& rcd) {
00213 edm::ESHandle<HcalTopology> htopo;
00214 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00215 const HcalTopology* topo=&(*htopo);
00216 return produce_impl<HcalGains> (topo,mInputs ["Gains"]);
00217 }
00218
00219 std::auto_ptr<HcalGainWidths> HcalTextCalibrations::produceGainWidths (const HcalGainWidthsRcd& rcd) {
00220 edm::ESHandle<HcalTopology> htopo;
00221 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00222 const HcalTopology* topo=&(*htopo);
00223 return produce_impl<HcalGainWidths> (topo,mInputs ["GainWidths"]);
00224 }
00225
00226 std::auto_ptr<HcalQIEData> HcalTextCalibrations::produceQIEData (const HcalQIEDataRcd& rcd) {
00227 edm::ESHandle<HcalTopology> htopo;
00228 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00229 const HcalTopology* topo=&(*htopo);
00230 return produce_impl<HcalQIEData> (topo,mInputs ["QIEData"]);
00231 }
00232
00233 std::auto_ptr<HcalChannelQuality> HcalTextCalibrations::produceChannelQuality (const HcalChannelQualityRcd& rcd) {
00234 edm::ESHandle<HcalTopology> htopo;
00235 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00236 const HcalTopology* topo=&(*htopo);
00237 return produce_impl<HcalChannelQuality> (topo,mInputs ["ChannelQuality"]);
00238 }
00239
00240 std::auto_ptr<HcalZSThresholds> HcalTextCalibrations::produceZSThresholds (const HcalZSThresholdsRcd& rcd) { edm::ESHandle<HcalTopology> htopo;
00241 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00242 const HcalTopology* topo=&(*htopo);
00243 return produce_impl<HcalZSThresholds> (topo,mInputs ["ZSThresholds"]);
00244 }
00245
00246 std::auto_ptr<HcalRespCorrs> HcalTextCalibrations::produceRespCorrs (const HcalRespCorrsRcd& rcd) {
00247 edm::ESHandle<HcalTopology> htopo;
00248 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00249 const HcalTopology* topo=&(*htopo);
00250 return produce_impl<HcalRespCorrs> (topo,mInputs ["RespCorrs"]);
00251 }
00252
00253 std::auto_ptr<HcalLUTCorrs> HcalTextCalibrations::produceLUTCorrs (const HcalLUTCorrsRcd& rcd) {
00254 edm::ESHandle<HcalTopology> htopo;
00255 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00256 const HcalTopology* topo=&(*htopo);
00257 return produce_impl<HcalLUTCorrs> (topo,mInputs ["LUTCorrs"]);
00258 }
00259
00260 std::auto_ptr<HcalPFCorrs> HcalTextCalibrations::producePFCorrs (const HcalPFCorrsRcd& rcd) {
00261 edm::ESHandle<HcalTopology> htopo;
00262 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00263 const HcalTopology* topo=&(*htopo);
00264 return produce_impl<HcalPFCorrs> (topo,mInputs ["PFCorrs"]);
00265 }
00266
00267 std::auto_ptr<HcalTimeCorrs> HcalTextCalibrations::produceTimeCorrs (const HcalTimeCorrsRcd& rcd) {
00268 edm::ESHandle<HcalTopology> htopo;
00269 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00270 const HcalTopology* topo=&(*htopo);
00271 return produce_impl<HcalTimeCorrs> (topo,mInputs ["TimeCorrs"]);
00272 }
00273
00274 std::auto_ptr<HcalL1TriggerObjects> HcalTextCalibrations::produceL1TriggerObjects (const HcalL1TriggerObjectsRcd& rcd) {
00275 edm::ESHandle<HcalTopology> htopo;
00276 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00277 const HcalTopology* topo=&(*htopo);
00278 return produce_impl<HcalL1TriggerObjects> (topo,mInputs ["L1TriggerObjects"]);
00279 }
00280
00281 std::auto_ptr<HcalElectronicsMap> HcalTextCalibrations::produceElectronicsMap (const HcalElectronicsMapRcd& rcd) {
00282 return produce_impl<HcalElectronicsMap> (mInputs ["ElectronicsMap"]);
00283 }
00284
00285 std::auto_ptr<HcalValidationCorrs> HcalTextCalibrations::produceValidationCorrs (const HcalValidationCorrsRcd& rcd) {
00286 edm::ESHandle<HcalTopology> htopo;
00287 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00288 const HcalTopology* topo=&(*htopo);
00289 return produce_impl<HcalValidationCorrs> (topo,mInputs ["ValidationCorrs"]);
00290 }
00291
00292 std::auto_ptr<HcalLutMetadata> HcalTextCalibrations::produceLutMetadata (const HcalLutMetadataRcd& rcd) {
00293 edm::ESHandle<HcalTopology> htopo;
00294 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00295 const HcalTopology* topo=&(*htopo);
00296 return produce_impl<HcalLutMetadata> (topo,mInputs ["LutMetadata"]);
00297 }
00298
00299 std::auto_ptr<HcalDcsValues>
00300 HcalTextCalibrations::produceDcsValues(HcalDcsRcd const & rcd) {
00301 return produce_impl<HcalDcsValues> (mInputs ["DcsValues"]);
00302 }
00303
00304 std::auto_ptr<HcalDcsMap> HcalTextCalibrations::produceDcsMap (const HcalDcsMapRcd& rcd) {
00305 return produce_impl<HcalDcsMap> (mInputs ["DcsMap"]);
00306 }
00307
00308 std::auto_ptr<HcalCovarianceMatrices> HcalTextCalibrations::produceCovarianceMatrices (const HcalCovarianceMatricesRcd& rcd) {
00309 edm::ESHandle<HcalTopology> htopo;
00310 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00311 const HcalTopology* topo=&(*htopo);
00312 return produce_impl<HcalCovarianceMatrices> (topo,mInputs ["CovarianceMatrices"]);
00313 }
00314
00315 std::auto_ptr<HcalCholeskyMatrices> HcalTextCalibrations::produceCholeskyMatrices (const HcalCholeskyMatricesRcd& rcd) {
00316 edm::ESHandle<HcalTopology> htopo;
00317 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00318 const HcalTopology* topo=&(*htopo);
00319 return produce_impl<HcalCholeskyMatrices> (topo,mInputs ["CholeskyMatrices"]);
00320 }
00321
00322 std::auto_ptr<HcalRecoParams> HcalTextCalibrations::produceRecoParams (const HcalRecoParamsRcd& rcd) {
00323 edm::ESHandle<HcalTopology> htopo;
00324 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00325 const HcalTopology* topo=&(*htopo);
00326 return produce_impl<HcalRecoParams> (topo,mInputs ["RecoParams"]);
00327 }
00328
00329 std::auto_ptr<HcalLongRecoParams> HcalTextCalibrations::produceLongRecoParams (const HcalLongRecoParamsRcd& rcd) {
00330 edm::ESHandle<HcalTopology> htopo;
00331 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00332 const HcalTopology* topo=&(*htopo);
00333 return produce_impl<HcalLongRecoParams> (topo,mInputs ["LongRecoParams"]);
00334 }
00335 std::auto_ptr<HcalTimingParams> HcalTextCalibrations::produceTimingParams (const HcalTimingParamsRcd& rcd) {
00336 edm::ESHandle<HcalTopology> htopo;
00337 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00338 const HcalTopology* topo=&(*htopo);
00339 return produce_impl<HcalTimingParams> (topo,mInputs ["TimingParams"]);
00340 }
00341 std::auto_ptr<HcalMCParams> HcalTextCalibrations::produceMCParams (const HcalMCParamsRcd& rcd) {
00342 edm::ESHandle<HcalTopology> htopo;
00343 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00344 const HcalTopology* topo=&(*htopo);
00345 return produce_impl<HcalMCParams> (topo,mInputs ["MCParams"]);
00346 }
00347
00348 std::auto_ptr<HcalFlagHFDigiTimeParams> HcalTextCalibrations::produceFlagHFDigiTimeParams (const HcalFlagHFDigiTimeParamsRcd& rcd) {
00349 edm::ESHandle<HcalTopology> htopo;
00350 rcd.getRecord<IdealGeometryRecord>().get(htopo);
00351 const HcalTopology* topo=&(*htopo);
00352 return produce_impl<HcalFlagHFDigiTimeParams> (topo,mInputs ["FlagHFDigiTimeParams"]);
00353 }