5 #include "trgStructures2007.h"
6 #include "TRG_Reader.hh"
7 using namespace OLDEVP;
9 int TRG_Reader::UnpackTrg2007(
Bank_TRGP *pTRGP){
10 int returnValue,npre,npost,swap,res;
13 printf(
"TRG_Reader::UnpackTrg2007 - not pTRGP\n");
17 assert(pTRGP->header.ByteOrder==0x01020304 ||
18 pTRGP->header.ByteOrder==0x04030201);
19 if(pTRGP->header.ByteOrder==0x04030201) {
24 returnValue=pTRGP->header.swap();
26 if(pTRGP->header.ByteOrder!=0x04030201){
27 printf(
"TRG_Reader::UnpackTrg2007: Swap Header error %s %d.\n",__FILE__,__LINE__);
30 printf(
"TRG_Reader::UnpackTrg2007: Token from Bank=%d\n",pTRGP->header.Token);
34 int size_off = pTRGP->theData.offset * 4;
35 int size_head =
sizeof(pTRGP->header);
44 if(pBankUnp!=0)
delete[] pBankUnp;
45 int sizeUnp = size_off + size_head + size_trg;
46 pBankUnp =
new char[sizeUnp];
47 char *trgd = pBankUnp + size_off + size_head;
51 memcpy(pBankUnp, pTRGP, size_off+size_head+size_desc+size_sum);
55 res=Swap2007_DescSum(trgd);
57 printf(
"TRG_Reader::UnpackTrg2007: Swap DescSum error %s %d.\n",__FILE__,__LINE__);
61 npre = p->EvtDesc.npre;
62 npost = p->EvtDesc.npost;
63 printf(
"TRG_Reader::UnpackTrg2007: TCUdataBytes = %d\n",p->EvtDesc.TCUdataBytes);
64 printf(
"TRG_Reader::UnpackTrg2007: Token = %d\n",p->EvtDesc.TrgToken);
65 printf(
"TRG_Reader::UnpackTrg2007: Npre=%d Npost=%d\n",npre,npost);
67 if(p->EvtDesc.TrgToken>4096) {
68 printf(
"TRG_Reader::UnpackTrg2007: Found Token beyond 4096\n");
71 if(npre>5 || npre<0 || npost>5 || npost<0) {
72 printf(
"TRG_Reader::UnpackTrg2007: Trigger data has more than 5 pre/post\n");
77 char* p_daq = (
char *)pTRGP + size_off + size_head + size_desc + size_sum;
78 char* p_unp = (
char *)pBankUnp + size_off + size_head + size_desc + size_sum;
81 memset(p_unp, 0, 11*size_raw);
84 for(
int i=0; i<1+npre+npost; i++){
85 unsigned short *nbytes = (
unsigned short *)p_daq;
86 if(swap) pTRGD->swapHerb2bytes(nbytes,1);
88 printf(
"TRG_Reader::UnpackTrg2007: Nprepost=%d RawDat Size=%d (byte) [%d]\n",i,n,size_raw);
91 pTRGD->swapHerb2bytes(nbytes,1);
95 printf(
"**********************************************************************************\n");
96 printf(
"TRG_Reader::UnpackTrg2007\n");
97 printf(
"\tWARNING! TrgRaw bank has improper reported size %d > %d\n",n,size_raw);
98 printf(
"\tSkipping event\n");
99 printf(
"**********************************************************************************\n");
103 printf(
"-> Doing memcpy to %p from %p\n",p_unp,p_daq);
104 memcpy(p_unp, p_daq, n);
111 printf(
"-> Checking if swap is necessary\n");
113 printf(
"-> Swap2007_Raw on %p\n",trgd);
114 res = Swap2007_Raw(trgd);
116 printf(
"TRG_Reader::UnpackTrg2007: Swap RawData error %s %d.\n",__FILE__,__LINE__);
122 printf(
"-> pBankTRGP set to (Bank_TRGP *) %p\n",pBankUnp);
128 int TRG_Reader::Swap2007_DescSum(
char *ptr){
131 pTRGD->swapHerb2bytes(&(p->EvtDesc.TCUdataBytes),1);
132 pTRGD->swapHerb4bytes(&(p->EvtDesc.bunchXing_hi),1);
133 pTRGD->swapHerb4bytes(&(p->EvtDesc.bunchXing_lo),1);
134 pTRGD->swapHerb2bytes(&(p->EvtDesc.actionWdDetectorBitMask),1);
135 pTRGD->swapHerb2bytes(&(p->EvtDesc.TrgToken),1);
136 pTRGD->swapHerb2bytes(&(p->EvtDesc.addBits),1);
137 pTRGD->swapHerb2bytes(&(p->EvtDesc.DSMInput),1);
138 pTRGD->swapHerb2bytes(&(p->EvtDesc.externalBusy),1);
139 pTRGD->swapHerb2bytes(&(p->EvtDesc.modifiedBusyStatus),1);
140 pTRGD->swapHerb2bytes(&(p->EvtDesc.physicsWord),1);
141 pTRGD->swapHerb2bytes(&(p->EvtDesc.TriggerWord),1);
142 pTRGD->swapHerb2bytes(&(p->EvtDesc.DSMAddress),1);
143 pTRGD->swapHerb2bytes(&(p->EvtDesc.contaminationBusyStatus),1);
144 pTRGD->swapHerb2bytes(&(p->EvtDesc.npre),1);
145 pTRGD->swapHerb2bytes(&(p->EvtDesc.npost),1);
146 pTRGD->swapHerb2bytes(&(p->EvtDesc.dummy),1);
148 pTRGD->swapHerb2bytes(&(p->TrgSum.TrgSumBytes),1);
149 pTRGD->swapHerb2bytes(&(p->TrgSum.TrgSumHeader),1);
150 pTRGD->swapHerb4bytes(&(p->TrgSum.L1Sum[0]),2);
151 pTRGD->swapHerb4bytes(&(p->TrgSum.L2Sum[0]),2);
152 pTRGD->swapHerb2bytes(&(p->TrgSum.L0SumBytes),1);
153 pTRGD->swapHerb2bytes(&(p->TrgSum.L0SumHeader),1);
154 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.MTD[0]),8);
155 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.VPD[0]),8);
156 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.CPA[0]),16);
157 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.CTB[0]),8);
158 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.lastDSM[0]),8);
159 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.VTX[0]),8);
160 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.EMC[0]),8);
161 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.BCdata[0]),16);
162 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.specialTriggers[0]),8);
163 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.FPD[0]),8);
164 pTRGD->swapHerb2bytes(&(p->TrgSum.L1SumBytes),1);
165 pTRGD->swapHerb2bytes(&(p->TrgSum.L1SumHeader),1);
166 pTRGD->swapHerb4bytes(&(p->TrgSum.L1Result[0]),32);
167 pTRGD->swapHerb2bytes(&(p->TrgSum.L2SumBytes),1);
168 pTRGD->swapHerb2bytes(&(p->TrgSum.L2SumHeader),1);
169 pTRGD->swapHerb4bytes(&(p->TrgSum.L2Result[0]),64);
171 int npre = p->EvtDesc.npre;
172 int npost = p->EvtDesc.npost;
173 if(npre<0 || npre>5 || npost<0 || npost>5)
return -1;
178 int TRG_Reader::Swap2007_Raw(
char *ptr) {
182 numToSwap=1+p->EvtDesc.npost+p->EvtDesc.npre;
184 for(i=0;i<numToSwap;i++) {
185 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].RawDetBytes),1);
186 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].CTBdataBytes),1);
187 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].MIXdataBytes),1);
188 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].MIXfiller),1);
189 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].BEMCdataBytes),1);
190 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].BEMCfiller),1);
191 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].BEMClayer1[0]),48);
192 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].EEMCdataBytes),1);
193 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].EEMCfiller),1);
194 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].EEMClayer1[0]),16);
195 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].FPDdataBytes),1);
196 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].FPDfiller),1);
197 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].FPDEastNSLayer1[0]),8);
198 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].BBCdataBytes),1);
199 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].BBCfiller),1);
200 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].BBClayer1[0]),16);
201 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].ZDClayer1[0]),8);
202 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].QQTdataBytes),1);
203 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].QQTfiller),1);
204 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].QQTdata[0]),1600);
205 int nqt = p->rawTriggerDet[i].QQTdataBytes/4;
206 int ac10 = p->rawTriggerDet[i].QQTdata[nqt-1];
207 printf(
"NQTdata = %d, AC10 = 0x%x\n",nqt,ac10);
208 if(nqt>0 && ac10 != 0xAC10){
209 printf(
"Last word of QT data is not 0xAC10 but 0x%x\n ",ac10);
225 void TRG_Reader::SanityCheck2007(
char *ptr,
int check_s=1) {
229 x=p->TrgSum.L1SumBytes; assert(x==0x0084||x==0x8400);
230 x=p->TrgSum.L2SumBytes; assert(x==0x0084||x==0x8400);
233 assert( p->rawTriggerDet[0].RawDetHeader[0] ==
'R');
234 assert( p->rawTriggerDet[0].RawDetHeader[1] ==
'D');
235 assert( p->rawTriggerDet[0].CTBdataHeader[0] ==
'C');
236 assert( p->rawTriggerDet[0].CTBdataHeader[1] ==
'T');
237 assert( p->rawTriggerDet[0].BEMCdataHeader[0]==
'E');
238 assert( p->rawTriggerDet[0].BEMCdataHeader[1]==
'M');
240 cout <<
"TRG_Reader::SanityCheck2007 : Data position sanity check is disabled" << endl;