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