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