CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CalibCalorimetry/CastorCalib/plugins/CastorDbProducer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    CastorDbProducer
00004 // Class:      CastorDbProducer
00005 // 
00013 //
00014 // Original Author:  Fedor Ratnikov
00015 //         Created:  Tue Aug  9 19:10:10 CDT 2005
00016 //         Adapted for CASTOR by L. Mundim
00017 // $Id: CastorDbProducer.cc,v 1.4 2012/11/12 21:06:22 dlange Exp $
00018 //
00019 //
00020 
00021 
00022 // system include files
00023 #include <iostream>
00024 #include <fstream>
00025 
00026 #include "FWCore/Framework/interface/ESHandle.h"
00027 
00028 #include "CalibCalorimetry/CastorCalib/interface/CastorDbASCIIIO.h"
00029 #include "CalibFormats/CastorObjects/interface/CastorDbService.h"
00030 #include "CalibFormats/CastorObjects/interface/CastorDbRecord.h"
00031 
00032 
00033 #include "CondFormats/CastorObjects/interface/AllObjects.h"
00034 
00035 #include "CastorDbProducer.h"
00036 
00037 CastorDbProducer::CastorDbProducer( const edm::ParameterSet& fConfig)
00038   : ESProducer(),
00039     mService (new CastorDbService (fConfig)),
00040     mDumpRequest (),
00041     mDumpStream(0)
00042 {
00043   //the following line is needed to tell the framework what
00044   // data is being produced
00045   setWhatProduced (this, (dependsOn (&CastorDbProducer::pedestalsCallback,
00046                                      &CastorDbProducer::gainsCallback) &
00047                           &CastorDbProducer::pedestalWidthsCallback &
00048                           &CastorDbProducer::QIEDataCallback &
00049                           &CastorDbProducer::gainWidthsCallback &
00050                           &CastorDbProducer::channelQualityCallback &
00051                           &CastorDbProducer::electronicsMapCallback
00052                           )
00053                    );
00054   
00055   //now do what ever other initialization is needed
00056 
00057   mDumpRequest = fConfig.getUntrackedParameter <std::vector <std::string> > ("dump", std::vector<std::string>());
00058   if (!mDumpRequest.empty()) {
00059     std::string otputFile = fConfig.getUntrackedParameter <std::string> ("file", "");
00060     mDumpStream = otputFile.empty () ? &std::cout : new std::ofstream (otputFile.c_str());
00061   }
00062 }
00063 
00064 
00065 CastorDbProducer::~CastorDbProducer()
00066 {
00067  
00068    // do anything here that needs to be done at desctruction time
00069    // (e.g. close files, deallocate resources etc.)
00070   if (mDumpStream != &std::cout) delete mDumpStream;
00071 }
00072 
00073 
00074 //
00075 // member functions
00076 //
00077 
00078 // ------------ method called to produce the data  ------------
00079 boost::shared_ptr<CastorDbService> CastorDbProducer::produce( const CastorDbRecord&)
00080 {
00081   return mService;
00082 }
00083 
00084 void CastorDbProducer::pedestalsCallback (const CastorPedestalsRcd& fRecord) {
00085 
00086   edm::ESHandle <CastorPedestals> item;
00087   fRecord.get (item);
00088 
00089   mService->setData (item.product ());
00090   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Pedestals")) != mDumpRequest.end()) {
00091     *mDumpStream << "New HCAL/CASTOR Pedestals set" << std::endl;
00092     CastorDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00093   }
00094 }
00095 
00096 void CastorDbProducer::pedestalWidthsCallback (const CastorPedestalWidthsRcd& fRecord) {
00097   edm::ESHandle <CastorPedestalWidths> item;
00098   fRecord.get (item);
00099   mService->setData (item.product ());
00100   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("PedestalWidths")) != mDumpRequest.end()) {
00101     *mDumpStream << "New HCAL/CASTOR Pedestals set" << std::endl;
00102     CastorDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00103   }
00104 }
00105 
00106 
00107 void CastorDbProducer::gainsCallback (const CastorGainsRcd& fRecord) {
00108   edm::ESHandle <CastorGains> item;
00109   fRecord.get (item);
00110   mService->setData (item.product ());
00111   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("Gains")) != mDumpRequest.end()) {
00112     *mDumpStream << "New HCAL/CASTOR Gains set" << std::endl;
00113     CastorDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00114   }
00115 }
00116 
00117 
00118 void CastorDbProducer::gainWidthsCallback (const CastorGainWidthsRcd& fRecord) {
00119   edm::ESHandle <CastorGainWidths> item;
00120   fRecord.get (item);
00121   mService->setData (item.product ());
00122   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("GainWidths")) != mDumpRequest.end()) {
00123     *mDumpStream << "New HCAL/CASTOR GainWidths set" << std::endl;
00124     CastorDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00125   }
00126 }
00127 
00128 void CastorDbProducer::QIEDataCallback (const CastorQIEDataRcd& fRecord) {
00129   edm::ESHandle <CastorQIEData> item;
00130   fRecord.get (item);
00131   mService->setData (item.product ());
00132   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("QIEData")) != mDumpRequest.end()) {
00133     *mDumpStream << "New HCAL/CASTOR QIEData set" << std::endl;
00134     CastorDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00135   }
00136 }
00137 
00138 void CastorDbProducer::channelQualityCallback (const CastorChannelQualityRcd& fRecord) {
00139   edm::ESHandle <CastorChannelQuality> item;
00140   fRecord.get (item);
00141   mService->setData (item.product ());
00142   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ChannelQuality")) != mDumpRequest.end()) {
00143     *mDumpStream << "New HCAL/CASTOR ChannelQuality set" << std::endl;
00144     CastorDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00145   }
00146 }
00147 
00148 void CastorDbProducer::electronicsMapCallback (const CastorElectronicsMapRcd& fRecord) {
00149   edm::ESHandle <CastorElectronicsMap> item;
00150   fRecord.get (item);
00151   mService->setData (item.product ());
00152   if (std::find (mDumpRequest.begin(), mDumpRequest.end(), std::string ("ElectronicsMap")) != mDumpRequest.end()) {
00153     *mDumpStream << "New HCAL/CASTOR Electronics Map set" << std::endl;
00154     CastorDbASCIIIO::dumpObject (*mDumpStream, *(item.product ()));
00155   }
00156 }
00157 
00158 
00159