6 #include "GaudiKernel/MsgStream.h"
7 #include "Gaudi/Property.h"
10 #include "eformat/Status.h"
12 #include "GaudiKernel/TypeNameString.h"
18 #include "GaudiKernel/ThreadLocalContext.h"
32 static const InterfaceID IID_ITBByteStreamCnvTool
33 (
"TBByteStreamCnvTool", 1, 0);
34 return IID_ITBByteStreamCnvTool;
40 (
const std::string&
type,
const std::string&
name,
const IInterface*
parent )
42 m_ByteStreamEventAccess(
"ByteStreamCnvSvc",
name),
43 m_rdpSvc(
"ROBDataProviderSvc",
name),
44 m_lastEventID(0, UINT_MAX), m_subdet_id(
eformat::TDAQ_BEAM_CRATE),
45 m_theRodBlock(0), m_theROB(0)
47 declareInterface< TBByteStreamCnvTool >(
this );
61 if (
sc!=StatusCode::SUCCESS)
67 sc =
detStore()->retrieve(online_id,
"LArOnlineID");
70 return StatusCode::FAILURE;
80 std::vector<std::string>::const_iterator
it =
m_keys.begin();
81 std::vector<std::string>::const_iterator it_e =
m_keys.end();
82 std::vector<std::string>
keys;
84 for(;
it!=it_e;++
it) {
85 const Gaudi::Utils::TypeNameString &
item(*
it);
86 const std::string &
t =
item.type();
87 const std::string &
nm =
item.name();
90 if(
t==
"TBTriggerPatternUnit")
keys[1]=
nm;
91 if(
t==
"TBTDCRawCont")
keys[2]=
nm;
92 if(
t==
"TBADCRawCont")
keys[3]=
nm;
93 if(
t==
"TBTailCatcherRaw")
keys[4]=
nm;
94 if(
t==
"TBBPCRawCont")
keys[5]=
nm;
95 if(
t==
"TBScintillatorRawCont")
keys[6]=
nm;
96 if(
t==
"TBMWPCRawCont")
keys[7]=
nm;
119 return StatusCode::SUCCESS;
124 return StatusCode::SUCCESS;
143 if (
sc!=StatusCode::SUCCESS)
144 {logstr << MSG::WARNING <<
"No EventInfo object found!" <<
endmsg;
149 {logstr << MSG::WARNING <<
"LArByteStrem persistency representation for Event #"<<thisEvent->event_number()
150 <<
" already created!" <<
endmsg;
151 return StatusCode::SUCCESS;
168 if (
sc!=StatusCode::SUCCESS)
177 const bool status_place=eformat::STATUS_BACK;
181 eformat::helper::SourceIdentifier robsid(
m_subdet_id, module_id);
183 (robsid.code(),run_no,lvl1_id,bc_id,lvl1_type,detev_type,
m_theRodBlock->size(),
187 logstr <<
MSG::DEBUG <<
"Appended TestBeam fragment to ByteStream" <<
endmsg;
188 return StatusCode::SUCCESS;
201 const TBTDC* tbtdc =
nullptr;
202 std::string tbtdc_Key(
"TBTDC");
204 if (
sc!=StatusCode::SUCCESS)
205 {logstr << MSG::ERROR <<
"Can't retrieve TBTDC with key "<< tbtdc_Key <<
" from StoreGate" <<
endmsg;
209 theRodBlock->push_back(4);
210 theRodBlock->push_back(0x03);
211 theRodBlock->push_back(tbtdc->
tdc());
212 theRodBlock->push_back(tbtdc->
tdcmin());
250 return StatusCode::SUCCESS;
276 if (
sc!=StatusCode::SUCCESS)
280 logstr <<
"ReadRodBlock: RodBlock too small!" <<
endmsg;
281 return StatusCode::FAILURE;
288 return StatusCode::SUCCESS;
368 logstr << MSG::ERROR <<
" Can not create a LArDigitContainer with key="<<
key<<
endmsg;
370 return StatusCode::FAILURE;
387 logstr << MSG::ERROR <<
" Can not create a LArCalibDigitContainer with key="<<
key<<
endmsg;
388 tblarcalibdigitcont =0;
389 return StatusCode::FAILURE;
396 eformat::SubDetector subdet_rod_id)
401 {logstr << MSG::ERROR <<
"ROBDataProviderSvc not loaded. Can't read ByteStream" <<
endmsg;
402 return StatusCode::FAILURE;
409 return StatusCode::FAILURE;
412 const size_t MAX_ROBFRAGMENTS = 2048*1024;
413 std::vector<OFFLINE_FRAGMENTS_NAMESPACE::PointerType> robF(MAX_ROBFRAGMENTS);
414 size_t robcount =
re->children(robF.data(),MAX_ROBFRAGMENTS);
416 if (robcount == MAX_ROBFRAGMENTS)
419 return StatusCode::FAILURE;
422 for (
size_t irob=0; irob<robcount; ++irob)
428 MSG::hex(logstr) <<
MSG::DEBUG <<
"Frag Size : " << rob.fragment_size_word() <<
endmsg;
429 MSG::hex(logstr) <<
MSG::DEBUG <<
"Header Size: " << rob.header_size_word() <<
endmsg;
430 MSG::hex(logstr) <<
MSG::DEBUG <<
"Source ID : " << rob.source_id() <<
endmsg;
438 logstr << MSG::ERROR <<
"Got invalid ROB fragment!" <<
endmsg;
439 return StatusCode::FAILURE;
443 MSG::hex(logstr) <<
MSG::DEBUG <<
"Frag Size : " << rob.rod_fragment_size_word() <<
endmsg;
444 MSG::hex(logstr) <<
MSG::DEBUG <<
"Header Size: " << rob.rod_header_size_word() <<
endmsg;
445 MSG::hex(logstr) <<
MSG::DEBUG <<
"Source ID : " << rob.rod_source_id() <<
endmsg;
446 MSG::hex(logstr) <<
MSG::DEBUG <<
"Run num : " << rob.rod_run_no() <<
endmsg;
447 MSG::hex(logstr) <<
MSG::DEBUG <<
"Version : " << rob.rod_version() <<
endmsg;
449 eformat::helper::SourceIdentifier rod_sid(rob.rod_source_id());
452 MSG::hex(logstr) <<
MSG::DEBUG <<
"Found requested ROD (id="
453 << rod_sid.subdetector_id() <<
")" <<
endmsg;
457 logstr<<
MSG::INFO <<
"Guessing from ROD header -> " ;
458 if (rob.rod_detev_type()&1)
460 logstr<<
" H6 !" <<
endmsg;
466 logstr<<
" H8 !" <<
endmsg;
477 rob.rod_data(rodPointer);
479 for(
size_t i=0;
i<rob.rod_ndata(); ++
i)
487 logstr <<
MSG::FATAL <<
"Error reading bytestream event: "
488 <<
"Empty ROD block" <<
endmsg;
489 return StatusCode::FAILURE;
491 logstr <<
MSG::DEBUG <<
"Got Rod Block for Test Beam Instrumentation data from ByteStream" <<
endmsg;
492 return StatusCode::SUCCESS;
496 MSG::hex(logstr) << MSG::WARNING <<
" Didn't find SubDet ID for Beam Instruments. Should be "<< subdet_id<<
endmsg;
497 return StatusCode::FAILURE;
516 const EventContext& ctx = Gaudi::Hive::currentContext();
523 std::ostringstream
os;
527 if (
sc!=StatusCode::SUCCESS)
531 logstr << MSG::ERROR <<
"ReadRodBlock: RodBlock too small!" <<
endmsg;
532 return StatusCode::FAILURE;
547 std::string
name1,name2;
596 short m_feedthrough[8] = {0,0,0,0,1,1,1,1};
597 int m_sampleOrder[32] = {
598 0,1,2,3,4,5,6,7,8,9,10,
599 11,12,13,14,15,16,17,18,19,20,
600 21,22,23,24,25,26,27,28,29,30,
602 int m_sort[64] = { 55, 39, 23, 7, 119, 103, 87, 71,
603 54, 38, 22, 6, 118, 102, 86, 70,
604 53, 37, 21, 5, 117, 101, 85, 69,
605 52, 36, 20, 4, 116, 100, 84, 68,
606 51, 35, 19, 3, 115, 99, 83, 67,
607 50, 34, 18, 2, 114, 98, 82, 66,
608 49, 33, 17, 1, 113, 97, 81, 65,
609 48, 32, 16, 0, 112, 96, 80, 64
613 constexpr
short m_slot[8]={5,7,9,11,3,4,5,6};
615 constexpr
int NWREC = 8;
617 for(
unsigned int nfeb=0;nfeb<
m_boards.size();nfeb++){
636 if((m_sampleOrder[0]=
m_febgain[nfeb])!=0){
637 for(
int j=0;j<
m_febgain[nfeb];j++) {m_sampleOrder[j+1]=j;}
640 samp=m_sampleOrder[
s];
643 for(
int i= 0 ;
i<64;
i++){
647 unsigned short gain1 = ((tmp1>>12)&3) - 1;
651 unsigned short gain2 = ((
tmp2>>12)&3) - 1;
678 for(
int i=0;
i<128;
i++) {
688 const std::vector<HWIdentifier>& calibChannelIDs=calibLine->
calibSlotLine(hwid);
689 if (calibChannelIDs.size() != 0) {
719 name1=
"word1frag0x03chan";
720 name2=
"word2frag0x03chan";
724 logstr<<MSG::ERROR<<
"Beam counter subfrag (0x03) has not expected size" <<
endmsg;
725 sc=StatusCode::FAILURE;
765 name1=
"word1frag0x06chan";
766 name2=
"word2frag0x06chan";
767 std::string tcname=
"tc";
768 std::vector<TBScintillatorRaw *> theScints;
770 logstr<<MSG::ERROR<<
"Beam counter subfrag (0x04) has not expected size" <<
endmsg;
771 sc=StatusCode::FAILURE;
775 for(
unsigned int i=0;
i<24;
i++){
798 os << tcname << 2*
i+1;
800 theScints.push_back(
s1);
801 theScints.push_back(
s2);
811 name1=
"word1frag0x05chan";
812 name2=
"word2frag0x05chan";
815 logstr <<
MSG::DEBUG <<
"H6BuildObject : number of BPCRaw "<< bpcnum <<
endmsg;
817 for(
int i=0;
i<bpcnum;
i++){
818 std::string bpcname =
"BPC";
822 std::vector<const TBTDCRaw*> theTDCs;
823 std::vector<const TBADCRaw*> theADCs;
826 unsigned int tmp1,
tmp2;
833 os << name2 << (
i*3);
842 os << name2 << (
i*3+1);
850 MSG::hex(logstr) <<
MSG::DEBUG << bpcname<<
" "<< tmp1;
851 MSG::hex(logstr) <<
" "<<
tmp2<<
" ";
859 os << name2 << (
i*3+2);
864 MSG::hex(logstr) <<
MSG::DEBUG << bpcname<<
" "<< tmp1;
868 theTDCs.push_back(tbtdcL);
869 theTDCs.push_back(tbtdcR);
870 theTDCs.push_back(tbtdcU);
871 theTDCs.push_back(tbtdcD);
872 theADCs.push_back(tbadcH);
873 theADCs.push_back(tbadcV);
884 name1=
"word1frag0x06chan";
885 name2=
"word2frag0x06chan";
887 logstr<<MSG::ERROR<<
"Beam counter subfrag (0x06) has not expected size" <<
endmsg;
888 sc=StatusCode::FAILURE;
902 logstr <<
MSG::DEBUG <<
" building muon counters:";
903 for(
int i=0;
i<8;
i++) {
904 std::string scintname=
"muon";
906 os << scintname << (
i+1);
942 for(
int i=0;
i<4;
i++) {
949 os << name2 << (0+3+
i);
954 if(
testbit(10,word2)) adc2->setOverflow();
1001 for(
int i=0;
i<8;
i++) {
1005 logstr <<
MSG::DEBUG <<
" Should I record TBScintillatorRawCont with key " <<
m_keys[6] <<
" ? " <<
endmsg;
1014 logstr <<
MSG::DEBUG <<
" Found MWPC subfragment. Nword= "<<nword <<
endmsg;
1016 std::string mwpcnames[8]= {
"X2",
"Y2",
"X3",
"Y3",
"X4",
"Y4",
"X5",
"Y5"};
1017 bool isX[9]={
true,
false,
true,
false,
true,
false,
true,
false};
1019 for(
int i=0;
i<8;
i++){
1068 w = (
int) (word2>>12);
c = (
int) ((0xfff & word2) -
w/2 + !(
w&1));
1083 for(
int i=0;
i<8;
i++){
1098 logstr << MSG::ERROR <<
"bad number of lines. nwords=" << nword <<
endmsg;
1101 int nline= nword / 16;
1103 for(
int i=0;
i<nline;
i++){
1105 std::string sline=
"";
1106 std::string skey=
"";
1107 for(
int j=0;j<63;j++) {
1108 if(strw[
i*64+j]==0)
break;
1109 sline+=strw[
i*64+j];
1112 std::istringstream iss (sline);
1114 if(skey==
"RunNumber") {
1118 if(skey==
"BeamMomentum") {
1122 if(skey==
"BeamParticle") {
1130 if(skey==
"CryoAngle") {
1134 if(skey==
"TableY") {
1138 if(skey==
"miniROD") {
1143 while(iss.good()) {iss>>board;
m_boards.push_back(board);}
1148 if(skey==
"FebSamples") {
1158 if(skey==
"FebGains") {
1170 if(skey==
"FebAuto") {
1180 if(skey==
"FebFirstSample") {
1185 while(iss.good()) {iss>>firstsample;
m_firstsamples.push_back(firstsample);}
1217 logstr <<
MSG::DEBUG <<
" Found Calib_ID subfragment. Nword= "<<nword <<
endmsg;
1219 logstr<<MSG::ERROR<<
"Calibration subfrag (0xff) has not expected size" <<
endmsg;
1220 sc=StatusCode::FAILURE;
1226 for(
int i=0;
i<4;
i++){
1238 for(
int byte=0;
byte<16;
byte++) {
1239 logstr <<
MSG::DEBUG <<
" byte " <<
byte <<
" : " ;
1240 for(
int bit=0; bit<8; bit++) {
1292 logstr <<
MSG::DEBUG <<
"H8BuildObject invoked for code " << unrec_code<<
endmsg;
1295 bool gotobject=
false;
1296 bool recordfailure=
false;
1298 bool goodRodBlock=
true;
1307 if (
sc!=StatusCode::SUCCESS) {
1309 logstr << MSG::ERROR <<
"ReadRodBlock: RodBlock error! Will try to fill SG with empty objects." <<
endmsg;
1313 logstr << MSG::ERROR <<
"ReadRodBlock: RodBlock too small! Will try to fill SG with empty objects." <<
endmsg;
1375 short tdc_order[4] = {2,3,0,1};
1376 for(
int i=0;
i<BPCNum;
i++){
1378 for(
int j=0;j<4;j++) BPCtdc[
i][j]=0;
1387 std::ostringstream
os;
1400 name=
"frag0x10chan";
1467 logstr <<
" " << S3rightadc->
getADC()<<
" " << muTagadc->
getADC() <<
" " << C1adc->
getADC();
1476 name=
"frag0x11chan";
1509 name=
"frag0x12chan";
1525 logstr <<
MSG::DEBUG << MSG::dec <<
"Pos=" <<
pos <<
" Chan "<<
chan <<
"=" << tdc <<
", OV=" << overflow
1526 <<
", UN=" <<underthresh <<
" EOD="<< endofdata <<
", corrupt=" << corrup
1532 if (!endofdata && !corrup) {
1537 ClockPhasetdc =
new TBTDCRaw(
os.str(),overflow,tdc,underthresh);
1541 S1tdc =
new TBTDCRaw(
os.str(),overflow,tdc,underthresh);
1545 S2downtdc =
new TBTDCRaw(
os.str(),overflow,tdc,underthresh);
1549 S3lefttdc =
new TBTDCRaw(
os.str(),overflow,tdc,underthresh);
1553 S2uptdc =
new TBTDCRaw(
os.str(),overflow,tdc,underthresh);
1557 S3righttdc =
new TBTDCRaw(
os.str(),overflow,tdc,underthresh);
1561 S0tdc =
new TBTDCRaw(
os.str(),overflow,tdc,underthresh);
1574 logstr << MSG::ERROR <<
" Unexpected end-of-data word found at pos " <<
pos <<
endmsg;
1577 logstr<< MSG::ERROR <<
"Corrupted data in SubFragment 0x12 pos=" <<
pos <<
"channel=" <<
chan <<
" [0x" <<
1585 name=
"frag0x13chan";
1596 logstr <<
MSG::DEBUG << MSG::dec <<
"Pos=" <<
pos <<
" Chan "<<
chan <<
"=" << tdc
1597 <<
" EOD="<< endofdata <<
", corrupt=" << corrup
1599 if (!endofdata && !corrup) {
1604 const short bpc_ind =
chan / 4 ;
1606 logstr<<
MSG::DEBUG <<
"Error in 0x13 : found chan="<<
chan<<
" corresponding to bpc "<<bpc_ind<<
endmsg;
1609 const short signaltype = tdc_order[
chan % 4];
1610 if (BPCtdc[bpc_ind][signaltype]==NULL)
1611 BPCtdc[bpc_ind][signaltype] = tbtdc;
1618 logstr << MSG::ERROR <<
" Unexpected end-of-data word found at pos " <<
pos <<
endmsg;
1621 logstr<< MSG::ERROR <<
"Corrupted data in SubFragment 0x13 pos=" <<
pos <<
"channel=" <<
chan <<
" [0x" <<
1629 name=
"frag0x14chan";
1647 logstr <<
MSG::DEBUG << MSG::dec <<
"Pos=" <<
pos <<
" Chan "<<
chan <<
"=" << tdc
1648 <<
" EOD="<< endofdata <<
", corrupt=" << corrup
1651 if (!endofdata && !corrup) {
1656 const short bpc_ind =
chan / 4 + 3;
1657 if(bpc_ind>4) { logstr<<
MSG::DEBUG <<
"Error in 0x14 : found chan="<<
chan<<
" corresponding to bpc "<<bpc_ind<<
endmsg;
continue;}
1658 const short signaltype = tdc_order[
chan % 4];
1659 if (BPCtdc[bpc_ind][signaltype]==NULL)
1660 BPCtdc[bpc_ind][signaltype] = tbtdc;
1667 logstr << MSG::ERROR <<
" Unexpected end-of-data word found at pos " <<
pos <<
endmsg;
1670 logstr<< MSG::ERROR <<
"Corrupted data in SubFragment 0x14 pos=" <<
pos <<
"channel=" <<
chan <<
" [0x" <<
1739 for(
int i=0;
i<BPCNum;
i++){
1740 std::vector<const TBTDCRaw*> listtdc;
1741 std::vector<const TBADCRaw*> listadc;
1742 for(
int j=0;j<4;j++){
1743 if(BPCtdc[
i][j]==0) listtdc.push_back(dummytdc);
1744 else listtdc.push_back(BPCtdc[
i][j]);
1746 listadc.push_back(dummyadc); listadc.push_back(dummyadc);
1758 if (
sc!=StatusCode::SUCCESS) {
1760 goodRodBlock =
false;
1761 logstr << MSG::ERROR <<
"Tile laser crate ROD block error! Nothing valid in SG." <<
endmsg;
1764 logstr << MSG::ERROR <<
"Tile laser crate ROD block too small! Nothing valid in SG" <<
endmsg;
1766 goodRodBlock =
false;
1799 for(
int i=0;
i<8;
i++){
1801 std::stringstream RawName;
1802 RawName <<
"frag0x1chan"<<
i;
1806 std::stringstream MuWallName;
1807 MuWallName <<
"MuWall"<<
i;
1820 for(
int i=0;
i<4;
i++){
1822 std::stringstream RawName;
1823 RawName <<
"frag0x1chan"<<(
i+8);
1827 std::stringstream MuWallName;
1828 MuWallName <<
"MuWall"<<
i+8;
1861 if (
sc.isFailure( ) ) {recordfailure=
true;
1864 }
else {
sc=StatusCode::SUCCESS; gotobject=
true;}
1869 if (
sc.isFailure( ) ) {recordfailure=
true;
1872 }
else {
sc=StatusCode::SUCCESS; gotobject=
true;}
1877 if (
sc.isFailure( ) ) {recordfailure=
true;
1880 }
else {
sc=StatusCode::SUCCESS; gotobject=
true;}
1884 if (
sc.isFailure( ) ) {recordfailure=
true;
1887 }
else {
sc=StatusCode::SUCCESS; gotobject=
true;}
1896 if (
sc.isFailure( ) ) {
1897 logstr << MSG::ERROR <<
"Cannot record TBTrigPat " <<
endmsg;
1900 sc=StatusCode::SUCCESS;
1906 if(!gotobject) {logstr<< MSG::ERROR<<
" Could not find object of type "<<unrec_code <<
endmsg;
sc=StatusCode::FAILURE;}
1907 if(recordfailure) {logstr<< MSG::ERROR<<
" One object could not be recorded "<<
endmsg;
sc=StatusCode::FAILURE;}
1918 logstr <<
MSG::DEBUG <<
"About to try recording. unrec_code = " << unrec_code <<
endmsg;
1921 logstr <<
MSG::DEBUG <<
" WARNING! Did not find TailCatcher. Returning an empty one : this may crash every attempt to use it" <<
endmsg;
1928 if (
sc.isFailure( ) ) {
1929 logstr << MSG::ERROR <<
"Cannot record TBTrigPat " <<
endmsg;
1936 if (
sc.isFailure( ) ) {
1937 logstr << MSG::ERROR <<
"Cannot record TailCatcherRaw " <<
endmsg;
1945 if (
sc.isFailure( ) ) {
1946 logstr << MSG::ERROR <<
"Cannot record BPCRawCont" <<
endmsg;
1957 if (
sc.isFailure( ) ) {
1958 logstr << MSG::ERROR <<
"Cannot record ScintRawCont " <<
endmsg;
1969 if (
sc.isFailure( ) ) {
1970 logstr << MSG::ERROR <<
"Cannot record MWPCRawCont " <<
endmsg;
1984 if (
sc.isFailure( ) ) {
1985 logstr << MSG::ERROR <<
"Cannot record TDCCont " <<
endmsg;
1997 if (
sc.isFailure( ) ) {
2005 for(
int c=10;
c<14;
c++){
2010 if (
sc.isFailure( ) ) {
2016 for(
int c=10;
c<14;
c++){
2021 if (
sc.isFailure( ) ) {
2029 if (
sc.isFailure( ) ) {