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 **************************************************************************/
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.
31 #include <Riostream.h>
35 #include "AliITSspdTestBeam.h"
37 ClassImp(AliITSspdTestBeam)
39 //----------------------------------------------------------------------
40 AliITSspdTestBeam::AliITSspdTestBeam(){
41 // Default Constructor for the Task AliITSspdTestBeam.
47 // A default constructed AliITSspdTestBeam class
69 //----------------------------------------------------------------------
70 AliITSspdTestBeam::AliITSspdTestBeam(const Char_t *filename,const Char_t *opt,
72 // Standard Constructor for the Task AliITSspdTestBeam.
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.
79 // A default constructed AliITSspdTestBeam class
103 OpenInputFile(filename,0,-1);
104 if(strcmp(opt,"2002")) cout << "2002 assumed" << endl;
107 //----------------------------------------------------------------------
108 AliITSspdTestBeam::~AliITSspdTestBeam(){
109 // Destructor. Frees up any memory allocated or closes any files opened.
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];
125 if(fNData) {delete[] fNData; fNData = 0;}
126 if(fData)for(i=0;i<np;i++){
127 if(fData[i]) delete[] fData[i];
129 if(fData) delete[] fData;
131 if(fHData)for(i=0;i<np;i++){
132 if(fHData[i]) delete[] fHData[i];
134 if(fHData) delete[] fHData;
136 if(fTData)for(i=0;i<np;i++){
137 if(fTData[i]) delete[] fTData[i];
139 if(fTData) delete[] fTData;
141 for(i=0;i<fMaxFiles;i++){
142 if(fFiles[i]!=0) delete fFiles[i];
144 if(fBrstSize)for(i=0;i<np;i++){
145 if(fBrstSize[i]) delete[] fBrstSize[i];
147 if(fBrstSize) {delete[] fBrstSize; fBrstSize = 0;}
149 fITS = 0; //delete fITS;
151 delete[] fNeventsStart;
152 delete[] fNeventsEnd;
154 //----------------------------------------------------------------------
155 Int_t AliITSspdTestBeam::OpenInputFile(const Char_t *filename,Int_t start,Int_t end){
156 // Opens input file for reading spd test beam data.
158 // const Char_t *filename file name to read data from
162 // An error number. 0=success, -1=failure.
167 fFiles = new ifstream*[fMaxFiles];
168 fNeventsStart = new Int_t[fMaxFiles];
169 fNeventsEnd = new Int_t[fMaxFiles];
171 if(fNfiles==fMaxFiles){// Need to expand array of open files.
172 ifstream **tmp = new ifstream*[fMaxFiles];
173 TArrayI st(fMaxFiles);
174 TArrayI en(fMaxFiles);
175 for(i=0;i<fMaxFiles;i++) { // copy pointers into tmp
178 st[i] = fNeventsStart[i];
179 en[i] = fNeventsEnd[i];
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;
193 fNeventsStart[i] = st[i];
194 fNeventsEnd[i] = en[i];
195 } // end if i<fNfiles
197 // the array of pointers tmp is deleted automatically.
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;
207 fNeventsStart[fNfiles] = start;
208 fNeventsEnd[fNfiles] = end;
212 //----------------------------------------------------------------------
213 Int_t AliITSspdTestBeam::Read(Int_t i){
214 // Read in one buffer's worth of the file.
216 // Int_t i Which file from the array of files to be read in.
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);
233 //----------------------------------------------------------------------
234 Int_t AliITSspdTestBeam::Decode(){
235 // Decode the fBuff read in.
241 // sets up the array fData fRH, and fRT
249 Int_t *ivnt,iburst,ip,np,i,j;
250 AliITSspdTestBeamData *d;
251 AliITSspdTestBeamBurst *b;
253 np = GetNumberOfPilots();
254 ivnt = new Int_t[np];
255 for(i=0;i<np;i++) ivnt[i] = 0;
256 fRH = (AliITSspdTestBeamHeader*) &(fBuff[0]); // Sets up the Run Header.
257 fRT = (AliITSspdTestBeamTail*)&(fBuff[fBuffSize-fRT->SizeOf()]);
259 tr = (UInt_t*) &(fBuff[fBuffSize-(fRT->SizeOf())-sizeof(UInt_t)]);
260 if(!(*tr==fTermination)){
261 cout << "Error Termination word not found at "<<tr<<endl;
264 if(fNData)for(i=0;i<np;i++){
265 if(fNData[i]) delete[] fNData[i];
267 if(fNData) {delete[] fNData; fNData = 0;}
268 if(fData)for(i=0;i<np;i++){
269 if(fData[i]) delete[] fData[i];
271 if(fData) {delete[] fData; fData = 0;}
272 if(fHData)for(i=0;i<np;i++){
273 if(fHData[i]) delete[] fHData[i];
275 if(fHData) {delete[] fHData; fHData = 0;}
276 if(fTData)for(i=0;i<np;i++){
277 if(fTData[i]) delete[] fTData[i];
279 if(fTData) {delete[] fTData; fTData = 0;}
280 if(fBrstSize)for(i=0;i<np;i++){
281 if(fBrstSize[i]) delete[] fBrstSize[i];
283 if(fBrstSize) {delete[] fBrstSize; fBrstSize = 0;}
284 fNEvents = fRH->GetNumberOfEvents();
285 fNBrst = fNEvents/fRH->GetBurstSize();
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];
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++){
305 if(fBrst){delete[] fBrst; fBrst = 0;}
306 size = fRH->SizeOf();
309 for(iburst=0;(*(u.wd) != fTermination)&&(u.wd<tr);iburst++){ // loop over Bursts
310 b = (AliITSspdTestBeamBurst *) u.wd;
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.
315 fBrstSize[ip][iburst] = (UInt_t) u.wd;
316 u.bt += sizeof(UInt_t); // increment wd byte wise
317 for(i=0;i<fBrstSize[ip][iburst];i++){ // loop over data
318 d = (AliITSspdTestBeamData *) u.wd;
320 case AliITSTestBeamData::kData :
321 fNData[ip][ivnt[ip]]++;
322 // set pointer to first data member
323 if(fData[ip][ivnt[ip]] == 0 ) fData[ip][ivnt[ip]] = d;
325 case AliITSTestBeamData::kHead :
326 fNData[ip][ivnt[ip]] = 0;
327 fData[ip][ivnt[ip]] = 0;
328 fHData[ip][ivnt[ip]++] = d;
330 case AliITSTestBeamData::kTail :
331 case AliITSTestBeamData::kAbort :
332 fTData[ip][ivnt[ip]] = d;
335 cout << "Unknown Data Type: wd="<<hex<<*(u.wd)<<dec<<endl;
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
345 //============================================================================
346 void AliITSspdTestBeamHeader::Print(ostream *os)const{
347 // print out the header information
349 // ostream *os Pointer to the output stream.
362 #if defined __ICC || defined __ECC
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;
381 //----------------------------------------------------------------------
382 ostream &operator<<(ostream &os,AliITSspdTestBeamHeader &p){
383 // Standard output operator. See Print
385 // ostream &os the output stream.
386 // AliITSspdTestBeamHeader &p the data to be printed out.
390 // ostream &os pointing now to the end of the present stream.
395 //============================================================================
396 void AliITSspdTestBeamTail::Print(ostream *os)const{
397 // print out the Tail information
399 // ostream *os Pointer to the output stream.
412 #if defined __ICC || defined __ECC
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;
425 //----------------------------------------------------------------------
426 ostream &operator<<(ostream &os,AliITSspdTestBeamTail &p){
427 // Standard output operator. See Print
429 // ostream &os the output stream.
430 // AliITSspdTestBeamHeader &p the data to be printed out.
434 // ostream &os pointing now to the end of the present stream.
439 //============================================================================
440 void AliITSspdTestBeamBurst::Print(ostream *os)const{
441 // print out the Burst information
443 // ostream *os Pointer to the output stream.
456 #if defined __ICC || defined __ECC
463 *os << "Burst Number: "<< fUnion.fBrst.fNumber << " Transfers: "
464 << fUnion.fBrst.fTransfers << endl;
467 //----------------------------------------------------------------------
468 ostream &operator<<(ostream &os,AliITSspdTestBeamBurst &p){
469 // Standard output operator. See Print
471 // ostream &os the output stream.
472 // AliITSspdTestBeamHeader &p the data to be printed out.
476 // ostream &os pointing now to the end of the present stream.
481 //======================================================================
482 void AliITSspdTestBeamData::Print(ostream *os)const{
483 // print out the the Test Beam Data information
485 // ostream *os Pointer to the output stream.
498 #if defined __ICC || defined __ECC
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()){
508 case AliITSTestBeamData::kData :
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;
513 case AliITSTestBeamData::kHead :
514 *os << " kHead Event Sync =" << fUnion.fDataH.fEventSync;
516 case AliITSTestBeamData::kTail :
517 *os << " kTail Transmitted word count =" << fUnion.fDataT.fTrans;
519 case AliITSTestBeamData::kAbort :
520 *os << " kAbort Transmitted word count =" << fUnion.fDataA.fTrans;
523 *os << " Unknown Data Type";
529 //----------------------------------------------------------------------
530 ostream &operator<<(ostream &os,AliITSspdTestBeamData &p){
531 // Standard output operator. See Print
533 // ostream &os the output stream.
534 // AliITSspdTestBeamHeader &p the data to be printed out.
538 // ostream &os pointing now to the end of the present stream.