JAPAn
Just Another Parity Analyzer
Loading...
Searching...
No Matches
Coda2EventDecoder.cc
Go to the documentation of this file.
1/*!
2 * \file Coda2EventDecoder.cc
3 * \brief CODA version 2 event decoder implementation
4 */
5
6#include "Coda2EventDecoder.h"
7#include "THaCodaFile.h"
8#include "QwOptions.h"
9
10#include <vector>
11#include <ctime>
12
13// Creates PHYS Event EVIO Header. See header for parameters and return value.
14std::vector<UInt_t> Coda2EventDecoder::EncodePHYSEventHeader(std::vector<ROCID_t> &ROCList)
15{
16 std::vector<UInt_t> header;
17 header.push_back((0x0001 << 16) | (0x10 << 8) | 0xCC);
18 // event type | event data type | event ID (0xCC for CODA event)
19 header.push_back(4); // size of header field
20 header.push_back((0xC000 << 16) | (0x01 << 8) | 0x00);
21 // bank type | bank data type (0x01 for uint32) | bank ID (0x00 for header event)
22 header.push_back(++fEvtNumber); // event number (initialized to 0, so increment before use to agree with CODA number)
23 header.push_back(1); // event class
24 header.push_back(0); // status summary
25 return header;
26}
27
28// Creates PRESTART Event EVIO Header. See header for parameters.
29void Coda2EventDecoder::EncodePrestartEventHeader(int* buffer, int runnumber, int runtype, int localtime)
30{
31 buffer[0] = 4; // Prestart event length
32 buffer[1] = ((kPRESTART_EVENT << 16) | (0x01 << 8) | 0xCC);
33 buffer[2] = localtime;
34 buffer[3] = runnumber;
35 buffer[4] = runtype;
36 ProcessPrestart(localtime, runnumber, runtype);
37}
38
39// Creates GO Event EVIO Header. See header for parameters.
40void Coda2EventDecoder::EncodeGoEventHeader(int* buffer, int eventcount, int localtime)
41{
42 buffer[0] = 4; // Go event length
43 buffer[1] = ((kGO_EVENT << 16) | (0x01 << 8) | 0xCC);
44 buffer[2] = localtime;
45 buffer[3] = 0; // unused
46 buffer[4] = eventcount;
47 ProcessGo(localtime, eventcount);
48}
49
50// Creates PAUSE Event EVIO Header. See header for parameters.
51void Coda2EventDecoder::EncodePauseEventHeader(int* buffer, int eventcount, int localtime)
52{
53 buffer[0] = 4; // Pause event length
54 buffer[1] = ((kPAUSE_EVENT << 16) | (0x01 << 8) | 0xCC);
55 buffer[2] = localtime;
56 buffer[3] = 0; // unused
57 buffer[4] = eventcount;
58 ProcessPause(localtime, eventcount);
59}
60
61// Creates END Event EVIO Header. See header for parameters.
62void Coda2EventDecoder::EncodeEndEventHeader(int* buffer, int eventcount, int localtime)
63{
64 buffer[0] = 4; // End event length
65 buffer[1] = ((kEND_EVENT << 16) | (0x01 << 8) | 0xCC);
66 buffer[2] = localtime;
67 buffer[3] = 0; // unused
68 buffer[4] = eventcount;
69 ProcessEnd(localtime, eventcount);
70}
71
72// Determine if a buffer contains a PHYS event, control event, or other event.
74{
75
76 UInt_t local_datatype;
77 UInt_t local_eventtype;
78
79 fPhysicsEventFlag = kFALSE;
80
81 QwDebug << "QwEventBuffer::DecodeEventIDBank: " << std::hex
82 << buffer[0] << " "
83 << buffer[1] << " "
84 << buffer[2] << " "
85 << buffer[3] << " "
86 << buffer[4] << std::dec
87 << QwLog::endl;
88
89 if ( buffer[0] == 0 ){
90 /*****************************************************************
91 * This buffer is empty. *
92 *****************************************************************/
93 fEvtLength = (1); // Pretend that there is one word.
94 fWordsSoFar = (1); // Mark that we've read the word already.
95 fEvtType = (0);
96 fEvtTag = 0;
97 fBankDataType = 0;
98 fIDBankNum = 0;
99 fEvtNumber = 0;
100 fEvtClass = 0;
101 fStatSum = 0;
102 } else {
103 /*****************************************************************
104 * This buffer contains data; fill the event ID parameters. *
105 *****************************************************************/
106 // First word is the number of long-words in the buffer.
107 fEvtLength = (buffer[0]+1);
108
109 // Second word contains the event type, for CODA events.
110 fEvtTag = (buffer[1] & 0xFFFF0000) >> 16; // (bits(31-16));
111 local_datatype = (buffer[1] & 0xFF00) >> 8; // (bits(15-8));
112 fIDBankNum = (buffer[1] & 0xFF); // (bits(7-0));
113 if ( fIDBankNum == 0xCC) {
114 // This is a CODA event bank; the event type is equal to
115 // the event tag.
116 local_eventtype = fEvtTag;
117 fEvtType = (local_eventtype);
118 fBankDataType = local_datatype;
119
120 // local_eventtype is unsigned int and always positive
121 if (/* local_eventtype >= 0 && */ local_eventtype <= 15) {
122 // This is a physics event; record the event number, event
123 // classification, and status summary.
124 fPhysicsEventFlag = kTRUE;
125 fEvtNumber = buffer[4];
126 fEvtClass = buffer[5];
127 fStatSum = buffer[6];
128 // Now skip to the first ROC data bank.
129 fWordsSoFar = (7);
130 } else {
131 // This is not a physics event, but is still in the CODA
132 // event format. The first two words have been examined.
133 fEvtNumber = 0;
134 fEvtClass = 0;
135 fStatSum = 0;
136 fWordsSoFar = (2);
137 // Run this event through the Control event processing.
138 // If it is not a control event, nothing will happen.
140 }
141 } else {
142 // This is not an event in the CODA event bank format,
143 // but it still follows the CEBAF common event format.
144 // Arbitrarily set the event type to "fEvtTag".
145 // The first two words have been examined.
146 fEvtType = (fEvtTag);
147 fBankDataType = local_datatype;
148 fEvtNumber = 0;
149 fEvtClass = 0;
150 fStatSum = 0;
151 fWordsSoFar = (2);
152 }
153 }
154 // Initialize the fragment size to the event size, in case the
155 // event is not subbanked.
157 QwDebug << Form("buffer[0-1] 0x%x 0x%x ; ",
158 buffer[0], buffer[1])
159 << Form("Length: %d; Tag: 0x%x; Bank data type: 0x%x; Bank ID num: 0x%x; ",
161 << Form("Evt type: 0x%x; Evt number %d; Evt Class 0x%.8x; ",
163 << Form("Status Summary: 0x%.8x; Words so far %d",
165 << QwLog::endl;
166
167 return CODA_OK;
168}
169
170// Print internal decoder information. See header for details.
172{
173
174 out << Form("Length: %d; Tag: 0x%x; Bank data type: 0x%x; Bank ID num: 0x%x; ",
176 << Form("Evt type: 0x%x; Evt number %d; Evt Class 0x%.8x; ",
178 << QwLog::endl;
179}
An options class which parses command line, config file and environment.
#define QwDebug
Predefined log drain for debugging output.
Definition QwLog.h:59
CODA version 2 event decoder implementation.
void EncodePauseEventHeader(int *buffer, int eventcount, int localtime) override
void EncodeEndEventHeader(int *buffer, int eventcount, int localtime) override
void EncodeGoEventHeader(int *buffer, int eventcount, int localtime) override
void PrintDecoderInfo(QwLog &out) override
Int_t DecodeEventIDBank(UInt_t *buffer) override
std::vector< UInt_t > EncodePHYSEventHeader(std::vector< ROCID_t > &ROCList) override
void EncodePrestartEventHeader(int *buffer, int runnumber, int runtype, int localtime) override
void ProcessPause(UInt_t local_time, UInt_t evt_count)
void ProcessGo(UInt_t local_time, UInt_t evt_count)
void ProcessPrestart(UInt_t local_time, UInt_t local_runnumber, UInt_t local_runtype)
void ProcessEnd(UInt_t local_time, UInt_t evt_count)
void ProcessControlEvent(UInt_t evtype, UInt_t *buffer)
Logging and output management system with configurable verbosity levels.
Definition QwLog.h:73
static std::ostream & endl(std::ostream &)
End of the line.
Definition QwLog.cc:297
Bool_t fPhysicsEventFlag
UInt_t fEvtNumber
CODA event number; only defined for physics events.