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 
0006 #ifndef JANA2_DETECTORMESSAGE_H
0007 #define JANA2_DETECTORMESSAGE_H
0008 
0009 #include <string>
0010 #include <chrono>
0011 #include <JANA/Streaming/JMessage.h>
0012 #include <JANA/JException.h>
0013 #include <JANA/JException.h>
0014 #include <cstring>
0015 
0016 struct ReadoutMessageAuto : public JEventMessage {
0017 
0018     static const size_t MAX_PAYLOAD_SIZE = 100;
0019 
0020     uint32_t run_number;
0021     uint32_t event_number;
0022     uint32_t payload_size = 0;
0023     float payload[MAX_PAYLOAD_SIZE];
0024 
0025 public:
0026     /// JMessage requires that we expose this as a raw byte array
0027 
0028     inline char* as_buffer() override { return reinterpret_cast<char*>(this); }
0029     inline const char* as_buffer() const override { return reinterpret_cast<const char*>(this); }
0030 
0031     inline size_t get_buffer_capacity() const override { return sizeof(*this); }
0032     inline bool is_end_of_stream() const override { return event_number == 0 && run_number == 0 && payload_size == 0; }
0033 
0034     inline void set_end_of_stream() {
0035         event_number = 0;
0036         run_number = 0;
0037         payload_size = 0;
0038     }
0039 
0040     inline size_t get_event_number() const override { return event_number; }
0041     inline size_t get_run_number() const override { return run_number; }
0042 
0043     ReadoutMessageAuto(JApplication*) {
0044     }
0045 
0046     inline friend std::ostream& operator<< (std::ostream& os, const ReadoutMessageAuto& msg) {
0047         std::stringstream ss;
0048         ss << msg.event_number << ": ";
0049         for (size_t i = 0; i < msg.payload_size; ++i) {
0050             ss << msg.payload[i] << ", ";
0051         }
0052         os << ss.str();
0053         return os;
0054     }
0055 
0056 };
0057 
0058 
0059 #endif //JANA2_DETECTORMESSAGE_H