Hall A ROOT/C++ Analyzer (podd)
Loading...
Searching...
No Matches
PipeliningModule.h
Go to the documentation of this file.
1#ifndef Podd_PipeliningModule_h_
2#define Podd_PipeliningModule_h_
3
5//
6// PipeliningModule
7// R. Michaels, Oct 2016
8//
9// This class splits the "CODA event buffer" into actual events so that the
10// Podd analyzer's event loop works as before.
11// An "event" is a particle hitting a target and making hits in detectors, etc.
12// A "CODA event buffer" can contain many "events"; the events are stored in
13// each module of this type (piplelining).
14//
15// All of the Jlab pipeline modules have the same data format with respect to
16// specific bits indicating data types.
17// All produce block headers, block trailers, and event headers.
18// All encode the slot number the same way in these headers and trailers.
19//
20// While we're at it, we also split by slot number
21// so that each module doesn't need to consider another module's data.
22// Note, one module belongs to one slot.
23//
24// The first event buffer will have the block header
25// the last event buffer will have the block trailer
26// and all event buffers will have an event header
27//
29
30#include "VmeModule.h"
31#include "CustomAlloc.h"
32#include <vector>
33#include <cstdint>
34#include <cassert>
35
36class THaSlotData;
37
38namespace Decoder {
39
41
42public:
43
45 PipeliningModule( UInt_t crate, UInt_t slot );
48 virtual ~PipeliningModule() = default;
49
50 using VmeModule::Init;
51 virtual void Init( const char* configstr );
52 virtual void Clear( Option_t *opt="" );
53
54 // Wrappers for LoadSlot methods to allow buffer preprocessing
55 virtual UInt_t LoadBlock( THaSlotData* sldat, const UInt_t* evbuffer,
56 const UInt_t* pstop );
57 virtual UInt_t LoadBank( THaSlotData* sldat, const UInt_t* evbuffer,
58 UInt_t pos, UInt_t len );
59
60protected:
61
62 virtual UInt_t LoadNextEvBuffer( THaSlotData *sldat );
63 UInt_t fBlockHeader; // Copy of block header word
64 UInt_t data_type_def; // Data type indicated by most recent header word
65
66 // Support for multi-block mode
67 VectorUIntNI fBuffer; // Copy of this module's chunk of the event buffer
68 std::vector<Long64_t> evtblk; // Event header positions
69 UInt_t index_buffer; // Index of next block to be decoded
70
71 enum { kBlockHeader = 0, kBlockTrailer = 1, kEventHeader = 2 };
72 static Long64_t FindIDWord( const uint32_t* buf, size_t start, size_t len,
73 uint32_t type );
74 static Long64_t FindIDWord( const uint32_t* buf, size_t start, size_t len,
75 uint32_t type, uint32_t slot );
77 const uint32_t* buf, size_t start, size_t len, uint32_t evthdr,
78 uint32_t blktrl, std::vector<Long64_t>& evtpos, uint32_t slot );
79
80 Long64_t VerifyBlockTrailer( const UInt_t* evbuffer, UInt_t pos, UInt_t len,
81 Long64_t ibeg, Long64_t iend ) const;
82
83 ClassDef(Decoder::PipeliningModule,0) // A pipelining module
84};
85
86//_____________________________________________________________________________
87inline
89 const uint32_t* buf, size_t start, size_t len, uint32_t type )
90{
91 // Search 'buf' for identifier word for 'type'.
92 // The format is (T=type)
93 // 1TTT TXXX XXXX XXXX XXXX XXXX XXXX XXXX
94 // bit 28 24 20 16 12 8 4 0
95 //
96 // The buffer is searched between [start,start+len)
97 // Returns the offset into 'buf' containing the word, or -1 if not found.
98
99 const uint32_t ID = BIT(31) | (type & 0x0F) << 27;
100 const auto* p = buf + start;
101 const auto* q = p + len;
102 while( p != q && (*p & 0xF8000000) != ID )
103 ++p;
104 return (p != q) ? p - buf : -1;
105}
106
107//_____________________________________________________________________________
108inline
110 const uint32_t* buf, size_t start, size_t len, uint32_t type, uint32_t slot )
111{
112 // Search 'buf' for data type identifier word encoding 'type' and 'slot'.
113 // The format is (T=type, S=slot)
114 // 1TTT TSSS SSXX XXXX XXXX XXXX XXXX XXXX
115 // bit 28 24 20 16 12 8 4 0
116 //
117 // The buffer is searched between [start,start+len)
118 // Returns the offset into 'buf' containing the word, or -1 if not found.
119
120 const uint32_t ID = BIT(31) | (type & 0x0F) << 27 | (slot & 0x1F) << 22;
121 const auto* p = buf + start;
122 const auto* q = p + len;
123 while( p != q && (*p & 0xFFC00000) != ID )
124 ++p;
125 return (p != q) ? p - buf : -1;
126}
127
128//_____________________________________________________________________________
129inline
131 const uint32_t* buf, size_t start, size_t len, uint32_t evthdr,
132 uint32_t blktrl, std::vector<Long64_t>& evtpos, uint32_t slot )
133{
134 // Search 'buf' for block trailer (identified by type = 'blktrl' and
135 // slot = 'slot', see FindIDWord for the bit format).
136 // While scanning, save any event headers (identified by type = 'evthdr'
137 // in vector 'evtpos'.
138 // The buffer is searched between [start,start+len).
139 // Returns the offset into 'buf' of the trailer word, or -1 if not found.
140
141 const uint32_t HDR = BIT(31) | (slot & 0x1F) << 22;
142 const uint32_t EVT = HDR | (evthdr & 0x0F) << 27;
143 const uint32_t TRL = HDR | (blktrl & 0x0F) << 27;
144 const auto* p = buf + start;
145 const auto* q = p + len;
146 while( p != q && (*p & 0xFFC00000) != TRL ) {
147 // Ignore the slot number in event headers since, anecdotally,
148 // it is not reliably present.
149 // Change the bit mask below to 0xFFC00000 to include the slot number.
150 if( (*p & 0xF8000000) == (EVT & 0xF8000000) )
151 evtpos.push_back(p - buf);
152 ++p;
153 }
154 return (p != q) ? p - buf : -1;
155}
156} //namespace Decoder
157
158#endif
unsigned int UInt_t
const char Option_t
#define ClassDef(name, id)
#define BIT(n)
winID h TVirtualViewer3D TVirtualGLPainter p
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
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 type
float * q
virtual void Init()
Definition Module.cxx:51
virtual UInt_t LoadNextEvBuffer(THaSlotData *sldat)
PipeliningModule(const PipeliningModule &fh)=delete
static Long64_t FindIDWord(const uint32_t *buf, size_t start, size_t len, uint32_t type)
std::vector< Long64_t > evtblk
virtual UInt_t LoadBank(THaSlotData *sldat, const UInt_t *evbuffer, UInt_t pos, UInt_t len)
virtual void Clear(Option_t *opt="")
virtual UInt_t LoadBlock(THaSlotData *sldat, const UInt_t *evbuffer, const UInt_t *pstop)
PipeliningModule & operator=(const PipeliningModule &fh)=delete
static Long64_t FindEventsInBlock(const uint32_t *buf, size_t start, size_t len, uint32_t evthdr, uint32_t blktrl, std::vector< Long64_t > &evtpos, uint32_t slot)
virtual ~PipeliningModule()=default
Long64_t VerifyBlockTrailer(const UInt_t *evbuffer, UInt_t pos, UInt_t len, Long64_t ibeg, Long64_t iend) const
long long Long64_t
std::vector< UInt_t, default_init_allocator< UInt_t > > VectorUIntNI
Definition CustomAlloc.h:38
start