]>
Commit | Line | Data |
---|---|---|
0eedb47d | 1 | /************************************************************************** |
2 | * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. * | |
3 | * * | |
4 | * Author: The ALICE Off-line Project. * | |
5 | * Contributors are mentioned in the code where appropriate. * | |
6 | * * | |
7 | * Permission to use, copy, modify and distribute this software and its * | |
8 | * documentation strictly for non-commercial purposes is hereby granted * | |
9 | * without fee, provided that the above copyright notice appears in all * | |
10 | * copies and that both the copyright notice and this permission notice * | |
11 | * appear in the supporting documentation. The authors make no claims * | |
12 | * about the suitability of this software for any purpose. It is * | |
13 | * provided "as is" without express or implied warranty. * | |
14 | **************************************************************************/ | |
15 | ||
16 | /* $Id$ */ | |
17 | ||
18 | #include "AliTRDtestBeam.h" | |
19 | ||
20 | #include "AliTRDRawStreamTB.h" | |
21 | #include "AliRawReaderMemory.h" | |
22 | ||
23 | #include <iostream> | |
24 | #include <fstream> | |
25 | ||
6511d650 | 26 | /* |
0eedb47d | 27 | #include <sys/types.h> |
28 | #include <sys/stat.h> | |
29 | #include <fcntl.h> | |
30 | #include <unistd.h> | |
6511d650 | 31 | */ |
0eedb47d | 32 | |
33 | ClassImp(AliTRDtestBeam) | |
34 | ||
6511d650 | 35 | const Long_t AliTRDtestBeam::fgkFileHeadSize = 544; // ? |
36 | const Long_t AliTRDtestBeam::fgkEventHeadSize = 68; //? | |
37 | const Long_t AliTRDtestBeam::fgkLdcHeadSize = 68; //? | |
38 | const Long_t AliTRDtestBeam::fgkEquipHeadSize = 28; // | |
39 | const Int_t AliTRDtestBeam::fgkVmeIn =1; //VME event in | |
40 | const Int_t AliTRDtestBeam::fgkSimIn =1; //Si-strips in | |
0eedb47d | 41 | |
42 | //typedef char byte; | |
43 | ||
44 | //offsets in bytes | |
6511d650 | 45 | const Int_t AliTRDtestBeam::fgkPosRun = 20; //run nr. (in file and event header) |
46 | const Int_t AliTRDtestBeam::fgkPosLength = 0; //event/equip. length | |
47 | const Int_t AliTRDtestBeam::fgkEqId = 8; //equipment id. | |
48 | const Int_t AliTRDtestBeam::fgkPosSiOff = 12; //Si data size offset (3 extra words!!!) | |
0eedb47d | 49 | |
50 | using namespace std; | |
51 | ||
52 | //____________________________________________________________________________ | |
53 | AliTRDtestBeam::AliTRDtestBeam() : | |
54 | fDataStream(0), | |
55 | fHeaderIsRead(0), | |
56 | fEventCount(0), | |
57 | fLimit(4), | |
58 | fCurrent(0), | |
59 | fDdlOff(0), | |
60 | fSiOff(0), | |
61 | fQdcOff(0), | |
62 | fDdlSize(0), | |
63 | fFileHeader(0), | |
64 | fEventHeader(0), | |
65 | fEventData(0), | |
66 | fNSi1(0), | |
67 | fNSi2(0), | |
68 | fCher(0), | |
69 | fPb(0) | |
70 | { | |
6511d650 | 71 | // |
72 | // Standard construction | |
73 | // | |
0eedb47d | 74 | |
75 | } | |
76 | //____________________________________________________________________________ | |
77 | AliTRDtestBeam::AliTRDtestBeam(const char *filename) : | |
78 | fDataStream(0), | |
79 | fHeaderIsRead(0), | |
80 | fEventCount(0), | |
81 | fLimit(4), | |
82 | fCurrent(0), | |
83 | fDdlOff(0), | |
84 | fSiOff(0), | |
85 | fQdcOff(0), | |
86 | fDdlSize(0), | |
87 | fFileHeader(0), | |
88 | fEventHeader(0), | |
89 | fEventData(0), | |
90 | fNSi1(0), | |
91 | fNSi2(0), | |
92 | fCher(0), | |
93 | fPb(0) | |
94 | { | |
6511d650 | 95 | // |
96 | // AliTRDtestBeam constructor | |
97 | // | |
0eedb47d | 98 | |
99 | fDataStream = new ifstream(filename, ifstream::in | ifstream::binary ); | |
100 | cout << fDataStream->is_open() << endl; | |
101 | //fHeaderIsRead = kTRUE; | |
102 | fHeaderIsRead = kTRUE; | |
103 | ||
6511d650 | 104 | fFileHeader = new Char_t[fgkFileHeadSize]; |
105 | fEventHeader = new Char_t[fgkEventHeadSize]; | |
0eedb47d | 106 | fEventData = new Char_t[fLimit]; |
6511d650 | 107 | |
0eedb47d | 108 | } |
6511d650 | 109 | |
0eedb47d | 110 | //____________________________________________________________________________ |
6511d650 | 111 | AliTRDtestBeam::~AliTRDtestBeam() |
112 | { | |
113 | // | |
114 | // Destructor | |
115 | // | |
0eedb47d | 116 | |
6511d650 | 117 | if (fDataStream) delete fDataStream; |
118 | if (fEventHeader) delete fEventHeader; | |
119 | if (fFileHeader) delete fFileHeader; | |
120 | if (fEventData) delete fEventData; | |
121 | ||
122 | } | |
123 | ||
124 | //____________________________________________________________________________ | |
125 | Int_t AliTRDtestBeam::NextEvent() | |
126 | { | |
127 | // | |
128 | // Read the next event | |
129 | // | |
0eedb47d | 130 | |
6511d650 | 131 | Long_t dataSize=0,ldcOff; //,ldc_id,ldc2_id; |
132 | Long_t ldcSize,eqId; //,ev_l2; | |
133 | Long_t eventNr,evL1; | |
0eedb47d | 134 | Long_t word; |
135 | ||
136 | if ( !fHeaderIsRead ) { | |
6511d650 | 137 | fDataStream->read(fFileHeader, fgkFileHeadSize); |
0eedb47d | 138 | if(fDataStream->fail()) { |
139 | cerr << "Error reading file header! " << endl; | |
140 | return false; | |
141 | } | |
6511d650 | 142 | cout << " Run nr. " << Int(fgkPosRun, fFileHeader) << endl; |
0eedb47d | 143 | fHeaderIsRead=kTRUE; |
144 | } | |
145 | ||
6511d650 | 146 | fDataStream->read(fEventHeader, fgkEventHeadSize); |
0eedb47d | 147 | if(fDataStream->fail()) { |
148 | cerr << "End of file, Event " << fEventCount << endl; | |
149 | return false; | |
150 | } | |
151 | ||
6511d650 | 152 | dataSize = Int(fgkPosLength, fEventHeader)-fgkEventHeadSize; //? |
153 | eventNr = Int((4+fgkPosRun), fEventHeader); //ev.nr. | |
154 | //cout << " Event " << eventNr <<" size "<< dataSize <<endl; | |
0eedb47d | 155 | |
6511d650 | 156 | if (eventNr <= fEventCount-1) { //watch-out ...event counter starts at 1? |
0eedb47d | 157 | cout << fEventCount << " End of file?, Event " << fEventCount << endl; |
158 | return false; | |
159 | } | |
6511d650 | 160 | //cout << "Run " << Int(fgkPosRun, header)<< " , Event " <<eventNr <<endl; |
0eedb47d | 161 | |
162 | // enough space for data? | |
6511d650 | 163 | if (fLimit < dataSize) { |
0eedb47d | 164 | delete[] fEventData; |
6511d650 | 165 | fEventData = new Char_t[dataSize]; |
166 | fLimit = dataSize; | |
0eedb47d | 167 | } |
168 | ||
6511d650 | 169 | fDataStream->read(fEventData, dataSize); |
0eedb47d | 170 | |
171 | if(fDataStream->fail()) { | |
172 | cerr << "End of file, Event " << fEventCount; // << endl; | |
173 | return false; | |
174 | } | |
175 | ||
176 | //cout << " ...IDs (size) : "; | |
177 | ||
6511d650 | 178 | ldcOff=0; // size of data from one DDL link |
0eedb47d | 179 | |
180 | for ( size_t k = 0; k < 2; k++ ) { // 2 LDCs (DDL & VME) | |
181 | ||
6511d650 | 182 | ldcSize = Int(ldcOff+fgkPosLength, fEventData); // |
183 | //ldcSize1=(ldcSize-fgkLdcHeadSize); | |
184 | eqId = Int(ldcOff+fgkLdcHeadSize+fgkEqId, fEventData); | |
185 | //cout << eqId <<" ("<<ldcSize<<") "; | |
0eedb47d | 186 | |
6511d650 | 187 | evL1 = Int((4+ldcOff+fgkPosRun), fEventData); //ev.nr. |
188 | if ( evL1 != eventNr ){ | |
189 | //cerr << "eqId " <<eqId<<" event nr. mismatch? " << eventNr <<" / "<< evL1 <<" ...LDC data size (header:68) " <<ldcSize<<endl; | |
0eedb47d | 190 | } |
191 | ||
6511d650 | 192 | if (eqId == 1024) { //DDL data |
193 | fDdlOff = ldcOff; //+fgkLdcHeadSize+fgkEquipHeadSize + 32; | |
194 | fDdlSize = ldcSize; | |
0eedb47d | 195 | } |
196 | ||
6511d650 | 197 | if (eqId == 550) { //Si-strip data (+QDC) |
0eedb47d | 198 | //cout << "550" << endl; |
6511d650 | 199 | fSiOff=ldcOff+fgkLdcHeadSize+fgkEquipHeadSize+fgkPosSiOff; |
0eedb47d | 200 | word = Int(fSiOff, fEventData); |
6511d650 | 201 | Short_t lenSi1 = (word >> 16) & 0xffff; |
202 | Short_t lenSi2 = word & 0xffff; | |
203 | fQdcOff=fSiOff+4*(lenSi1+lenSi2+1)+fgkEquipHeadSize+4; | |
0eedb47d | 204 | } |
6511d650 | 205 | else if (eqId == 1182) { //QDC first... |
0eedb47d | 206 | //cout << "1182" << endl; |
6511d650 | 207 | fQdcOff=ldcOff+fgkLdcHeadSize+fgkEquipHeadSize+fgkPosSiOff; |
208 | fSiOff=fQdcOff+fgkEquipHeadSize+4; | |
0eedb47d | 209 | } |
210 | ||
6511d650 | 211 | ldcOff=ldcSize; |
0eedb47d | 212 | |
213 | } | |
214 | //cout << endl; | |
215 | ||
216 | //cout << "DDL = " << fDdlOff << endl; | |
217 | // cout << "Si = " << fSiOff << endl; | |
218 | //cout << "QDC = " << fQdcOff << endl; | |
219 | ||
220 | DecodeSi(); | |
221 | ||
222 | fEventCount++; //event counter | |
223 | return true; | |
224 | } | |
6511d650 | 225 | |
0eedb47d | 226 | //____________________________________________________________________________ |
6511d650 | 227 | Int_t AliTRDtestBeam::DecodeSi() |
228 | { | |
229 | // | |
230 | // Decode the silicon detector | |
231 | // | |
0eedb47d | 232 | |
233 | if (fSiOff < 0) return 0; | |
234 | ||
235 | // cout << "decoding Si data" << endl; | |
236 | ||
237 | Long_t word; | |
238 | ||
239 | word=Int(fSiOff, fEventData); | |
240 | fNSi1 = (word >> 16) & 0xffff; | |
241 | fNSi2 = word & 0xffff; | |
242 | ||
243 | Int_t cSi=fSiOff; // | |
244 | for (int i = 0; i < fNSi1; i++) { | |
245 | fSi1Address[i] = ( Int(cSi, fEventData) >> 12 ) & 0x7ff; | |
246 | fSi1Charge[i] = Int(cSi, fEventData) & 0xfff; | |
247 | cSi+=4; | |
248 | } | |
249 | ||
250 | for (int i = 0; i < fNSi2; i++) { //1,for Date! | |
251 | fSi2Address[i] = ( Int(cSi, fEventData) >> 12 ) & 0x7ff; | |
252 | fSi2Charge[i] = Int(cSi, fEventData) & 0xfff; | |
253 | cSi+=4; | |
254 | } | |
255 | ||
256 | // reconstruction | |
257 | ||
6511d650 | 258 | int aLenSiX = 640; |
0eedb47d | 259 | |
260 | int qmaxX; int amaxX; | |
261 | int qmaxY; int amaxY; | |
262 | ||
263 | qmaxX = 5; | |
264 | qmaxY = 5; | |
265 | amaxX = -1; | |
6511d650 | 266 | amaxY = -1+aLenSiX; |
0eedb47d | 267 | |
268 | for( int i = 0; i < GetNSi1(); i++ ) { | |
269 | ||
270 | if (fSi1Address[i] == 0) continue; // noise | |
271 | ||
6511d650 | 272 | if (fSi1Address[i] < aLenSiX ) { |
0eedb47d | 273 | if( fSi1Charge[i] > qmaxX ) { |
274 | qmaxX = fSi1Charge[i]; | |
275 | amaxX = fSi1Address[i]; | |
276 | } | |
277 | } else { | |
278 | if( fSi1Charge[i] > qmaxY ) { | |
279 | qmaxY = fSi1Charge[i]; | |
280 | amaxY = fSi1Address[i]; | |
281 | } | |
282 | } | |
283 | } | |
284 | ||
285 | fX[0] = (float)(amaxX*0.05); // [mm] | |
6511d650 | 286 | fY[0] = (float)((amaxY-aLenSiX)*0.05); |
0eedb47d | 287 | fQx[0] = (float)qmaxX; |
288 | fQy[0] = (float)qmaxY; | |
289 | ||
290 | // | |
291 | qmaxX = 5; | |
292 | qmaxY = 5; | |
293 | amaxX = -1; | |
6511d650 | 294 | amaxY = -1+aLenSiX; |
0eedb47d | 295 | |
296 | for( int i = 0; i < GetNSi2(); i++ ) { | |
297 | ||
298 | if (fSi2Address[i] == 1279) continue; // noise | |
299 | if (fSi2Address[i] == 0) continue; // noise | |
300 | ||
6511d650 | 301 | if(fSi2Address[i] < aLenSiX) { |
0eedb47d | 302 | if( fSi2Charge[i] > qmaxX ) { |
303 | qmaxX = fSi2Charge[i]; | |
304 | amaxX = fSi2Address[i]; | |
305 | } | |
306 | } else { | |
307 | if( fSi2Charge[i] > qmaxY ) { | |
308 | //if (fSi2Charge[i] > 50) cout << fSi2Charge[i] << " " << i << " " << fSi2Address[i] << endl; | |
309 | qmaxY = fSi2Charge[i]; | |
310 | amaxY = fSi2Address[i]; | |
311 | } | |
312 | } | |
313 | } | |
314 | ||
315 | fX[1] = (float)(amaxX*0.05); // [mm] | |
6511d650 | 316 | fY[1] = (float)((amaxY-aLenSiX)*0.05); |
0eedb47d | 317 | fQx[1] = (float)qmaxX; |
318 | fQy[1] = (float)qmaxY; | |
319 | ||
320 | if (fQdcOff < 0) return 0; | |
321 | ||
322 | word=Int(fQdcOff, fEventData); | |
323 | fPb = (Double_t)((word >> 16) & 0xFFF); | |
324 | fCher = (Double_t)((word ) & 0xFFF); | |
325 | ||
326 | //cout << fCher << " " << fPb << endl; | |
327 | return 1; | |
6511d650 | 328 | |
0eedb47d | 329 | } |
330 | //____________________________________________________________________________ | |
6511d650 | 331 | AliTRDRawStreamTB *AliTRDtestBeam::GetTRDrawStream() |
332 | { | |
333 | // | |
334 | // Get the TRD raw stream | |
335 | // | |
0eedb47d | 336 | |
337 | // needs AliTRDRawStreamTB | |
338 | //cout << "Chamber reader:" << (Int_t)(fEventData+fDdlOff) << " " << fDdlSize << endl; | |
339 | //int ifout = open("dump.dat", O_WRONLY | O_TRUNC | O_CREAT); | |
340 | //write(ifout, (void*)(fEventData+fDdlOff+16), fDdlSize); | |
341 | //close(ifout); | |
342 | ||
343 | AliRawReaderMemory *reader = new AliRawReaderMemory((UChar_t*)(fEventData+fDdlOff), (UInt_t)fDdlSize); | |
344 | reader->SetEquipmentID(1024); | |
345 | reader->ReadHeader(); | |
346 | AliTRDRawStreamTB::RawBufferMissAligned(kTRUE); | |
347 | AliTRDRawStreamTB::SupressWarnings(kTRUE); | |
348 | ||
349 | AliTRDRawStreamTB *tb = new AliTRDRawStreamTB(reader); | |
350 | tb->Init(); | |
351 | return tb; | |
352 | /* | |
353 | return | |
354 | ||
355 | AliRawReaderMemory *rmem = data->GetRawReader(); | |
356 | rmem->ReadHeader(); | |
357 | ||
358 | AliTRDRawStreamTB tb(rmem); | |
359 | tb.Init(); | |
360 | AliTRDRawStreamTB::SupressWarnings(kTRUE); | |
361 | ||
362 | */ | |
363 | } | |
0eedb47d | 364 | |
6511d650 | 365 | //____________________________________________________________________________ |
366 | Int_t AliTRDtestBeam::Int(Int_t i, Char_t *start) | |
367 | { | |
368 | // | |
369 | // ????? | |
370 | // | |
0eedb47d | 371 | |
372 | bool swap = kFALSE; | |
373 | ||
374 | if(swap) { | |
375 | char *q=(char*)(start+i); | |
376 | char p[] = {q[3], q[2], q[1], q[0]}; | |
377 | return *((int*) p); | |
378 | } else return *((int*)(start+i)); | |
6511d650 | 379 | |
0eedb47d | 380 | } |
381 | ||
382 | //____________________________________________________________________________ |