using namespace std;
#include "hstartunpacker.h"
#include "hstartdef.h"
#include "hcategory.h"
#include "hstartraw.h"
#include "hevent.h"
#include "hldsubevt.h"
#include "hades.h"
#include "hspectrometer.h"
#include "hdetector.h"
#include "hruntimedb.h"
#include "hstartlookup.h"
#include "hdebug.h"
#include "heventheader.h"
#include "hdatasource.h"
#include <iostream>
#include <iomanip>
#include <stdlib.h>
ClassImp(HStartUnpacker)
HStartUnpacker::HStartUnpacker(Int_t id) {
subEvtId=id;
pRawCat=0;
lookup=0;
}
Bool_t HStartUnpacker::init(void) {
pRawCat=(HCategory*)gHades->getCurrentEvent()->getCategory(catStartRaw);
if (!pRawCat) {
pRawCat=gHades->getSetup()->getDetector("Start")->buildCategory(catStartRaw);
if (!pRawCat) return kFALSE;
gHades->getCurrentEvent()
->addCategory(catStartRaw,pRawCat,"Start");
}
loc.set(2,0,0);
lookup=(HStartLookup*)(gHades->getRuntimeDb()
->getContainer("StartLookup"));
if(!lookup) return kFALSE;
return kTRUE;
}
Int_t HStartUnpacker::execute() {
#if DEBUG_LEVEL>4
gDebuger->enterFunc("HStartUnpacker::execute\n");
#endif
if (gHades->isCalibration()) {
return 1;
}
if (pSubEvt) {
UInt_t* data=pSubEvt->getData();
UInt_t* end=pSubEvt->getEnd();
UInt_t uBlockSize = 0;
Int_t nEvt=gHades->getCurrentEvent()->getHeader()->getEventSeqNumber();
#if DEBUG_LEVEL>4
printf("Next SubEvt. data between: %p and %p\n",data,end);
pSubEvt->dumpIt();
#endif
while (++data<end && *data!=0x0) {
#if DEBUG_LEVEL>2
printf("Data word: %p\n",*data);
#endif
if (((*data >>24) & 0x6)==0) {
uBlockSize = (*data) & 0x0000003ff;
UInt_t uBoardType = (*data >> 12 ) & 0x1;
if(uBoardType==1) {
data+=uBlockSize;
continue;
} else if (uBoardType==0) {
#if DEBUG_LEVEL>2
printf("TIP-block 0x%08x Size %i Board %i\n",
*data,uBlockSize,uBoardType);
#endif
continue;
} else {
Error("execute","Unknown BoardType=%i",uBoardType);
}
} else if ( ((*data>>24) & 0x6)==2 ) {
uBlockSize=((*data) >> 8) & 0xff;
Int_t nCrate =((*data) >> 16) & 0xff;
Int_t nSlot =((*data) >> 27) & 0x1f;
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;
}
#if DEBUG_LEVEL>4
printf("TDC header 0x%08x.Size: %i.Crate: %i.Slot: %i.\n",
*data,uBlockSize,nCrate,nSlot);
#endif
UInt_t* uTmp=data;
HStartLookupTdc* pTdc=lookup->getTdc(nCrate-1,nSlot-1);
if (pTdc) {
UInt_t uWordCount=0;
while (++data && data<(uTmp + uBlockSize+1) && *data!=0x0) {
uWordCount++;
Int_t nChannel=(*(data) >> 16) & 0x003f;
Int_t nData =*data & 0xfff;
HStartLookupChan* tc=pTdc->getChannel(nChannel);
if (tc) {
Int_t nMod=-1;
Int_t nStrip=-1;
tc->getAddress(nMod,nStrip);
if (nMod>=0 && nStrip>=0) {
loc[0]=nMod;
loc[1]=nStrip;
HStartRaw* pRaw=(HStartRaw*)pRawCat->getObject(loc);
if (!pRaw) {
pRaw=(HStartRaw*)pRawCat->getSlot(loc);
if (pRaw) {
pRaw=new (pRaw) HStartRaw;
} else {
Error("execute()","Can't get slot\n");
return EXIT_FAILURE;
}
} else {
#if DEBUG_LEVEL>2
Info("execute()","Slot already exists!\n");
#endif
}
Char_t cType='\0';
Int_t nType=-1;
cType = tc->getType();
if (cType !='\0') {
switch(cType) {
case 'R':
nType = TYPE_RIGHT;
break;
case 'L':
nType = TYPE_LEFT;
break;
case 'M':
nType = TYPE_MEANTIMER;
break;
default:
break;
}
pRaw->fill(nData,nMod,nStrip,nType);
} else {
pRaw->fill(nData,nMod,nStrip);
}
#if DEBUG_LEVEL>2
printf("Evt:%d Mod:%d Str:%d Typ:%d Data:%d\n",
nEvt,nMod,nStrip,nType,nData);
#endif
} else {
#if DEBUG_LEVEL>4
Error("execute()","Wrong address! Mod: %i Strip; %i",
nMod,nStrip);
#endif
}
} else {
#if DEBUG_LEVEL>2
Info("execute()","TDC channel: %i not found",nChannel);
#endif
}
}
if (uWordCount!=uBlockSize) {
Error("execute()","Found %i but expecting % words!!!",
uWordCount,uBlockSize);
}
} else {
#if DEBUG_LEVEL>4
Error("execute()","Can not get TDC for create %i and slot %i",
nCrate-1,nSlot-1);
#endif
data+=uBlockSize+1;
}
} 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("HStartUnpacker::execute\n");
#endif
return 1;
}
Last change: Sat May 22 13:14:56 2010
Last generated: 2010-05-22 13:14
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.