Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:31

0001 /** \file
0002  *
0003  *  \author S. Argiro - N. Amapane - M. Zanetti 
0004  * FRC 060906
0005  */
0006 
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 
0009 #include <FWCore/Framework/interface/Event.h>
0010 #include <DataFormats/Common/interface/Handle.h>
0011 #include <FWCore/Framework/interface/ESHandle.h>
0012 #include <FWCore/Framework/interface/EventSetup.h>
0013 #include <FWCore/ParameterSet/interface/ParameterSet.h>
0014 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0016 
0017 #include <EventFilter/DTRawToDigi/plugins/DTUnpackingModule.h>
0018 #include <DataFormats/DTDigi/interface/DTControlData.h>
0019 
0020 #include <DataFormats/FEDRawData/interface/FEDRawData.h>
0021 #include <DataFormats/FEDRawData/interface/FEDNumbering.h>
0022 #include <DataFormats/DTDigi/interface/DTDigiCollection.h>
0023 #include <DataFormats/DTDigi/interface/DTLocalTriggerCollection.h>
0024 
0025 #include <EventFilter/DTRawToDigi/plugins/DTDDUUnpacker.h>
0026 #include <EventFilter/DTRawToDigi/plugins/DTROS25Unpacker.h>
0027 #include <EventFilter/DTRawToDigi/plugins/DTROS8Unpacker.h>
0028 
0029 using namespace edm;
0030 using namespace std;
0031 
0032 #define SLINK_WORD_SIZE 8
0033 
0034 DTUnpackingModule::DTUnpackingModule(const edm::ParameterSet& ps) : unpacker(nullptr), dataType("") {
0035   dataType = ps.getParameter<string>("dataType");
0036 
0037   ParameterSet unpackerParameters = ps.getParameter<ParameterSet>("readOutParameters");
0038 
0039   if (dataType == "DDU") {
0040     unpacker = new DTDDUUnpacker(unpackerParameters);
0041   } else if (dataType == "ROS25") {
0042     unpacker = new DTROS25Unpacker(unpackerParameters.getParameter<ParameterSet>("rosParameters"));
0043   } else if (dataType == "ROS8") {
0044     unpacker = new DTROS8Unpacker(unpackerParameters);
0045   } else {
0046     throw cms::Exception("InvalidParameter") << "DTUnpackingModule: dataType " << dataType << " is unknown";
0047   }
0048 
0049   inputLabel = consumes<FEDRawDataCollection>(ps.getParameter<InputTag>("inputLabel"));  // default was: source
0050   mappingToken_ = esConsumes<DTReadOutMapping, DTReadOutMappingRcd>();
0051   useStandardFEDid_ = ps.getParameter<bool>("useStandardFEDid");  // default was: true
0052   minFEDid_ = ps.getUntrackedParameter<int>("minFEDid", 770);     // default: 770
0053   maxFEDid_ = ps.getUntrackedParameter<int>("maxFEDid", 779);     // default 779
0054   dqmOnly = ps.getParameter<bool>("dqmOnly");                     // default: false
0055   performDataIntegrityMonitor =
0056       unpackerParameters.getUntrackedParameter<bool>("performDataIntegrityMonitor", false);  // default: false
0057 
0058   if (!dqmOnly) {
0059     produces<DTDigiCollection>();
0060     produces<DTLocalTriggerCollection>();
0061   }
0062   if (performDataIntegrityMonitor) {
0063     produces<std::vector<DTDDUData>>();
0064     produces<std::vector<std::vector<DTROS25Data>>>();
0065   }
0066 }
0067 
0068 DTUnpackingModule::~DTUnpackingModule() { delete unpacker; }
0069 
0070 void DTUnpackingModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0071   edm::ParameterSetDescription desc;
0072   desc.add<std::string>("dataType", "DDU");
0073   desc.add<edm::InputTag>("inputLabel", edm::InputTag("rawDataCollector"));
0074   desc.add<bool>("useStandardFEDid", true);
0075   desc.addUntracked<int>("minFEDid", 770);
0076   desc.addUntracked<int>("maxFEDid", 779);
0077   desc.addOptional<bool>("fedbyType");  // never used, only kept here for back-compatibility
0078   {
0079     edm::ParameterSetDescription psd0;
0080     psd0.addUntracked<bool>("debug", false);
0081     {
0082       edm::ParameterSetDescription psd1;
0083       psd1.addUntracked<bool>("writeSC", true);
0084       psd1.addUntracked<bool>("readingDDU", true);
0085       psd1.addUntracked<bool>("performDataIntegrityMonitor", false);
0086       psd1.addUntracked<bool>("readDDUIDfromDDU", true);
0087       psd1.addUntracked<bool>("debug", false);
0088       psd1.addUntracked<bool>("localDAQ", false);
0089       psd0.add<edm::ParameterSetDescription>("rosParameters", psd1);
0090     }
0091     psd0.addUntracked<bool>("performDataIntegrityMonitor", false);
0092     psd0.addUntracked<bool>("localDAQ", false);
0093     desc.add<edm::ParameterSetDescription>("readOutParameters", psd0);
0094   }
0095   desc.add<bool>("dqmOnly", false);
0096   descriptions.add("dtUnpackingModule", desc);
0097 }
0098 
0099 void DTUnpackingModule::produce(Event& e, const EventSetup& context) {
0100   Handle<FEDRawDataCollection> rawdata;
0101   e.getByToken(inputLabel, rawdata);
0102 
0103   if (!rawdata.isValid()) {
0104     LogError("DTUnpackingModule::produce") << " unable to get raw data from the event" << endl;
0105     return;
0106   }
0107 
0108   // Get the mapping from the setup
0109   ESHandle<DTReadOutMapping> mapping = context.getHandle(mappingToken_);
0110 
0111   // Create the result i.e. the collections of MB Digis and SC local triggers
0112   auto detectorProduct = std::make_unique<DTDigiCollection>();
0113   auto triggerProduct = std::make_unique<DTLocalTriggerCollection>();
0114 
0115   auto dduProduct = std::make_unique<std::vector<DTDDUData>>();
0116   auto ros25Product = std::make_unique<DTROS25Collection>();
0117 
0118   // Loop over the DT FEDs
0119   int FEDIDmin = 0, FEDIDMax = 0;
0120   if (useStandardFEDid_) {
0121     FEDIDmin = FEDNumbering::MINDTFEDID;
0122     FEDIDMax = FEDNumbering::MAXDTFEDID;
0123   } else {
0124     FEDIDmin = minFEDid_;
0125     FEDIDMax = maxFEDid_;
0126   }
0127 
0128   for (int id = FEDIDmin; id <= FEDIDMax; ++id) {
0129     const FEDRawData& feddata = rawdata->FEDData(id);
0130 
0131     if (feddata.size()) {
0132       // Unpack the data
0133       unpacker->interpretRawData(reinterpret_cast<const unsigned int*>(feddata.data()),
0134                                  feddata.size(),
0135                                  id,
0136                                  mapping,
0137                                  detectorProduct,
0138                                  triggerProduct);
0139       if (performDataIntegrityMonitor) {
0140         if (dataType == "DDU") {
0141           dduProduct->push_back(dynamic_cast<DTDDUUnpacker*>(unpacker)->getDDUControlData());
0142           ros25Product->push_back(dynamic_cast<DTDDUUnpacker*>(unpacker)->getROSsControlData());
0143         } else if (dataType == "ROS25") {
0144           ros25Product->push_back(dynamic_cast<DTROS25Unpacker*>(unpacker)->getROSsControlData());
0145         }
0146       }
0147     }
0148   }
0149 
0150   // commit to the event
0151   if (!dqmOnly) {
0152     e.put(std::move(detectorProduct));
0153     e.put(std::move(triggerProduct));
0154   }
0155   if (performDataIntegrityMonitor) {
0156     e.put(std::move(dduProduct));
0157     e.put(std::move(ros25Product));
0158   }
0159 }