JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
Coda3EventDecoder.h
Go to the documentation of this file.
1/*!
2 * \file Coda3EventDecoder.h
3 * \brief CODA version 3 event decoder implementation
4 */
5
6#pragma once
7
8#include "VEventDecoder.h"
9#include "Rtypes.h"
10
11#include <vector>
12
13/**
14 * \class Coda3EventDecoder
15 * \ingroup QwAnalysis
16 * \brief CODA version 3 event decoder implementation
17 *
18 * Concrete decoder for CODA 3.x format event streams, handling the specific
19 * data structures, bank formats, and trigger information used in CODA 3.
20 * Provides encoding and decoding capabilities for both real and mock data.
21 */
23{
24public:
26 tsEvType(0),
27 block_size(0),
28 evt_time(0),
29 trigger_bits(0),
30 TSROCNumber(0) { }
31 ~Coda3EventDecoder() override { }
32public:
33 // Encoding Functions
34 /** Create a PHYS event EVIO header.
35 * @param ROCList List of ROC IDs.
36 * @return Vector of 32-bit words containing the header.
37 */
38 std::vector<UInt_t> EncodePHYSEventHeader(std::vector<ROCID_t> &ROCList) override;
39 /** Create a PRESTART event EVIO header.
40 * @param buffer Output buffer (>= 5 words).
41 * @param runnumber Run number.
42 * @param runtype Run type.
43 * @param localtime Event time.
44 */
45 void EncodePrestartEventHeader(int* buffer, int runnumber, int runtype, int localtime) override;
46 /** Create a GO event EVIO header.
47 * @param buffer Output buffer (>= 5 words).
48 * @param eventcount Number of events.
49 * @param localtime Event time.
50 */
51 void EncodeGoEventHeader(int* buffer, int eventcount, int localtime) override;
52 /** Create a PAUSE event EVIO header.
53 * @param buffer Output buffer (>= 5 words).
54 * @param eventcount Number of events.
55 * @param localtime Event time.
56 */
57 void EncodePauseEventHeader(int* buffer, int eventcount, int localtime) override;
58 /** Create an END event EVIO header.
59 * @param buffer Output buffer (>= 5 words).
60 * @param eventcount Number of events.
61 * @param localtime Event time.
62 */
63 void EncodeEndEventHeader(int* buffer, int eventcount, int localtime) override;
64
65public:
66 // Decoding Functions
67 /** Determine if a buffer contains a PHYS, control, or other event.
68 * @param buffer Event buffer to decode.
69 * @return CODA_OK on success.
70 */
71 Int_t DecodeEventIDBank(UInt_t *buffer) override;
72private:
73 // Debugging Functions
74 /** Print non-PHYS, non-control "user" events. */
75 void printUserEvent(const UInt_t *buffer);
76 /** Print internal decoder state for diagnostics. */
77 void PrintDecoderInfo(QwLog& out) override;
78protected:
79 // TI Decoding Functions
80 /** Determine event type and set control/physics flags based on bank tag. */
81 UInt_t InterpretBankTag(UInt_t tag);
82 /** Decode the TI trigger bank for PHYS events. */
83 Int_t trigBankDecode(UInt_t* buffer);
84 /** Display a warning and reset state for a given TI error flag. */
85 void trigBankErrorHandler( Int_t flag );
86
87 ULong64_t GetEvTime() const { return evt_time; }
88 void SetEvTime(ULong64_t evtime) { evt_time = evtime; }
90 ULong64_t evt_time; // Event time (for CODA 3.* this is a 250 Mhz clock)
91 UInt_t trigger_bits; // (Not completely sure) The TS# trigger for the TS
92public:
93 // Ti Specific Functions
94 enum { HED_OK = 0, HED_WARN = -63, HED_ERR = -127, HED_FATAL = -255 };
95 class coda_format_error : public std::runtime_error {
96 public:
97 explicit coda_format_error( const std::string& what_arg ) : std::runtime_error(what_arg) {}
98 explicit coda_format_error( const char* what_arg ) : std::runtime_error(what_arg) {}
99 };
100
101 // Trigger Bank OBJect
102 class TBOBJ {
103 public:
104 TBOBJ() : blksize(0), tag(0), nrocs(0), len(0), tsrocLen(0), evtNum(0),
105 runInfo(0), start(nullptr), evTS(nullptr), evType(nullptr),
106 TSROC(nullptr) {}
107 void Clear() { memset(this, 0, sizeof(*this)); }
108 uint32_t Fill( const uint32_t* evbuffer, uint32_t blkSize, uint32_t tsroc );
109 bool withTimeStamp() const { return (tag & 1) != 0; }
110 bool withRunInfo() const { return (tag & 2) != 0; }
111 bool withTriggerBits() const { return (tsrocLen > 2*blksize);}
112
113 uint32_t blksize; /* total number of triggers in the Bank */
114 uint16_t tag; /* Trigger Bank Tag ID = 0xff2x */
115 uint16_t nrocs; /* Number of ROC Banks in the Event Block (val = 1-256) */
116 uint32_t len; /* Total Length of the Trigger Bank - including Bank header */
117 uint32_t tsrocLen; /* Number of words in TSROC array */
118 uint64_t evtNum; /* Starting Event # of the Block */
119 uint64_t runInfo; /* Run Info Data (optional) */
120 const uint32_t *start; /* Pointer to start of the Trigger Bank */
121 const uint64_t *evTS; /* Pointer to the array of Time Stamps (optional) */
122 const uint16_t *evType; /* Pointer to the array of Event Types */
123 const uint32_t *TSROC; /* Pointer to Trigger Supervisor ROC segment data */
124 };
125
126protected:
127 /** Load TI trigger bank info for the i-th event in block. */
128 Int_t LoadTrigBankInfo( UInt_t index_buffer );
130
131public:
132 // Hall A analyzer keywords (analyzer/Decoder.h)
133 // Keywords that collide with JAPAN have been removed (deferring to JAPAN's definitions)
134 static const UInt_t MAX_PHYS_EVTYPE = 14; // Types up to this are physics
135 static const UInt_t TS_PRESCALE_EVTYPE = 120;
136 // TODO:
137 // Do we need any of these keywords?
138 static const UInt_t PRESCALE_EVTYPE = 133;
139 static const UInt_t DETMAP_FILE = 135; // Most likely do not need this one
140 static const UInt_t DAQCONFIG_FILE1 = 137;
141 static const UInt_t DAQCONFIG_FILE2 = 138;
142 static const UInt_t TRIGGER_FILE = 136;
143 static const UInt_t SCALER_EVTYPE = 140;
144 static const UInt_t SBSSCALER_EVTYPE = 141;
145 static const UInt_t HV_DATA_EVTYPE = 150;
146
147protected:
148 // TODO:
149 // How does JAPAN want to handle a TS?
150 // Currently implemented as 0
151 uint32_t TSROCNumber;
152};
Virtual base class for event decoders to encode and decode CODA data.
unsigned long long ULong64_t
Definition QwBlinder.h:41
void EncodePauseEventHeader(int *buffer, int eventcount, int localtime) override
static const UInt_t SCALER_EVTYPE
static const UInt_t TRIGGER_FILE
std::vector< UInt_t > EncodePHYSEventHeader(std::vector< ROCID_t > &ROCList) override
Int_t trigBankDecode(UInt_t *buffer)
ULong64_t GetEvTime() const
void trigBankErrorHandler(Int_t flag)
void printUserEvent(const UInt_t *buffer)
static const UInt_t TS_PRESCALE_EVTYPE
static const UInt_t SBSSCALER_EVTYPE
void EncodeGoEventHeader(int *buffer, int eventcount, int localtime) override
static const UInt_t HV_DATA_EVTYPE
~Coda3EventDecoder() override
static const UInt_t DAQCONFIG_FILE2
Int_t LoadTrigBankInfo(UInt_t index_buffer)
void PrintDecoderInfo(QwLog &out) override
static const UInt_t DAQCONFIG_FILE1
void SetEvTime(ULong64_t evtime)
void EncodeEndEventHeader(int *buffer, int eventcount, int localtime) override
static const UInt_t MAX_PHYS_EVTYPE
UInt_t InterpretBankTag(UInt_t tag)
void EncodePrestartEventHeader(int *buffer, int runnumber, int runtype, int localtime) override
static const UInt_t DETMAP_FILE
static const UInt_t PRESCALE_EVTYPE
Int_t DecodeEventIDBank(UInt_t *buffer) override
coda_format_error(const std::string &what_arg)
uint32_t Fill(const uint32_t *evbuffer, uint32_t blkSize, uint32_t tsroc)
Logging and output management system with configurable verbosity levels.
Definition QwLog.h:73