12 #include "interface/evb/i2oEVBMsgs.h"
13 #include "interface/shared/frl_header.h"
14 #include "interface/shared/fed_header.h"
15 #include "interface/shared/fed_trailer.h"
21 using std::stringstream;
22 using std::ostringstream;
34 if (res_->iBlock_ == res_->nBlock_) {
36 res_->nBlock_ = 0xffffffff;
39 I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME *
block =
40 (I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME*) bufRef->getDataLocation();
42 UInt_t iBlock = block->blockNb;
43 UInt_t nBlock = block->nbBlocksInSuperFragment;
44 UInt_t iSuperFrag = block->superFragmentNb;
45 UInt_t nSuperFrag = block->nbSuperFragmentsInEvent;
46 UInt_t fuResourceId = block->fuTransactionId;
47 UInt_t buResourceId = block->buResourceId;
48 UInt_t evtNumber = block->eventNumber;
50 oss <<
"TransId:" << fuResourceId <<
" BUResourceId:" << buResourceId
51 <<
" eventNumber:" << evtNumber <<
" ";
53 if (fuResourceId != res_->fuResourceId_) {
56 oss <<
"RU/FU fuResourceId mismatch." <<
" Received:" << fuResourceId
57 <<
" Expected:" << res_->fuResourceId_;
62 if (iBlock != res_->iBlock_) {
64 oss <<
"RU/FU block number mismatch." <<
" Received:" << iBlock
65 <<
" Expected:" << res_->iBlock_;
70 if (iSuperFrag != res_->iSuperFrag_) {
72 oss <<
"RU/FU superfragment number mismatch." <<
" Received:"
73 << iSuperFrag <<
" Expected:" << res_->iSuperFrag_;
79 res_->nBlock_ = nBlock;
82 if (nBlock != res_->nBlock_) {
84 oss <<
"RU/FU number of blocks mismatch." <<
" Received:" << nBlock
85 <<
" Expected:" << res_->nBlock_;
92 if (iBlock == 0 && iSuperFrag == 0) {
93 res_->evtNumber_ = evtNumber;
94 res_->buResourceId_ = buResourceId;
95 res_->nSuperFrag_ = nSuperFrag;
97 res_->shmCell_->setEvtNumber(evtNumber);
98 res_->shmCell_->setBuResourceId(buResourceId);
101 if (res_->nSuperFrag_ > res_->nSuperFragMax_) {
103 oss <<
"Invalid maximum number of superfragments."
104 <<
" fuResourceId:" << res_->fuResourceId_ <<
" evtNumber:"
105 << res_->evtNumber_ <<
" nSuperFrag:" << res_->nSuperFrag_
106 <<
" nSuperFragMax:" << res_->nSuperFragMax_;
114 if (evtNumber != res_->evtNumber_) {
116 oss <<
"RU/FU evtNumber mismatch." <<
" Received:" << evtNumber
117 <<
" Expected:" << res_->evtNumber_;
122 if (buResourceId != res_->buResourceId_) {
124 oss <<
"RU/FU buResourceId mismatch."
125 << buResourceId <<
" Expected:" << res_->buResourceId_;
130 if (nSuperFrag != res_->nSuperFrag_) {
132 oss <<
"RU/FU number of superfragments mismatch." <<
" Received:"
133 << nSuperFrag <<
" Expected:" << res_->nSuperFrag_;
140 checkDataBlockPayload(bufRef);
142 oss <<
"data block payload failed check." <<
" evtNumber:"
143 << res_->evtNumber_ <<
" buResourceId:" << res_->buResourceId_
144 <<
" iSuperFrag:" << res_->iSuperFrag_;
148 res_->appendBlockToSuperFrag(bufRef);
154 bool lastBlockInSuperFrag = (iBlock == nBlock - 1);
155 if (lastBlockInSuperFrag) {
160 res_->superFragSize();
162 oss <<
"Invalid super fragment size." <<
" evtNumber:"
163 << res_->evtNumber_ <<
" buResourceId:"
164 << res_->buResourceId_ <<
" iSuperFrag:"
165 << res_->iSuperFrag_;
166 res_->removeLastAppendedBlockFromSuperFrag();
170 res_->fillSuperFragPayload();
174 oss <<
"Invalid super fragment." <<
" evtNumber:"
175 << res_->evtNumber_ <<
" buResourceId:"
176 << res_->buResourceId_ <<
" iSuperFrag:"
177 << res_->iSuperFrag_;
178 res_->removeLastAppendedBlockFromSuperFrag();
184 res_->releaseSuperFrag();
187 oss <<
"Failed to release super fragment." <<
" evtNumber:"
188 << res_->evtNumber_ <<
" buResourceId:"
189 << res_->buResourceId_ <<
" iSuperFrag:"
190 << res_->iSuperFrag_;
208 UInt_t segSizeExpected = 0;
210 frlh_t *frlHeader = 0;
215 frameSize =
sizeof(I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME);
217 blockAddr = (
UChar_t*) bufRef->getDataLocation();
218 frlHeaderAddr = blockAddr + frameSize;
219 frlHeader = (frlh_t*) frlHeaderAddr;
221 I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME *
block =
222 (I2O_EVENT_DATA_BLOCK_MESSAGE_FRAME*) blockAddr;
225 if (res_->evtNumber_ != frlHeader->trigno) {
228 oss <<
"FRL header \"trigno\" does not match " <<
"FU \"evtNumber\"."
229 <<
" trigno:" << frlHeader->trigno <<
" evtNumber:"
235 if (block->eventNumber != frlHeader->trigno) {
238 oss <<
"FRL header \"trigno\" does not match "
239 <<
"RU builder header \"eventNumber\"." <<
" trigno:"
240 << frlHeader->trigno <<
" eventNumber:" << block->eventNumber;
245 if (block->blockNb != frlHeader->segno) {
248 oss <<
"FRL header \"segno\" does not match"
249 <<
"RU builder header \"blockNb\"." <<
" segno:"
250 << frlHeader->segno <<
" blockNb:" << block->blockNb;
255 if (block->blockNb != res_->iBlock_) {
258 oss <<
"Incorrect block number." <<
" Expected:" << res_->iBlock_
259 <<
" Received:" << block->blockNb;
264 bufSize = bufRef->getDataSize();
265 segSizeExpected = bufSize - frameSize -
sizeof(frlh_t);
266 segSize = frlHeader->segsize & FRL_SEGSIZE_MASK;
267 if (segSize != segSizeExpected) {
270 oss <<
"FRL header segment size is not as expected." <<
" Expected:"
271 << segSizeExpected <<
" Received:" << segSize;
276 bool fuLastBlockInSuperFrag = (block->blockNb
277 == (block->nbBlocksInSuperFragment - 1));
278 bool frlLastBlockInSuperFrag = ((frlHeader->segsize & FRL_LAST_SEGM) != 0);
279 if (fuLastBlockInSuperFrag != frlLastBlockInSuperFrag) {
282 oss <<
"FU / FRL header end-of-superfragment mismatch."
283 <<
" FU header:" << fuLastBlockInSuperFrag <<
" FRL header:"
284 << frlLastBlockInSuperFrag;
311 fedTrailerAddr = superFragAddr + superFragSize -
sizeof(
fedt_t);
313 while (fedTrailerAddr > superFragAddr) {
315 fedTrailer = (
fedt_t*) fedTrailerAddr;
317 sumOfFedSizes += fedSize;
323 oss <<
"Missing FED trailer id." <<
" evtNumber:"
328 fedHeaderAddr = fedTrailerAddr - fedSize +
sizeof(
fedt_t);
331 if (fedHeaderAddr < superFragAddr) {
334 oss <<
"FED header address out-of-bounds." <<
" evtNumber:"
340 if ((fedHeaderAddr +
sizeof(
fedh_t)) > (superFragAddr + superFragSize)) {
343 oss <<
"FED payload out-of-bounds." <<
" evtNumber:"
348 fedHeader = (
fedh_t*) fedHeaderAddr;
354 oss <<
"Missing FED header id." <<
" evtNumber:"
366 oss <<
"FU / FED evtNumber mismatch." <<
" FU:" <<
res_->
evtNumber_
367 <<
" FED:" << evtNumber <<
" fedid:" << fedId;
376 "Invalid fedid. Data will still be logged" <<
" evtNumber:"
386 "Duplicated fedid. Data will be lost for" <<
" evtNumber:"
427 <<
" fedid:" << fedId <<
" crc:" << crc <<
" chk:"
429 LOG4CPLUS_INFO(
res_->
log_, oss.str());
431 res_->
app_->notifyQualified(
"error", sentinelException);
442 oss <<
"Failed to mark fed in buffer." <<
" evtNumber:"
444 << fedSize <<
" fedAddr:0x" << hex
445 << (
unsigned long) fedHeaderAddr << dec;
450 fedTrailerAddr = fedTrailerAddr - fedSize;
454 if ((fedTrailerAddr +
sizeof(
fedh_t)) != superFragAddr) {
456 oss <<
"First FED in superfragment ouf-of-bound." <<
" evtNumber:"
static bool doFedIdCheck_
struct fedt_struct fedt_t
bool gtpe_board_sense(const unsigned char *p)
unsigned int get(const unsigned char *, bool)
ResourceChecker(FUResource *const resToCheck)
toolbox::mem::Reference MemRef_t
void processDataBlock(MemRef_t *bufRef)
bool markFed(unsigned int i, unsigned int size, unsigned char *addr)
void checkDataBlockPayload(MemRef_t *bufRef)
evf::FUShmRawCell * shmCell_
static unsigned int gtpDaqId_
unsigned int getlbn(const unsigned char *)
unsigned short compute_crc(unsigned char *buffer, unsigned int bufSize)
unsigned char * superFragAddr(unsigned int i) const
void setEvtNumber(unsigned int evt)
bool evm_board_sense(const unsigned char *p, size_t size)
unsigned int superFragSize(unsigned int i) const
static unsigned int gtpeId_
void setLumiSection(unsigned int)
static unsigned int gtpEvmId_
unsigned int gtpe_get(const unsigned char *)
bool daq_board_sense(const unsigned char *p)
bool nextEventWillHaveCRCError_