#ifndef GET4_MESSAGE_H #define GET4_MESSAGE_H #include "base/Message.h" #include namespace get4 { enum SysMessageTypesGet4 { SYSMSG_GET4V1_32BIT_0 = 240, // Get4 V1.0, 32bit mode, Raw messages chip 0 link 1 SYSMSG_GET4V1_32BIT_1 = 241, // Get4 V1.0, 32bit mode, Raw messages chip 1 link 1 SYSMSG_GET4V1_32BIT_2 = 242, // Get4 V1.0, 32bit mode, Raw messages chip 2 link 1 SYSMSG_GET4V1_32BIT_3 = 243, // Get4 V1.0, 32bit mode, Raw messages chip 3 link 1 SYSMSG_GET4V1_32BIT_4 = 244, // Get4 V1.0, 32bit mode, Raw messages chip 4 link 1 SYSMSG_GET4V1_32BIT_5 = 245, // Get4 V1.0, 32bit mode, Raw messages chip 5 link 1 SYSMSG_GET4V1_32BIT_6 = 246, // Get4 V1.0, 32bit mode, Raw messages chip 6 link 1 SYSMSG_GET4V1_32BIT_7 = 247, // Get4 V1.0, 32bit mode, Raw messages chip 7 link 1 SYSMSG_GET4V1_32BIT_8 = 248, // Get4 V1.0, 32bit mode, Raw messages chip 0 link 2 SYSMSG_GET4V1_32BIT_9 = 249, // Get4 V1.0, 32bit mode, Raw messages chip 1 link 2 SYSMSG_GET4V1_32BIT_10 = 250, // Get4 V1.0, 32bit mode, Raw messages chip 2 link 2 SYSMSG_GET4V1_32BIT_11 = 251, // Get4 V1.0, 32bit mode, Raw messages chip 3 link 2 SYSMSG_GET4V1_32BIT_12 = 252, // Get4 V1.0, 32bit mode, Raw messages chip 4 link 2 SYSMSG_GET4V1_32BIT_13 = 253, // Get4 V1.0, 32bit mode, Raw messages chip 5 link 2 SYSMSG_GET4V1_32BIT_14 = 254, // Get4 V1.0, 32bit mode, Raw messages chip 6 link 2 SYSMSG_GET4V1_32BIT_15 = 255 // Get4 V1.0, 32bit mode, Raw messages chip 7 link 2 }; enum MessageTypes32 { MSG_GET4_EPOCH = 0, MSG_GET4_SLOWCTRL = 1, MSG_GET4_ERROR = 2, MSG_GET4_HIT = 3 }; class Message : public base::Message { public: Message() : base::Message() {} inline bool assign(void* src, int fmt = base::formatNormal) { switch (fmt) { case base::formatEth2: memcpy(&data, src, 6); return true; case base::formatOptic2: data = (*((uint64_t*) src) >> 16) | (*((uint64_t*) src) << 48); // memcpy(&data, (uint8_t*) src + 2, 6); // setRocNumber(*((uint16_t*) src)); return true; case base::formatNormal: memcpy(&data, src, 8); return true; } return false; } // ---------- 24bit Epoch2 marker access methods ------------ ///> 12; } ///> shift) & ((1 << len) - 1); } inline uint8_t getBitBE(unsigned shift) const { return (dataBE() >> shift) & 1; } inline uint64_t dataBE() const { return ( ((uint64_t) getField( 0, 8) & 0x00000000000000FFLU)<<56)+ ( ((uint64_t) getField( 0, 16) & 0x000000000000FF00LU)<<40)+ ( ((uint64_t) getField( 0, 24) & 0x0000000000FF0000LU)<<24)+ ( (((uint64_t)getField( 8, 24) <<8) & 0x00000000FF000000LU)<< 8)+ ( (((uint64_t)getField(16, 24))<<8) & 0x00000000FF000000LU)+ ( ((uint64_t) getField(24, 24) )& 0x0000000000FF0000LU)+ ( ((uint64_t) getField(40, 16) )& 0x000000000000FF00LU)+ ( ((uint64_t) getField(56, 8) )& 0x00000000000000FFLU); } /** \brief Returns true, when 32-bit read message is detected */ inline bool isGet4V10R32() const { return (getMessageType() == base::MSG_SYS) && (getSysMesType() >= SYSMSG_GET4V1_32BIT_0); } inline bool is32bitEpoch2() const { return isGet4V10R32() && (getGet4V10R32MessageType() == MSG_GET4_EPOCH); } inline bool is32bitSlow() const { return isGet4V10R32() && (getGet4V10R32MessageType() == MSG_GET4_SLOWCTRL); } inline bool is32bitError() const { return isGet4V10R32() && (getGet4V10R32MessageType() == MSG_GET4_ERROR); } inline bool is32bitHit() const { return isGet4V10R32() && (getGet4V10R32MessageType() == MSG_GET4_HIT); } inline uint8_t getGet4V10R32ChipId() const { return getSysMesType() & 0xF; } inline uint8_t getGet4V10R32MessageType() const { return getFieldBE(46, 2); } // type 0 => Epoch message inline uint32_t getGet4V10R32EpochNumber() const { return getFieldBE(17,24); } inline uint8_t getGet4V10R32SyncFlag() const { return getBitBE(16); } // type 1 => Slow control inline uint32_t getGet4V10R32SlData() const { return getFieldBE(16, 24); } inline uint8_t getGet4V10R32SlType() const { return getFieldBE(40, 2); } inline uint8_t getGet4V10R32SlEdge() const { return getBitBE(42); } inline uint8_t getGet4V10R32SlChan() const { return getFieldBE(43, 2); } // type 2 => Error message inline uint8_t getGet4V10R32ErrorData() const { return getFieldBE(16, 7); } inline uint8_t getGet4V10R32ErrorChan() const { return getFieldBE(42, 2); } inline uint8_t getGet4V10R32ErrorEdge() const { return getBitBE(44); } // type 3 => Hit Data inline uint8_t getGet4V10R32HitTot() const { return getFieldBE(16, 8); } inline uint8_t getGet4V10R32HitFt() const { return getFieldBE(24, 7); } inline uint32_t getGet4V10R32HitTs() const { return getFieldBE(31,12); } inline uint32_t getGet4V10R32HitTimeBin() const { return getFieldBE(24,19); } inline uint8_t getGet4V10R32HitChan() const { return getFieldBE(43, 2); } inline uint8_t getGet4V10R32HitDllFlag() const { return getBitBE(45); } void printData(unsigned kind = base::msg_print_Prefix | base::msg_print_Data, uint32_t epoch = 0, double localtm = 0) const; void printData(std::ostream& os, unsigned kind = base::msg_print_Human, uint32_t epoch = 0, double localtm = 0) const; }; } #endif