Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
CodaDecoder.h
Go to the documentation of this file.
1#ifndef Podd_CodaDecoder_h_
2#define Podd_CodaDecoder_h_
3
5//
6// CodaDecoder
7//
8// Object Oriented version of decoder
9// Sept, 2014 R. Michaels
10//
12
13#include "THaEvData.h"
14#include <vector>
15#include <cstdint>
16#include <stdexcept>
17#include <string>
18
19namespace Decoder {
20
21class CodaDecoder : public THaEvData {
22public:
24 virtual ~CodaDecoder();
25
26 virtual Int_t Init();
27
28 virtual Int_t LoadEvent(const UInt_t* evbuffer);
29
30 virtual UInt_t GetPrescaleFactor( UInt_t trigger ) const;
31 virtual void SetRunTime( ULong64_t tloc );
32 virtual Int_t SetDataVersion( Int_t version ) { return SetCodaVersion(version); }
33 //FIXME: this one should call SetDataVersion, not the other way round
34 Int_t SetCodaVersion( Int_t version );
35
37 virtual Int_t LoadFromMultiBlock();
39 Bool_t BlockIsDone() const { return fBlockIsDone; };
40
41 virtual Int_t FillBankData( UInt_t* rdat, UInt_t roc, Int_t bank,
42 UInt_t offset = 0, UInt_t num = 1 ) const;
43
44 UInt_t GetTSEvType() const { return tsEvType; }
45 UInt_t GetBlockIndex() const { return blkidx; }
46 enum { MAX_PSFACT = 12 };
47
48 // CODA file format exception, thrown by LoadEvent/LoadFromMultiBlock
49 class coda_format_error : public std::runtime_error {
50 public:
51 explicit coda_format_error( const std::string& what_arg )
52 : std::runtime_error(what_arg) {}
53 explicit coda_format_error( const char* what_arg )
54 : std::runtime_error(what_arg) {}
55 };
56
57 static UInt_t InterpretBankTag( UInt_t tag );
58
59 struct BankInfo {
60 BankInfo() : pos_{0}, len_{0}, tag_{0}, otag_{0}, dtyp_{0}, npad_{0},
61 blksz_{0}, status_{kOK} {}
63 enum EDataSize { kUndef = 0, k8bit = 1, k16bit = 2, k32bit = 4, k64bit = 8 };
64 enum EIntFloat { kInteger = 0, kFloat };
66 Int_t Fill( const UInt_t* evbuf, UInt_t pos, UInt_t len );
67 EDataSize GetDataSize() const; // Size of data in bytes/element
68 EIntFloat GetFloat() const;
69 ESigned GetSigned() const;
70 const char* Errtxt() const;
71 const char* Typtxt() const;
72 UInt_t pos_; // First word of payload
73 UInt_t len_; // pos_ + len_ = first word after payload
74 UInt_t tag_; // Bank tag
75 UInt_t otag_; // Bank tag of "outer" bank if bank of banks
76 UInt_t dtyp_; // Data type
77 UInt_t npad_; // Number of padding bytes at end of data
78 UInt_t blksz_; // Block size (multiple events per buffer)
79 EBankErr status_; // Decoding status
80 };
81 static BankInfo GetBank( const UInt_t* evbuf, UInt_t pos, UInt_t len ) {
82 BankInfo ifo;
83 ifo.Fill(evbuf, pos, len);
84 return ifo;
85 }
86
87protected:
88 virtual Int_t LoadIfFlagData(const UInt_t* evbuffer);
89
90 Int_t FindRocs(const UInt_t *evbuffer); // CODA2 version
91 Int_t FindRocsCoda3(const UInt_t *evbuffer); // CODA3 version
92 Int_t roc_decode( UInt_t roc, const UInt_t* evbuffer, UInt_t ipt, UInt_t istop );
93 Int_t bank_decode( UInt_t roc, const UInt_t* evbuffer, UInt_t ipt, UInt_t istop );
94 Int_t physics_decode( const UInt_t* evbuffer );
95
96 void CompareRocs();
97 void ChkFbSlot( UInt_t roc, const UInt_t* evbuffer, UInt_t ipt, UInt_t istop );
98 void ChkFbSlots();
99
100 virtual Int_t init_slotdata();
101 virtual Int_t interpretCoda3( const UInt_t* buffer );
102 virtual Int_t trigBankDecode( const UInt_t* evbuffer );
103 Int_t daqConfigDecode( const UInt_t* evbuf ); //FIXME: BCI: make virtual
104 Int_t prescale_decode_coda2( const UInt_t* evbuffer );
105 Int_t prescale_decode_coda3( const UInt_t* evbuffer );
106 void dump( const UInt_t* evbuffer ) const;
107 void debug_print( const UInt_t* evbuffer ) const;
108 void PrintBankInfo() const;
109
110 // Data
112 std::vector<UInt_t> irn;
113 std::vector<bool> fbfound;
114 std::vector<UInt_t> psfact;
117
118 class BankDat_t { // Coordinates of bank data in raw event
119 public:
120 BankDat_t() : key(kMaxUInt), pos(0), len(0) {}
122 bool operator==( const BankDat_t& rhs ) const { return key == rhs.key; }
123 bool operator==( UInt_t key_to_find ) const { return key == key_to_find; }
124 bool operator< ( const BankDat_t& rhs ) const { return key < rhs.key; }
125 UInt_t key; // bank number + (roc << 16)
126 UInt_t pos; // position in evbuffer[]
127 UInt_t len; // length of data including pos, so pos+len-1 = last word of data
128 };
129 std::vector<BankDat_t> bankdat;
130 BankDat_t* CheckForBank( UInt_t roc, UInt_t slot );
131
132 // CODA3 stuff
133 UInt_t blkidx; // Event block index (0 <= blkidx < block_size)
136
137public:
138 class TBOBJ {
139 public:
140 TBOBJ() : blksize(0), tag(0), nrocs(0), len(0), tsrocLen(0), evtNum(0),
141 runInfo(0), start(nullptr), evTS(nullptr), evType(nullptr),
142 TSROC(nullptr) {}
143 void Clear() { memset(this, 0, sizeof(*this)); }
144 uint32_t Fill( const uint32_t* evbuffer, uint32_t blkSize, uint32_t tsroc );
145 bool withTimeStamp() const { return (tag & 1) != 0; }
146 bool withRunInfo() const { return (tag & 2) != 0; }
147 bool withTriggerBits() const { return (tsrocLen > 2*blksize);}
148
149 uint32_t blksize; /* total number of triggers in the Bank */
150 uint16_t tag; /* Trigger Bank Tag ID = 0xff2x */
151 uint16_t nrocs; /* Number of ROC Banks in the Event Block (val = 1-256) */
152 uint32_t len; /* Total Length of the Trigger Bank - including Bank header */
153 uint32_t tsrocLen; /* Number of words in TSROC array */
154 uint64_t evtNum; /* Starting Event # of the Block */
155 uint64_t runInfo; /* Run Info Data (optional) */
156 const uint32_t *start; /* Pointer to start of the Trigger Bank */
157 const uint64_t *evTS; /* Pointer to the array of Time Stamps (optional) */
158 const uint16_t *evType; /* Pointer to the array of Event Types */
159 const uint32_t *TSROC; /* Pointer to Trigger Supervisor ROC segment data */
160 };
161
162protected:
163 Int_t LoadTrigBankInfo( UInt_t index_buffer );
165
166 ClassDef(CodaDecoder,0) // Decoder for CODA event buffer
167};
168
169}
170
171#endif
int Int_t
unsigned int UInt_t
bool Bool_t
const UInt_t kMaxUInt
#define ClassDef(name, id)
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
bool operator==(const BankDat_t &rhs) const
bool operator==(UInt_t key_to_find) const
bool operator<(const BankDat_t &rhs) const
BankDat_t(UInt_t key, UInt_t pos, UInt_t len)
uint32_t Fill(const uint32_t *evbuffer, uint32_t blkSize, uint32_t tsroc)
coda_format_error(const std::string &what_arg)
Definition CodaDecoder.h:51
coda_format_error(const char *what_arg)
Definition CodaDecoder.h:53
Int_t physics_decode(const UInt_t *evbuffer)
virtual Int_t SetDataVersion(Int_t version)
Definition CodaDecoder.h:32
Int_t prescale_decode_coda2(const UInt_t *evbuffer)
Int_t prescale_decode_coda3(const UInt_t *evbuffer)
virtual Int_t LoadIfFlagData(const UInt_t *evbuffer)
BankDat_t * CheckForBank(UInt_t roc, UInt_t slot)
Int_t daqConfigDecode(const UInt_t *evbuf)
void ChkFbSlot(UInt_t roc, const UInt_t *evbuffer, UInt_t ipt, UInt_t istop)
std::vector< UInt_t > psfact
virtual void SetRunTime(ULong64_t tloc)
static BankInfo GetBank(const UInt_t *evbuf, UInt_t pos, UInt_t len)
Definition CodaDecoder.h:81
virtual Int_t init_slotdata()
virtual Int_t interpretCoda3(const UInt_t *buffer)
virtual UInt_t GetPrescaleFactor(UInt_t trigger) const
Bool_t IsMultiBlockMode() const
Definition CodaDecoder.h:38
void PrintBankInfo() const
Bool_t BlockIsDone() const
Definition CodaDecoder.h:39
virtual Int_t LoadFromMultiBlock()
std::vector< BankDat_t > bankdat
Int_t roc_decode(UInt_t roc, const UInt_t *evbuffer, UInt_t ipt, UInt_t istop)
Int_t SetCodaVersion(Int_t version)
virtual Int_t FillBankData(UInt_t *rdat, UInt_t roc, Int_t bank, UInt_t offset=0, UInt_t num=1) const
std::vector< bool > fbfound
virtual Bool_t DataCached()
Definition CodaDecoder.h:36
Int_t bank_decode(UInt_t roc, const UInt_t *evbuffer, UInt_t ipt, UInt_t istop)
UInt_t GetBlockIndex() const
Definition CodaDecoder.h:45
std::vector< UInt_t > irn
Int_t FindRocsCoda3(const UInt_t *evbuffer)
static UInt_t InterpretBankTag(UInt_t tag)
virtual Int_t Init()
void dump(const UInt_t *evbuffer) const
virtual Int_t LoadEvent(const UInt_t *evbuffer)
UInt_t GetTSEvType() const
Definition CodaDecoder.h:44
void debug_print(const UInt_t *evbuffer) const
Int_t LoadTrigBankInfo(UInt_t index_buffer)
virtual Int_t trigBankDecode(const UInt_t *evbuffer)
Int_t FindRocs(const UInt_t *evbuffer)
const UInt_t * buffer
Definition THaEvData.h:202
unsigned long long ULong64_t
STL namespace.
const char * Typtxt() const
Int_t Fill(const UInt_t *evbuf, UInt_t pos, UInt_t len)
const char * Errtxt() const