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
|
/*----------------------------------------------------------*/
/* DCC DATA PARSER */
/* */
/* Author : N.Almeida (LIP) Date : 30/05/2004 */
/*----------------------------------------------------------*/
#ifndef DCCTBDATAPARSER_HH
#define DCCTBDATAPARSER_HH
#include <fstream> //STL
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cstdio> //C
#include "ECALParserException.h" //DATA DECODER
#include "DCCEventBlock.h"
#include "DCCDataMapper.h"
class DCCTBDataMapper;
class DCCTBEventBlock;
class DCCTBDataParser {
public:
/**
Class constructor: takes a vector of 10 parameters and flags for parseInternalData and debug
Parameters are:
0 - crystal samples (default is 10)
1 - number of trigger time samples (default is 1)
2 - number of TT (default is 68)
3 - number of SR Flags (default is 68)
4 - DCC id
5 - SR id
[6-9] - TCC[6-9] id
*/
DCCTBDataParser(const std::vector<uint32_t> &parserParameters, bool parseInternalData = true, bool debug = true);
/**
Parse data from file
*/
void parseFile(std::string fileName, bool singleEvent = false);
/**
Parse data from a buffer
*/
void parseBuffer(const uint32_t *buffer, uint32_t bufferSize, bool singleEvent = false);
/**
Get method for DCCTBDataMapper
*/
DCCTBDataMapper *mapper();
/**
Check if EVENT LENGTH is coeherent and if BOE/EOE are correctly written
returns 3 bits code with the error found + event length
*/
std::pair<uint32_t, uint32_t> checkEventLength(const uint32_t *pointerToEvent,
uint32_t bytesToEnd,
bool singleEvent = false);
/**
Get methods for parser parameters;
*/
std::vector<uint32_t> parserParameters();
uint32_t numbXtalSamples();
uint32_t numbTriggerSamples();
uint32_t numbTTs();
uint32_t numbSRF();
uint32_t dccId();
uint32_t srpId();
uint32_t tcc1Id();
uint32_t tcc2Id();
uint32_t tcc3Id();
uint32_t tcc4Id();
/**
Set method for parser parameters
*/
void setParameters(const std::vector<uint32_t> &newParameters);
/**
Get methods for block sizes
*/
uint32_t srpBlockSize();
uint32_t tccBlockSize();
/**
Get methods for debug flag
*/
bool debug();
/**
Get method for DCCEventBlocks vector
*/
std::vector<DCCTBEventBlock *> &dccEvents();
/**
Get method for error counters map
*/
std::map<std::string, uint32_t> &errorCounters();
/**
* Get method for events
*/
std::vector<std::pair<uint32_t, std::pair<const uint32_t *, uint32_t> > > events();
/**
Reset Error Counters
*/
void resetErrorCounters();
/**
Methods to get data strings formatted as decimal/hexadecimal, indexes and indexed data
*/
std::string getDecString(uint32_t data);
std::string getHexString(uint32_t data);
std::string index(uint32_t position);
std::string getIndexedData(uint32_t indexed, uint32_t *pointer);
/**
* Retrieves a pointer to the data buffer
*/
const uint32_t *getBuffer() { return buffer_; }
/**
Class destructor
*/
~DCCTBDataParser();
enum DCCDataParserGlobalFields {
EMPTYEVENTSIZE = 32 //bytes
};
protected:
void computeBlockSizes();
const uint32_t *buffer_; //data buffer
uint32_t bufferSize_; //buffer size
uint32_t srpBlockSize_; //SR block size
uint32_t tccBlockSize_; //TCC block size
uint32_t processedEvent_;
std::string eventErrors_;
DCCTBDataMapper *mapper_;
std::vector<DCCTBEventBlock *> dccEvents_;
// std::pair< errorMask, std::pair< pointer to event, event size (number of DW)> >
std::vector<std::pair<uint32_t, std::pair<const uint32_t *, uint32_t> > > events_;
bool parseInternalData_; //parse internal data flag
bool debug_; //debug flag
std::map<std::string, uint32_t> errors_; //errors map
std::vector<uint32_t> parameters; //parameters vector
enum DCCTBDataParserFields {
EVENTLENGTHMASK = 0xFFFFFF,
BOEBEGIN = 28, //begin of event (on 32 bit string starts at bit 28)
BOEMASK = 0xF, //mask is 4 bits (F)
BOE = 0x5, //B'0101'
EOEBEGIN = 28, //end of event
EOEMASK = 0xF, //4 bits
EOE = 0xA //B'1010'
};
};
inline DCCTBDataMapper *DCCTBDataParser::mapper() { return mapper_; }
inline std::vector<uint32_t> DCCTBDataParser::parserParameters() { return parameters; }
inline uint32_t DCCTBDataParser::numbXtalSamples() { return parameters[0]; }
inline uint32_t DCCTBDataParser::numbTriggerSamples() { return parameters[1]; }
inline uint32_t DCCTBDataParser::numbTTs() { return parameters[2]; }
inline uint32_t DCCTBDataParser::numbSRF() { return parameters[3]; }
inline uint32_t DCCTBDataParser::dccId() { return parameters[4]; }
inline uint32_t DCCTBDataParser::srpId() { return parameters[5]; }
inline uint32_t DCCTBDataParser::tcc1Id() { return parameters[6]; }
inline uint32_t DCCTBDataParser::tcc2Id() { return parameters[7]; }
inline uint32_t DCCTBDataParser::tcc3Id() { return parameters[8]; }
inline uint32_t DCCTBDataParser::tcc4Id() { return parameters[9]; }
inline void DCCTBDataParser::setParameters(const std::vector<uint32_t> &newParameters) {
parameters = newParameters;
computeBlockSizes();
}
inline uint32_t DCCTBDataParser::srpBlockSize() { return srpBlockSize_; }
inline uint32_t DCCTBDataParser::tccBlockSize() { return tccBlockSize_; }
inline bool DCCTBDataParser::debug() { return debug_; }
inline std::vector<DCCTBEventBlock *> &DCCTBDataParser::dccEvents() { return dccEvents_; }
inline std::map<std::string, uint32_t> &DCCTBDataParser::errorCounters() { return errors_; }
inline std::vector<std::pair<uint32_t, std::pair<const uint32_t *, uint32_t> > > DCCTBDataParser::events() {
return events_;
}
#endif
|