13 #include "GaudiKernel/MsgStream.h"
15 #include "eformat/SourceIdentifier.h"
16 using eformat::helper::SourceIdentifier;
45 for (
const std::vector<uint32_t>&
v : allmap) {
49 std::vector<uint32_t>
data(
v.begin()+1,
v.end());
63 eformat::SubDetector detid[6];
65 detid[0] = eformat::TILECAL_LASER_CRATE;
66 detid[1] = eformat::TILECAL_BARREL_A_SIDE;
67 detid[2] = eformat::TILECAL_BARREL_C_SIDE;
68 detid[3] = eformat::TILECAL_EXT_A_SIDE;
69 detid[4] = eformat::TILECAL_EXT_C_SIDE;
70 detid[5] = eformat::TDAQ_BEAM_CRATE;
98 SourceIdentifier sid = SourceIdentifier(detid[
ros],
id);
133 eformat::SubDetector detid[6];
135 detid[0] = eformat::TILECAL_LASER_CRATE;
136 detid[1] = eformat::TILECAL_BARREL_A_SIDE;
137 detid[2] = eformat::TILECAL_BARREL_C_SIDE;
138 detid[3] = eformat::TILECAL_EXT_A_SIDE;
139 detid[4] = eformat::TILECAL_EXT_C_SIDE;
140 detid[5] = eformat::TDAQ_BEAM_CRATE;
157 id = (
drawer >> 3) + 0x100;
161 id = (
drawer >> 2) + 0x100;
164 SourceIdentifier sid = SourceIdentifier(detid[
ros],
id);
177 int size=ROD2ROB.size();
182 if ( frag < 0x2000 ) {
190 log << MSG::INFO <<
"TileHid2RESrcID:: mapping frag 0x"<< MSG::hex
191 << frag <<
" to ROB 0x" << rob << MSG::dec <<
endmsg;
194 log << MSG::ERROR <<
"You are using obsolete ROD to ROB mapping" <<
endmsg;
195 log << MSG::ERROR <<
"Please, replace it by frag -> ROB mapping" <<
endmsg;
200 log << MSG::INFO <<
"TileHid2RESrcID:: " << fragCount
201 <<
" frag to ROD remappings set via jobOptions" <<
endmsg;
213 if ( ( (
runnum>318000 &&
m_runnum<=318000) || (runnum<=318000 && m_runnum>318000) ) ) {
214 log << MSG::INFO <<
"Reinitializing TileHid2RESrcID for run " <<
runnum <<
endmsg;
218 uint32_t nBeamFrag=0, nRODfrag=0, nDataFrag[10]={0,0,0,0,0,0,0,0,0,0},
flags=0xFFFF,
flags5=0xFFFF;
219 std::map<int,int> fragMap;
220 std::map<int,int> beamMap;
223 bool cisparFound =
false;
227 for (
size_t idet=0; idet<ndet; ++idet) {
229 event->child(fpdet, idet);
234 const auto ROBSubDetID = eformat::helper::SourceIdentifier(ROBid).subdetector_id();
235 const auto ROBSubDetGroup = eformat::helper::SourceIdentifier(ROBid).subdetector_group();
236 if (ROBSubDetGroup == eformat::SubDetectorGroup::TILECAL ||
237 ROBSubDetID == eformat::SubDetector::TDAQ_BEAM_CRATE || ROBSubDetID == 0) {
239 unsigned int source_id = robf.rod_source_id();
240 eformat::helper::SourceIdentifier
id = eformat::helper::SourceIdentifier(source_id);
241 unsigned int subdet_id =
id.subdetector_id();
243 unsigned int size = robf.rod_ndata();
244 unsigned int max_allowed_size = robf.rod_fragment_size_word();
245 unsigned int delta = robf.rod_header_size_word() + robf.rod_trailer_size_word();
246 if (max_allowed_size > delta) max_allowed_size-=delta;
else max_allowed_size=0;
247 if (
size > max_allowed_size)
size = max_allowed_size;
251 if (robf.rod_status_position()==0 &&
252 robf.rod_nstatus() + robf.rod_header_size_word() + robf.rod_trailer_size_word() >= robf.rod_fragment_size_word()) {
253 robf.rod_status(
data);
258 switch ( subdet_id ) {
267 unsigned int offset = 0, sizePos = 1, idPos = 2;
268 if ( *(
data) != 0xff1234ff ) {
280 if ( fragsize <= idPos || fragsize >
size)
break;
282 int fragtype = upperhalf & 0xFF;
284 if (fragtype >= 0x40 && fragtype < 0x50) {
286 int ros = subdet_id&0xF;
289 int nmod = (
ros>2)?8:4;
290 fragid = (
ros<<8) | (source_id&0xF)*nmod;
294 log << MSG::INFO <<
"New TMDB frag 0x" << MSG::hex << fragid
295 <<
" type 0x" << fragtype <<
" vers 0x"<< vers
296 <<
" in ROB 0x" << ROBid << MSG::dec <<
endmsg;
298 if ( (*it).second != ROBid ) {
299 log << MSG::INFO <<
"TMDB frag 0x" << MSG::hex << fragid
300 <<
" type 0x" << fragtype <<
" vers 0x"<< vers
301 <<
" remapping from ROB 0x" << (*it).second
302 <<
" to 0x" << ROBid << MSG::dec <<
endmsg;
305 <<
" type 0x" << fragtype <<
" vers 0x"<< vers
306 <<
" found in ROB 0x" << (*it).second
307 <<
" as expected" << MSG::dec <<
endmsg;
310 for (
int nf=0; nf<nmod; ++nf) {
322 FRAGFULLMAP::const_iterator
it =
m_frag2ROD.find(fragid);
324 log << MSG::INFO <<
"New frag 0x" << MSG::hex << fragid
325 <<
" in ROB 0x" << ROBid << MSG::dec <<
endmsg;
327 if ( (*it).second[0] != ROBid ) {
328 log << MSG::INFO <<
"Frag 0x" << MSG::hex << fragid
329 <<
" remapping from ROB 0x" << (*it).second[0]
330 <<
" to 0x" << ROBid << MSG::dec <<
endmsg;
333 <<
" found in ROB 0x" << (*it).second
334 <<
" as expected" << MSG::dec <<
endmsg;
342 }
else if (fragid < 0x100) {
345 if (fragtype == 0x30) {
351 }
else if (fragid < 0x500 || fragtype == 6) {
360 if (fragtype == 4)
flags = upperhalf;
361 else if (fragtype == 5) {
363 fragIDs.push_back((
int)fragid);
378 log << MSG::INFO <<
"TileHid2RESrcID: Attention! Taking CISpar from lastROD 0x" << MSG::hex << lascisROB << MSG::dec <<
endmsg;
380 log << MSG::INFO <<
"TileHid2RESrcID: no CISpar in the data" <<
endmsg;
383 log << MSG::INFO <<
"TileHid2RESrcID: " << nBeamFrag <<
" beam sub-frags (";
384 std::map<int,int>::const_iterator itr=beamMap.begin();
385 std::map<int,int>::const_iterator
end=beamMap.end();
386 for (; itr!=
end; ++itr) {
387 log <<
" type=0x" << MSG::hex << itr->first << MSG::dec <<
" nf="<<itr->second;
389 log << MSG::INFO <<
" ) and " << nRODfrag <<
" ROD sub-frags (";
392 for (; itr!=
end; ++itr) {
393 log <<
" type=0x" << MSG::hex << itr->first << MSG::dec <<
" nf="<<itr->second;
394 if (itr->first < 10) nDataFrag[itr->first]+=itr->second;
397 log <<
" ) was found in the data" <<
endmsg;
403 if (nDataFrag[4]!=0) {
404 if ((
flags & 0x3000) < 0x3000)
406 }
else if (nDataFrag[5]!=0) {
407 if ((
flags5 & 0x3000) < 0x3000)
412 if (
of2 != of2Default) {
413 log << MSG::INFO <<
"Setting OF2 flag in in TileROD_Decoder to " << ((
of2) ?
"True" :
"False")
414 <<
" instead of " << ((of2Default) ?
"True" :
"False") <<
endmsg;
425 std::cout <<
" TileHid2RESrcID invalid FRAG ID 0x"<<std::hex<<frag_id<<std::dec<<std::endl;
430 if (
it->second.size() < 2) {
431 it->second.resize(2);
433 it->second[1] = bs_frag;
441 std::cout <<
" TileHid2RESrcID invalid FRAG ID 0x"<<std::hex<<frag_id<<std::dec<<std::endl;
446 size_t siz =
it->second.size();
448 it->second.resize(3);
450 it->second[1] = frag_id;
468 FRAGFULLMAP::const_iterator
it =
m_frag2ROD.find(frag_id);
471 std::cout <<
" TileHid2RESrcID invalid FRAG ID 0x"<<std::hex<<frag_id<<std::dec<<std::endl;
477 return ( (*it).second[0] ) ;
484 FRAGFULLMAP::const_iterator
it =
m_frag2ROD.find(frag_id);
487 std::cout <<
" TileHid2RESrcID invalid FRAG ID 0x"<<std::hex<<frag_id<<std::dec<<std::endl;
493 return ((((*it).second.size()>1) ? (*it).second[1] : frag_id) ) ;
500 FRAGFULLMAP::const_iterator
it =
m_frag2ROD.find(frag_id);
502 std::cout <<
" TileHid2RESrcID invalid FRAG ID 0x"<<std::hex<<frag_id<<std::dec<<std::endl;
507 return (((*it).second.size()>2) ? (*it).second[2] : 0);
514 FRAGFULLMAP::const_iterator
it =
m_frag2ROD.find(frag_id);
516 std::cout <<
" TileHid2RESrcID invalid FRAG ID 0x"<<std::hex<<frag_id<<std::dec<<std::endl;
540 if (
v.second.size()>1) {
562 SourceIdentifier
id = SourceIdentifier(rob_id);
563 SourceIdentifier
id2 = SourceIdentifier(
id.subdetector_id(),0);
574 SourceIdentifier
id = SourceIdentifier(ros_id);
575 SourceIdentifier
id2 = SourceIdentifier(
id.subdetector_id(),0);
592 std::cout <<
" TileHid2RESrcID invalid FRAG ID 0x"<<std::hex<<frag_id<<std::dec<<std::endl;
597 return ( (*it).second ) ;
602 const char *
names[] = {
"Legacy",
"Demo",
"DemoEB",
"Unknown"};
604 const std::vector<uint32_t> &
v =
it.second;
606 if (
it.first !=
static_cast<int>(
v[1])) {
607 log << MSG::INFO <<
"Frag 0x" << std::hex <<
it.first <<
" is taken from bytestream frag 0x" <<
v[1] << std::dec <<
endmsg;
610 log << MSG::INFO <<
"Frag 0x" << std::hex <<
it.first <<
" fragment type is "