8 #include <StEventTypes.h>
11 #include <StDAQMaker/StEEMCReader.h>
13 #include <StEEmcUtil/database/StEEmcDb.h>
14 #include <StEEmcUtil/database/EEmcDbItem.h>
15 #include <StEEmcUtil/database/EEmcDbCrate.h>
17 #include <StEEmcUtil/EEfeeRaw/EEfeeDataBlock.h>
18 #include "StMuDSTMaker/EZTREE/EztEmcRawData.h"
20 #include "StEemcRaw.h"
21 #include "StEmcRawMaker.h"
22 #include "DAQ_READER/daq_det.h"
23 #include "DAQ_ETOW/daq_etow.h"
24 #include "DAQ_ESMD/daq_esmd.h"
25 #include "DAQ_EMC/daq_emc.h"
26 #include "StChain/StRtsTable.h"
34 memset(hs,0,
sizeof(hs));
38 StEemcRaw::~StEemcRaw()
49 StEmcRawData *eemcRaw = mEvent->emcCollection()->eemcRawData();
51 if(!maker || !mDb || ! eemcRaw )
53 gMessMgr->Message(
"",
"W") << GetName()<<
"::makeEemc() , some pointers are ZERO, code is sick, chain should be aborted, no EEMC data processed,JB :" <<maker << mDb << eemcRaw <<endm;
60 if(! copyRawData(maker, eemcRaw) )
70 gMessMgr->Message(
"",
"W") << GetName()<<
"::makeEemc() , l0Trigger data, EEMC not verified, abort all EEMC hits in StEvent EmcCollection, but raw data are saved" << endm;
75 int token=trg->triggerToken();
77 int runId=mEvent->runId();
78 int time=mEvent->time();
80 if( headersAreSick(maker, eemcRaw, token, runId, time) )
85 if( towerDataAreSick( eemcRaw))
97 StRtsTable* etow = maker->GetDaqElement(
"etow/adc");
101 for(
int icr = 0; icr < ETOW_MAXFEE; icr++){
105 raw->createBank(icr,fiber->
nHead,fiber->
nCh);
106 for(
int i = 0; i < fiber->
nCh; i++){
107 raw->setData(icr,i,etowdata->adc[icr][i]);
110 for(
int i = 0; i < fiber->
nHead; i++){
111 raw->setHeader(icr,i,etowdata->preamble[icr][i]);
116 LOG_ERROR<<
"ETOW Structure not found"<<endm;
118 StRtsTable* esmd = maker->GetDaqElement(
"esmd/adc");
121 for(
int icr = 0; icr < ESMD_MAXFEE;icr++){
123 int id = icr + ETOW_MAXFEE;
126 raw->createBank(
id,fiber->
nHead,fiber->
nCh);
127 for(
int i = 0; i < fiber->
nCh; i++){
128 raw->setData(
id,i,esmddata->adc[icr][i]);
131 for(
int i = 0; i < fiber->
nHead; i++){
132 raw->setHeader(
id,i,esmddata->preamble[icr][i]);
137 LOG_ERROR<<
"ESMD Structure not found"<<endm;
140 LOG_INFO <<
"StEemcRaw::copyRawData() "<<nb<<
" data bloks copied" << endm;
148 gMessMgr->Message(
"",
"W") <<
"StEemcRaw::headersAreSick() no EEMC raw data" << endm;
159 LOG_INFO <<
"StEemcRaw::headersAreSick() --> Nfibers=" << mDb->getNFiber() << endm;
163 for(icr=0;icr<mDb->getNFiber();icr++)
172 if(raw->sizeHeader(icr)<=0) {
173 LOG_WARN <<Form(
"StEemcRaw::headersAreSick() sizeHeader(icr=%d)<=0, crID=%d, skip it\n",icr,fiber->
crID)<<endm;
178 int isOff=EztEmcRawData::isCrateOFF(raw->header(icr));
182 mDb->setFiberOff(icr);
183 LOG_WARN <<
"StEemcRaw::headersAreSick() detected icr="<<icr<<
", name="<<fiber->
name<<
" is OFF,\n this fiber will ignored till the end of this job" << endm;
188 block.setHead(raw->header(icr));
190 int lenCount=fiber->
nCh+fiber->
nHead;
196 if(fiber->
type==
'S' && time<1104537600 && runId<6000000)
204 int sanity=block.isHeadValid(token,fiber->
crIDswitch,lenCount,trigCommand,errFlag);
207 cout<<(short)block.getCrateID()<<
" "<<fiber->
crIDswitch<<
" :::: "<<block.getLenCount()<<
" "<<lenCount<<
" :::: "<<block.getTrigComm()<<
" "<<trigCommand<<
" :::: "<<block.getErrFlag()<<
" "<<errFlag<<endl;
221 LOG_DEBUG << GetName()<<
"::checkHeader("<<fiber->
name<<
"), errorCode="<<sanity<<endm;
222 if(sanity) LOG_WARN << GetName()<<
"::checkHeader("<<fiber->
name<<
"), errorCode="<<sanity<<endm;
226 hs[4]->Fill(totErrBit);
228 LOG_INFO<< GetName()<<
"::checkHeader --> totErrBit "<<totErrBit<<
" in "<<nOn<<
" crates"<<endm;
242 StEmcRawData *eemcRaw = mEvent->emcCollection()->eemcRawData();
244 if(!eeReader || !mDb || ! eemcRaw )
246 gMessMgr->Message(
"",
"W") << GetName()<<
"::makeEemc() , some pointers are ZERO, code is sick, chain should be aborted, no EEMC data processed,JB :" <<eeReader << mDb << eemcRaw <<endm;
253 if(! copyRawData(eeReader, eemcRaw) )
263 gMessMgr->Message(
"",
"W") << GetName()<<
"::makeEemc() , l0Trigger data, EEMC not verified, abort all EEMC hits in StEvent EmcCollection, but raw data are saved" << endm;
268 int token=trg->triggerToken();
270 int runId=mEvent->runId();
271 int time=mEvent->time();
273 if( headersAreSick(eeReader, eemcRaw, token, runId, time) )
278 if( towerDataAreSick( eemcRaw))
294 for(icr=0;icr<mDb->getNFiber();icr++)
297 if(!eeReader->isEemcBankIn(fiber->
type))
301 raw->createBank(icr,fiber->
nHead,fiber->
nCh);
302 raw->setHeader(icr,eeReader->getEemcHeadBlock(fiber->
fiber,fiber->
type));
303 raw->setData(icr,eeReader->getEemcDataBlock(fiber->
fiber,fiber->
type));
305 gMessMgr->Message(
"",
"I") <<
"StEemcRaw::copyRawData() "<<nb<<
" data bloks copied" << endm;
318 gMessMgr->Message(
"",
"W") <<
"StEemcRaw::headersAreSick() no EEMC raw data" << endm;
329 LOG_INFO <<
"StEemcRaw::headersAreSick() --> Nfibers=" << mDb->getNFiber() << endm;
330 LOG_INFO <<
"StEemcRaw::headersAreSick() --> isEemcBankIn('T')=" << eeReader->isEemcBankIn(
'T') << endm;
331 LOG_INFO <<
"StEemcRaw::headersAreSick() --> isEemcBankIn('S')=" << eeReader->isEemcBankIn(
'S') << endm;
333 for(icr=0;icr<mDb->getNFiber();icr++)
339 if (fiber->
type ==
'T' && !eeReader->isEemcBankIn(
'T'))
continue;
340 if (fiber->
type ==
'S' && !eeReader->isEemcBankIn(
'S'))
continue;
342 if(raw->sizeHeader(icr)<=0) {
343 gMessMgr->Message(
"",
"W") <<Form(
"StEemcRaw::headersAreSick() sizeHeader(icr=%d)<=0, crID=%d, skip it\n",icr,fiber->
crID)<<endm;
348 int isOff=EztEmcRawData::isCrateOFF(raw->header(icr));
352 mDb->setFiberOff(icr);
353 gMessMgr->Message(
"",
"W") <<
"StEemcRaw::headersAreSick() detected icr="<<icr<<
", name="<<fiber->
name<<
" is OFF,\n this fiber will ignored till the end of this job" << endm;
358 block.setHead(raw->header(icr));
360 int lenCount=fiber->
nCh+fiber->
nHead;
366 if(fiber->
type==
'S' && time<1104537600 && runId<6000000)
374 int sanity=block.isHeadValid(token,fiber->
crIDswitch,lenCount,trigCommand,errFlag);
387 LOG_DEBUG << GetName()<<
"::checkHeader("<<fiber->
name<<
"), errorCode="<<sanity<<endm;
388 if(sanity) LOG_WARN << GetName()<<
"::checkHeader("<<fiber->
name<<
"), errorCode="<<sanity<<endm;
392 hs[4]->Fill(totErrBit);
394 gMessMgr->Message(
"",
"I") << GetName()<<
"::checkHeader --> totErrBit "<<totErrBit<<
" in "<<nOn<<
" crates"<<endm;
404 const int mxN256one=5;
405 const int mxN256tot=40;
407 int nGhostTot=0, n256Tot=0;
409 for(icr=0;icr<mDb->getNFiber();icr++)
416 const UShort_t*
data=raw->data(icr);
419 int nGhost=0, n256=0;
420 for(i=0;i<raw->sizeData(icr);i++)
422 if((data[i] &0xff)==0 )
424 if(i>=121 && data[i]>40)
445 hs[1]->Fill(n256Tot);
447 hs[2]->Fill(nGhostTot);
449 gMessMgr->Message(
"",
"I") << GetName()<<
"::checkTowerAdc-->total n256="<<n256Tot <<
", nGhost="<<nGhostTot<<endm;
452 if(n256Tot>mxN256tot)
461 void StEemcRaw::raw2pixels(
StEvent* mEvent)
467 gMessMgr->Message(
"",
"W") << GetName()<<
"::raw2pixels() no emc collection, skip"<<endm;
474 gMessMgr->Message(
"",
"W") <<
"StEemcRaw::raw2pixels() no EEMC raw data" << endm;
481 StDetectorId emcId[kEndcapSmdVStripId+1];
482 memset(emcDet,0,
sizeof(emcDet));
485 for(det = kEndcapEmcTowerId; det<= kEndcapSmdVStripId; det++)
487 emcId[det] = StDetectorId(det);
489 emcC->setDetector(emcDet[det]);
492 gMessMgr->Message(
"",
"I") << GetName()<<
"::raw2pixels() collections created"<<endm;
497 int nTow=0, nPre=0,nSmd=0;
499 for(icr=0;icr<mDb->getNFiber();icr++)
505 const UShort_t* data=raw->data(icr);
508 for(
int chan=0;chan<raw->sizeData(icr);chan++)
519 char type=x->
name[2];
521 int sub=1+x->sub-
'A';
524 int rawAdc=data[chan];
525 float energy=123.456;
530 det = kEndcapEmcTowerId;
537 det = kEndcapEmcPreShowerId;
545 det = kEndcapSmdUStripId;
547 det = kEndcapSmdVStripId;
556 gMessMgr->Message(
"",
"W") <<
"StEemcRaw::raw2pixels(), logic error2, skip" << endm;
563 emcDet[det]->addHit(h);
570 gMessMgr->Message(
"",
"I") << GetName()<<
"::raw2pixels() finished nDrop chan="<< nDrop<<
",nMap="<< nMap<<
",nTow="<<nTow <<
",nPre="<<nPre <<
", nSmd="<<nSmd <<endm;
578 void StEemcRaw::initHisto()
581 hs[0]=
new TH1F(
"EndcapHealth",
"raw data health; X: 0=nEve, 1=raw, 2=OKhead , 3=tower(No ghost/n256)",9,-1.5,7.5);
583 hs[1]=
new TH1F(
"EndcapN256",
"No. of n256/eve, all header OK",100, -1.5,98.5);
584 hs[2]=
new TH1F(
"EndcapGhost",
"No. of tower nGhost/eve, all header OK, chan>119",100,-1.5,98.5);
586 hs[3]=
new TH1F(
"EndcapCorrBytes",
"sanity, crates Tw cr=0-5, Mapmt cr=6-53, X= bits(cr)+ cr*10;bits: 0=crID, 1=token,2=len,3=trgCom,4=ErrFlg,5=Ghost,6=n256 ",540,-0.5,539.5);
588 hs[4]=
new TH1F(
"EndcapCorrTot",
"total # of corruption bits in Headers per eve",220,-0.5,219.5);
659 #if 0 // test of tower data storage
661 int det= kEndcapEmcTowerId;
662 int eta,sub=1,sec=12;
663 for(sec=1;sec<=12;sec++)
664 for(sub=1;sub<=5;sub++)
665 for(eta=1;eta<=12;eta++)
667 int adc=1000+ (eta-1) + (sub-1)*12 +(sec-1)*60;
670 emcDet[det]->addHit(h);
677 #if 0 // test of Pre/post data storage
679 int det= kEndcapEmcPreShowerId;
680 int eta,sub,sec=12, pre=1;
681 for(pre=1;pre<=3;pre++)
682 for(sec=1;sec<=12;sec++)
683 for(sub=1;sub<=5;sub++)
684 for(eta=1;eta<=12;eta++)
686 int ssub=sub + 5*(pre-1);
687 int adc= eta-1 + (sub-1)*12 +(sec-1)*60 +pre*1000;
689 emcDet[det]->addHit(h);
696 #if 0 // test of U-smd data storage
698 det = kEndcapSmdUStripId;
699 int eta,sub=1,sec=12;
700 for(sec=1;sec<=12;sec++)
701 for(eta=1;eta<=288;eta++)
703 int adc= 1000 + eta-1 +(sec-1)*300;
705 emcDet[det]->addHit(h);
709 for(det = kEndcapEmcTowerId; det<= kEndcapSmdVStripId; det++)
713 gMessMgr->Message(
"",
"I") <<
" StEmcDetectorID="<< StDetectorId(det)<<
" nHits="<<emcDetX->numberOfHits()<<endm;
722 #if 0 // test of new access method
724 for(icr=0;icr<mDb->getNCrate();icr++)
727 printf(
"geting data for fiber: ");
730 printf(
"---- HEAD ----\n");
731 for(ch=0;ch<crate->
nHead;ch++)
734 val=steemcreader->getEemcHead(crate->
fiber,ch,crate->
type);
735 printf(
"cr=%d ch=%d val=0x%04x\n",crate->
crID,ch,val);
738 printf(
"---- DATA ----\n");
739 for(ch=0;ch<crate->nch;ch++)
742 val=steemcreader->getEemcData(crate->
fiber,ch,type);
743 printf(
"cr=%d ch=%d val=0x%04x\n",crate->
crID,ch,val);
int nCh
no. of valid channels for the crate
char name[StEEmcNameLen]
ASCII name of the channel, see Readme.
int nHead
no. of header words
int useIt
flag to ignore data from misconfig/broken crate/box
char name[CrateNameLen]
crT1,... for towers, 06S1,... for mapmt
int fiber
position of the crate in the .daq data stream, couting from 0
char type
is 'T' for towers & 'S' for MAPMT
int crIDswitch
crate ID set by hardware switch