From Jochen - EveHLT development accumulated since the end of March.
[u/mrichter/AliRoot.git] / EVE / hlt-macros / DIMUONRawReader.C
CommitLineData
46eadbb4 1#include "AliMUONTrackerDDLDecoder.h"
2#include "AliMUONTrackerDDLDecoderEventHandler.h"
3
4#include "hlt_structs.C"
5
6
7class DiMuonTrackerCustomHandler : public AliMUONTrackerDDLDecoderEventHandler
8{
9public:
10
11// void OnData(UInt_t data) // Old type
12 void OnNewBusPatch(const AliMUONBusPatchHeaderStruct* header, const void* data)
13 {
14 fBusPatchId = header->fBusPatchId;
15 }
16
17 void OnData(const UInt_t data, bool isTrue)
18 {
19
20 fData[fDataCount].fDataId &= 0x0;
21 fData[fDataCount].fDataId = (fData[fDataCount].fDataId|fBusPatchId)<<17;
22 fData[fDataCount].fDataId |= ((UInt_t)(data>>12) & 0x1FFFF) ;
23
24 fData[fDataCount].fADC = (UShort_t)(data) & 0xFFF;
25
26 fDataCount++;
27 if(fDataCount>(27000-1))
28 cerr<<"Running Out of memory "<<endl;
29
30 };
31
32 void OnError(ErrorCode code, const void* location)
33 {
34
35 printf("Errorcode : %d, %s, %s\n",
36 code,ErrorCodeToString(code),ErrorCodeToMessage(code));
37 };
38
39 void ResetDataCounter(){
40 fDataCount = 0;
41 }
42
43 Int_t GetDataSize(){return fDataCount;};
44
45 AliHLTMUONTrackerRawData GetData(Int_t iData){return fData[iData] ;};
46
47private:
48 Int_t fDataCount;
49 Int_t fMaxDataCount;
50 UInt_t fBusPatchId;
51 AliHLTMUONTrackerRawData fData[27000];
52};
53
54class DiMuonTriggerDDLDecoder : public TObject
55{
56public :
57
58 DiMuonTriggerDDLDecoder(){;}
59 virtual ~DiMuonTriggerDDLDecoder(void){;}
60 void SetTriggerMappingData(AliHLTMUONTriggerMappingData* mappingData){ fMapData = mappingData;}
61 bool Decode(int* rawData);
62
63 void ResetDataCounter(){
64 fDataCount = 0;
65 }
66 Int_t GetDataSize(){return fDataCount;}
67
68 AliHLTMUONTriggerPointData GetData(Int_t iData){return fData[iData] ;}
69
70
71private:
72 AliHLTMUONTriggerMappingData* fMapData;
73 Int_t fDataCount;
74 Int_t fMaxDataCount;
75 AliHLTMUONTriggerPointData fData[27000];
76};
77
78bool DiMuonTriggerDDLDecoder::Decode(int* rawData)
79{
80
81 int nofTrigRec = 0;
82 int index = 0;
83 int reg_output, reg_phys_trig_occur;
84 int iLocIndex,loc,locDec,triggY,sign,loDev,triggX;
85 short pattern[2][4]; // 2 stands for two cathode planes and 4 stands for 4 chambers
86
87 int phys_trig_occur = (rawData[index]>>30)&0x1; // 1 for physics trigger, 0 for software trigger
88
89 if (not phys_trig_occur) // for software trigger
90 index += 8 ;// corresponding to scalar words
91
92 index += 1 ; // To skip the separator 0xDEADFACE
93
94 index += 4 ; // corresponding to global input
95
96 index += 1 ; // reaches to global output
97
98 if (not phys_trig_occur) index += 10; // corresponds to scalar words
99
100 index += 1; // separator 0xDEADBEEF
101
102 for (int iReg = 0; iReg < 8; iReg++){
103
104 index += 1; // DARC Status Word
105 index += 1; // Regeional Word
106 reg_output = rawData[index] & 0xFF;
107 reg_phys_trig_occur = ( rawData[index] >> 31) & 0x1;
108// cout<<" reg_phys_trig_occur : "<<reg_phys_trig_occur<<endl;
109 index += 2; // 2 words for regional input
110
111 index += 1; // L0 counter
112
113 if (not reg_phys_trig_occur) index += 10;
114
115 index += 1; // end of Regeonal header 0xBEEFFACE
116
117 for(int iLoc = 0; iLoc < 16 ; iLoc++){
118
119 iLocIndex = index;
120
121 loc = (rawData[index+5] >> 19) & 0xF ;
122
123 locDec = (rawData[index+5] >> 15) & 0xF;
124 triggY = (rawData[index+5] >> 14) & 0x1;
125 sign = (rawData[index+5] >> 9) & 0x1;
126 loDev = (rawData[index+5] >> 5) & 0xF ;
127 triggX = (loDev >> 4 & 0x1 ) && !(loDev & 0xF);
128
129 if( locDec != 0x9 ){ // check for Dec
130
131 index += 1;
132 pattern[0][0] = rawData[index] & 0xFFFF; // x-strip pattern for chamber 0
133 pattern[0][1] = (rawData[index] >> 16) & 0xFFFF; // x-strip pattern for chamber 1
134 index += 1;
135 pattern[0][2] = rawData[index] & 0xFFFF;
136 pattern[0][3] = (rawData[index] >> 16) & 0xFFFF;
137
138 index += 1;
139 pattern[1][0] = rawData[index] & 0xFFFF; // y-strip pattern for chamber 0
140 pattern[1][1] = (rawData[index] >> 16) & 0xFFFF; // y-strip pattern for chamber 0
141 index += 1;
142 pattern[1][2] = rawData[index] & 0xFFFF;
143 pattern[1][3] = (rawData[index] >> 16) & 0xFFFF;
144
145
146 if (pattern[0][0] || pattern[0][1] || pattern[0][2] || pattern[0][3]
147 || pattern[1][0] || pattern[1][1] || pattern[1][2] || pattern[1][3]
148 ){
149
150
151 bool Xset[4] = {false, false, false, false};
152 bool Yset[4] = {false, false, false, false};
153 AliHLTMUONTriggerPointData fHit[4];
154
155 for (int iChamber = 0; iChamber < 4 ; iChamber++){ //4 chambers per DDL
156 for (int iPlane = 0; iPlane < 2 ; iPlane++){ // 2 cathode plane
157 for (Int_t ibitxy = 0; ibitxy < 16; ++ibitxy){
158
159 if (((pattern[iPlane][iChamber] >> ibitxy) & 0x1) != 0x1)
160 continue;
161
162 if (iPlane == 1){
163 if((fMapData->fLut[iReg][iLoc][iChamber][iPlane][ibitxy]).fX != 0){
164
165 fHit[iChamber].fX = (fMapData->fLut[iReg][iLoc][iChamber][iPlane][ibitxy]).fX ;
166 fHit[iChamber].fDetElemId = (fMapData->fLut[iReg][iLoc][iChamber][iPlane][ibitxy]).fDetElemId ;
167
168 Xset[iChamber] = true ;
169 }
170 }
171 else{
172 if((fMapData->fLut[iReg][iLoc][iChamber][iPlane][ibitxy]).fY != 0){
173
174 fHit[iChamber].fY = (fMapData->fLut[iReg][iLoc][iChamber][iPlane][ibitxy]).fY ;
175 fHit[iChamber].fZ = (fMapData->fLut[iReg][iLoc][iChamber][iPlane][ibitxy]).fZ ;
176
177// cout<<"2: X : "<<fMapData[iReg][iLoc][iChamber][iPlane][ibitxy].fX<<endl;
178// cout<<"2: Y : "<<fMapData[iReg][iLoc][iChamber][iPlane][ibitxy].fY<<endl;
179// cout<<"2: Z : "<<fMapData[iReg][iLoc][iChamber][iPlane][ibitxy].fZ<<endl;
180
181 Yset[iChamber] = true ;
182 }
183 }
184
185 }// loop of ibitxy
186 }// iplane
187
188// cout<<endl;
189
190 }// ichamber
191
192 for (int iChamber = 0; iChamber < 4 ; iChamber++){ //4 chambers per DDL
193 if(Yset[iChamber] and Xset[iChamber]){
194// cout<<"chamber : "<<iChamber
195// <<", (X, Y, Z) : ("<<fHit[iChamber].fX
196// <<", "<<fHit[iChamber].fY
197// <<", "<<fHit[iChamber].fZ
198// <<") "<<endl;
199 fData[fDataCount].fDetElemId = fHit[iChamber].fDetElemId ;
200 fData[fDataCount].fX = fHit[iChamber].fX ;
201 fData[fDataCount].fY = fHit[iChamber].fY ;
202 fData[fDataCount].fZ = fHit[iChamber].fZ ;
203 fDataCount++;
204
205 if(fDataCount>(27000-1)){
206 cerr<<"Running Out of memory "<<endl;
207 return false;
208 }// if data overflow quit
209
210 }// of both chamber
211 }// chamber loop
212
213 nofTrigRec++;
214
215
216 }// if any non zero pattern found
217
218 index += 1 ; // the last word, important one
219 }// Dec Condn
220
221 if (not reg_phys_trig_occur)
222 index += 45;
223
224 index += 1; // end of local Data 0xCAFEFADE
225
226 index = iLocIndex + 6; //important to reset the index counter for fake locids like 235
227 }// iLoc loop
228 }// iReg Loop
229
230 return true;
231}