Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:17:19

0001 
0002 // Copyright 2020, Jefferson Science Associates, LLC.
0003 // Subject to the terms in the LICENSE file found in the top-level directory.
0004 
0005 #ifndef JANA2_DETECTORMESSAGE_H
0006 #define JANA2_DETECTORMESSAGE_H
0007 
0008 #include <string>
0009 #include <chrono>
0010 #include <JANA/Streaming/JMessage.h>
0011 #include <JANA/JException.h>
0012 #include <cstring>
0013 
0014 /// If we know that both our producer and our consumer were compiled with the same
0015 /// compiler and running on architectures with the same endianness, it is probably
0016 /// safe (and certainly more convenient) to create JMessages like ReadoutMessageAuto.
0017 /// However, if we can't make these assumptions, or if we want to explicitly control
0018 /// where each individual byte goes, we design our JMessage like this instead:
0019 
0020 class ReadoutMessageManual : public JEventMessage {
0021 
0022     /// Under the hood, ReadoutMessage is just a fixed-size buffer of char.
0023     /// We use getter and setter methods to create a 'view' into this buffer
0024     /// which automatically does the unpacking.
0025     static const size_t BUFFER_SIZE = 1024;
0026     char m_buffer[BUFFER_SIZE];
0027     size_t m_data_size;
0028 
0029 public:
0030     /// Supplying the missing virtual functions needed to send the buffer over the wire
0031 
0032     inline char* as_buffer() override { return m_buffer; }
0033     inline size_t get_buffer_size() override { return BUFFER_SIZE; }
0034     inline size_t get_data_size() override { return BUFFER_SIZE; } // TODO: This is more complicated
0035     inline bool is_end_of_stream() override { return get_source_id() == 0 && get_message_id() == 0 && get_payload_size() == 0; }
0036 
0037     ReadoutMessage end_of_stream() override { return {}; }
0038 
0039 
0040     /// Exposing ReadoutMessage to us as a high-level object
0041 
0042     ReadoutMessage(uint32_t source_id = 0, uint32_t message_id = 0) {
0043         set_source_id(source_id);
0044         set_message_id(message_id);
0045     }
0046 
0047     inline friend std::ostream& operator<< (std::ostream& os, const ReadoutMessage& msg) {
0048         std::stringstream ss;
0049         ss << msg.message_id << ": ";
0050         for (int i=0; i<5 && i<N; ++i) {
0051             ss << msg.payload[i] << ", ";
0052         }
0053         ss << "...";
0054         os << ss.str();
0055         return os;
0056     }
0057 
0058     inline size_t get_event_number() override {
0059         return 0;
0060     }
0061 
0062     inline size_t get_run_number() override {
0063         return 0;
0064     }
0065 
0066 };
0067 
0068 
0069 #endif //JANA2_DETECTORMESSAGE_H