StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
code2003.cxx
1 // This is the analog of duplicated.code for the version of trgStructures.h
2 // which I (Herb) label "2003".
3 
4 #define PREPOST 11 // This is also defined in TRG_Reader.cxx.
5 
6 #include <assert.h>
7 #include "trgStructures2003.h"
8 #include "TRG_Reader.hh"
9 
10 using namespace OLDEVP;
11 
12 typedef struct {
13  EvtDescData2003 EvtDesc; /* L1 Event Descriptor Data */
14  TrgSumData2003 TrgSum; /* summary data */
15  RawTrgDet2003 RAW[PREPOST];
17 MarilynMonroe *gs2003;
18 
19 int Bank_TRGD::HerbSwap2003(char *ptr) {
20  int numToSwap,returnValue,i;
21 
22  gs2003=(MarilynMonroe*)ptr;
23 
24  assert(header.ByteOrder==0x01020304||header.ByteOrder==0x04030201);
25  if(header.ByteOrder==0x04030201) return 0;
26  returnValue=header.swap();
27  assert(header.ByteOrder==0x04030201);
28 
29  swapHerb2bytes(&(gs2003->EvtDesc.TCUdataBytes),1);
30  swapHerb4bytes(&(gs2003->EvtDesc.bunchXing_hi),1);
31  swapHerb4bytes(&(gs2003->EvtDesc.bunchXing_lo),1);
32  swapHerb2bytes(&(gs2003->EvtDesc.actionWdDetectorBitMask),1);
33  swapHerb2bytes(&(gs2003->EvtDesc.TrgToken),1);
34  swapHerb2bytes(&(gs2003->EvtDesc.addBits),1);
35  swapHerb2bytes(&(gs2003->EvtDesc.DSMInput),1);
36  swapHerb2bytes(&(gs2003->EvtDesc.externalBusy),1);
37  swapHerb2bytes(&(gs2003->EvtDesc.modifiedBusyStatus),1);
38  swapHerb2bytes(&(gs2003->EvtDesc.physicsWord),1);
39  swapHerb2bytes(&(gs2003->EvtDesc.TriggerWord),1);
40  swapHerb2bytes(&(gs2003->EvtDesc.DSMAddress),1);
41  swapHerb2bytes(&(gs2003->EvtDesc.contaminationBusyStatus),1);
42  swapHerb2bytes(&(gs2003->EvtDesc.npre),1);
43  swapHerb2bytes(&(gs2003->EvtDesc.npost),1);
44  swapHerb2bytes(&(gs2003->EvtDesc.dummy),1);
45 
46  swapHerb2bytes(&(gs2003->TrgSum.TrgSumBytes),1);
47  swapHerb2bytes(&(gs2003->TrgSum.TrgSumHeader),1);
48  swapHerb4bytes(&(gs2003->TrgSum.L1Sum[0]),2);
49  swapHerb4bytes(&(gs2003->TrgSum.L2Sum[0]),2);
50  swapHerb2bytes(&(gs2003->TrgSum.L0SumBytes),1);
51  swapHerb2bytes(&(gs2003->TrgSum.L0SumHeader),1);
52  swapHerb2bytes(&(gs2003->TrgSum.DSMdata.CPA[0]),32);
53  swapHerb2bytes(&(gs2003->TrgSum.DSMdata.quadDSM[0]),8);
54  swapHerb2bytes(&(gs2003->TrgSum.DSMdata.lastDSM[0]),8);
55  swapHerb2bytes(&(gs2003->TrgSum.DSMdata.VTX[0]),8);
56  swapHerb2bytes(&(gs2003->TrgSum.DSMdata.EMC[0]),8);
57  swapHerb2bytes(&(gs2003->TrgSum.DSMdata.BCdata[0]),16);
58  swapHerb2bytes(&(gs2003->TrgSum.DSMdata.specialTriggers[0]),8);
59  swapHerb2bytes(&(gs2003->TrgSum.DSMdata.FPD[0]),8);
60  swapHerb2bytes(&(gs2003->TrgSum.L1SumBytes),1);
61  swapHerb2bytes(&(gs2003->TrgSum.L1SumHeader),1);
62  swapHerb4bytes(&(gs2003->TrgSum.L1Result[0]),32);
63  swapHerb2bytes(&(gs2003->TrgSum.L2SumBytes),1);
64  swapHerb2bytes(&(gs2003->TrgSum.L2SumHeader),1);
65  swapHerb4bytes(&(gs2003->TrgSum.L2Result[0]),32);
66 
67  // Herb, Mar 28 2003. There is a bug, from which the npre/npost numbers in the
68  // trigger data (5/5) sometimes do not agree with the bank len in the TRGD header, which causes a seg vio
69  // in the for() loop below. Here I check for the bug, and if it's present, I override npre and npost.
70  if( 4*header.BankLength < int((1+gs2003->EvtDesc.npre+gs2003->EvtDesc.npost) * sizeof(RawTrgDet2003)) ) {
71  gs2003->EvtDesc.npre=0; gs2003->EvtDesc.npost=0; return -1;
72  }
73 
74  numToSwap=1+gs2003->EvtDesc.npost+gs2003->EvtDesc.npre; assert(numToSwap<50&&numToSwap>0);
75  assert(numToSwap>=0&&numToSwap<=PREPOST);
76 
77 
78  for(i=0;i<numToSwap;i++) { // loop over NPRE, NPOST as well
79  swapHerb2bytes(&(gs2003->RAW[i].RawDetBytes),1);
80  swapHerb2bytes(&(gs2003->RAW[i].CTBdataBytes),1);
81  swapHerb2bytes(&(gs2003->RAW[i].MWCdataBytes),1);
82  swapHerb4bytes(&(gs2003->RAW[i].MWCfiller),1);
83  swapHerb2bytes(&(gs2003->RAW[i].BEMCdataBytes),1);
84  swapHerb4bytes(&(gs2003->RAW[i].BEMCfiller),1);
85  swapHerb2bytes(&(gs2003->RAW[i].BEMClayer1[0]),48);
86  swapHerb2bytes(&(gs2003->RAW[i].EEMCdataBytes),1);
87  swapHerb4bytes(&(gs2003->RAW[i].EEMCfiller),1);
88  swapHerb2bytes(&(gs2003->RAW[i].EEMClayer1[0]),16);
89  swapHerb2bytes(&(gs2003->RAW[i].FPDdataBytes),1);
90  swapHerb4bytes(&(gs2003->RAW[i].FPDfiller),1);
91  swapHerb2bytes(&(gs2003->RAW[i].FPDEastNSLayer1[0]),8);
92  swapHerb2bytes(&(gs2003->RAW[i].FPDEastTBLayer1[0]),8);
93  swapHerb2bytes(&(gs2003->RAW[i].FPDWestNSLayer1[0]),8);
94  swapHerb2bytes(&(gs2003->RAW[i].FPDWestTBLayer1[0]),8);
95  swapHerb2bytes(&(gs2003->RAW[i].BBCdataBytes),1);
96  swapHerb4bytes(&(gs2003->RAW[i].BBCfiller),1);
97  swapHerb2bytes(&(gs2003->RAW[i].BBClayer1[0]),16);
98  swapHerb2bytes(&(gs2003->RAW[i].ZDClayer1[0]),8);
99  }
100 
101  return returnValue;
102 }
103 
113 void TRG_Reader::SanityCheck2003(char *ptr, int check_s=1) {
114 
115  gs2003=(MarilynMonroe*)ptr;
116  unsigned short x;
117 
118  x=gs2003->TrgSum.L1SumBytes; assert(x==0x0084||x==0x8400);
119  x=gs2003->TrgSum.L2SumBytes; assert(x==0x0084||x==0x8400);
120 
121  /* As of Jan 14 2003, the trigger data is messed up, and this sanity check
122  ** will fail. Under pressure to get the chain running, I'm commenting it
123  ** out. We'll depend upon the above checks, which are not messed up.
124  if (check_s){
125  assert( gs2003->RAW[0].RawDetHeader[0] =='R');
126  assert( gs2003->RAW[0].RawDetHeader[1] =='D');
127  assert( gs2003->RAW[0].CTBdataHeader[0] =='C');
128  assert( gs2003->RAW[0].CTBdataHeader[1] =='T');
129  assert( gs2003->RAW[0].MWCdataHeader[0] =='M');
130  assert( gs2003->RAW[0].MWCdataHeader[1] =='W');
131  assert( gs2003->RAW[0].BEMCdataHeader[0]=='E');
132  assert( gs2003->RAW[0].BEMCdataHeader[1]=='M');
133  } else {
134  cout << "TRG_Reader::SanityCheck2003 : Bank position and summary sanity check is disabled" << endl;
135  }
136  */
137 }