Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /****************************************************************************
0002  *
0003  * This is a part of HGCAL offline software.
0004  * Authors:
0005  *   Laurent Forthomme, CERN
0006  *
0007  ****************************************************************************/
0008 
0009 #ifndef EventFilter_HGCalRawToDigi_HGCalFrameGenerator_h
0010 #define EventFilter_HGCalRawToDigi_HGCalFrameGenerator_h
0011 
0012 #include "DataFormats/HGCalDigi/interface/HGCalRawDataEmulatorInfo.h"
0013 #include "EventFilter/HGCalRawToDigi/interface/HGCalECONDEmulatorParameters.h"
0014 #include "EventFilter/HGCalRawToDigi/interface/SlinkTypes.h"
0015 
0016 #include <cstdint>
0017 #include <vector>
0018 
0019 namespace edm {
0020   class ParameterSet;
0021   class ParameterSetDescription;
0022 }  // namespace edm
0023 namespace CLHEP {
0024   class HepRandomEngine;
0025 }
0026 
0027 namespace hgcal {
0028   namespace econd {
0029     class Emulator;
0030   }
0031   /// A S-link/ECON-D payload generator helper
0032   class HGCalFrameGenerator {
0033   public:
0034     explicit HGCalFrameGenerator(const edm::ParameterSet&);
0035 
0036     static edm::ParameterSetDescription description();
0037 
0038     /// Set the random number generator engine
0039     void setRandomEngine(CLHEP::HepRandomEngine& rng);
0040     /// Set the emulation source for ECON-D frames
0041     void setEmulator(econd::Emulator&);
0042 
0043     /// Produce a S-link event from an emulated event
0044     std::vector<uint64_t> produceSlinkEvent(unsigned int fed_id) const;
0045     /// Produce a capture block from an emulated event
0046     /// \params[in] cb_id capture block identifier
0047     std::vector<uint64_t> produceCaptureBlockEvent(unsigned int cb_id) const;
0048     /// Produce a ECON-D event from an emulated event
0049     /// \param[in] econd_id ECON-D identifier
0050     /// \param[in] cb_id capture block identifier
0051     std::vector<uint64_t> produceECONEvent(unsigned int econd_id, unsigned int cb_id = 0) const;
0052 
0053     /// Retrieve the last ECON-D event emulated
0054     const econd::ECONDInput& lastECONDEmulatedInput() const { return last_emul_event_; }
0055     /// Retrieve the metadata generated along with the last S-link emulated payload
0056     const HGCalSlinkEmulatorInfo& lastSlinkEmulatedInfo() const { return last_slink_emul_info_; }
0057 
0058     /// List of S-link operational parameters for emulation
0059     struct SlinkParameters {
0060       std::vector<unsigned int> active_econds{};
0061       unsigned int boe_marker{0}, eoe_marker{0}, format_version{0}, num_capture_blocks{1};
0062       bool store_header_trailer{true};
0063     };
0064     /// List of S-link operational parameters for emulation
0065     const SlinkParameters& slinkParams() const { return slink_params_; }
0066     /// List of ECON-D operational parameters for emulation
0067     const std::map<unsigned int, econd::EmulatorParameters>& econdParams() const { return econd_params_; }
0068 
0069   private:
0070     econd::ERxChannelEnable generateEnabledChannels(unsigned int) const;
0071     std::vector<uint32_t> generateERxData(unsigned int,
0072                                           const econd::ERxInput&,
0073                                           std::vector<econd::ERxChannelEnable>&) const;
0074 
0075     static constexpr size_t kMaxNumECONDs = 12;
0076 
0077     struct HeaderBits {
0078       bool bitO, bitB, bitE, bitT, bitH, bitS;
0079     };
0080     HeaderBits generateStatusBits(unsigned int) const;
0081     /// 32bit CRC
0082     uint32_t computeCRC(const std::vector<uint32_t>&) const;
0083 
0084     SlinkParameters slink_params_;
0085     std::map<unsigned int, econd::EmulatorParameters> econd_params_;
0086 
0087     CLHEP::HepRandomEngine* rng_{nullptr};    // NOT owning
0088     mutable econd::Emulator* emul_{nullptr};  // NOT owning
0089 
0090     mutable HGCalSlinkEmulatorInfo last_slink_emul_info_;
0091     mutable econd::ECONDInput last_emul_event_;
0092   };
0093 }  // namespace hgcal
0094 
0095 #endif