EventDecoder.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 //
3 // Decoder for the DAQ events for charg readout
4 // The general idea is to try to make this object threadsave when possible
5 //
6 //
7 //////////////////////////////////////////////////////////////////////////////////////
8 
9 #ifndef __EVENTDECODER_H__
10 #define __EVENTDECODER_H__
11 
12 // for mutexes
13 #include <pthread.h>
14 
15 #include "dlardaq.h"
16 
17 // for compressed data
18 #include "HuffDataCompressor.h"
19 
20 // max time to wait to receive data
21 #define TMAXWAIT 2
22 
23 namespace dlardaq
24 {
26  {
27  public:
28  EventDecoder(size_t nch, size_t nsample);
29  ~EventDecoder();
30 
31  void SetNCh(size_t val){ m_nch = val; }
32  void SetNSample(size_t val){ m_nsample = val; }
33 
34  size_t GetNCh() const { return m_nch; }
35  size_t GetNSample() const { return m_nsample; }
36 
37  // open input file
38  ssize_t Open(std::string finname);
39  void Close();
40 
41  // get a given event from fil
42  ssize_t GetEvent( size_t evnum, dlardaq::evheader_t &eh,
43  std::vector<adc16_t> &adc );
44 
45  // get event from buffer
46  ssize_t GetEvent( dlardaq::evheader_t &eh,
47  std::vector<adc16_t> &adc );
48 
49  // read event from online buffer
50  // and store data internally
51  void ReadBuffer(const char *buf, size_t nb);
52 
53 
54  //
55  bool Compressed() const { return m_dcflag; }
56 
57 
58  size_t GetTotEvents() const { return m_totev; }
59 
63 
64  std::ifstream m_file;
65 
66  protected:
67  int lock(pthread_mutex_t &mutex) { return pthread_mutex_lock(&mutex); }
68  int trylock(pthread_mutex_t &mutex) { return pthread_mutex_trylock(&mutex); }
69  int unlock(pthread_mutex_t &mutex) { return pthread_mutex_unlock(&mutex); }
70 
71 
72  // decode event bytes
73  void ReadEvent(std::vector<adc16_t> &adc, bool headonly = false);
74 
75  // read a byte fector from current position
76  void ReadBytes( std::vector<BYTE> &bytes );
77  ssize_t Decode( const char *buf, size_t nb, bool cflag,
78  std::vector<adc16_t> &adc);
79 
80  bool IsFirstPacket(const char *buf, size_t nb);
81 
82  //
83  int m_Verbosity; //
84 
85  std::vector<BYTE> m_RunHeadBuf; // buffer to hold run header info
86  std::vector<BYTE> m_EveHeadBuf; // buffer to hold event header info
87  std::vector<BYTE> m_EndFootBuf; // buffer to hold file end info
88  std::vector<BYTE> m_EveDataBuf; // event data buffer
89 
90  std::vector<adc16_t> m_EveData; // event adc data
91 
92  //
93  ssize_t m_bytes_left;
94 
95 
96 
100 
101  //
102  std::streampos m_pstart;
103  std::streampos m_pend;
104  std::vector<std::streampos> m_events;
105 
106  // total number of events in the file
107  size_t m_totev;
108 
109  // basic data parameters
110  short m_nadc;
111  size_t m_nch;
112  size_t m_nsample;
113 
114  // data compression flag
115  bool m_dcflag;
116 
117  // mutex
118  pthread_mutex_t m_data_mutex;
119  };
120 }
121 
122 #endif
pthread_mutex_t m_data_mutex
Definition: EventDecoder.h:118
static constexpr double nb
Definition: Units.h:81
ssize_t Open(std::string finname)
std::streampos m_pstart
Definition: EventDecoder.h:102
std::string string
Definition: nybbler.cc:12
size_t GetNCh() const
Definition: EventDecoder.h:34
std::streampos m_pend
Definition: EventDecoder.h:103
std::vector< std::streampos > m_events
Definition: EventDecoder.h:104
std::vector< BYTE > m_EndFootBuf
Definition: EventDecoder.h:87
int16_t adc
Definition: CRTFragment.hh:202
std::vector< BYTE > m_EveDataBuf
Definition: EventDecoder.h:88
int trylock(pthread_mutex_t &mutex)
Definition: EventDecoder.h:68
bool Compressed() const
Definition: EventDecoder.h:55
evheader_t GetEventHeader()
Definition: EventDecoder.h:61
int lock(pthread_mutex_t &mutex)
Definition: EventDecoder.h:67
std::ifstream m_file
Definition: EventDecoder.h:64
size_t GetNSample() const
Definition: EventDecoder.h:35
void ReadEvent(std::vector< adc16_t > &adc, bool headonly=false)
size_t GetTotEvents() const
Definition: EventDecoder.h:58
ssize_t GetEvent(size_t evnum, dlardaq::evheader_t &eh, std::vector< adc16_t > &adc)
runheader_t GetRunHeader()
Definition: EventDecoder.h:60
void ReadBytes(std::vector< BYTE > &bytes)
footer_t GetFileFooter()
Definition: EventDecoder.h:62
std::vector< BYTE > m_EveHeadBuf
Definition: EventDecoder.h:86
int unlock(pthread_mutex_t &mutex)
Definition: EventDecoder.h:69
ssize_t Decode(const char *buf, size_t nb, bool cflag, std::vector< adc16_t > &adc)
void ReadBuffer(const char *buf, size_t nb)
void SetNSample(size_t val)
Definition: EventDecoder.h:32
void SetNCh(size_t val)
Definition: EventDecoder.h:31
std::vector< BYTE > m_RunHeadBuf
Definition: EventDecoder.h:85
byte bytes
Alias for common language habits.
Definition: datasize.h:101
std::vector< adc16_t > m_EveData
Definition: EventDecoder.h:90
EventDecoder(size_t nch, size_t nsample)
bool IsFirstPacket(const char *buf, size_t nb)