1717
1818#include < gsl/span>
1919#include < unordered_set>
20+ #include < unordered_map>
2021
2122#include " Headers/RDHAny.h"
2223#include " MCHBase/Digit.h"
@@ -40,17 +41,62 @@ struct OrbitInfoHash {
4041 }
4142};
4243
44+ void dumpOrbits (const std::unordered_set<OrbitInfo, OrbitInfoHash>& mOrbits );
45+
4346// _________________________________________________________________
4447//
4548// Data decoder
4649// _________________________________________________________________
4750class DataDecoder
4851{
4952 public:
53+ struct SampaInfo {
54+ union {
55+ uint32_t id = 0 ;
56+ struct {
57+ uint32_t chip : 1 ;
58+ uint32_t ds : 6 ;
59+ uint32_t solar : 16 ;
60+ uint32_t unused : 9 ;
61+ };
62+ };
63+
64+ union {
65+ // default value
66+ uint64_t time = 0x0000000000000000 ;
67+ struct { // /
68+ uint32_t sampaTime : 10 ; // / bit 0 to 9: sampa time
69+ uint32_t bunchCrossing : 20 ; // / bit 10 to 29: bunch crossing counter
70+ uint32_t reserved : 2 ; // / bit 30 to 31: reserved
71+ uint32_t orbit; // / bit 32 to 63: orbit
72+ }; // /
73+ };
74+ uint32_t getBXTime ()
75+ {
76+ return (bunchCrossing + (sampaTime * 4 ));
77+ }
78+ };
79+
80+ struct SampaTimeFrameStart {
81+ SampaTimeFrameStart (uint32_t orbit, uint32_t bunchCrossing) : mOrbit (orbit), mBunchCrossing (bunchCrossing) {}
82+
83+ uint32_t mOrbit {0 };
84+ int32_t mBunchCrossing {0 };
85+ };
86+
87+ using SampaTimeFrameStarts = std::unordered_map<uint32_t , std::optional<SampaTimeFrameStart>>;
88+
5089 DataDecoder (SampaChannelHandler channelHandler, RdhHandler rdhHandler, std::string mapCRUfile, std::string mapFECfile, bool ds2manu, bool verbose);
5190
5291 void reset ();
53- void decodeBuffer (gsl::span<const std::byte> page);
92+ void decodeBuffer (gsl::span<const std::byte> buf);
93+
94+ static int32_t digitsTimeDiff (uint32_t orbit1, uint32_t bc1, uint32_t orbit2, uint32_t bc2);
95+ static void computeDigitsTime_ (std::vector<o2::mch::Digit>& digits, std::vector<SampaInfo>& sampaInfo, SampaTimeFrameStarts& sampaTimeFrameStarts, bool debug);
96+ void computeDigitsTime ()
97+ {
98+ computeDigitsTime_ (mOutputDigits , mSampaInfos , mSampaTimeFrameStarts , mDebug );
99+ }
54100
55101 const std::vector<o2::mch::Digit>& getOutputDigits () const { return mOutputDigits ; }
56102 const std::unordered_set<OrbitInfo, OrbitInfoHash>& getOrbits () const { return mOrbits ; }
@@ -59,22 +105,28 @@ class DataDecoder
59105 void initElec2DetMapper (std::string filename);
60106 void initFee2SolarMapper (std::string filename);
61107 void init ();
108+ void decodePage (gsl::span<const std::byte> page);
109+ void dumpDigits (bool bending);
62110
63- Elec2DetMapper mElec2Det {nullptr };
64- FeeLink2SolarMapper mFee2Solar {nullptr };
65- o2::mch::raw::PageDecoder mDecoder ;
66- size_t mNrdhs {0 };
67- std::vector<o2::mch::Digit> mOutputDigits ;
68- std::unordered_set<OrbitInfo, OrbitInfoHash> mOrbits ; // /< list of orbits in the processed buffer
111+ Elec2DetMapper mElec2Det {nullptr }; // /< front-end electronics mapping
112+ FeeLink2SolarMapper mFee2Solar {nullptr }; // /< CRU electronics mapping
113+ std::string mMapFECfile ; // /< optional text file with custom front-end electronics mapping
114+ std::string mMapCRUfile ; // /< optional text file with custom CRU mapping
69115
70- SampaChannelHandler mChannelHandler ;
71- std::function<void (o2::header::RDHAny*)> mRdhHandler ;
116+ o2::mch::raw::PageDecoder mDecoder ; // /< CRU page decoder
117+
118+ std::vector<o2::mch::Digit> mOutputDigits ; // /< vector of decoded digits
119+ std::vector<SampaInfo> mSampaInfos ; // /< vector of auxiliary SampaInfo objects
120+
121+ std::unordered_set<OrbitInfo, OrbitInfoHash> mOrbits ; // /< list of orbits in the processed buffer
122+ SampaTimeFrameStarts mSampaTimeFrameStarts ; // /< time stamps of the TimeFrames in the processed buffer
72123
73- std::string mMapCRUfile ;
74- std::string mMapFECfile ;
124+ SampaChannelHandler mChannelHandler ; // /< optional user function to be called for each decoded SAMPA hit
125+ std::function< void (o2::header::RDHAny*)> mRdhHandler ; // /< optional user function to be called for each RDH
75126
76127 bool mDebug {false };
77128 bool mDs2manu {false };
129+ uint32_t mOrbit {0 };
78130};
79131
80132} // namespace raw
0 commit comments