CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CalibCalorimetry/HcalPlugins/src/HcalDbProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    HcalDbProducer
00004 // Class:      HcalDbProducer
00005 // 
00013 //
00014 // Original Author:  Fedor Ratnikov
00015 //         Created:  Tue Aug  9 19:10:10 CDT 2005
00016 // $Id: HcalDbProducer.cc,v 1.28 2012/11/12 20:42:39 dlange Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <iostream>
00023 #include <fstream>
00024 
00025 #include "FWCore/Framework/interface/ESHandle.h"
00026 
00027 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
00028 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00029 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00030 
00031 
00032 #include "CondFormats/HcalObjects/interface/AllObjects.h"
00033 
00034 #include "HcalDbProducer.h"
00035 
00036 HcalDbProducer::HcalDbProducer( const edm::ParameterSet& fConfig)
00037   : ESProducer(),
00038     mService (new HcalDbService (fConfig)),
00039     mDumpRequest (),
00040     mDumpStream(0)
00041 {
00042   //the following line is needed to tell the framework what data is being produced
00043   // comments of dependsOn:
00044   // 1) There are two ways one can use 'dependsOn' the first is passing it up to three arguments.  
00045   //    However, one can also extend the dependencies by first calling 'dependsOn() and then using '&' to add additional dependencies.  So
00046   //      dependsOn(&FooProd::func1, &FooProd::func2, &FooProd::func3)
00047   //    gives the same result as
00048   //      dependsOn(&FooProd::func1) & (&FooProd::func2) & (&FooProd::func3)
00049   // 2) Upon IOV change, all callbacks are called, in the inverse order of their specification below (tested).
00050   setWhatProduced (this, (dependsOn (&HcalDbProducer::pedestalsCallback) &
00051                           &HcalDbProducer::pedestalWidthsCallback &
00052                           &HcalDbProducer::respCorrsCallback &
00053                           &HcalDbProducer::gainsCallback &
00054                           &HcalDbProducer::LUTCorrsCallback &
00055                           &HcalDbProducer::PFCorrsCallback &
00056                           &HcalDbProducer::timeCorrsCallback &
00057                           &HcalDbProducer::QIEDataCallback &
00058                           &HcalDbProducer::gainWidthsCallback &
00059                           &HcalDbProducer::channelQualityCallback &
00060                           &HcalDbProducer::zsThresholdsCallback &
00061                           &HcalDbProducer::L1triggerObjectsCallback &
00062                           &HcalDbProducer::electronicsMapCallback &
00063                           &HcalDbProducer::lutMetadataCallback 
00064                           )
00065                    );
00066   
00067   //now do what ever other initialization is needed
00068 
00069   mDumpRequest = fConfig.getUntrackedParameter <std::vector <std::string> > ("dump", std::vector<std::string>());
00070   if (!mDumpRequest.empty()) {
00071     std::string otputFile = fConfig.getUntrackedParameter <std::string> ("file", "");
00072     mDumpStream = otputFile.empty () ? &std::cout : new std::ofstream (otputFile.c_str());
00073   }
00074 }
00075 
00076 
00077 HcalDbProducer::~HcalDbProducer()
00078 {
00079  
00080    // do anything here that needs to be done at desctruction time
00081    // (e.g. close files, deallocate resources etc.)
00082   if (mDumpStream != &std::cout) delete mDumpStream;
00083 }
00084 
00085 
00086 //
00087 // member functions
00088 //
00089 
00090 // ------------ method called to produce the data  ------------
00091 boost::shared_ptr<HcalDbService> HcalDbProducer::produce( const HcalDbRecord&)
00092 {
00093   return mService;
00094 }
00095 
00096 void HcalDbProducer::pedestalsCallback (const HcalPedestalsRcd& fRecord) {
00097   edm::ESHandle <HcalPedestals> item;
00098   fRecord.get (item);
00099 
00100   if (item->topo()==0) {
00101     edm::ESHandle<HcalTopology> htopo;
00102     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00103     const HcalTopology* topo=&(*htopo);
00104     item->setTopo(topo);
00105   }
00106 
00107   mService->setData (item.product ());
00108   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Pedestals")) != mDumpRequest.end()) {
00109     *mDumpStream << "New HCAL Pedestals set" << std::endl;
00110     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00111   }
00112 }
00113 
00114 void HcalDbProducer::pedestalWidthsCallback (const HcalPedestalWidthsRcd& fRecord) {
00115   edm::ESHandle <HcalPedestalWidths> item;
00116   fRecord.get (item);
00117 
00118   if (item->topo()==0) {
00119     edm::ESHandle<HcalTopology> htopo;
00120     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00121     const HcalTopology* topo=&(*htopo);
00122     item->setTopo(topo);
00123   }
00124 
00125   mService->setData (item.product ());
00126   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("PedestalWidths")) != mDumpRequest.end()) {
00127     *mDumpStream << "New HCAL PedestalWidths set" << std::endl;
00128     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00129   }
00130 }
00131 
00132 
00133 void HcalDbProducer::gainsCallback (const HcalGainsRcd& fRecord) {
00134   edm::ESHandle <HcalGains> item;
00135   fRecord.get (item);
00136 
00137   if (item->topo()==0) {
00138     edm::ESHandle<HcalTopology> htopo;
00139     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00140     const HcalTopology* topo=&(*htopo);
00141     item->setTopo(topo);
00142   }
00143 
00144   mService->setData (item.product ());
00145   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Gains")) != mDumpRequest.end()) {
00146     *mDumpStream << "New HCAL Gains set" << std::endl;
00147     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00148   }
00149 }
00150 
00151 
00152 void HcalDbProducer::gainWidthsCallback (const HcalGainWidthsRcd& fRecord) {
00153   edm::ESHandle <HcalGainWidths> item;
00154   fRecord.get (item);
00155 
00156   if (item->topo()==0) {
00157     edm::ESHandle<HcalTopology> htopo;
00158     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00159     const HcalTopology* topo=&(*htopo);
00160     item->setTopo(topo);
00161   }
00162 
00163   mService->setData (item.product ());
00164   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("GainWidths")) != mDumpRequest.end()) {
00165     *mDumpStream << "New HCAL GainWidths set" << std::endl;
00166     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00167   }
00168 }
00169 
00170 void HcalDbProducer::QIEDataCallback (const HcalQIEDataRcd& fRecord) {
00171   edm::ESHandle <HcalQIEData> item;
00172   fRecord.get (item);
00173 
00174   if (item->topo()==0) {
00175     edm::ESHandle<HcalTopology> htopo;
00176     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00177     const HcalTopology* topo=&(*htopo);
00178     item->setTopo(topo);
00179   }
00180 
00181   mService->setData (item.product ());
00182   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("QIEData")) != mDumpRequest.end()) {
00183     *mDumpStream << "New HCAL QIEData set" << std::endl;
00184     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00185   }
00186 }
00187 
00188 void HcalDbProducer::channelQualityCallback (const HcalChannelQualityRcd& fRecord) {
00189   edm::ESHandle <HcalChannelQuality> item;
00190   fRecord.get (item);
00191 
00192   if (item->topo()==0) {
00193     edm::ESHandle<HcalTopology> htopo;
00194     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00195     const HcalTopology* topo=&(*htopo);
00196     item->setTopo(topo);
00197   }
00198 
00199   mService->setData (item.product ());
00200   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ChannelQuality")) != mDumpRequest.end()) {
00201     *mDumpStream << "New HCAL ChannelQuality set" << std::endl;
00202     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00203   }
00204 }
00205 
00206 void HcalDbProducer::respCorrsCallback (const HcalRespCorrsRcd& fRecord) {
00207   edm::ESHandle <HcalRespCorrs> item;
00208   fRecord.get (item);
00209 
00210   if (item->topo()==0) {
00211     edm::ESHandle<HcalTopology> htopo;
00212     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00213     const HcalTopology* topo=&(*htopo);
00214     item->setTopo(topo);
00215   }
00216 
00217   mService->setData (item.product ());
00218   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("RespCorrs")) != mDumpRequest.end()) {
00219     *mDumpStream << "New HCAL RespCorrs set" << std::endl;
00220     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00221   }
00222 }
00223 
00224 void HcalDbProducer::LUTCorrsCallback (const HcalLUTCorrsRcd& fRecord) {
00225   edm::ESHandle <HcalLUTCorrs> item;
00226   fRecord.get (item);
00227 
00228   if (item->topo()==0) {
00229     edm::ESHandle<HcalTopology> htopo;
00230     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00231     const HcalTopology* topo=&(*htopo);
00232     item->setTopo(topo);
00233   }
00234 
00235   mService->setData (item.product ());
00236   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("LUTCorrs")) != mDumpRequest.end()) {
00237     *mDumpStream << "New HCAL LUTCorrs set" << std::endl;
00238     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00239   }
00240 }
00241 
00242 void HcalDbProducer::PFCorrsCallback (const HcalPFCorrsRcd& fRecord) {
00243   edm::ESHandle <HcalPFCorrs> item;
00244   fRecord.get (item);
00245 
00246   if (item->topo()==0) {
00247     edm::ESHandle<HcalTopology> htopo;
00248     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00249     const HcalTopology* topo=&(*htopo);
00250     item->setTopo(topo);
00251   }
00252 
00253   mService->setData (item.product ());
00254   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("PFCorrs")) != mDumpRequest.end()) {
00255     *mDumpStream << "New HCAL PFCorrs set" << std::endl;
00256     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00257   }
00258 }
00259 
00260 void HcalDbProducer::timeCorrsCallback (const HcalTimeCorrsRcd& fRecord) {
00261   edm::ESHandle <HcalTimeCorrs> item;
00262   fRecord.get (item);
00263 
00264   if (item->topo()==0) {
00265     edm::ESHandle<HcalTopology> htopo;
00266     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00267     const HcalTopology* topo=&(*htopo);
00268     item->setTopo(topo);
00269   }
00270 
00271   mService->setData (item.product ());
00272   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("TimeCorrs")) != mDumpRequest.end()) {
00273     *mDumpStream << "New HCAL TimeCorrs set" << std::endl;
00274     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00275   }
00276 }
00277 
00278 void HcalDbProducer::zsThresholdsCallback (const HcalZSThresholdsRcd& fRecord) {
00279   edm::ESHandle <HcalZSThresholds> item;
00280   fRecord.get (item);
00281 
00282   if (item->topo()==0) {
00283     edm::ESHandle<HcalTopology> htopo;
00284     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00285     const HcalTopology* topo=&(*htopo);
00286     item->setTopo(topo);
00287   }
00288 
00289   mService->setData (item.product ());
00290   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ZSThresholds")) != mDumpRequest.end()) {
00291     *mDumpStream << "New HCAL ZSThresholds set" << std::endl;
00292     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00293   }
00294 }
00295 
00296 void HcalDbProducer::L1triggerObjectsCallback (const HcalL1TriggerObjectsRcd& fRecord) {
00297   edm::ESHandle <HcalL1TriggerObjects> item;
00298   fRecord.get (item);
00299 
00300   if (item->topo()==0) {
00301     edm::ESHandle<HcalTopology> htopo;
00302     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00303     const HcalTopology* topo=&(*htopo);
00304     item->setTopo(topo);
00305   }
00306 
00307   mService->setData (item.product ());
00308   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("L1TriggerObjects")) != mDumpRequest.end()) {
00309     *mDumpStream << "New HCAL L1TriggerObjects set" << std::endl;
00310     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00311   }
00312 }
00313 
00314 void HcalDbProducer::electronicsMapCallback (const HcalElectronicsMapRcd& fRecord) {
00315   edm::ESHandle <HcalElectronicsMap> item;
00316   fRecord.get (item);
00317   mService->setData (item.product ());
00318   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ElectronicsMap")) != mDumpRequest.end()) {
00319     *mDumpStream << "New HCAL Electronics Map set" << std::endl;
00320     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00321   }
00322 }
00323 
00324 void HcalDbProducer::lutMetadataCallback (const HcalLutMetadataRcd& fRecord) {
00325   edm::ESHandle <HcalLutMetadata> item;
00326   fRecord.get (item);
00327 
00328   if (item->topo()==0) {
00329     edm::ESHandle<HcalTopology> htopo;
00330     fRecord.getRecord<IdealGeometryRecord>().get(htopo);
00331     const HcalTopology* topo=&(*htopo);
00332     item->setTopo(topo);
00333   }
00334 
00335   mService->setData (item.product ());
00336   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("LutMetadata")) != mDumpRequest.end()) {
00337     *mDumpStream << "New HCAL LUT Metadata set" << std::endl;
00338     HcalDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00339   }
00340 }
00341 
00342 
00343