]> git.uio.no Git - u/mrichter/AliRoot.git/blame_incremental - TRD/AliTRDtestBeam.cxx
coding conventions
[u/mrichter/AliRoot.git] / TRD / AliTRDtestBeam.cxx
... / ...
CommitLineData
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
26/*
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <fcntl.h>
30#include <unistd.h>
31*/
32
33ClassImp(AliTRDtestBeam)
34
35const Long_t AliTRDtestBeam::fgkFileHeadSize = 544; // ?
36const Long_t AliTRDtestBeam::fgkEventHeadSize = 68; //?
37const Long_t AliTRDtestBeam::fgkLdcHeadSize = 68; //?
38const Long_t AliTRDtestBeam::fgkEquipHeadSize = 28; //
39const Int_t AliTRDtestBeam::fgkVmeIn =1; //VME event in
40const Int_t AliTRDtestBeam::fgkSimIn =1; //Si-strips in
41
42//typedef char byte;
43
44//offsets in bytes
45const Int_t AliTRDtestBeam::fgkPosRun = 20; //run nr. (in file and event header)
46const Int_t AliTRDtestBeam::fgkPosLength = 0; //event/equip. length
47const Int_t AliTRDtestBeam::fgkEqId = 8; //equipment id.
48const Int_t AliTRDtestBeam::fgkPosSiOff = 12; //Si data size offset (3 extra words!!!)
49
50using namespace std;
51
52//____________________________________________________________________________
53AliTRDtestBeam::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{
71 //
72 // Standard construction
73 //
74
75}
76//____________________________________________________________________________
77AliTRDtestBeam::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{
95 //
96 // AliTRDtestBeam constructor
97 //
98
99 fDataStream = new ifstream(filename, ifstream::in | ifstream::binary );
100 cout << fDataStream->is_open() << endl;
101 //fHeaderIsRead = kTRUE;
102 fHeaderIsRead = kTRUE;
103
104 fFileHeader = new Char_t[fgkFileHeadSize];
105 fEventHeader = new Char_t[fgkEventHeadSize];
106 fEventData = new Char_t[fLimit];
107
108}
109
110//____________________________________________________________________________
111AliTRDtestBeam::~AliTRDtestBeam()
112{
113 //
114 // Destructor
115 //
116
117 if (fDataStream) delete fDataStream;
118 if (fEventHeader) delete fEventHeader;
119 if (fFileHeader) delete fFileHeader;
120 if (fEventData) delete fEventData;
121
122}
123
124//____________________________________________________________________________
125Int_t AliTRDtestBeam::NextEvent()
126{
127 //
128 // Read the next event
129 //
130
131 Long_t dataSize=0,ldcOff; //,ldc_id,ldc2_id;
132 Long_t ldcSize,eqId; //,ev_l2;
133 Long_t eventNr,evL1;
134 Long_t word;
135
136 if ( !fHeaderIsRead ) {
137 fDataStream->read(fFileHeader, fgkFileHeadSize);
138 if(fDataStream->fail()) {
139 cerr << "Error reading file header! " << endl;
140 return false;
141 }
142 cout << " Run nr. " << Int(fgkPosRun, fFileHeader) << endl;
143 fHeaderIsRead=kTRUE;
144 }
145
146 fDataStream->read(fEventHeader, fgkEventHeadSize);
147 if(fDataStream->fail()) {
148 cerr << "End of file, Event " << fEventCount << endl;
149 return false;
150 }
151
152 dataSize = Int(fgkPosLength, fEventHeader)-fgkEventHeadSize; //?
153 eventNr = Int((4+fgkPosRun), fEventHeader); //ev.nr.
154 //cout << " Event " << eventNr <<" size "<< dataSize <<endl;
155
156 if (eventNr <= fEventCount-1) { //watch-out ...event counter starts at 1?
157 cout << fEventCount << " End of file?, Event " << fEventCount << endl;
158 return false;
159 }
160 //cout << "Run " << Int(fgkPosRun, header)<< " , Event " <<eventNr <<endl;
161
162 // enough space for data?
163 if (fLimit < dataSize) {
164 delete[] fEventData;
165 fEventData = new Char_t[dataSize];
166 fLimit = dataSize;
167 }
168
169 fDataStream->read(fEventData, dataSize);
170
171 if(fDataStream->fail()) {
172 cerr << "End of file, Event " << fEventCount; // << endl;
173 return false;
174 }
175
176 //cout << " ...IDs (size) : ";
177
178 ldcOff=0; // size of data from one DDL link
179
180 for ( size_t k = 0; k < 2; k++ ) { // 2 LDCs (DDL & VME)
181
182 ldcSize = Int(ldcOff+fgkPosLength, fEventData); //
183 //ldcSize1=(ldcSize-fgkLdcHeadSize);
184 eqId = Int(ldcOff+fgkLdcHeadSize+fgkEqId, fEventData);
185 //cout << eqId <<" ("<<ldcSize<<") ";
186
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;
190 }
191
192 if (eqId == 1024) { //DDL data
193 fDdlOff = ldcOff; //+fgkLdcHeadSize+fgkEquipHeadSize + 32;
194 fDdlSize = ldcSize;
195 }
196
197 if (eqId == 550) { //Si-strip data (+QDC)
198 //cout << "550" << endl;
199 fSiOff=ldcOff+fgkLdcHeadSize+fgkEquipHeadSize+fgkPosSiOff;
200 word = Int(fSiOff, fEventData);
201 Short_t lenSi1 = (word >> 16) & 0xffff;
202 Short_t lenSi2 = word & 0xffff;
203 fQdcOff=fSiOff+4*(lenSi1+lenSi2+1)+fgkEquipHeadSize+4;
204 }
205 else if (eqId == 1182) { //QDC first...
206 //cout << "1182" << endl;
207 fQdcOff=ldcOff+fgkLdcHeadSize+fgkEquipHeadSize+fgkPosSiOff;
208 fSiOff=fQdcOff+fgkEquipHeadSize+4;
209 }
210
211 ldcOff=ldcSize;
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}
225
226//____________________________________________________________________________
227Int_t AliTRDtestBeam::DecodeSi()
228{
229 //
230 // Decode the silicon detector
231 //
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
258 int aLenSiX = 640;
259
260 int qmaxX; int amaxX;
261 int qmaxY; int amaxY;
262
263 qmaxX = 5;
264 qmaxY = 5;
265 amaxX = -1;
266 amaxY = -1+aLenSiX;
267
268 for( int i = 0; i < GetNSi1(); i++ ) {
269
270 if (fSi1Address[i] == 0) continue; // noise
271
272 if (fSi1Address[i] < aLenSiX ) {
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]
286 fY[0] = (float)((amaxY-aLenSiX)*0.05);
287 fQx[0] = (float)qmaxX;
288 fQy[0] = (float)qmaxY;
289
290 //
291 qmaxX = 5;
292 qmaxY = 5;
293 amaxX = -1;
294 amaxY = -1+aLenSiX;
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
301 if(fSi2Address[i] < aLenSiX) {
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]
316 fY[1] = (float)((amaxY-aLenSiX)*0.05);
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;
328
329}
330//____________________________________________________________________________
331AliTRDRawStreamTB *AliTRDtestBeam::GetTRDrawStream()
332{
333 //
334 // Get the TRD raw stream
335 //
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}
364
365//____________________________________________________________________________
366Int_t AliTRDtestBeam::Int(Int_t i, Char_t *start)
367{
368 //
369 // ?????
370 //
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));
379
380}
381
382//____________________________________________________________________________