]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSspdTestBeam.cxx
Bug fix - It should compile also on 64bit systems, however this code must be revised...
[u/mrichter/AliRoot.git] / ITS / AliITSspdTestBeam.cxx
CommitLineData
37c3bb97 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/*
17 $Id$
18*/
888c388d 19
20// A set of classes/routines that can read the SPD test beam data of 2002
21// and create AliITSdigits. The posibility to use these routines to do the
22// same for later and other detectors has yet to be demonstrated. At present
23// there remains a bug in that the TreeE of event headders isn't created
24// properly. See the macro AliITSspdTestBeam2Digits.C. The geometry from
25// the class AliITSvSPD002 must be read in, one way or the other, so that
26// the Geometry transoformation class AliITSgeom will prpoerly be inilized.
27
bf6adc12 28
29//#include <Riostream.h>
dd9692e9 30#include <TArrayI.h>
37c3bb97 31
32#include "AliITSspdTestBeam.h"
33
34ClassImp(AliITSspdTestBeam)
35
36//----------------------------------------------------------------------
37AliITSspdTestBeam::AliITSspdTestBeam(){
38 // Default Constructor for the Task AliITSspdTestBeam.
39 // Inputs:
40 // none.
41 // Outputs:
42 // none.
43 // Return:
44 // A default constructed AliITSspdTestBeam class
45
5590a2e3 46 fRH = 0;
47 fRT = 0;
37c3bb97 48 fNBrst = 0;
49 fBrstSize = 0;
50 fBrst = 0;
51 fNData = 0;
52 fData = 0;
53 fHData = 0;
54 fTData = 0;
55 SetTerminationWord();
56 fNEvents = 0;
57 fBuffSize = 0;
58 fBuff = 0;
37c3bb97 59 fITS = 0;
60 fNfiles = 0;
61 fMaxFiles = 0;
62 fFiles = 0;
63 fNeventsStart = 0;
64 fNeventsEnd = 0;
65}
66//----------------------------------------------------------------------
67AliITSspdTestBeam::AliITSspdTestBeam(const Char_t *filename,const Char_t *opt,
68 AliITS *its){
69 // Standard Constructor for the Task AliITSspdTestBeam.
70 // Inputs:
71 // const Char_t *filename File where to read in the SPD test beam data
72 // const Char_t *opt Option, 2002 => 2002 test beam data.
73 // Outputs:
74 // none.
75 // Return:
76 // A default constructed AliITSspdTestBeam class
77
5590a2e3 78 fRH = 0;
79 fRT = 0;
37c3bb97 80 fNBrst = 0;
81 fBrstSize = 0;
82 fBrst = 0;
83 fNData = 0;
84 fData = 0;
85 fHData = 0;
86 fTData = 0;
87 SetTerminationWord();
88 fNEvents = 0;
89 fBuffSize = 0;
90 fBuff = 0;
37c3bb97 91 fITS = 0;
92 fNfiles = 0;
93 fMaxFiles = 0;
94 fFiles = 0;
95 fNeventsStart = 0;
96 fNeventsEnd = 0;
97 //
98 fITS = its;
99 fNfiles = 0;
100 OpenInputFile(filename,0,-1);
101 if(strcmp(opt,"2002")) cout << "2002 assumed" << endl;
102}
103
104//----------------------------------------------------------------------
105AliITSspdTestBeam::~AliITSspdTestBeam(){
106 // Destructor. Frees up any memory allocated or closes any files opened.
107 // Inputs:
108 // none.
109 // Outputs:
110 // none.
111 // Return:
112 // nothing.
5590a2e3 113 Int_t i,np;
37c3bb97 114
5590a2e3 115 np = GetNumberOfPilots();
116 fRH = 0; // Just a Pointer into fBuff.
117 fRT = 0; // Just a Pointer into fBuff.
118 if(fBrst){delete[] fBrst; fBrst = 0;}
119 if(fNData)for(i=0;i<np;i++){
120 if(fNData[i]) delete[] fNData[i];
37c3bb97 121 } // end if
5590a2e3 122 if(fNData) {delete[] fNData; fNData = 0;}
123 if(fData)for(i=0;i<np;i++){
124 if(fData[i]) delete[] fData[i];
37c3bb97 125 } // end if
5590a2e3 126 if(fData) delete[] fData;
127 fData = 0;
128 if(fHData)for(i=0;i<np;i++){
129 if(fHData[i]) delete[] fHData[i];
37c3bb97 130 } // end if
5590a2e3 131 if(fHData) delete[] fHData;
132 fHData = 0;
133 if(fTData)for(i=0;i<np;i++){
134 if(fTData[i]) delete[] fTData[i];
37c3bb97 135 } // end if
5590a2e3 136 if(fTData) delete[] fTData;
137 fTData = 0;
138 for(i=0;i<fMaxFiles;i++){
139 if(fFiles[i]!=0) delete fFiles[i];
140 } // end for i
141 if(fBrstSize)for(i=0;i<np;i++){
142 if(fBrstSize[i]) delete[] fBrstSize[i];
37c3bb97 143 } // end if
5590a2e3 144 if(fBrstSize) {delete[] fBrstSize; fBrstSize = 0;}
145 delete[] fBuff;
146 fITS = 0; //delete fITS;
147 delete[] fFiles;
148 delete[] fNeventsStart;
149 delete[] fNeventsEnd;
37c3bb97 150}
151//----------------------------------------------------------------------
152Int_t AliITSspdTestBeam::OpenInputFile(const Char_t *filename,Int_t start,Int_t end){
153 // Opens input file for reading spd test beam data.
154 // Inputs:
155 // const Char_t *filename file name to read data from
156 // Outputs:
157 // none.
158 // Return:
159 // An error number. 0=success, -1=failure.
160 Int_t stat = 0,i;
161
162 if(fMaxFiles==0) {
163 fMaxFiles = 5;
164 fFiles = new ifstream*[fMaxFiles];
37c3bb97 165 fNeventsStart = new Int_t[fMaxFiles];
166 fNeventsEnd = new Int_t[fMaxFiles];
167 } // end if
168 if(fNfiles==fMaxFiles){// Need to expand array of open files.
dd9692e9 169 ifstream **tmp = new ifstream*[fMaxFiles];
170 TArrayI st(fMaxFiles);
171 TArrayI en(fMaxFiles);
37c3bb97 172 for(i=0;i<fMaxFiles;i++) { // copy pointers into tmp
173 tmp[i] = fFiles[i];
174 fFiles[i] = 0;
175 st[i] = fNeventsStart[i];
176 en[i] = fNeventsEnd[i];
177 } // end for i
178 delete fFiles;
179 fMaxFiles += 5; // expand by 5.
180 fFiles = new ifstream*[fMaxFiles];
181 fNeventsStart = new Int_t[fMaxFiles];
182 fNeventsEnd = new Int_t[fMaxFiles];
183 for(i=0;i<fMaxFiles;i++) { // copy pointers back into fFiles
184 fFiles[i] = 0; // and zero rest.
185 fNeventsStart[i] = 0;
186 fNeventsEnd[i] = 0;
187 if(i<fNfiles) {
188 fFiles[i] = tmp[i];
189 tmp[i] = 0;
190 fNeventsStart[i] = st[i];
191 fNeventsEnd[i] = en[i];
192 } // end if i<fNfiles
193 } // end for i
194 // the array of pointers tmp is deleted automatically.
dd9692e9 195 delete [] tmp;
37c3bb97 196 } // end if
197 // Open file
f65ac70b 198#ifndef __DECCXX
37c3bb97 199 fFiles[fNfiles] = new ifstream(filename,ios::in|ios::binary);
f65ac70b 200#else
201 fFiles[fNfiles] = new ifstream(filename,ios::in);
202#endif
37c3bb97 203 if(fFiles[fNfiles]==0){// file open error
204 cout << "Error opening input file " << filename << endl;
205 stat = -1;
206 return stat;
207 } // end if
208 fNeventsStart[fNfiles] = start;
209 fNeventsEnd[fNfiles] = end;
210 fNfiles++;
211 return stat;
212}
213//----------------------------------------------------------------------
214Int_t AliITSspdTestBeam::Read(Int_t i){
215 // Read in one buffer's worth of the file.
216 // Inputs:
217 // Int_t i Which file from the array of files to be read in.
218 // Outputs:
219 // none.
220 // Return:
221 // size of file.
222 Int_t filesize=0;
223
224 fFiles[i]->seekg(0,ios::end);
225 filesize = fFiles[i]->tellg();
226 fFiles[i]->seekg(0,ios::beg);
227 if(fBuff) delete[] fBuff;
228 fBuffSize = filesize;
229 fBuff = new UChar_t[fBuffSize];
230 fFiles[i]->read((Char_t*)fBuff,fBuffSize);
231 fFiles[i] ->close();
232 return filesize;
233}
234//----------------------------------------------------------------------
235Int_t AliITSspdTestBeam::Decode(){
236 // Decode the fBuff read in.
237 // Inputs:
238 // none.
239 // Outputs:
240 // none.
241 // Return:
242 // sets up the array fData fRH, and fRT
243 Int_t stat=0;
244 UInt_t *tr;
245 union {
246 UInt_t *wd;
247 UChar_t *bt;
248 }u; // end union
249 Int_t size;
250 Int_t *ivnt,iburst,ip,np,i,j;
251 AliITSspdTestBeamData *d;
252 AliITSspdTestBeamBurst *b;
253
254 np = GetNumberOfPilots();
37c3bb97 255 ivnt = new Int_t[np];
256 for(i=0;i<np;i++) ivnt[i] = 0;
5590a2e3 257 fRH = (AliITSspdTestBeamHeader*) &(fBuff[0]); // Sets up the Run Header.
258 fRT = (AliITSspdTestBeamTail*)&(fBuff[fBuffSize-fRT->SizeOf()]);
37c3bb97 259 // Check termination
5590a2e3 260 tr = (UInt_t*) &(fBuff[fBuffSize-(fRT->SizeOf())-sizeof(UInt_t)]);
37c3bb97 261 if(!(*tr==fTermination)){
5590a2e3 262 cout << "Error Termination word not found at "<<tr<<endl;
37c3bb97 263 exit(-1);
264 } // end if
5590a2e3 265 if(fNData)for(i=0;i<np;i++){
266 if(fNData[i]) delete[] fNData[i];
267 } // end if
268 if(fNData) {delete[] fNData; fNData = 0;}
269 if(fData)for(i=0;i<np;i++){
270 if(fData[i]) delete[] fData[i];
271 } // end if
272 if(fData) {delete[] fData; fData = 0;}
273 if(fHData)for(i=0;i<np;i++){
274 if(fHData[i]) delete[] fHData[i];
275 } // end if
276 if(fHData) {delete[] fHData; fHData = 0;}
277 if(fTData)for(i=0;i<np;i++){
278 if(fTData[i]) delete[] fTData[i];
279 } // end if
280 if(fTData) {delete[] fTData; fTData = 0;}
281 if(fBrstSize)for(i=0;i<np;i++){
282 if(fBrstSize[i]) delete[] fBrstSize[i];
283 } // end if
284 if(fBrstSize) {delete[] fBrstSize; fBrstSize = 0;}
285 fNEvents = fRH->GetNumberOfEvents();
286 fNBrst = fNEvents/fRH->GetBurstSize();
37c3bb97 287 fBrst = new AliITSspdTestBeamBurst*[fNBrst];
5087adf0 288 //orig fBrstSize = new Int_t*[np];
289 fBrstSize = new UInt_t**[np];
37c3bb97 290 fNData = new Int_t*[np];
291 fData = new AliITSspdTestBeamData**[np];
292 fHData = new AliITSspdTestBeamData**[np];
293 fTData = new AliITSspdTestBeamData**[np];
294 for(i=0;i<np;i++){
5087adf0 295 //orig fBrstSize[i] = new Int_t[fNBrst];
296 fBrstSize[i] = new UInt_t*[fNBrst];
37c3bb97 297 fNData[i] = new Int_t[fNEvents];
298 fData[i] = new AliITSspdTestBeamData*[fNEvents];
299 fHData[i] = new AliITSspdTestBeamData*[fNEvents];
300 fTData[i] = new AliITSspdTestBeamData*[fNEvents];
301 for(j=0;j<fNEvents;j++){
302 fNData[i][j] = 0;
303 fData[i][j] = 0;
304 fHData[i][j] = 0;
305 fTData[i][j] = 0;
306 } // end for j
307 } // end for i
5590a2e3 308 if(fBrst){delete[] fBrst; fBrst = 0;}
309 size = fRH->SizeOf();
37c3bb97 310 u.bt = &fBuff[size];
311 //
5590a2e3 312 for(iburst=0;(*(u.wd) != fTermination)&&(u.wd<tr);iburst++){ // loop over Bursts
313 b = (AliITSspdTestBeamBurst *) u.wd;
37c3bb97 314 fBrst[iburst] = b;
315 u.bt += b->SizeOf(); // increment wd byte wise
316 for(ip=0;ip<np;ip++){ // loop over pilots
317 // Get size of data stored for this pilot.
5087adf0 318 //orig fBrstSize[ip][iburst] = (UInt_t) u.wd;
319 fBrstSize[ip][iburst] = u.wd;
37c3bb97 320 u.bt += sizeof(UInt_t); // increment wd byte wise
5087adf0 321 //orig for(i=0;i<fBrstSize[ip][iburst];i++){ // loop over data
322 for(i=0;i<(Int_t)(*fBrstSize[ip][iburst]);i++){ // loop over data
5590a2e3 323 d = (AliITSspdTestBeamData *) u.wd;
37c3bb97 324 switch (d->Mode()){
325 case AliITSTestBeamData::kData :
326 fNData[ip][ivnt[ip]]++;
327 // set pointer to first data member
5590a2e3 328 if(fData[ip][ivnt[ip]] == 0 ) fData[ip][ivnt[ip]] = d;
37c3bb97 329 break;
330 case AliITSTestBeamData::kHead :
37c3bb97 331 fNData[ip][ivnt[ip]] = 0;
332 fData[ip][ivnt[ip]] = 0;
5590a2e3 333 fHData[ip][ivnt[ip]++] = d;
37c3bb97 334 break;
335 case AliITSTestBeamData::kTail :
336 case AliITSTestBeamData::kAbort :
5590a2e3 337 fTData[ip][ivnt[ip]] = d;
37c3bb97 338 break;
339 default:
340 cout << "Unknown Data Type: wd="<<hex<<*(u.wd)<<dec<<endl;
341 break;
342 } // end switch
343 u.bt += d->SizeOf(); // increment wd byte wise
344 } // end for i (next data word).
345 } // end for loop over pilots (ip).
346 } // end for loop over bursts
347 delete[] ivnt;
348 return stat;
349}
37c3bb97 350//============================================================================
888c388d 351void AliITSspdTestBeamHeader::Print(ostream *os)const{
37c3bb97 352 // print out the header information
353 // Inputs:
354 // ostream *os Pointer to the output stream.
355 // Outputs:
356 // none.
357 // Return:
358 // none.
359/*
360#if defined __GNUC__
361#if __GNUC__ > 2
362 ios::fmtflags fmt;
363#else
364 Int_t fmt;
365#endif
366#else
367#if defined __ICC || defined __ECC
368 ios::fmtflags fmt;
369#else
370 Int_t fmt;
371#endif
372#endif
373*/
5590a2e3 374 *os<<"Version: "<<fUnion.fHead.fVersion<<" Written: "<<fUnion.fHead.fDate;
375 *os<<" " << fUnion.fHead.fTime << endl;
376 *os<<"Buffer Size [0], [1], [2]: " << fUnion.fHead.fBuffSize[0] << ",";
377 *os<<fUnion.fHead.fBuffSize[1]<<"," <<fUnion.fHead.fBuffSize[2] << endl;
378 *os<<"Test Pulse: " << fUnion.fHead.fTestPulse << endl;
379 *os<<"Trigger Mode General, [0], [1], [2]: " << fUnion.fHead.fTriggerMode;
380 *os<<","<<fUnion.fHead.fTrigger[0]<<","<<fUnion.fHead.fTrigger[1]<< ",";
381 *os<<fUnion.fHead.fTrigger[2] << endl;
382 *os<<"Number of Events: " << fUnion.fHead.fNEvents << " Burst Size: ";
383 *os<<fUnion.fHead.fBurstSize << endl;
37c3bb97 384 return;
385}
386//----------------------------------------------------------------------
387ostream &operator<<(ostream &os,AliITSspdTestBeamHeader &p){
388 // Standard output operator. See Print
389 // Inputs:
390 // ostream &os the output stream.
391 // AliITSspdTestBeamHeader &p the data to be printed out.
392 // Outputs:
393 // none.
394 // Return:
395 // ostream &os pointing now to the end of the present stream.
396
397 p.Print(&os);
398 return os;
399}
400//============================================================================
888c388d 401void AliITSspdTestBeamTail::Print(ostream *os)const{
37c3bb97 402 // print out the Tail information
403 // Inputs:
404 // ostream *os Pointer to the output stream.
405 // Outputs:
406 // none.
407 // Return:
408 // none.
409/*
410#if defined __GNUC__
411#if __GNUC__ > 2
412 ios::fmtflags fmt;
413#else
414 Int_t fmt;
415#endif
416#else
417#if defined __ICC || defined __ECC
418 ios::fmtflags fmt;
419#else
420 Int_t fmt;
421#endif
422#endif
423*/
5590a2e3 424 *os << "Number of Events: "<< fUnion.fTail.fEvents << " Written: "
425 << fUnion.fTail.fDate;
426 *os << " " << fUnion.fTail.fTime << endl;
427 *os <<"Termination Flag: " << fUnion.fTail.fTermMode << endl;
37c3bb97 428 return;
429}
430//----------------------------------------------------------------------
431ostream &operator<<(ostream &os,AliITSspdTestBeamTail &p){
432 // Standard output operator. See Print
433 // Inputs:
434 // ostream &os the output stream.
435 // AliITSspdTestBeamHeader &p the data to be printed out.
436 // Outputs:
437 // none.
438 // Return:
439 // ostream &os pointing now to the end of the present stream.
440
441 p.Print(&os);
442 return os;
443}
444//============================================================================
888c388d 445void AliITSspdTestBeamBurst::Print(ostream *os)const{
37c3bb97 446 // print out the Burst information
447 // Inputs:
448 // ostream *os Pointer to the output stream.
449 // Outputs:
450 // none.
451 // Return:
452 // none.
453/*
454#if defined __GNUC__
455#if __GNUC__ > 2
456 ios::fmtflags fmt;
457#else
458 Int_t fmt;
459#endif
460#else
461#if defined __ICC || defined __ECC
462 ios::fmtflags fmt;
463#else
464 Int_t fmt;
465#endif
466#endif
467*/
5590a2e3 468 *os << "Burst Number: "<< fUnion.fBrst.fNumber << " Transfers: "
469 << fUnion.fBrst.fTransfers << endl;
37c3bb97 470 return;
471}
472//----------------------------------------------------------------------
473ostream &operator<<(ostream &os,AliITSspdTestBeamBurst &p){
474 // Standard output operator. See Print
475 // Inputs:
476 // ostream &os the output stream.
477 // AliITSspdTestBeamHeader &p the data to be printed out.
478 // Outputs:
479 // none.
480 // Return:
481 // ostream &os pointing now to the end of the present stream.
482
483 p.Print(&os);
484 return os;
485}
486//======================================================================
888c388d 487void AliITSspdTestBeamData::Print(ostream *os)const{
37c3bb97 488 // print out the the Test Beam Data information
489 // Inputs:
490 // ostream *os Pointer to the output stream.
491 // Outputs:
492 // none.
493 // Return:
494 // none.
495/*
496#if defined __GNUC__
497#if __GNUC__ > 2
498 ios::fmtflags fmt;
499#else
500 Int_t fmt;
501#endif
502#else
503#if defined __ICC || defined __ECC
504 ios::fmtflags fmt;
505#else
506 Int_t fmt;
507#endif
508#endif
509*/
5590a2e3 510 *os << "Word=" << hex << fUnion.fBuf[0] << hex << fUnion.fBuf[1]
511 << hex << fUnion.fBuf[2] << hex << fUnion.fBuf[3] << dec;
512 switch (this->Mode()){
37c3bb97 513 case AliITSTestBeamData::kData :
5590a2e3 514 *os << " kData chip=" << setw(3) << fUnion.fDataD.fChip;
515 *os << " Row=" << setw(3) << fUnion.fDataD.fRow;
516 *os << " Column=" << setw(3) << fUnion.fDataD.fColm;
37c3bb97 517 break;
518 case AliITSTestBeamData::kHead :
5590a2e3 519 *os << " kHead Event Sync =" << fUnion.fDataH.fEventSync;
37c3bb97 520 break;
521 case AliITSTestBeamData::kTail :
5590a2e3 522 *os << " kTail Transmitted word count =" << fUnion.fDataT.fTrans;
37c3bb97 523 break;
524 case AliITSTestBeamData::kAbort :
5590a2e3 525 *os << " kAbort Transmitted word count =" << fUnion.fDataA.fTrans;
37c3bb97 526 break;
527 default:
528 *os << " Unknown Data Type";
529 break;
530 } // end switch
531 *os << endl;
532 return;
533}
534//----------------------------------------------------------------------
535ostream &operator<<(ostream &os,AliITSspdTestBeamData &p){
536 // Standard output operator. See Print
537 // Inputs:
538 // ostream &os the output stream.
539 // AliITSspdTestBeamHeader &p the data to be printed out.
540 // Outputs:
541 // none.
542 // Return:
543 // ostream &os pointing now to the end of the present stream.
544
5590a2e3 545 p.Print(&os);
37c3bb97 546 return os;
547}