CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/CalibCalorimetry/CastorCalib/plugins/CastorTextCalibrations.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include <iostream>
00003 #include <fstream>
00004 
00005 #include "FWCore/Utilities/interface/Exception.h"
00006 #include "FWCore/ParameterSet/interface/FileInPath.h"
00007 
00008 #include "FWCore/Framework/interface/ValidityInterval.h"
00009 
00010 #include "CalibCalorimetry/CastorCalib/interface/CastorDbASCIIIO.h"
00011 
00012 #include "CondFormats/CastorObjects/interface/CastorPedestals.h"
00013 #include "CondFormats/CastorObjects/interface/CastorPedestalWidths.h"
00014 #include "CondFormats/CastorObjects/interface/CastorGains.h"
00015 #include "CondFormats/CastorObjects/interface/CastorGainWidths.h"
00016 #include "CondFormats/CastorObjects/interface/CastorElectronicsMap.h"
00017 #include "CondFormats/CastorObjects/interface/CastorChannelQuality.h"
00018 #include "CondFormats/CastorObjects/interface/CastorQIEData.h"
00019 
00020 #include "CondFormats/DataRecord/interface/CastorPedestalsRcd.h"
00021 #include "CondFormats/DataRecord/interface/CastorPedestalWidthsRcd.h"
00022 #include "CondFormats/DataRecord/interface/CastorGainsRcd.h"
00023 #include "CondFormats/DataRecord/interface/CastorGainWidthsRcd.h"
00024 #include "CondFormats/DataRecord/interface/CastorElectronicsMapRcd.h"
00025 #include "CondFormats/DataRecord/interface/CastorChannelQualityRcd.h"
00026 #include "CondFormats/DataRecord/interface/CastorQIEDataRcd.h"
00027 #include "CondFormats/DataRecord/interface/CastorRecoParamsRcd.h"
00028 
00029 
00030 #include "CastorTextCalibrations.h"
00031 //
00032 // class decleration
00033 //
00034 
00035 using namespace cms;
00036 
00037 CastorTextCalibrations::CastorTextCalibrations ( const edm::ParameterSet& iConfig ) 
00038   
00039 {
00040   //parsing parameters
00041   std::vector<edm::ParameterSet> data = iConfig.getParameter<std::vector<edm::ParameterSet> >("input");
00042   std::vector<edm::ParameterSet>::iterator request = data.begin ();
00043   for (; request != data.end (); request++) {
00044     std::string objectName = request->getParameter<std::string> ("object");
00045     edm::FileInPath fp = request->getParameter<edm::FileInPath>("file");
00046     mInputs [objectName] = fp.fullPath();
00047     if (objectName == "Pedestals") {
00048       setWhatProduced (this, &CastorTextCalibrations::producePedestals);
00049       findingRecord <CastorPedestalsRcd> ();
00050     }
00051     else if (objectName == "PedestalWidths") {
00052       setWhatProduced (this, &CastorTextCalibrations::producePedestalWidths);
00053       findingRecord <CastorPedestalWidthsRcd> ();
00054     }
00055     else if (objectName == "Gains") {
00056       setWhatProduced (this, &CastorTextCalibrations::produceGains);
00057       findingRecord <CastorGainsRcd> ();
00058     }
00059     else if (objectName == "GainWidths") {
00060       setWhatProduced (this, &CastorTextCalibrations::produceGainWidths);
00061       findingRecord <CastorGainWidthsRcd> ();
00062     }
00063     else if (objectName == "QIEData") {
00064       setWhatProduced (this, &CastorTextCalibrations::produceQIEData);
00065       findingRecord <CastorQIEDataRcd> ();
00066     }
00067     else if (objectName == "ChannelQuality") {
00068       setWhatProduced (this, &CastorTextCalibrations::produceChannelQuality);
00069       findingRecord <CastorChannelQualityRcd> ();
00070     }
00071     else if (objectName == "ElectronicsMap") {
00072       setWhatProduced (this, &CastorTextCalibrations::produceElectronicsMap);
00073       findingRecord <CastorElectronicsMapRcd> ();
00074     }
00075     else if (objectName == "RecoParams") {
00076       setWhatProduced (this, &CastorTextCalibrations::produceRecoParams);
00077       findingRecord <CastorRecoParamsRcd> ();
00078     }
00079     else {
00080       std::cerr << "CastorTextCalibrations-> Unknown object name '" << objectName 
00081                 << "', known names are: "
00082                 << "Pedestals PedestalWidths Gains GainWidths QIEData ChannelQuality ElectronicsMap RecoParams"
00083                 << std::endl;
00084     }
00085   }
00086   //  setWhatProduced(this);
00087 }
00088 
00089 
00090 CastorTextCalibrations::~CastorTextCalibrations()
00091 {
00092 }
00093 
00094 
00095 //
00096 // member functions
00097 //
00098 void 
00099 CastorTextCalibrations::setIntervalFor( const edm::eventsetup::EventSetupRecordKey& iKey, const edm::IOVSyncValue& iTime, edm::ValidityInterval& oInterval ) {
00100   std::string record = iKey.name ();
00101   oInterval = edm::ValidityInterval (edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime()); //infinite
00102 }
00103 
00104 template <class T>
00105 std::auto_ptr<T> produce_impl (const std::string& fFile) {
00106   std::auto_ptr<T> result (new T ());
00107   std::ifstream inStream (fFile.c_str ());
00108   if (!inStream.good ()) {
00109     std::cerr << "CastorTextCalibrations-> Unable to open file '" << fFile << "'" << std::endl;
00110     throw cms::Exception("FileNotFound") << "Unable to open '" << fFile << "'" << std::endl;
00111   }
00112   if (!CastorDbASCIIIO::getObject (inStream, &*result)) {
00113     std::cerr << "CastorTextCalibrations-> Can not read object from file '" << fFile << "'" << std::endl;
00114     throw cms::Exception("ReadError") << "Can not read object from file '" << fFile << "'" << std::endl;
00115   }
00116   return result;
00117 }
00118 
00119 
00120 std::auto_ptr<CastorPedestals> CastorTextCalibrations::producePedestals (const CastorPedestalsRcd&) {
00121   return produce_impl<CastorPedestals> (mInputs ["Pedestals"]);
00122 }
00123 
00124 std::auto_ptr<CastorPedestalWidths> CastorTextCalibrations::producePedestalWidths (const CastorPedestalWidthsRcd&) {
00125   return produce_impl<CastorPedestalWidths> (mInputs ["PedestalWidths"]);
00126 }
00127 
00128 std::auto_ptr<CastorGains> CastorTextCalibrations::produceGains (const CastorGainsRcd&) {
00129   return produce_impl<CastorGains> (mInputs ["Gains"]);
00130 }
00131 
00132 std::auto_ptr<CastorGainWidths> CastorTextCalibrations::produceGainWidths (const CastorGainWidthsRcd&) {
00133   return produce_impl<CastorGainWidths> (mInputs ["GainWidths"]);
00134 }
00135 
00136 std::auto_ptr<CastorQIEData> CastorTextCalibrations::produceQIEData (const CastorQIEDataRcd& rcd) {
00137   return produce_impl<CastorQIEData> (mInputs ["QIEData"]);
00138 }
00139 
00140 std::auto_ptr<CastorChannelQuality> CastorTextCalibrations::produceChannelQuality (const CastorChannelQualityRcd& rcd) {
00141   return produce_impl<CastorChannelQuality> (mInputs ["ChannelQuality"]);
00142 }
00143 
00144 std::auto_ptr<CastorElectronicsMap> CastorTextCalibrations::produceElectronicsMap (const CastorElectronicsMapRcd& rcd) {
00145   return produce_impl<CastorElectronicsMap> (mInputs ["ElectronicsMap"]);
00146 }
00147 std::auto_ptr<CastorRecoParams> CastorTextCalibrations::produceRecoParams (const CastorRecoParamsRcd& rcd) {
00148   return produce_impl<CastorRecoParams> (mInputs ["RecoParams"]);
00149 }