Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:02

0001 #include "SiStripDigiToRawModule.h"
0002 #include "SiStripDigiToRaw.h"
0003 
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "FWCore/Framework/interface/EventSetup.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/Utilities/interface/EDGetToken.h"
0010 #include "FWCore/Utilities/interface/InputTag.h"
0011 #include "DataFormats/Common/interface/Handle.h"
0012 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0013 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0015 #include <cstdlib>
0016 
0017 namespace sistrip {
0018 
0019   //fill Descriptions needed to define default parameters
0020   void DigiToRawModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0021     edm::ParameterSetDescription desc;
0022     desc.add<std::string>("FedReadoutMode", "ZERO_SUPPRESSED");
0023     desc.add<std::string>("PacketCode", "ZERO_SUPPRESSED");
0024     desc.add<bool>("UseFedKey", false);
0025     desc.add<bool>("UseWrongDigiType", false);
0026     desc.add<bool>("CopyBufferHeader", false);
0027     desc.add<edm::InputTag>("InputDigis", edm::InputTag("simSiStripDigis", "ZeroSuppressed"));
0028     desc.add<edm::InputTag>("RawDataTag", edm::InputTag("rawDataCollector"));
0029     descriptions.add("SiStripDigiToRawModule", desc);
0030   }
0031 
0032   // -----------------------------------------------------------------------------
0033   /** 
0034       Creates instance of DigiToRaw converter, defines EDProduct type.
0035   */
0036   DigiToRawModule::DigiToRawModule(const edm::ParameterSet& pset)
0037       : copyBufferHeader_(pset.getParameter<bool>("CopyBufferHeader")),
0038         mode_(fedReadoutModeFromString(pset.getParameter<std::string>("FedReadoutMode"))),
0039         packetCode_(packetCodeFromString(pset.getParameter<std::string>("PacketCode"), mode_)),
0040         rawdigi_(false),
0041         digiToRaw_(nullptr),
0042         eventCounter_(0),
0043         inputDigiTag_(pset.getParameter<edm::InputTag>("InputDigis")),
0044         rawDataTag_(pset.getParameter<edm::InputTag>("RawDataTag")),
0045         tokenCabling(esConsumes<SiStripFedCabling, SiStripFedCablingRcd>()) {
0046     if (edm::isDebugEnabled()) {
0047       LogDebug("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
0048                                   << " Constructing object...";
0049     }
0050 
0051     switch (mode_) {
0052       case READOUT_MODE_ZERO_SUPPRESSED:
0053         rawdigi_ = false;
0054         break;
0055       case READOUT_MODE_ZERO_SUPPRESSED_FAKE:
0056         rawdigi_ = false;
0057         break;
0058       case READOUT_MODE_ZERO_SUPPRESSED_LITE10:
0059         rawdigi_ = false;
0060         break;
0061       case READOUT_MODE_ZERO_SUPPRESSED_LITE10_CMOVERRIDE:
0062         rawdigi_ = false;
0063         break;
0064       case READOUT_MODE_ZERO_SUPPRESSED_LITE8:
0065         rawdigi_ = false;
0066         break;
0067       case READOUT_MODE_ZERO_SUPPRESSED_LITE8_CMOVERRIDE:
0068         rawdigi_ = false;
0069         break;
0070       case READOUT_MODE_ZERO_SUPPRESSED_LITE8_TOPBOT:
0071         rawdigi_ = false;
0072         break;
0073       case READOUT_MODE_ZERO_SUPPRESSED_LITE8_TOPBOT_CMOVERRIDE:
0074         rawdigi_ = false;
0075         break;
0076       case READOUT_MODE_ZERO_SUPPRESSED_LITE8_BOTBOT:
0077         rawdigi_ = false;
0078         break;
0079       case READOUT_MODE_ZERO_SUPPRESSED_LITE8_BOTBOT_CMOVERRIDE:
0080         rawdigi_ = false;
0081         break;
0082       case READOUT_MODE_PREMIX_RAW:
0083         rawdigi_ = false;
0084         break;
0085       case READOUT_MODE_VIRGIN_RAW:
0086         rawdigi_ = true;
0087         break;
0088       case READOUT_MODE_PROC_RAW:
0089         rawdigi_ = true;
0090         break;
0091       case READOUT_MODE_SCOPE:
0092         rawdigi_ = true;
0093         break;
0094       case READOUT_MODE_INVALID: {
0095         if (edm::isDebugEnabled()) {
0096           edm::LogWarning("DigiToRawModule")
0097               << "[sistrip::DigiToRawModule::DigiToRawModule]"
0098               << " UNKNOWN readout mode: " << pset.getParameter<std::string>("FedReadoutMode");
0099         }
0100       } break;
0101       case READOUT_MODE_SPY: {
0102         if (edm::isDebugEnabled()) {
0103           edm::LogWarning("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
0104                                              << " Digi to raw is not supported for spy channel data";
0105         }
0106       } break;
0107     }
0108     if (pset.getParameter<bool>("UseWrongDigiType")) {
0109       rawdigi_ = !rawdigi_;
0110       if (edm::isDebugEnabled()) {
0111         edm::LogWarning("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
0112                                            << " You are using the wrong type of digis!";
0113       }
0114     }
0115 
0116     // Create instance of DigiToRaw formatter
0117     digiToRaw_ = new DigiToRaw(mode_, packetCode_, pset.getParameter<bool>("UseFedKey"));
0118 
0119     if (rawdigi_) {
0120       tokenRawDigi = consumes<edm::DetSetVector<SiStripRawDigi> >(inputDigiTag_);
0121     } else {
0122       tokenDigi = consumes<edm::DetSetVector<SiStripDigi> >(inputDigiTag_);
0123     }
0124     if (copyBufferHeader_) {
0125       //CAMM input raw module label or same as digi ????
0126       if (edm::isDebugEnabled()) {
0127         edm::LogWarning("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
0128                                            << "Copying buffer header from collection " << rawDataTag_;
0129       }
0130       tokenRawBuffer = consumes<FEDRawDataCollection>(rawDataTag_);
0131     }
0132 
0133     produces<FEDRawDataCollection>();
0134   }
0135 
0136   // -----------------------------------------------------------------------------
0137   /** */
0138   DigiToRawModule::~DigiToRawModule() {
0139     if (edm::isDebugEnabled()) {
0140       LogDebug("DigiToRaw") << "[sistrip::DigiToRawModule::~DigiToRawModule]"
0141                             << " Destructing object...";
0142     }
0143     if (digiToRaw_)
0144       delete digiToRaw_;
0145   }
0146 
0147   // -----------------------------------------------------------------------------
0148   /** 
0149       Retrieves cabling map from EventSetup, retrieves a DetSetVector of
0150       SiStripDigis from Event, creates a FEDRawDataCollection
0151       (EDProduct), uses DigiToRaw converter to fill
0152       FEDRawDataCollection, attaches FEDRawDataCollection to Event.
0153   */
0154   void DigiToRawModule::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
0155     eventCounter_++;
0156 
0157     auto buffers = std::make_unique<FEDRawDataCollection>();
0158 
0159     edm::ESHandle<SiStripFedCabling> cabling = iSetup.getHandle(tokenCabling);
0160 
0161     //get buffer header from original rawdata
0162     edm::Handle<FEDRawDataCollection> rawbuffers;
0163     if (copyBufferHeader_) {
0164       if (edm::isDebugEnabled()) {
0165         edm::LogWarning("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
0166                                            << "Getting raw buffer: ";
0167       }
0168       try {
0169         iEvent.getByToken(tokenRawBuffer, rawbuffers);
0170       } catch (const cms::Exception& e) {
0171         if (edm::isDebugEnabled()) {
0172           edm::LogWarning("DigiToRawModule") << "[sistrip::DigiToRawModule::DigiToRawModule]"
0173                                              << " Failed to get collection " << rawDataTag_;
0174         }
0175       }
0176     }
0177 
0178     if (rawdigi_) {
0179       edm::Handle<edm::DetSetVector<SiStripRawDigi> > rawdigis;
0180       iEvent.getByToken(tokenRawDigi, rawdigis);
0181       if (copyBufferHeader_)
0182         digiToRaw_->createFedBuffers(iEvent, cabling, rawbuffers, rawdigis, buffers);
0183       else
0184         digiToRaw_->createFedBuffers(iEvent, cabling, rawdigis, buffers);
0185     } else {
0186       edm::Handle<edm::DetSetVector<SiStripDigi> > digis;
0187       iEvent.getByToken(tokenDigi, digis);
0188       if (copyBufferHeader_)
0189         digiToRaw_->createFedBuffers(iEvent, cabling, rawbuffers, digis, buffers);
0190       else
0191         digiToRaw_->createFedBuffers(iEvent, cabling, digis, buffers);
0192     }
0193 
0194     iEvent.put(std::move(buffers));
0195   }
0196 
0197   void DigiToRawModule::endStream() { digiToRaw_->printWarningSummary(); }
0198 }  // namespace sistrip