-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleLib.h
350 lines (297 loc) · 8.4 KB
/
simpleLib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
#ifndef __SIMPLELIBH__
#define __SIMPLELIBH__
/*----------------------------------------------------------------------------*/
/**
* @mainpage
* <pre>
* Copyright (c) 2014 Southeastern Universities Research Association, *
* Thomas Jefferson National Accelerator Facility *
* *
* This software was developed under a United States Government license *
* described in the NOTICE file included as part of this distribution. *
* *
* Authors: Bryan Moffit *
* moffit@jlab.org Jefferson Lab, MS-12B3 *
* Phone: (757) 269-5660 12000 Jefferson Ave. *
* Fax: (757) 269-5800 Newport News, VA 23606 *
* *
*----------------------------------------------------------------------------*
*
* Description:
* Header for
* (S)econdary (I)nstance (M)ultiblock (P)rocessing (L)ist (E)xtraction
*
* </pre>
*----------------------------------------------------------------------------*/
#define SIMPLE_MAX_MODULE_TYPES 4
#define SIMPLE_MAX_BLOCKLEVEL 255
#define SIMPLE_MAX_ROCS 255
#define SIMPLE_MAX_BANKS 255
#define SIMPLE_MAX_SLOTS 32
#define BANK_ID_MASK 0xFFFF0000
#ifndef ERROR
#define ERROR -1
#endif
#ifndef OK
#define OK 0
#endif
/* Standard JLab Module Data Format */
#define DATA_TYPE_DEFINING_MASK 0x80000000
#define DATA_TYPE_MASK 0x78000000
#define BLOCK_HEADER_SLOT_MASK 0x07C00000
#define BLOCK_HEADER_MODID_MASK 0x003C0000
#define BLOCK_HEADER_BLK_NUM_MASK 0x0003FF00
#define BLOCK_HEADER_BLK_LVL_MASK 0x000000FF
#define TRIG_HEADER2_ID_MASK 0xFF100000
#define TRIG_HEADER2_HAS_TIMESTAMP_MASK (1<<16)
#define TRIG_HEADER2_NEVENTS_MASK 0x000000FF
#define BLOCK_TRAILER_SLOT_MASK 0x07C00000
#define BLOCK_TRAILER_NWORDS 0x003FFFFF
#define EVENT_HEADER_SLOT_MASK 0x07C00000
#define EVENT_HEADER_EVT_NUM_MASK 0x003FFFFF
#define TRIG_EVENT_HEADER_TYPE_MASK 0xFF000000
#define TRIG_EVENT_HEADER_WORD_COUNT_MASK 0x0000FFFF
#define FILLER_SLOT_MASK 0x07C00000
typedef struct
{
unsigned int undef:27;
unsigned int data_type_tag:4;
unsigned int data_type_defining:1;
} jlab_data_word;
typedef union
{
unsigned int raw;
jlab_data_word bf;
} jlab_data_word_t;
/* 0: BLOCK HEADER */
typedef struct
{
unsigned int number_of_events_in_block:8;
unsigned int event_block_number:10;
unsigned int module_ID:4;
unsigned int slot_number:5;
unsigned int data_type_tag:4;
unsigned int data_type_defining:1;
} block_header;
typedef union
{
unsigned int raw;
block_header bf;
} block_header_t;
/* 1: BLOCK TRAILER */
typedef struct
{
unsigned int words_in_block:22;
unsigned int slot_number:5;
unsigned int data_type_tag:4;
unsigned int data_type_defining:1;
} block_trailer;
typedef union
{
unsigned int raw;
block_trailer bf;
} block_trailer_t;
/* 2: EVENT HEADER */
typedef struct
{
unsigned int event_number:22;
unsigned int slot_number:5;
unsigned int data_type_tag:4;
unsigned int data_type_defining:1;
} event_header;
typedef union
{
unsigned int raw;
event_header bf;
} event_header_t;
/* 12: SCALER HEADER */
typedef struct
{
unsigned int scaler_words:6;
unsigned int _blank:16;
unsigned int slot_number:5;
unsigned int data_type_tag:4;
unsigned int data_type_defining:1;
} scaler_header;
typedef union
{
unsigned int raw;
scaler_header bf;
} scaler_header_t;
/* Bank type definitions - These are in evioDictEntry.hxx */
enum DataType {
EVIO_UNKNOWN32 = (0x0),
EVIO_UINT32 = (0x1),
EVIO_FLOAT32 = (0x2),
EVIO_CHARSTAR8 = (0x3),
EVIO_SHORT16 = (0x4),
EVIO_USHORT16 = (0x5),
EVIO_CHAR8 = (0x6),
EVIO_UCHAR8 = (0x7),
EVIO_DOUBLE64 = (0x8),
EVIO_LONG64 = (0x9),
EVIO_ULONG64 = (0xa),
EVIO_INT32 = (0xb),
EVIO_TAGSEGMENT = (0xc),
EVIO_ALSOSEGMENT = (0xd),
EVIO_ALSOBANK = (0xe),
EVIO_COMPOSITE = (0xf),
EVIO_BANK = (0x10),
EVIO_SEGMENT = (0x20)
};
typedef enum jlabDataTypes
{
BLOCK_HEADER = 0,
BLOCK_TRAILER = 1,
EVENT_HEADER = 2,
TRIGGER_TIME = 3,
SCALER_HEADER = 12,
DATA_NOT_VALID = 14,
FILLER = 15
} DataTypes;
typedef enum jlabModuleTypes
{
MODID_TI = 0,
MODID_FA250 = 1,
MODID_FA125 = 2,
MODID_F1TDC_V2 = 3,
MODID_F1TDC_V3 = 4,
MODID_TS = 5,
MODID_TD = 6,
MODID_SSP = 7,
MODID_JLAB_DISC = 8,
MODID_OTHER = 9,
MODID_OTHER_ONCE = 10,
MAX_MODID
} ModuleID;
typedef enum simpleEndianType
{
SIMPLE_LITTLE_ENDIAN = 0,
SIMPLE_BIG_ENDIAN = 1
} simpleEndian;
typedef enum simpleDebugType
{
SIMPLE_SHOW_BLOCK_HEADER = (1<<0),
SIMPLE_SHOW_BLOCK_TRAILER = (1<<1),
SIMPLE_SHOW_EVENT_HEADER = (1<<2),
SIMPLE_SHOW_EVENT_TIMESTAMP = (1<<3),
SIMPLE_SHOW_OTHER = (1<<4),
SIMPLE_SHOW_BANK_FOUND = (1<<5),
SIMPLE_SHOW_FILL_EVENTS = (1<<6),
SIMPLE_SHOW_SECOND_PASS = (1<<7),
SIMPLE_SHOW_UNBLOCK = (1<<8),
SIMPLE_SHOW_IGNORED_BANKS = (1<<9),
SIMPLE_SHOW_SEGMENT_FOUND = (1<<10),
SIMPLE_SHOW_BANK_NOT_FOUND = (1<<11),
SIMPLE_SHOW_SCALER_HEADER = (1<<12)
} simpleDebug;
typedef struct
{
unsigned int num:8;
unsigned int type:6;
unsigned int padding:2;
unsigned int tag:16;
} bankHeader;
typedef union
{
unsigned int raw;
bankHeader bf;
} bankHeader_t;
typedef struct
{
unsigned int num:16;
unsigned int type:6;
unsigned int padding:2;
unsigned int tag:8;
} segmentHeader;
typedef union
{
unsigned int raw;
segmentHeader bf;
} segmentHeader_t;
typedef struct CodaBankInfoStruct
{
int length;
bankHeader_t header;
int index;
} codaBankInfo;
typedef struct CodaSegmentInfoStruct
{
int length;
segmentHeader_t header;
int index;
} codaSegmentInfo;
typedef struct BankConfigStruct
{
int length;
bankHeader_t header;
int rocID;
int endian;
int isBlocked;
unsigned int module_header;
unsigned int header_mask;
void *firstPassRoutine;
} simpleBankConfig;
typedef struct RocBankStruct
{
int length;
bankHeader_t header;
int index;
int rocID;
int nbanks;
codaBankInfo dataBank[SIMPLE_MAX_BANKS];
} rocBankInfo;
typedef struct TriggerBankStruct
{
int length;
bankHeader_t header;
int index;
int nrocs;
codaSegmentInfo segTime;
codaSegmentInfo segEvType;
codaSegmentInfo segRoc[SIMPLE_MAX_ROCS];
} trigBankInfo;
typedef struct BankDataStruct
{
int rocID;
int bankID;
int blkIndex[SIMPLE_MAX_SLOTS];
int blkTrailerIndex[SIMPLE_MAX_SLOTS];
int blkLevel;
int evtCounter;
unsigned int slotMask;
int evtIndex[SIMPLE_MAX_SLOTS][SIMPLE_MAX_BLOCKLEVEL+1];
int evtLength[SIMPLE_MAX_SLOTS][SIMPLE_MAX_BLOCKLEVEL+1];
} bankDataInfo;
typedef struct OtherBankStruct
{
int ID;
int once;
} otherBankInfo;
/* prototypes */
#ifdef __cplusplus
extern "C" {
#endif
int simpleInit();
void simpleConfigSetDebug(int dbMask);
int simpleConfigBank(int rocID, int tag, int num,
int endian, int isBlocked, void *firstPassRoutine);
int simpleConfigIgnoreUndefinedBlocks(int ignore);
int simpleScan(volatile unsigned int *data, int nwords);
int simpleScanCodaEvent(volatile unsigned int *data);
int simpleScanBank(volatile unsigned int *data, int rocID, int bankNumber);
int simpleGetRocBanks(int rocID, int bankID, int *bankList);
int simpleGetRocSlotmask(int rocID, int bankID, unsigned int *slotmask);
int simpleGetRocBlockLevel(int rocID, int bankID, int *blockLevel);
int simpleGetRocBankData(int rocID, int bankID, unsigned int **buffer);
int simpleGetSlotBlockHeader(int rocID, int bank, int slot, unsigned int *header);
int simpleGetSlotEventHeader(int rocID, int bank, int slot, int evt, unsigned int *header);
int simpleGetSlotEventData(int rocID, int bank, int slot, int evt, unsigned int **buffer);
int simpleGetSlotBlockTrailer(int rocID, int bank, int slot, unsigned int *trailer);
int simpleGetTriggerBankTimeSegment(unsigned long long **buffer);
int simpleGetTriggerBankTypeSegment(unsigned short **buffer);
int simpleGetTriggerBankRocSegment(int rocID, unsigned int **buffer);
#ifdef __cplusplus
}
#endif
#endif /* __SIMPLELIBH__ */