CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/DTRawToDigi/plugins/DTUnpackingModule.cc

Go to the documentation of this file.
00001 
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 
00011 #include <FWCore/Framework/interface/Event.h>
00012 #include <DataFormats/Common/interface/Handle.h>
00013 #include <FWCore/Framework/interface/ESHandle.h>
00014 #include <FWCore/Framework/interface/EventSetup.h>
00015 #include <FWCore/ParameterSet/interface/ParameterSet.h>
00016 
00017 #include <EventFilter/DTRawToDigi/plugins/DTUnpackingModule.h>
00018 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
00019 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
00020 #include <DataFormats/FEDRawData/interface/FEDRawDataCollection.h>
00021 #include <DataFormats/DTDigi/interface/DTDigiCollection.h>
00022 #include <DataFormats/DTDigi/interface/DTLocalTriggerCollection.h>
00023 
00024 #include <CondFormats/DataRecord/interface/DTReadOutMappingRcd.h>
00025 
00026 #include <EventFilter/DTRawToDigi/plugins/DTDDUUnpacker.h>
00027 #include <EventFilter/DTRawToDigi/plugins/DTROS25Unpacker.h>
00028 #include <EventFilter/DTRawToDigi/plugins/DTROS8Unpacker.h>
00029 
00030 
00031 using namespace edm;
00032 using namespace std;
00033 
00034 
00035 
00036 #define SLINK_WORD_SIZE 8 
00037 
00038 
00039 DTUnpackingModule::DTUnpackingModule(const edm::ParameterSet& ps) : unpacker(0) {
00040 
00041   const string & dataType = ps.getParameter<string>("dataType");
00042 
00043   ParameterSet unpackerParameters = ps.getParameter<ParameterSet>("readOutParameters");
00044   
00045 
00046   if (dataType == "DDU") {
00047     unpacker = new DTDDUUnpacker(unpackerParameters);
00048   } 
00049   else if (dataType == "ROS25") {
00050     unpacker = new DTROS25Unpacker(unpackerParameters.getParameter<ParameterSet>("rosParameters"));
00051   } 
00052   else if (dataType == "ROS8") {
00053     unpacker = new DTROS8Unpacker(unpackerParameters);
00054   } 
00055   else {
00056     throw cms::Exception("InvalidParameter") << "DTUnpackingModule: dataType "
00057                                              << dataType << " is unknown";
00058   }
00059 
00060   inputLabel = ps.getParameter<InputTag>("inputLabel"); // default was: source
00061   useStandardFEDid_ = ps.getParameter<bool>("useStandardFEDid"); // default was: true
00062   minFEDid_ = ps.getUntrackedParameter<int>("minFEDid",770); // default: 770
00063   maxFEDid_ = ps.getUntrackedParameter<int>("maxFEDid",779); // default 779
00064   dqmOnly = ps.getParameter<bool>("dqmOnly"); // default: false
00065 
00066   if(!dqmOnly) {
00067     produces<DTDigiCollection>();
00068     produces<DTLocalTriggerCollection>();
00069   }
00070 }
00071 
00072 DTUnpackingModule::~DTUnpackingModule(){
00073   delete unpacker;
00074 }
00075 
00076 
00077 void DTUnpackingModule::produce(Event & e, const EventSetup& context){
00078 
00079   Handle<FEDRawDataCollection> rawdata;
00080   e.getByLabel(inputLabel, rawdata);
00081 
00082   if(!rawdata.isValid()){
00083     LogError("DTUnpackingModule::produce") << " unable to get raw data from the event" << endl;
00084     return;
00085   }
00086 
00087   // Get the mapping from the setup
00088   ESHandle<DTReadOutMapping> mapping;
00089   context.get<DTReadOutMappingRcd>().get(mapping);
00090   
00091   // Create the result i.e. the collections of MB Digis and SC local triggers
00092   auto_ptr<DTDigiCollection> detectorProduct(new DTDigiCollection);
00093   auto_ptr<DTLocalTriggerCollection> triggerProduct(new DTLocalTriggerCollection);
00094 
00095 
00096   // Loop over the DT FEDs
00097   int FEDIDmin = 0, FEDIDMax = 0;
00098   if (useStandardFEDid_){
00099     FEDIDmin = FEDNumbering::MINDTFEDID;
00100     FEDIDMax = FEDNumbering::MAXDTFEDID;
00101   }
00102   else {
00103     FEDIDmin = minFEDid_;
00104     FEDIDMax = maxFEDid_;
00105   }
00106   
00107   for (int id=FEDIDmin; id<=FEDIDMax; ++id){ 
00108     
00109     const FEDRawData& feddata = rawdata->FEDData(id);
00110     
00111     if (feddata.size()){
00112       
00113       // Unpack the data
00114       unpacker->interpretRawData(reinterpret_cast<const unsigned int*>(feddata.data()), 
00115                                  feddata.size(), id, mapping, detectorProduct, triggerProduct);
00116     }
00117   }
00118 
00119   // commit to the event  
00120   if(!dqmOnly) {
00121     e.put(detectorProduct);
00122     e.put(triggerProduct);
00123   }
00124 }
00125