using namespace std;
#include "htboxunpacker.h"
#include "hstartdef.h"
#include "hcategory.h"
#include "hevent.h"
#include "hldsubevt.h"
#include "hades.h"
#include "htboxchan.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hdebug.h"
#include "heventheader.h"
#include "hdatasource.h"
#include <iostream>
#include <iomanip>
#include <stdlib.h>
ClassImp(HTBoxUnpacker)
HTBoxUnpacker::HTBoxUnpacker(Int_t id) {
subEvtId=id;
tboxCat=0;
}
Bool_t HTBoxUnpacker::init(void) {
tboxCat=(HCategory*)gHades->getCurrentEvent()->getCategory(catTBoxChan);
if (!tboxCat) {
tboxCat=gHades->getSetup()->getDetector("TBox")->buildCategory(catTBoxChan);
if (tboxCat) gHades->getCurrentEvent()->addCategory(catTBoxChan,tboxCat,"TBox");
else return kFALSE;
}
loc.set(2,0,0);
return kTRUE;
}
Int_t HTBoxUnpacker::execute() {
#if DEBUG_LEVEL>4
gDebuger->enterFunc("HTBoxUnpacker::execute\n");
#endif
if (!(gHades->isCalibration())) {
return 1;
}
Bool_t bIsOld = kFALSE;
Int_t nEvtId = 0;
Int_t nEvt = 0;
UInt_t uOldCalType = 0;
UInt_t uTrigbits = 0;
UInt_t uBlockSize = 0;
UInt_t uBoardType = 0;
UInt_t uStruck = 0;
UInt_t* uTmp = NULL;
UInt_t uWordCount = 0;
if (subEvtId==412) {
if (pSubEvt) {
UInt_t* data = pSubEvt->getData();
UInt_t* end = pSubEvt->getEnd();
#if DEBUG_LEVEL>4
printf("Next SubEvt. data between: %p and %p\n",data,end);
pSubEvt->dumpIt();
#endif
nEvtId=gHades->getCurrentEvent()->getHeader()->getId();
nEvt=gHades->getCurrentEvent()->getHeader()->getEventSeqNumber();
uOldCalType=(*data & 0xf00);
uTmp=data;
bIsOld=gHades->getCurrentEvent()->getHeader()->isOldDAQ();
while (++data<end && *data!=0x0) {
#if DEBUG_LEVEL>2
printf("Data word: %p\n",*data);
#endif
if (nEvtId==5 && (*(data) == 0x8000000) && bIsOld && uOldCalType==0x900) {
data--;
data = fillScaler(data,&uTrigbits,kTRUE);
} else {
if (((*data >>24) & 0x6)==0) {
uBlockSize=(*data) & 0x0000003ff;
uBoardType=(*data >> 12 ) & 0x1;
uStruck =(*data >> 10 ) & 0x3f;
#if DEBUG_LEVEL>4
cout<<"Struck "<<uStruck <<" BoardType:"<< uBoardType<<endl;
#endif
if (uBoardType==1) {
if (uStruck == SCALER){
uTrigbits=uTrigbits | 0x100;
data=fillScaler(data,&uTrigbits,kFALSE,SCALER);
} else if (uStruck == SCALER_JAN04){
data=fillScaler(data,&uTrigbits,kFALSE,SCALER_JAN04);
} else if (uStruck == LATCH) {
data = skipLatch(data);
} else if (uStruck == DEBUG) {
data+=uBlockSize;
continue;
} else {
Error("execute","Unknown type=%i",uStruck);
}
} else if (uBoardType!=0) {
Error("execute","Unknown BoardType=%i",uBoardType);
}
} else if (((*data>>24) & 0x6)==2) {
uBlockSize=((*data) >> 8) & 0xff;
if ((*(data + uBlockSize+1) >>24 & 0x6)!=4) {
Error("execute","Header found but no trailer!!");
continue;
}
if ((*(data+uBlockSize+1)&0xff)!=((UInt_t)pSubEvt->getTrigNr()&0xFF)) {
Error("execute","Trigger tag mismatch: EventSeqNumber= %i! Skip event...",nEvt);
}
uTmp=data;
uWordCount=0;
while (++data && data<(uTmp + uBlockSize+1) && *data!=0x0) {
uWordCount++;
}
if (uWordCount!=uBlockSize) {
Error("execute()","Found %i but expecting % words!!!",
uWordCount,uBlockSize);
}
} else if (((*data>>24) & 0x6)==6) {
#if DEBUG_LEVEL>2
Error("execute()","Evt: %i, Invalid Data Word! Type: %d,Skipping 0x%08x",
nEvt,((*data>>24) & 0x6),*data);
pSubEvt->dumpIt();
#endif
} else if (((*data>>24) & 0x6)==0) {
Error("execute()","Evt: %i, Data follow, but no header",nEvt);
} else {
Error("execute()","Evt: %i, Unknow raw data type %i",
nEvt,((*data>>24) & 0x6));
}
}
}
}
} else if(subEvtId==416) {
if (pSubEvt) {
UInt_t* data = pSubEvt->getData();
UInt_t* end = pSubEvt->getEnd();
#if DEBUG_LEVEL>4
printf("Next SubEvt. data between: %p and %p\n",data,end);
pSubEvt->dumpIt();
#endif
nEvtId=gHades->getCurrentEvent()->getHeader()->getId();
nEvt=gHades->getCurrentEvent()->getHeader()->getEventSeqNumber();
while (++data<end && *data!=0x0) {
#if DEBUG_LEVEL>2
printf("Data word: %p\n",*data);
#endif
if (((*data >>24) & 0x6)==0 && (((*data) & 0x3fffff )!=0)) {
uBlockSize = (*data) & 0x0000003ff;
uBoardType = (*data >> 10 ) & 0x3f;
#if DEBUG_LEVEL>4
printf("BoardType: %d\n ",uBoardType);
#endif
if (uBoardType==SCALER_AUG04) {
#if DEBUG_LEVEL>4
printf("Total scalers block size is :%d \n",uBlockSize);
#endif
UInt_t* pScalerTrailer=0;
UInt_t uScalerSize=0;
UInt_t uScalerTotalSize=0;
UInt_t* pScalerHeader = 0;
Int_t nScalerCounts=0;
Int_t nScalerCountsTotal=0;
while( uScalerTotalSize < uBlockSize ) {
pScalerTrailer = data+uBlockSize-uScalerTotalSize;
uScalerSize=((*pScalerTrailer) & 0x7fffff)/4;
pScalerHeader = pScalerTrailer-uScalerSize+1;
uScalerTotalSize = uScalerTotalSize+uScalerSize;
if ((*pScalerHeader & 0x3fffff )==0) {
nScalerCounts++;
} else {
data+=uBlockSize;
break;
}
}
nScalerCountsTotal=nScalerCounts;
#if DEBUG_LEVEL>2
printf("Found %d scaler(s)\n",nScalerCounts);
#endif
pScalerTrailer=0;
uScalerSize=0;
uScalerTotalSize=0;
pScalerHeader = 0;
nScalerCounts=0;
clearScalData();
while( uScalerTotalSize < uBlockSize ){
pScalerTrailer = data+uBlockSize-uScalerTotalSize;
uScalerSize=((*pScalerTrailer) & 0x7fffff)/4;
pScalerHeader = pScalerTrailer-uScalerSize+1;
uScalerTotalSize = uScalerTotalSize+uScalerSize;
#if DEBUG_LEVEL>4
printf("Scaler header 0x%08x trailer 0x%08x\n",
*pScalerHeader,*pScalerTrailer);
#endif
if ((*pScalerHeader & 0x3fffff )==0) {
#if DEBUG_LEVEL>4
printf("Found valid scaler header and trailer\n");
printf("Size of scaler is %d\n",
((*pScalerTrailer) & 0x7fffff)/4-2);
#endif
fillScalerData(nScalerCountsTotal-nScalerCounts-1,pScalerHeader,uScalerSize-2);
nScalerCounts++;
} else {
printf("No valid SIS header for scalers found. Data may be corrupted. Skipping it.\n");
data+=uBlockSize;
break;
}
}
fillScalers(nScalerCounts);
data+=uBlockSize;
} else if (uBoardType!=0) {
Error("execute","Unknown BoardType=%i",uBoardType);
}
} else if (((*data>>24) & 0x6)==2) {
uBlockSize = ( (*data) >> 8 ) & 0xff;
if ((*(data + uBlockSize+1) >>24 & 0x6)!=4) {
Error("execute","Header found but no trailer!!");
continue;
}
if ((*(data+uBlockSize+1)&0xff)!=((UInt_t)pSubEvt->getTrigNr()&0xFF)) {
Error("execute","Trigger tag mismatch: EventSeqNumber= %i! Skip event...",nEvt);
if(!gHades->getForceNoSkip()) return kDsSkip;
}
uTmp=data;
uWordCount=0;
while( ++data && data<(uTmp + uBlockSize+1) && *data!=0x0 ){
uWordCount++;
}
if (uWordCount!=uBlockSize) {
Error("execute()","Found %i but expecting % words!!!",
uWordCount,uBlockSize);
}
} else if (((*data) & 0x3fffff )==0) {
UInt_t uGeo = (*data)>>27 &0x1F;
#if DEBUG_LEVEL>4
printf("Trying to find the size \n");
#endif
UInt_t* pLatchTmp=data;
if (++pLatchTmp && ((*pLatchTmp)>>27 &0x1F)==uGeo) {
Warning("execute()","Empty LATCH !!!!!!");
} else if (!(++pLatchTmp && ((*pLatchTmp)>>27 &0x1F)==uGeo) ) {
Error("execute()","Wrong latch data!");
}
data=pLatchTmp;
} else if ( ((*data>>24) & 0x6)==6 ) {
#if DEBUG_LEVEL>2
Error("execute()","Evt: %i, Invalid Data Word! Type: %d,Skipping 0x%08x",
nEvt,((*data>>24) & 0x6),*data);
pSubEvt->dumpIt();
#endif
} else if (((*data>>24) & 0x6)==0) {
Error("execute()","Evt: %i, Data follow, but no header",nEvt);
} else {
Error("execute()","Evt: %i, Unknow raw data type %i",
nEvt,((*data>>24) & 0x6));
}
}
}
}
#if DEBUG_LEVEL>4
gDebuger->leaveFunc("HTBoxUnpacker::execute\n");
#endif
return 1;
}
UInt_t* HTBoxUnpacker::fillScaler(UInt_t* pData,UInt_t* uTrigbits,Bool_t bOld,Int_t nType){
HTBoxChan* ptboxchan = 0;
UInt_t uWordCount = 0;
UInt_t* uTmp = NULL;
UInt_t uBlockSize = 0;
Int_t nCountBox = 0;
*uTrigbits = *uTrigbits | 0x100;
uBlockSize = (*pData) & 0x0000003ff;
clearScalData();
if (bOld) {
uBlockSize=34;
}
#if DEBUG_LEVEL>2
printf("Scaler data 0x%08x Size: %d\n",*pData,uBlockSize);
#endif
if (*++pData == 0x08000000 || nType==SCALER_JAN04) {
#warning FIXME scaler trailer !!!!
if (!bOld && (*(pData+uBlockSize-1)>>24)!=0x8 && nType!=SCALER_JAN04) {
Error("fillScaler","Header found but no trailer!!");
clearScalData();
return pSubEvt->getEnd();
} else {
uTmp=pData;
if (nType==SCALER_JAN04) {
uTmp=pData;
pData--;
}
uWordCount=0;
nCountBox=0;
while (++pData && pData<uTmp+uBlockSize && (*pData>>8) != 0x80000) {
uWordCount++;
if(nCountBox < 32) {
if ((*pData & 0xff000000) != 0x0) {
scalData[nCountBox] = 0x0;
} else {
scalData[nCountBox] = (*pData & 0xffffff);
}
nCountBox++;
} else {
Error("fillScaler","Evt %d. Too many data words for scaler",
gHades->getCurrentEvent()->getHeader()->getEventSeqNumber());
clearScalData();
return pSubEvt->getEnd();
}
}
if (!bOld && ((nType==SCALER_JAN04 && uWordCount!=uBlockSize) || (nType!=SCALER_JAN04 && uWordCount!=(uBlockSize-2)))) {
Error("fillScaler",
"Found %i but expecting %i words!!!", uWordCount,uBlockSize);
return pSubEvt->getEnd();
}
if (nType==SCALER_JAN04) pData--;
}
if(tboxCat) {
for (Int_t i=0; i<8; i++) {
ptboxchan=(HTBoxChan*)tboxCat->getNewSlot(loc);
if(!ptboxchan) continue;
ptboxchan = new(ptboxchan) HTBoxChan;
ptboxchan->set(i,scalData[i],scalData[i+8],scalData[i+16],scalData[i+24]);
}
}
} else {
Error("fillScaler",
"Header for scaler data %p not found!",*pData);
}
return pData;
}
void HTBoxUnpacker::fillScalerData(Int_t n,UInt_t* pScalerData,Int_t nSize){
for (Int_t i=0;i<nSize;i++) {
pScalerData++;
scalData[n*32 + i] = (*pScalerData & 0xffffffff);
}
}
void HTBoxUnpacker::fillScalers(Int_t nScalerCounts) {
HTBoxChan* ptboxchan = NULL;
if (tboxCat) {
for (Int_t i=0;i<8;i++) {
ptboxchan=(HTBoxChan*)tboxCat->getNewSlot(loc);
if (!ptboxchan) {
printf("Can not get new slot for HTBoxChan\n");
continue;
} else {
ptboxchan = new(ptboxchan) HTBoxChan;
for (Int_t s=0;s<nScalerCounts;s++){
ptboxchan->set(i,scalData[i+s*32],
scalData[i+s*32+8],
scalData[i+s*32+16],
scalData[i+s*32+24],s);
}
}
}
}
}
UInt_t* HTBoxUnpacker::skipLatch(UInt_t* pData) {
UInt_t uWordCount = 0;
UInt_t* uTmp = NULL;
UInt_t uBlockSize = 0;
uBlockSize = (*pData) & 0x0000003ff;
#if DEBUG_LEVEL>2
printf("Latch data 0x%08x Size: %d\n",*pData,uBlockSize);
#endif
if (*++pData == 0x8000000) {
#warning FIXME latch trailer !!!!
if ((*(pData+uBlockSize-1)>>24)!=0x8) {
Error("skipLatch","Header found but no trailer!!");
clearScalData();
} else {
uTmp=pData;
uWordCount=0;
while (++pData && pData<uTmp+uBlockSize-1 && *pData!=0x0) {
uWordCount++;
if (uWordCount== 1){
} else {
Error("skipLatch","Too many data words for Latch!!!!");
return pSubEvt->getEnd();
}
}
if (uWordCount!=(uBlockSize-2)) {
Error("skipLatch()",
"Found %i but expecting %i words!!!", uWordCount,uBlockSize);
return pSubEvt->getEnd();
}
}
} else{
Error("skipLatch",
"Header for latch data not found!");
return pData;
}
return pData;
}
Last change: Sat May 22 13:15:08 2010
Last generated: 2010-05-22 13:15
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.