CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/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 #include "CondFormats/DataRecord/interface/CastorSaturationCorrsRcd.h"
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 if (objectName == "SaturationCorrs") {
00080       setWhatProduced (this, &CastorTextCalibrations::produceSaturationCorrs);
00081       findingRecord <CastorSaturationCorrsRcd> ();
00082     }
00083     else {
00084       std::cerr << "CastorTextCalibrations-> Unknown object name '" << objectName 
00085                 << "', known names are: "
00086                 << "Pedestals PedestalWidths Gains GainWidths QIEData ChannelQuality ElectronicsMap RecoParams SaturationCorrs"
00087                 << std::endl;
00088     }
00089   }
00090   //  setWhatProduced(this);
00091 }
00092 
00093 
00094 CastorTextCalibrations::~CastorTextCalibrations()
00095 {
00096 }
00097 
00098 
00099 //
00100 // member functions
00101 //
00102 void 
00103 CastorTextCalibrations::setIntervalFor( const edm::eventsetup::EventSetupRecordKey& iKey, const edm::IOVSyncValue& iTime, edm::ValidityInterval& oInterval ) {
00104   std::string record = iKey.name ();
00105   oInterval = edm::ValidityInterval (edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime()); //infinite
00106 }
00107 
00108 template <class T>
00109 std::auto_ptr<T> produce_impl (const std::string& fFile) {
00110   std::auto_ptr<T> result (new T ());
00111   std::ifstream inStream (fFile.c_str ());
00112   if (!inStream.good ()) {
00113     std::cerr << "CastorTextCalibrations-> Unable to open file '" << fFile << "'" << std::endl;
00114     throw cms::Exception("FileNotFound") << "Unable to open '" << fFile << "'" << std::endl;
00115   }
00116   if (!CastorDbASCIIIO::getObject (inStream, &*result)) {
00117     std::cerr << "CastorTextCalibrations-> Can not read object from file '" << fFile << "'" << std::endl;
00118     throw cms::Exception("ReadError") << "Can not read object from file '" << fFile << "'" << std::endl;
00119   }
00120   return result;
00121 }
00122 
00123 
00124 std::auto_ptr<CastorPedestals> CastorTextCalibrations::producePedestals (const CastorPedestalsRcd&) {
00125   return produce_impl<CastorPedestals> (mInputs ["Pedestals"]);
00126 }
00127 
00128 std::auto_ptr<CastorPedestalWidths> CastorTextCalibrations::producePedestalWidths (const CastorPedestalWidthsRcd&) {
00129   return produce_impl<CastorPedestalWidths> (mInputs ["PedestalWidths"]);
00130 }
00131 
00132 std::auto_ptr<CastorGains> CastorTextCalibrations::produceGains (const CastorGainsRcd&) {
00133   return produce_impl<CastorGains> (mInputs ["Gains"]);
00134 }
00135 
00136 std::auto_ptr<CastorGainWidths> CastorTextCalibrations::produceGainWidths (const CastorGainWidthsRcd&) {
00137   return produce_impl<CastorGainWidths> (mInputs ["GainWidths"]);
00138 }
00139 
00140 std::auto_ptr<CastorQIEData> CastorTextCalibrations::produceQIEData (const CastorQIEDataRcd& rcd) {
00141   return produce_impl<CastorQIEData> (mInputs ["QIEData"]);
00142 }
00143 
00144 std::auto_ptr<CastorChannelQuality> CastorTextCalibrations::produceChannelQuality (const CastorChannelQualityRcd& rcd) {
00145   return produce_impl<CastorChannelQuality> (mInputs ["ChannelQuality"]);
00146 }
00147 
00148 std::auto_ptr<CastorElectronicsMap> CastorTextCalibrations::produceElectronicsMap (const CastorElectronicsMapRcd& rcd) {
00149   return produce_impl<CastorElectronicsMap> (mInputs ["ElectronicsMap"]);
00150 }
00151 
00152 std::auto_ptr<CastorRecoParams> CastorTextCalibrations::produceRecoParams (const CastorRecoParamsRcd& rcd) {
00153   return produce_impl<CastorRecoParams> (mInputs ["RecoParams"]);
00154 }
00155 
00156 std::auto_ptr<CastorSaturationCorrs> CastorTextCalibrations::produceSaturationCorrs (const CastorSaturationCorrsRcd& rcd) {
00157   return produce_impl<CastorSaturationCorrs> (mInputs ["SaturationCorrs"]);
00158 }