using namespace std;
#include "htrb3unpacker.h"
#include "hdatasource.h"
#include "hdebug.h"
#include "hades.h"
#include "hevent.h"
#include "hldsubevt.h"
#include "heventheader.h"
#include "htrb3tdciterator.h"
#include "htrb3calpar.h"
#include "hruntimedb.h"
#include <iostream>
#include <iomanip>
#include <stdlib.h>
ClassImp(HTrb3Unpacker)
HTrb3Unpacker::HTrb3Unpacker(vector<UInt_t>& ids) :
HldUnpack(),
uHUBId(0x9000),
uCTSId(0x8000),
debugFlag(0),
quietMode(kFALSE),
reportCritical(kFALSE)
{
fsubEvtIds.clear();
for(UInt_t i=0;i<ids.size();i++){
fsubEvtIds.push_back(ids[i]);
}
fCurrentsubEvtId = 0;
}
HTrb3Unpacker::~HTrb3Unpacker()
{
fsubEvtIds.clear();
}
void HTrb3Unpacker::clearAll(void)
{
}
Bool_t HTrb3Unpacker::decode(void)
{
clearAll();
HldEvt* evt = getHldEvt( );
if(evt){
evt->getSubEventForIds(fsubEvtIds,fsubEvts);
} else {
cout<<"HTrb3Unpacker::decode() HldEvt pointer is NULL!"<<endl;
return kTRUE;
}
for(UInt_t i=0;i<fsubEvts.size();i++)
{
pSubEvt = &(fsubEvts[i]);
if (pSubEvt==0) continue;
setCurrentSubEvtId(pSubEvt->getId());
UInt_t* raw_data = pSubEvt->getData();
UInt_t* raw_end = pSubEvt->getEnd();
UInt_t nEvt = gHades->getCurrentEvent()->getHeader()->getEventSeqNumber();
if(debugFlag > 0) {
cout<<"-0-EvNb "<<nEvt<<", "<<hex<<"data word: "<<*raw_data<<dec<<" --NetSubevent(TRB) Header"<<endl;
}
if(debugFlag > 0){
cout<<"-0a-EvNb "<<nEvt<<", data word: "<<hex<<*raw_data<<dec<<" --"<<endl;
}
UInt_t ix = 0;
UInt_t trbSubEvSize = raw_end - raw_data;
while (ix < trbSubEvSize) {
UInt_t data = raw_data[ix++];
UInt_t datalen = (data >> 16) & 0xFFFF;
UInt_t trbaddr = data & 0xFFFF;
if ((trbaddr & 0xFF00) == (uHUBId & 0xFF00)) {
if(debugFlag > 0)
printf(" HUB header: 0x%08x, size=%u (ignore)\n", (UInt_t) data, datalen);
continue;
}
if ((trbaddr & 0xFF00) == (uCTSId & 0xFF00)) {
if(debugFlag > 0)
printf(" CTS header: 0x%x, size=%d\n", (UInt_t) data, datalen);
ix+=datalen;
continue;
}
if (trbaddr == 0x5555) {
if(debugFlag > 0)
printf(" Dummy header: 0x%x, size=%d\n", (UInt_t) data, datalen);
while (datalen-- > 0) {
data = raw_data[ix++];
if(debugFlag > 0)
printf(" word: 0x%08x\n", (UInt_t) data);
}
continue;
}
if (decodeData(trbaddr, datalen, raw_data + ix))
{
ix+=datalen;
continue;
}
if(debugFlag > 0)
printf("Unknown header %x length %u in TDC subevent\n", trbaddr, datalen);
ix+=datalen;
}
}
return kTRUE;
}