Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 
0002 #ifndef EventFilter_SiStripRawToDigi_SiStripRawToDigiUnpacker_H
0003 #define EventFilter_SiStripRawToDigi_SiStripRawToDigiUnpacker_H
0004 
0005 #include "DataFormats/Common/interface/Handle.h"
0006 #include "DataFormats/Common/interface/DetSetVector.h"
0007 #include "DataFormats/DetId/interface/DetIdVector.h"
0008 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0009 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"
0010 #include "FWCore/Utilities/interface/Visibility.h"
0011 #include "WarningSummary.h"
0012 
0013 /// sistrip classes
0014 namespace sistrip {
0015   class RawToClustersLazyUnpacker;
0016 }
0017 namespace sistrip {
0018   class RawToDigiUnpacker;
0019 }
0020 
0021 /// other classes
0022 class FEDRawDataCollection;
0023 class FEDRawData;
0024 class SiStripDigi;
0025 class SiStripRawDigi;
0026 class SiStripEventSummary;
0027 class SiStripFedCabling;
0028 
0029 namespace sistrip {
0030 
0031   class dso_hidden RawToDigiUnpacker {
0032     friend class RawToClustersLazyUnpacker;
0033 
0034   public:
0035     typedef edm::DetSetVector<SiStripDigi> Digis;
0036     typedef edm::DetSetVector<SiStripRawDigi> RawDigis;
0037 
0038     /// constructor
0039     RawToDigiUnpacker(int16_t appended_bytes,
0040                       int16_t fed_buffer_dump_freq,
0041                       int16_t fed_event_dump_freq,
0042                       int16_t trigger_fed_id,
0043                       bool using_fed_key,
0044                       bool unpack_bad_channels,
0045                       bool mark_missing_feds,
0046                       const uint32_t errorThreshold);
0047 
0048     /// private default constructor
0049     RawToDigiUnpacker() = delete;
0050 
0051     /// default constructor
0052     ~RawToDigiUnpacker();
0053 
0054     /// creates digis
0055     void createDigis(const SiStripFedCabling&,
0056                      const FEDRawDataCollection&,
0057                      SiStripEventSummary&,
0058                      RawDigis& scope_mode,
0059                      RawDigis& virgin_raw,
0060                      RawDigis& proc_raw,
0061                      Digis& zero_suppr,
0062                      DetIdVector&,
0063                      RawDigis& common_mode);
0064 
0065     /// trigger info
0066     void triggerFed(const FEDRawDataCollection&, SiStripEventSummary&, const uint32_t& event);
0067 
0068     /// Removes any data appended prior to FED buffer and reorders 32-bit words if swapped.
0069     void locateStartOfFedBuffer(const uint16_t& fed_id, const FEDRawData& input, FEDRawData& output);
0070 
0071     /// verbosity
0072     inline void quiet(bool);
0073 
0074     /// EventSummary update request -> not yet implemented for FEDBuffer class
0075     inline void useDaqRegister(bool);
0076 
0077     inline void extractCm(bool);
0078 
0079     inline void doFullCorruptBufferChecks(bool);
0080 
0081     inline void doAPVEmulatorCheck(bool);
0082 
0083     inline void legacy(bool);
0084 
0085     void printWarningSummary() const { warnings_.printSummary(); }
0086 
0087   private:
0088     /// fill DetSetVectors using registries
0089     void update(
0090         RawDigis& scope_mode, RawDigis& virgin_raw, RawDigis& proc_raw, Digis& zero_suppr, RawDigis& common_mode);
0091 
0092     /// sets the SiStripEventSummary -> not yet implemented for FEDBuffer class
0093     void updateEventSummary(const sistrip::FEDBuffer&, SiStripEventSummary&);
0094 
0095     /// order of strips
0096     inline void readoutOrder(uint16_t& physical_order, uint16_t& readout_order);
0097 
0098     /// order of strips
0099     inline void physicalOrder(uint16_t& readout_order, uint16_t& physical_order);
0100 
0101     /// returns buffer format
0102     inline sistrip::FedBufferFormat fedBufferFormat(const uint16_t& register_value);
0103 
0104     /// returns buffer readout mode
0105     inline sistrip::FedReadoutMode fedReadoutMode(const uint16_t& register_value);
0106 
0107     /// dumps raw data to stdout (NB: payload is byte-swapped,headers/trailer are not).
0108     static void dumpRawData(uint16_t fed_id, const FEDRawData&, std::stringstream&);
0109 
0110     /// method to clear registries and digi collections
0111     void cleanupWorkVectors();
0112 
0113     /// private class to register start and end index of digis in a collection
0114     class Registry {
0115     public:
0116       /// constructor
0117       Registry(uint32_t aDetid, uint16_t firstStrip, size_t indexInVector, uint16_t numberOfDigis)
0118           : detid(aDetid), first(firstStrip), index(indexInVector), length(numberOfDigis) {}
0119       /// < operator to sort registries
0120       bool operator<(const Registry& other) const {
0121         return (detid != other.detid ? detid < other.detid : first < other.first);
0122       }
0123       /// public data members
0124       uint32_t detid;
0125       uint16_t first;
0126       size_t index;
0127       uint16_t length;
0128     };
0129 
0130     /// configurables
0131     int16_t headerBytes_;
0132     int16_t fedBufferDumpFreq_;
0133     int16_t fedEventDumpFreq_;
0134     int16_t triggerFedId_;
0135     bool useFedKey_;
0136     bool unpackBadChannels_;
0137     bool markMissingFeds_;
0138 
0139     /// other values
0140     uint32_t event_;
0141     bool once_;
0142     bool first_;
0143     bool useDaqRegister_;
0144     bool quiet_;
0145     bool extractCm_;
0146     bool doFullCorruptBufferChecks_;
0147     bool doAPVEmulatorCheck_;
0148     bool legacy_;
0149     uint32_t errorThreshold_;
0150 
0151     /// registries
0152     std::vector<Registry> zs_work_registry_;
0153     std::vector<Registry> virgin_work_registry_;
0154     std::vector<Registry> scope_work_registry_;
0155     std::vector<Registry> proc_work_registry_;
0156     std::vector<Registry> cm_work_registry_;
0157 
0158     /// digi collections
0159     std::vector<SiStripDigi> zs_work_digis_;
0160     std::vector<SiStripRawDigi> virgin_work_digis_;
0161     std::vector<SiStripRawDigi> scope_work_digis_;
0162     std::vector<SiStripRawDigi> proc_work_digis_;
0163     std::vector<SiStripRawDigi> cm_work_digis_;
0164 
0165     WarningSummary warnings_;
0166   };
0167 }  // namespace sistrip
0168 
0169 void sistrip::RawToDigiUnpacker::readoutOrder(uint16_t& physical_order, uint16_t& readout_order) {
0170   readout_order = (4 * ((static_cast<uint16_t>((static_cast<float>(physical_order) / 8.0))) % 4) +
0171                    static_cast<uint16_t>(static_cast<float>(physical_order) / 32.0) + 16 * (physical_order % 8));
0172 }
0173 
0174 void sistrip::RawToDigiUnpacker::physicalOrder(uint16_t& readout_order, uint16_t& physical_order) {
0175   physical_order = ((32 * (readout_order % 4)) + (8 * static_cast<uint16_t>(static_cast<float>(readout_order) / 4.0)) -
0176                     (31 * static_cast<uint16_t>(static_cast<float>(readout_order) / 16.0)));
0177 }
0178 
0179 sistrip::FedBufferFormat sistrip::RawToDigiUnpacker::fedBufferFormat(const uint16_t& register_value) {
0180   if ((register_value & 0xF) == 0x1) {
0181     return sistrip::FULL_DEBUG_FORMAT;
0182   } else if ((register_value & 0xF) == 0x2) {
0183     return sistrip::APV_ERROR_FORMAT;
0184   } else if ((register_value & 0xF) == 0x0) {
0185     return sistrip::UNDEFINED_FED_BUFFER_FORMAT;
0186   } else {
0187     return sistrip::UNKNOWN_FED_BUFFER_FORMAT;
0188   }
0189 }
0190 
0191 sistrip::FedReadoutMode sistrip::RawToDigiUnpacker::fedReadoutMode(const uint16_t& register_value) {
0192   return static_cast<sistrip::FedReadoutMode>(register_value & 0xF);
0193 }
0194 
0195 void sistrip::RawToDigiUnpacker::quiet(bool quiet) { quiet_ = quiet; }
0196 
0197 void sistrip::RawToDigiUnpacker::useDaqRegister(bool use) { useDaqRegister_ = use; }
0198 
0199 void sistrip::RawToDigiUnpacker::extractCm(bool extract_cm) { extractCm_ = extract_cm; }
0200 
0201 void sistrip::RawToDigiUnpacker::doFullCorruptBufferChecks(bool do_full_corrupt_buffer_checks) {
0202   doFullCorruptBufferChecks_ = do_full_corrupt_buffer_checks;
0203 }
0204 
0205 void sistrip::RawToDigiUnpacker::doAPVEmulatorCheck(bool do_APVEmulator_check) {
0206   doAPVEmulatorCheck_ = do_APVEmulator_check;
0207 }
0208 
0209 void sistrip::RawToDigiUnpacker::legacy(bool legacy) { legacy_ = legacy; }
0210 
0211 #endif  // EventFilter_SiStripRawToDigi_SiStripRawToDigiUnpacker_H