CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/CastorRawToDigi/plugins/CastorDigiToRaw.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/CastorObjects/interface/CastorDbService.h"
00006 #include "CalibFormats/CastorObjects/interface/CastorDbRecord.h"
00007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00008 #include <iostream>
00009 
00010 #include "EventFilter/CastorRawToDigi/interface/CastorCollections.h"
00011 #include "EventFilter/CastorRawToDigi/plugins/CastorDigiToRaw.h"
00012 
00013 using namespace std;
00014 
00015 CastorDigiToRaw::CastorDigiToRaw(edm::ParameterSet const& conf) :
00016   castorTag_(conf.getUntrackedParameter("CASTOR",edm::InputTag())),
00017   calibTag_(conf.getUntrackedParameter("CALIB",edm::InputTag())),
00018   trigTag_(conf.getUntrackedParameter("TRIG",edm::InputTag())),
00019   usingctdc_(conf.getUntrackedParameter<bool>("CastorCtdc",false))
00020 
00021 {
00022   produces<FEDRawDataCollection>();
00023 }
00024 
00025 // Virtual destructor needed.
00026 CastorDigiToRaw::~CastorDigiToRaw() { }  
00027 
00028 // Functions that gets called by framework every event
00029 void CastorDigiToRaw::produce(edm::Event& e, const edm::EventSetup& es)
00030 {
00031   CastorCollections colls;
00032  
00033   // Step A: Get Inputs 
00034   edm::Handle<CastorDigiCollection> castor;
00035   if (!castorTag_.label().empty()) {
00036     e.getByLabel(castorTag_,castor);
00037     colls.castorCont=castor.product();  
00038   }
00039   // get the mapping
00040   edm::ESHandle<CastorDbService> pSetup;
00041   es.get<CastorDbRecord>().get( pSetup );
00042   const CastorElectronicsMap* readoutMap=pSetup->getCastorMapping();
00043   // Step B: Create empty output
00044   std::auto_ptr<FEDRawDataCollection> raw=std::auto_ptr<FEDRawDataCollection>(new FEDRawDataCollection());
00045 
00046   const int ifed_first=FEDNumbering::MINCASTORFEDID;  //690
00047   const int ifed_last=FEDNumbering::MAXCASTORFEDID;   //693
00048 
00049   int orbitN=e.id().event();
00050   int bcnN=2000;
00051 
00052   // Step C: pack all requested FEDs
00053   for (int ifed=ifed_first; ifed<=ifed_last; ++ifed) {
00054     FEDRawData& fed = raw->FEDData(ifed);
00055     try {
00056                 if ( usingctdc_ ) {
00057       ctdcpacker_.pack(ifed,ifed-ifed_first, e.id().event(),
00058                    orbitN, bcnN, colls, *readoutMap, fed);
00059                  } else {
00060       packer_.pack(ifed,ifed-ifed_first, e.id().event(),
00061                    orbitN, bcnN, colls, *readoutMap, fed);       }
00062     } catch (cms::Exception& e) {
00063       edm::LogWarning("Unpacking error") << e.what();
00064     } catch (...) {
00065       edm::LogWarning("Unpacking exception");
00066     }
00067   }
00068 
00069   e.put(raw);
00070 }
00071 
00072