Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-08-25 01:53:27

0001 /****************************************************************************
0002 *
0003 * This is a part of TOTEM offline software.
0004 * Authors:
0005 *   Jan Kašpar (jan.kaspar@gmail.com)
0006 *   Nicola Minafra
0007 *   Laurent Forthomme
0008 *
0009 ****************************************************************************/
0010 
0011 #include "FWCore/Framework/interface/stream/EDProducer.h"
0012 #include "FWCore/Framework/interface/Event.h"
0013 #include "FWCore/Framework/interface/MakerMacros.h"
0014 #include "FWCore/Utilities/interface/InputTag.h"
0015 #include "FWCore/Framework/interface/ESHandle.h"
0016 #include "FWCore/Framework/interface/EventSetup.h"
0017 #include "FWCore/Utilities/interface/ESGetToken.h"
0018 
0019 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0020 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0021 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0022 
0023 #include "DataFormats/CTPPSDigi/interface/TotemRPDigi.h"
0024 #include "DataFormats/CTPPSDigi/interface/TotemVFATStatus.h"
0025 #include "DataFormats/CTPPSDigi/interface/TotemFEDInfo.h"
0026 
0027 #include "CondFormats/DataRecord/interface/TotemReadoutRcd.h"
0028 #include "CondFormats/PPSObjects/interface/TotemDAQMapping.h"
0029 #include "CondFormats/PPSObjects/interface/TotemAnalysisMask.h"
0030 
0031 #include "EventFilter/CTPPSRawToDigi/interface/SimpleVFATFrameCollection.h"
0032 #include "EventFilter/CTPPSRawToDigi/interface/RawDataUnpacker.h"
0033 #include "EventFilter/CTPPSRawToDigi/interface/RawToDigiConverter.h"
0034 
0035 #include "DataFormats/CTPPSDigi/interface/TotemTimingDigi.h"
0036 #include "DataFormats/TotemReco/interface/TotemT2Digi.h"
0037 
0038 #include <string>
0039 
0040 class TotemVFATRawToDigi : public edm::stream::EDProducer<> {
0041 public:
0042   explicit TotemVFATRawToDigi(const edm::ParameterSet &);
0043   ~TotemVFATRawToDigi() override;
0044 
0045   void produce(edm::Event &, const edm::EventSetup &) override;
0046   void endStream() override;
0047 
0048 private:
0049   std::string subSystemName;
0050 
0051   enum { ssUndefined, ssTrackingStrip, ssTimingDiamond, ssTotemTiming, ssTotemT2 } subSystem;
0052 
0053   std::vector<unsigned int> fedIds;
0054 
0055   edm::EDGetTokenT<FEDRawDataCollection> fedDataToken;
0056   edm::ESGetToken<TotemDAQMapping, TotemReadoutRcd> totemMappingToken;
0057   edm::ESGetToken<TotemAnalysisMask, TotemReadoutRcd> analysisMaskToken;
0058 
0059   pps::RawDataUnpacker rawDataUnpacker;
0060   RawToDigiConverter rawToDigiConverter;
0061 
0062   template <typename DigiType>
0063   void run(edm::Event &, const edm::EventSetup &);
0064 };
0065 
0066 using namespace edm;
0067 using namespace std;
0068 
0069 TotemVFATRawToDigi::TotemVFATRawToDigi(const edm::ParameterSet &conf)
0070     : subSystemName(conf.getParameter<string>("subSystem")),
0071       subSystem(ssUndefined),
0072       fedIds(conf.getParameter<vector<unsigned int>>("fedIds")),
0073       rawDataUnpacker(conf.getParameterSet("RawUnpacking")),
0074       rawToDigiConverter(conf.getParameterSet("RawToDigi")) {
0075   fedDataToken = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("rawDataTag"));
0076 
0077   // validate chosen subSystem
0078   if (subSystemName == "TrackingStrip")
0079     subSystem = ssTrackingStrip;
0080   else if (subSystemName == "TimingDiamond")
0081     subSystem = ssTimingDiamond;
0082   else if (subSystemName == "TotemTiming")
0083     subSystem = ssTotemTiming;
0084   else if (subSystemName == "TotemT2")
0085     subSystem = ssTotemT2;
0086 
0087   if (subSystem == ssUndefined)
0088     throw cms::Exception("TotemVFATRawToDigi::TotemVFATRawToDigi")
0089         << "Unknown sub-system string " << subSystemName << "." << endl;
0090 
0091   // FED (OptoRx) headers and footers
0092   produces<vector<TotemFEDInfo>>(subSystemName);
0093 
0094   // declare products
0095   if (subSystem == ssTrackingStrip)
0096     produces<DetSetVector<TotemRPDigi>>(subSystemName);
0097 
0098   else if (subSystem == ssTimingDiamond)
0099     produces<DetSetVector<CTPPSDiamondDigi>>(subSystemName);
0100 
0101   else if (subSystem == ssTotemTiming)
0102     produces<DetSetVector<TotemTimingDigi>>(subSystemName);
0103 
0104   else if (subSystem == ssTotemT2)
0105     produces<edmNew::DetSetVector<TotemT2Digi>>(subSystemName);
0106 
0107   // set default IDs
0108   if (fedIds.empty()) {
0109     if (subSystem == ssTrackingStrip) {
0110       for (int id = FEDNumbering::MINTotemRPHorizontalFEDID; id <= FEDNumbering::MAXTotemRPHorizontalFEDID; ++id)
0111         fedIds.push_back(id);
0112 
0113       for (int id = FEDNumbering::MINTotemRPVerticalFEDID; id <= FEDNumbering::MAXTotemRPVerticalFEDID; ++id)
0114         fedIds.push_back(id);
0115     }
0116 
0117     else if (subSystem == ssTimingDiamond) {
0118       for (int id = FEDNumbering::MINCTPPSDiamondFEDID; id <= FEDNumbering::MAXCTPPSDiamondFEDID; ++id)
0119         fedIds.push_back(id);
0120     }
0121 
0122     else if (subSystem == ssTotemTiming) {
0123       for (int id = FEDNumbering::MINTotemRPTimingVerticalFEDID; id <= FEDNumbering::MAXTotemRPTimingVerticalFEDID;
0124            ++id)
0125         fedIds.push_back(id);
0126     }
0127 
0128     else if (subSystem == ssTotemT2) {
0129       for (int id = FEDNumbering::MINTotemT2FEDID; id < FEDNumbering::MAXTotemT2FEDID; ++id)
0130         fedIds.push_back(id);
0131     }
0132   }
0133 
0134   // conversion status
0135   produces<DetSetVector<TotemVFATStatus>>(subSystemName);
0136 
0137   totemMappingToken = esConsumes<TotemDAQMapping, TotemReadoutRcd>(ESInputTag("", subSystemName));
0138   analysisMaskToken = esConsumes<TotemAnalysisMask, TotemReadoutRcd>(ESInputTag("", subSystemName));
0139 }
0140 
0141 TotemVFATRawToDigi::~TotemVFATRawToDigi() {}
0142 
0143 void TotemVFATRawToDigi::produce(edm::Event &event, const edm::EventSetup &es) {
0144   if (subSystem == ssTrackingStrip)
0145     run<DetSetVector<TotemRPDigi>>(event, es);
0146 
0147   else if (subSystem == ssTimingDiamond)
0148     run<DetSetVector<CTPPSDiamondDigi>>(event, es);
0149 
0150   else if (subSystem == ssTotemTiming)
0151     run<DetSetVector<TotemTimingDigi>>(event, es);
0152 
0153   else if (subSystem == ssTotemT2)
0154     run<edmNew::DetSetVector<TotemT2Digi>>(event, es);
0155 }
0156 
0157 template <typename DigiType>
0158 void TotemVFATRawToDigi::run(edm::Event &event, const edm::EventSetup &es) {
0159   // get DAQ mapping
0160   ESHandle<TotemDAQMapping> mapping = es.getHandle(totemMappingToken);
0161 
0162   // get analysis mask to mask channels
0163   ESHandle<TotemAnalysisMask> analysisMask = es.getHandle(analysisMaskToken);
0164 
0165   // raw data handle
0166   edm::Handle<FEDRawDataCollection> rawData;
0167   event.getByToken(fedDataToken, rawData);
0168 
0169   // book output products
0170   vector<TotemFEDInfo> fedInfo;
0171   DigiType digi;
0172   DetSetVector<TotemVFATStatus> conversionStatus;
0173 
0174   // raw-data unpacking
0175   SimpleVFATFrameCollection vfatCollection;
0176   for (const auto &fedId : fedIds) {
0177     const FEDRawData &data = rawData->FEDData(fedId);
0178     if (data.size() > 0)
0179       rawDataUnpacker.run(fedId, data, fedInfo, vfatCollection);
0180   }
0181 
0182   // raw-to-digi conversion
0183   rawToDigiConverter.run(vfatCollection, *mapping, *analysisMask, digi, conversionStatus);
0184 
0185   // commit products to event
0186   event.put(make_unique<vector<TotemFEDInfo>>(fedInfo), subSystemName);
0187   event.put(make_unique<DigiType>(digi), subSystemName);
0188   event.put(make_unique<DetSetVector<TotemVFATStatus>>(conversionStatus), subSystemName);
0189 }
0190 
0191 void TotemVFATRawToDigi::endStream() { rawToDigiConverter.printSummaries(); }
0192 
0193 DEFINE_FWK_MODULE(TotemVFATRawToDigi);