5 #include "trgStructures2008.h"
6 #include "TRG_Reader.hh"
7 using namespace OLDEVP;
9 int TRG_Reader::UnpackTrg2008(
Bank_TRGP *pTRGP){
10 int returnValue,npre,npost,swap,res;
13 printf(
"TRG_Reader::UnpackTrg2008 - 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::UnpackTrg2008: Swap Header error %s %d.\n", __FILE__ , __LINE__ );
30 printf(
"TRG_Reader::UnpackTrg2008: Token from Bank=%d\n",pTRGP->header.Token);
34 int size_off = pTRGP->theData.offset * 4;
35 int size_head =
sizeof(pTRGP->header);
44 char* cttt = (
char*)pTRGP + size_off + size_head;
47 res=Swap2008_TrgTowerTrnfer(cttt);
49 printf(
"TRG_Reader::UnpackTrg2008: Swap TrgTowerTrnfer error %s %d.\n", __FILE__ , __LINE__ );
53 int offset = ttt->OffsetBlock[y8TRG_INDEX].offset;
54 int length = ttt->OffsetBlock[y8TRG_INDEX].length;
55 printf(
"TRG_Reader::UnpackTrg2008: TrgTowerTrnfer byet_version=0x%x offset=%d length=%d\n",
56 ttt->byteCount_Version,offset,length);
58 printf(
"TRG_Reader::UnpackTrg2008: No Trigger Data %s %d.\n", __FILE__ , __LINE__ );
61 char* trg_version = (
char*)pTRGP + size_off + size_head + offset + 3;
62 printf(
"TRG_Reader::UnpackTrg2008: trg_version = 0x%x\n",*trg_version);
63 if(*trg_version != 0x32) {
64 printf(
"TRG_Reader::UnpackTrg2008: Trigger version error %s %d.\n",*trg_version, __FILE__ , __LINE__ );
69 if(pBankUnp!=0)
delete[] pBankUnp;
70 int sizeUnp = size_off + size_head + size_trg;
71 pBankUnp =
new char[sizeUnp];
72 char *trgd = pBankUnp + size_off + size_head;
76 memcpy(pBankUnp, pTRGP, size_off+size_head);
77 memcpy(pBankUnp+size_off+size_head, (
char*)pTRGP+size_off+size_head+offset, size_desc+size_sum);
79 res=Swap2008_DescSum(trgd);
81 npre = p->EvtDesc.npre;
82 npost = p->EvtDesc.npost;
83 printf(
"TRG_Reader::UnpackTrg2008: TCUdataBytes = %d Token = %d Npre/Npost=%d/%d\n",
84 p->EvtDesc.TCUdataBytes, p->EvtDesc.TrgToken, npre,npost);
86 printf(
"TRG_Reader::UnpackTrg2008: Swap DescSum error %s %d.\n", __FILE__ , __LINE__ );
90 if(p->EvtDesc.TrgToken>4096) {
91 printf(
"TRG_Reader::UnpackTrg2008: Found Token beyond 4096\n");
94 if(npre>5 || npre<0 || npost>5 || npost<0) {
95 printf(
"TRG_Reader::UnpackTrg2008: Trigger data has more than 5 pre/post\n");
100 char* p_daq = (
char *)pTRGP + size_off + size_head + size_desc + size_sum + offset;
101 char* p_unp = (
char *)pBankUnp + size_off + size_head + size_desc + size_sum;
104 memset(p_unp, 0, 11*size_raw);
107 for(
int i=0; i<1+npre+npost; i++){
108 unsigned short *nbytes = (
unsigned short *)p_daq;
109 if(swap) pTRGD->swapHerb2bytes(nbytes,1);
114 pTRGD->swapHerb2bytes(nbytes,1);
118 printf(
"**********************************************************************************\n");
119 printf(
"TRG_Reader::UnpackTrg2008\n");
120 printf(
"\tWARNING! TrgRaw bank has improper reported size %d > %d\n",n,size_raw);
121 printf(
"\tSkipping event\n");
122 printf(
"**********************************************************************************\n");
127 memcpy(p_unp, p_daq, n);
137 res = Swap2008_Raw(trgd);
139 printf(
"TRG_Reader::UnpackTrg2008: Swap RawData error %s %d.\n", __FILE__ , __LINE__ );
151 int TRG_Reader::Swap2008_TrgTowerTrnfer(
char *ptr){
153 pTRGD->swapHerb4bytes(&(p->byteCount_Version),1);
154 pTRGD->swapHerb4bytes(&(p->OffsetBlock[0].offset),2 * y8MAX_OFFSET);
158 int TRG_Reader::Swap2008_DescSum(
char *ptr){
161 pTRGD->swapHerb2bytes(&(p->EvtDesc.TCUdataBytes),1);
162 pTRGD->swapHerb4bytes(&(p->EvtDesc.bunchXing_hi),1);
163 pTRGD->swapHerb4bytes(&(p->EvtDesc.bunchXing_lo),1);
164 pTRGD->swapHerb2bytes(&(p->EvtDesc.actionWdDetectorBitMask),1);
165 pTRGD->swapHerb2bytes(&(p->EvtDesc.TrgToken),1);
166 pTRGD->swapHerb2bytes(&(p->EvtDesc.addBits),1);
167 pTRGD->swapHerb2bytes(&(p->EvtDesc.DSMInput),1);
168 pTRGD->swapHerb2bytes(&(p->EvtDesc.externalBusy),1);
169 pTRGD->swapHerb2bytes(&(p->EvtDesc.modifiedBusyStatus),1);
170 pTRGD->swapHerb2bytes(&(p->EvtDesc.physicsWord),1);
171 pTRGD->swapHerb2bytes(&(p->EvtDesc.TriggerWord),1);
172 pTRGD->swapHerb2bytes(&(p->EvtDesc.DSMAddress),1);
173 pTRGD->swapHerb2bytes(&(p->EvtDesc.contaminationBusyStatus),1);
174 pTRGD->swapHerb2bytes(&(p->EvtDesc.npre),1);
175 pTRGD->swapHerb2bytes(&(p->EvtDesc.npost),1);
176 pTRGD->swapHerb2bytes(&(p->EvtDesc.dummy),1);
178 pTRGD->swapHerb2bytes(&(p->TrgSum.TrgSumBytes),1);
179 pTRGD->swapHerb2bytes(&(p->TrgSum.TrgSumHeader),1);
180 pTRGD->swapHerb4bytes(&(p->TrgSum.L1Sum[0]),2);
181 pTRGD->swapHerb4bytes(&(p->TrgSum.L2Sum[0]),2);
182 pTRGD->swapHerb2bytes(&(p->TrgSum.L0SumBytes),1);
183 pTRGD->swapHerb2bytes(&(p->TrgSum.L0SumHeader),1);
184 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.MTD[0]),8);
185 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.VPD[0]),8);
186 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.CPA[0]),16);
187 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.CTB[0]),8);
188 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.lastDSM[0]),8);
189 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.VTX[0]),8);
190 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.EMC[0]),8);
191 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.BCdata[0]),16);
192 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.specialTriggers[0]),8);
193 pTRGD->swapHerb2bytes(&(p->TrgSum.DSMdata.FPD[0]),8);
194 pTRGD->swapHerb2bytes(&(p->TrgSum.L1SumBytes),1);
195 pTRGD->swapHerb2bytes(&(p->TrgSum.L1SumHeader),1);
196 pTRGD->swapHerb4bytes(&(p->TrgSum.L1Result[0]),32);
197 pTRGD->swapHerb2bytes(&(p->TrgSum.L2SumBytes),1);
198 pTRGD->swapHerb2bytes(&(p->TrgSum.L2SumHeader),1);
199 pTRGD->swapHerb4bytes(&(p->TrgSum.L2Result[0]),64);
201 int npre = p->EvtDesc.npre;
202 int npost = p->EvtDesc.npost;
203 if(npre<0 || npre>5 || npost<0 || npost>5)
return -1;
208 int TRG_Reader::Swap2008_Raw(
char *ptr) {
212 numToSwap=1+p->EvtDesc.npost+p->EvtDesc.npre;
214 for(i=0;i<numToSwap;i++) {
215 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].RawDetBytes),1);
216 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].CTBdataBytes),1);
217 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].MIXdataBytes),1);
218 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].MIXfiller),1);
219 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].BEMCdataBytes),1);
220 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].BEMCfiller),1);
221 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].BEMClayer1[0]),48);
222 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].EEMCdataBytes),1);
223 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].EEMCfiller),1);
224 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].EEMClayer1[0]),16);
225 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].FPDdataBytes),1);
226 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].FPDfiller),1);
227 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].FPDEastNSLayer1[0]),8);
228 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].BBCdataBytes),1);
229 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].BBCfiller),1);
230 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].BBClayer1[0]),16);
231 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].ZDClayer1[0]),8);
232 pTRGD->swapHerb2bytes(&(p->rawTriggerDet[i].QQTdataBytes),1);
233 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].QQTfiller),1);
234 pTRGD->swapHerb4bytes(&(p->rawTriggerDet[i].QQTdata[0]),1600);
235 int nqt = p->rawTriggerDet[i].QQTdataBytes/4;
236 int ac10 = p->rawTriggerDet[i].QQTdata[nqt-1];
237 printf(
"NQTdata = %d, Last word check = 0x%x (should be ac10)\n",nqt,ac10);
238 if(nqt>0 && ac10 != 0xAC10){
239 printf(
"Last word of QT data is not 0xAC10 but 0x%x\n ",ac10);
255 void TRG_Reader::SanityCheck2008(
char *ptr,
int check_s=1) {
259 x=p->TrgSum.L1SumBytes; assert(x==0x0084||x==0x8400);
260 x=p->TrgSum.L2SumBytes; assert(x==0x0084||x==0x8400);
263 assert( p->rawTriggerDet[0].RawDetHeader[0] ==
'R');
264 assert( p->rawTriggerDet[0].RawDetHeader[1] ==
'D');
265 assert( p->rawTriggerDet[0].CTBdataHeader[0] ==
'C');
266 assert( p->rawTriggerDet[0].CTBdataHeader[1] ==
'T');
267 assert( p->rawTriggerDet[0].BEMCdataHeader[0]==
'E');
268 assert( p->rawTriggerDet[0].BEMCdataHeader[1]==
'M');
270 cout <<
"TRG_Reader::SanityCheck2008 : Data position sanity check is disabled" << endl;