CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/HcalRawToDigi/plugins/HcalDigiToRaw.cc

Go to the documentation of this file.
00001 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00002 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00003 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00006 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include <iostream>
00009 
00010 
00011 #include "EventFilter/HcalRawToDigi/plugins/HcalDigiToRaw.h"
00012 
00013 using namespace std;
00014 
00015 
00016 HcalDigiToRaw::HcalDigiToRaw(edm::ParameterSet const& conf) :
00017   hbheTag_(conf.getUntrackedParameter("HBHE",edm::InputTag())),
00018   hoTag_(conf.getUntrackedParameter("HO",edm::InputTag())),
00019   hfTag_(conf.getUntrackedParameter("HF",edm::InputTag())),
00020   zdcTag_(conf.getUntrackedParameter("ZDC",edm::InputTag())),
00021   calibTag_(conf.getUntrackedParameter("CALIB",edm::InputTag())),
00022   trigTag_(conf.getUntrackedParameter("TRIG",edm::InputTag()))
00023 {
00024   produces<FEDRawDataCollection>();
00025 }
00026 
00027 // Virtual destructor needed.
00028 HcalDigiToRaw::~HcalDigiToRaw() { }  
00029 
00030 // Functions that gets called by framework every event
00031 void HcalDigiToRaw::produce(edm::Event& e, const edm::EventSetup& es)
00032 {
00033   HcalPacker::Collections colls;
00034 
00035   
00036   // Step A: Get Inputs 
00037   edm::Handle<HBHEDigiCollection> hbhe;
00038   if (!hbheTag_.label().empty()) {
00039     e.getByLabel(hbheTag_,hbhe);
00040     colls.hbhe=hbhe.product();
00041   }
00042   edm::Handle<HODigiCollection> ho;
00043   if (!hoTag_.label().empty()) {
00044     e.getByLabel(hoTag_,ho);
00045     colls.hoCont=ho.product();
00046   }
00047   edm::Handle<HFDigiCollection> hf;
00048   if (!hfTag_.label().empty()) {
00049     e.getByLabel(hfTag_,hf);
00050     colls.hfCont=hf.product();
00051   }
00052   edm::Handle<HcalCalibDigiCollection> Calib;
00053   if (!calibTag_.label().empty()) {
00054     e.getByLabel(calibTag_,Calib);
00055     colls.calibCont=Calib.product();
00056   }
00057   edm::Handle<ZDCDigiCollection> zdc;
00058   if (!zdcTag_.label().empty()) {
00059     e.getByLabel(zdcTag_,zdc);
00060     colls.zdcCont=zdc.product();
00061   }
00062   edm::Handle<HcalTrigPrimDigiCollection> htp;
00063   if (!trigTag_.label().empty()) {
00064     e.getByLabel(trigTag_,htp);
00065     colls.tpCont=htp.product();
00066   }
00067   // get the mapping
00068   edm::ESHandle<HcalDbService> pSetup;
00069   es.get<HcalDbRecord>().get( pSetup );
00070   const HcalElectronicsMap* readoutMap=pSetup->getHcalMapping();
00071   // Step B: Create empty output
00072   std::auto_ptr<FEDRawDataCollection> raw=std::auto_ptr<FEDRawDataCollection>(new FEDRawDataCollection());
00073 
00074   const int ifed_first=FEDNumbering::MINHCALFEDID;
00075   const int ifed_last=FEDNumbering::MAXHCALFEDID;
00076 
00077   int orbitN=e.id().event();
00078   int bcnN=2000;
00079 
00080   // Step C: pack all requested FEDs
00081   for (int ifed=ifed_first; ifed<=ifed_last; ++ifed) {
00082     FEDRawData& fed = raw->FEDData(ifed);
00083     try {
00084       packer_.pack(ifed,ifed-ifed_first, e.id().event(),
00085                    orbitN, bcnN, colls, *readoutMap, fed);
00086     } catch (cms::Exception& e) {
00087       edm::LogWarning("Unpacking error") << e.what();
00088     } catch (...) {
00089       edm::LogWarning("Unpacking exception");
00090     }
00091   }
00092 
00093 
00094   e.put(raw);
00095 }
00096 
00097