Go to the documentation of this file.00001 #include "EventFilter/DTRawToDigi/plugins/DTDigiToRawModule.h"
00002 #include "EventFilter/DTRawToDigi/plugins/DTDigiToRaw.h"
00003 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00004 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00005 #include "DataFormats/DTDigi/interface/DTDigiCollection.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "FWCore/Framework/interface/Event.h"
00008
00009 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
00010 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00011 #include "FWCore/Utilities/interface/CRC16.h"
00012
00013 #include "CondFormats/DataRecord/interface/DTReadOutMappingRcd.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015
00016 #include <iostream>
00017
00018 using namespace edm;
00019 using namespace std;
00020
00021 DTDigiToRawModule::DTDigiToRawModule(const edm::ParameterSet& ps) {
00022 produces<FEDRawDataCollection>();
00023
00024 dduID = ps.getUntrackedParameter<int>("dduID", 770);
00025 debug = ps.getUntrackedParameter<bool>("debugMode", false);
00026 digicoll = ps.getUntrackedParameter<string>("digiColl", "dtunpacker");
00027 digibyType = ps.getUntrackedParameter<bool>("digibytype", true);
00028
00029 useStandardFEDid_ = ps.getUntrackedParameter<bool>("useStandardFEDid", true);
00030 minFEDid_ = ps.getUntrackedParameter<int>("minFEDid", 770);
00031 maxFEDid_ = ps.getUntrackedParameter<int>("maxFEDid", 775);
00032
00033 packer = new DTDigiToRaw(ps);
00034 if (debug) cout << "[DTDigiToRawModule]: constructor" << endl;
00035 }
00036
00037 DTDigiToRawModule::~DTDigiToRawModule(){
00038 delete packer;
00039 if (debug) cout << "[DTDigiToRawModule]: destructor" << endl;
00040 }
00041
00042
00043 void DTDigiToRawModule::produce(Event & e, const EventSetup& iSetup) {
00044
00045 auto_ptr<FEDRawDataCollection> fed_buffers(new FEDRawDataCollection);
00046
00047
00048 Handle<DTDigiCollection> digis;
00049 if (digibyType) {
00050 e.getByType(digis);
00051 }
00052 else {
00053 e.getByLabel(digicoll, digis);
00054 }
00055
00056
00057 edm::ESHandle<DTReadOutMapping> map;
00058 iSetup.get<DTReadOutMappingRcd>().get( map );
00059
00060
00061 int FEDIDmin = 0, FEDIDMax = 0;
00062 if (useStandardFEDid_){
00063 FEDIDmin = FEDNumbering::MINDTFEDID;
00064 FEDIDMax = FEDNumbering::MAXDTFEDID;
00065 }
00066 else {
00067 FEDIDmin = minFEDid_;
00068 FEDIDMax = maxFEDid_;
00069 }
00070
00071 for (int id=FEDIDmin; id<=FEDIDMax; ++id){
00072
00073 packer->SetdduID(id);
00074 FEDRawData* rawData = packer->createFedBuffers(*digis, map);
00075
00076 FEDRawData& fedRawData = fed_buffers->FEDData(id);
00077 fedRawData = *rawData;
00078 delete rawData;
00079
00080 FEDHeader dtFEDHeader(fedRawData.data());
00081 dtFEDHeader.set(fedRawData.data(), 0, e.id().event(), 0, id);
00082
00083 FEDTrailer dtFEDTrailer(fedRawData.data()+(fedRawData.size()-8));
00084 dtFEDTrailer.set(fedRawData.data()+(fedRawData.size()-8), fedRawData.size()/8, evf::compute_crc(fedRawData.data(),fedRawData.size()), 0, 0);
00085
00086 }
00087
00088 e.put(fed_buffers);
00089
00090 }
00091