1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
21 #include <Riostream.h>
24 #include "AliITSspdTestBeam.h"
26 ClassImp(AliITSspdTestBeam)
28 //----------------------------------------------------------------------
29 AliITSspdTestBeam::AliITSspdTestBeam(){
30 // Default Constructor for the Task AliITSspdTestBeam.
36 // A default constructed AliITSspdTestBeam class
58 //----------------------------------------------------------------------
59 AliITSspdTestBeam::AliITSspdTestBeam(const Char_t *filename,const Char_t *opt,
61 // Standard Constructor for the Task AliITSspdTestBeam.
63 // const Char_t *filename File where to read in the SPD test beam data
64 // const Char_t *opt Option, 2002 => 2002 test beam data.
68 // A default constructed AliITSspdTestBeam class
92 OpenInputFile(filename,0,-1);
93 if(strcmp(opt,"2002")) cout << "2002 assumed" << endl;
96 //----------------------------------------------------------------------
97 AliITSspdTestBeam::~AliITSspdTestBeam(){
98 // Destructor. Frees up any memory allocated or closes any files opened.
107 np = GetNumberOfPilots();
108 fRH = 0; // Just a Pointer into fBuff.
109 fRT = 0; // Just a Pointer into fBuff.
110 if(fBrst){delete[] fBrst; fBrst = 0;}
111 if(fNData)for(i=0;i<np;i++){
112 if(fNData[i]) delete[] fNData[i];
114 if(fNData) {delete[] fNData; fNData = 0;}
115 if(fData)for(i=0;i<np;i++){
116 if(fData[i]) delete[] fData[i];
118 if(fData) delete[] fData;
120 if(fHData)for(i=0;i<np;i++){
121 if(fHData[i]) delete[] fHData[i];
123 if(fHData) delete[] fHData;
125 if(fTData)for(i=0;i<np;i++){
126 if(fTData[i]) delete[] fTData[i];
128 if(fTData) delete[] fTData;
130 for(i=0;i<fMaxFiles;i++){
131 if(fFiles[i]!=0) delete fFiles[i];
133 if(fBrstSize)for(i=0;i<np;i++){
134 if(fBrstSize[i]) delete[] fBrstSize[i];
136 if(fBrstSize) {delete[] fBrstSize; fBrstSize = 0;}
138 fITS = 0; //delete fITS;
140 delete[] fNeventsStart;
141 delete[] fNeventsEnd;
143 //----------------------------------------------------------------------
144 Int_t AliITSspdTestBeam::OpenInputFile(const Char_t *filename,Int_t start,Int_t end){
145 // Opens input file for reading spd test beam data.
147 // const Char_t *filename file name to read data from
151 // An error number. 0=success, -1=failure.
156 fFiles = new ifstream*[fMaxFiles];
157 fNeventsStart = new Int_t[fMaxFiles];
158 fNeventsEnd = new Int_t[fMaxFiles];
160 if(fNfiles==fMaxFiles){// Need to expand array of open files.
161 ifstream *tmp[fMaxFiles];
162 Int_t st[fMaxFiles],en[fMaxFiles];
163 for(i=0;i<fMaxFiles;i++) { // copy pointers into tmp
166 st[i] = fNeventsStart[i];
167 en[i] = fNeventsEnd[i];
170 fMaxFiles += 5; // expand by 5.
171 fFiles = new ifstream*[fMaxFiles];
172 fNeventsStart = new Int_t[fMaxFiles];
173 fNeventsEnd = new Int_t[fMaxFiles];
174 for(i=0;i<fMaxFiles;i++) { // copy pointers back into fFiles
175 fFiles[i] = 0; // and zero rest.
176 fNeventsStart[i] = 0;
181 fNeventsStart[i] = st[i];
182 fNeventsEnd[i] = en[i];
183 } // end if i<fNfiles
185 // the array of pointers tmp is deleted automatically.
188 fFiles[fNfiles] = new ifstream(filename,ios::in|ios::binary);
189 if(fFiles[fNfiles]==0){// file open error
190 cout << "Error opening input file " << filename << endl;
194 fNeventsStart[fNfiles] = start;
195 fNeventsEnd[fNfiles] = end;
199 //----------------------------------------------------------------------
200 Int_t AliITSspdTestBeam::Read(Int_t i){
201 // Read in one buffer's worth of the file.
203 // Int_t i Which file from the array of files to be read in.
210 fFiles[i]->seekg(0,ios::end);
211 filesize = fFiles[i]->tellg();
212 fFiles[i]->seekg(0,ios::beg);
213 if(fBuff) delete[] fBuff;
214 fBuffSize = filesize;
215 fBuff = new UChar_t[fBuffSize];
216 fFiles[i]->read((Char_t*)fBuff,fBuffSize);
220 //----------------------------------------------------------------------
221 Int_t AliITSspdTestBeam::Decode(){
222 // Decode the fBuff read in.
228 // sets up the array fData fRH, and fRT
236 Int_t *ivnt,iburst,ip,np,i,j;
237 AliITSspdTestBeamData *d;
238 AliITSspdTestBeamBurst *b;
240 np = GetNumberOfPilots();
241 ivnt = new Int_t[np];
242 for(i=0;i<np;i++) ivnt[i] = 0;
243 fRH = (AliITSspdTestBeamHeader*) &(fBuff[0]); // Sets up the Run Header.
244 fRT = (AliITSspdTestBeamTail*)&(fBuff[fBuffSize-fRT->SizeOf()]);
246 tr = (UInt_t*) &(fBuff[fBuffSize-(fRT->SizeOf())-sizeof(UInt_t)]);
247 if(!(*tr==fTermination)){
248 cout << "Error Termination word not found at "<<tr<<endl;
251 if(fNData)for(i=0;i<np;i++){
252 if(fNData[i]) delete[] fNData[i];
254 if(fNData) {delete[] fNData; fNData = 0;}
255 if(fData)for(i=0;i<np;i++){
256 if(fData[i]) delete[] fData[i];
258 if(fData) {delete[] fData; fData = 0;}
259 if(fHData)for(i=0;i<np;i++){
260 if(fHData[i]) delete[] fHData[i];
262 if(fHData) {delete[] fHData; fHData = 0;}
263 if(fTData)for(i=0;i<np;i++){
264 if(fTData[i]) delete[] fTData[i];
266 if(fTData) {delete[] fTData; fTData = 0;}
267 if(fBrstSize)for(i=0;i<np;i++){
268 if(fBrstSize[i]) delete[] fBrstSize[i];
270 if(fBrstSize) {delete[] fBrstSize; fBrstSize = 0;}
271 fNEvents = fRH->GetNumberOfEvents();
272 fNBrst = fNEvents/fRH->GetBurstSize();
273 fBrst = new AliITSspdTestBeamBurst*[fNBrst];
274 fBrstSize = new Int_t*[np];
275 fNData = new Int_t*[np];
276 fData = new AliITSspdTestBeamData**[np];
277 fHData = new AliITSspdTestBeamData**[np];
278 fTData = new AliITSspdTestBeamData**[np];
280 fBrstSize[i] = new Int_t[fNBrst];
281 fNData[i] = new Int_t[fNEvents];
282 fData[i] = new AliITSspdTestBeamData*[fNEvents];
283 fHData[i] = new AliITSspdTestBeamData*[fNEvents];
284 fTData[i] = new AliITSspdTestBeamData*[fNEvents];
285 for(j=0;j<fNEvents;j++){
292 if(fBrst){delete[] fBrst; fBrst = 0;}
293 size = fRH->SizeOf();
296 for(iburst=0;(*(u.wd) != fTermination)&&(u.wd<tr);iburst++){ // loop over Bursts
297 b = (AliITSspdTestBeamBurst *) u.wd;
299 u.bt += b->SizeOf(); // increment wd byte wise
300 for(ip=0;ip<np;ip++){ // loop over pilots
301 // Get size of data stored for this pilot.
302 fBrstSize[ip][iburst] = (UInt_t) u.wd;
303 u.bt += sizeof(UInt_t); // increment wd byte wise
304 for(i=0;i<fBrstSize[ip][iburst];i++){ // loop over data
305 d = (AliITSspdTestBeamData *) u.wd;
307 case AliITSTestBeamData::kData :
308 fNData[ip][ivnt[ip]]++;
309 // set pointer to first data member
310 if(fData[ip][ivnt[ip]] == 0 ) fData[ip][ivnt[ip]] = d;
312 case AliITSTestBeamData::kHead :
313 fNData[ip][ivnt[ip]] = 0;
314 fData[ip][ivnt[ip]] = 0;
315 fHData[ip][ivnt[ip]++] = d;
317 case AliITSTestBeamData::kTail :
318 case AliITSTestBeamData::kAbort :
319 fTData[ip][ivnt[ip]] = d;
322 cout << "Unknown Data Type: wd="<<hex<<*(u.wd)<<dec<<endl;
325 u.bt += d->SizeOf(); // increment wd byte wise
326 } // end for i (next data word).
327 } // end for loop over pilots (ip).
328 } // end for loop over bursts
332 //============================================================================
333 void AliITSspdTestBeamHeader::Print(ostream *os){
334 // print out the header information
336 // ostream *os Pointer to the output stream.
349 #if defined __ICC || defined __ECC
356 *os<<"Version: "<<fUnion.fHead.fVersion<<" Written: "<<fUnion.fHead.fDate;
357 *os<<" " << fUnion.fHead.fTime << endl;
358 *os<<"Buffer Size [0], [1], [2]: " << fUnion.fHead.fBuffSize[0] << ",";
359 *os<<fUnion.fHead.fBuffSize[1]<<"," <<fUnion.fHead.fBuffSize[2] << endl;
360 *os<<"Test Pulse: " << fUnion.fHead.fTestPulse << endl;
361 *os<<"Trigger Mode General, [0], [1], [2]: " << fUnion.fHead.fTriggerMode;
362 *os<<","<<fUnion.fHead.fTrigger[0]<<","<<fUnion.fHead.fTrigger[1]<< ",";
363 *os<<fUnion.fHead.fTrigger[2] << endl;
364 *os<<"Number of Events: " << fUnion.fHead.fNEvents << " Burst Size: ";
365 *os<<fUnion.fHead.fBurstSize << endl;
368 //----------------------------------------------------------------------
369 ostream &operator<<(ostream &os,AliITSspdTestBeamHeader &p){
370 // Standard output operator. See Print
372 // ostream &os the output stream.
373 // AliITSspdTestBeamHeader &p the data to be printed out.
377 // ostream &os pointing now to the end of the present stream.
382 //============================================================================
383 void AliITSspdTestBeamTail::Print(ostream *os){
384 // print out the Tail information
386 // ostream *os Pointer to the output stream.
399 #if defined __ICC || defined __ECC
406 *os << "Number of Events: "<< fUnion.fTail.fEvents << " Written: "
407 << fUnion.fTail.fDate;
408 *os << " " << fUnion.fTail.fTime << endl;
409 *os <<"Termination Flag: " << fUnion.fTail.fTermMode << endl;
412 //----------------------------------------------------------------------
413 ostream &operator<<(ostream &os,AliITSspdTestBeamTail &p){
414 // Standard output operator. See Print
416 // ostream &os the output stream.
417 // AliITSspdTestBeamHeader &p the data to be printed out.
421 // ostream &os pointing now to the end of the present stream.
426 //============================================================================
427 void AliITSspdTestBeamBurst::Print(ostream *os){
428 // print out the Burst information
430 // ostream *os Pointer to the output stream.
443 #if defined __ICC || defined __ECC
450 *os << "Burst Number: "<< fUnion.fBrst.fNumber << " Transfers: "
451 << fUnion.fBrst.fTransfers << endl;
454 //----------------------------------------------------------------------
455 ostream &operator<<(ostream &os,AliITSspdTestBeamBurst &p){
456 // Standard output operator. See Print
458 // ostream &os the output stream.
459 // AliITSspdTestBeamHeader &p the data to be printed out.
463 // ostream &os pointing now to the end of the present stream.
468 //======================================================================
469 void AliITSspdTestBeamData::Print(ostream *os){
470 // print out the the Test Beam Data information
472 // ostream *os Pointer to the output stream.
485 #if defined __ICC || defined __ECC
492 *os << "Word=" << hex << fUnion.fBuf[0] << hex << fUnion.fBuf[1]
493 << hex << fUnion.fBuf[2] << hex << fUnion.fBuf[3] << dec;
494 switch (this->Mode()){
495 case AliITSTestBeamData::kData :
496 *os << " kData chip=" << setw(3) << fUnion.fDataD.fChip;
497 *os << " Row=" << setw(3) << fUnion.fDataD.fRow;
498 *os << " Column=" << setw(3) << fUnion.fDataD.fColm;
500 case AliITSTestBeamData::kHead :
501 *os << " kHead Event Sync =" << fUnion.fDataH.fEventSync;
503 case AliITSTestBeamData::kTail :
504 *os << " kTail Transmitted word count =" << fUnion.fDataT.fTrans;
506 case AliITSTestBeamData::kAbort :
507 *os << " kAbort Transmitted word count =" << fUnion.fDataA.fTrans;
510 *os << " Unknown Data Type";
516 //----------------------------------------------------------------------
517 ostream &operator<<(ostream &os,AliITSspdTestBeamData &p){
518 // Standard output operator. See Print
520 // ostream &os the output stream.
521 // AliITSspdTestBeamHeader &p the data to be printed out.
525 // ostream &os pointing now to the end of the present stream.