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.
29 //#include <Riostream.h>
32 #include "AliITSspdTestBeam.h"
34 ClassImp(AliITSspdTestBeam)
36 //----------------------------------------------------------------------
37 AliITSspdTestBeam::AliITSspdTestBeam(){
38 // Default Constructor for the Task AliITSspdTestBeam.
44 // A default constructed AliITSspdTestBeam class
66 //----------------------------------------------------------------------
67 AliITSspdTestBeam::AliITSspdTestBeam(const Char_t *filename,const Char_t *opt,
69 // Standard Constructor for the Task AliITSspdTestBeam.
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.
76 // A default constructed AliITSspdTestBeam class
100 OpenInputFile(filename,0,-1);
101 if(strcmp(opt,"2002")) cout << "2002 assumed" << endl;
104 //----------------------------------------------------------------------
105 AliITSspdTestBeam::~AliITSspdTestBeam(){
106 // Destructor. Frees up any memory allocated or closes any files opened.
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];
122 if(fNData) {delete[] fNData; fNData = 0;}
123 if(fData)for(i=0;i<np;i++){
124 if(fData[i]) delete[] fData[i];
126 if(fData) delete[] fData;
128 if(fHData)for(i=0;i<np;i++){
129 if(fHData[i]) delete[] fHData[i];
131 if(fHData) delete[] fHData;
133 if(fTData)for(i=0;i<np;i++){
134 if(fTData[i]) delete[] fTData[i];
136 if(fTData) delete[] fTData;
138 for(i=0;i<fMaxFiles;i++){
139 if(fFiles[i]!=0) delete fFiles[i];
141 if(fBrstSize)for(i=0;i<np;i++){
142 if(fBrstSize[i]) delete[] fBrstSize[i];
144 if(fBrstSize) {delete[] fBrstSize; fBrstSize = 0;}
146 fITS = 0; //delete fITS;
148 delete[] fNeventsStart;
149 delete[] fNeventsEnd;
151 //----------------------------------------------------------------------
152 Int_t AliITSspdTestBeam::OpenInputFile(const Char_t *filename,Int_t start,Int_t end){
153 // Opens input file for reading spd test beam data.
155 // const Char_t *filename file name to read data from
159 // An error number. 0=success, -1=failure.
164 fFiles = new ifstream*[fMaxFiles];
165 fNeventsStart = new Int_t[fMaxFiles];
166 fNeventsEnd = new Int_t[fMaxFiles];
168 if(fNfiles==fMaxFiles){// Need to expand array of open files.
169 ifstream **tmp = new ifstream*[fMaxFiles];
170 TArrayI st(fMaxFiles);
171 TArrayI en(fMaxFiles);
172 for(i=0;i<fMaxFiles;i++) { // copy pointers into tmp
175 st[i] = fNeventsStart[i];
176 en[i] = fNeventsEnd[i];
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;
190 fNeventsStart[i] = st[i];
191 fNeventsEnd[i] = en[i];
192 } // end if i<fNfiles
194 // the array of pointers tmp is deleted automatically.
199 fFiles[fNfiles] = new ifstream(filename,ios::in|ios::binary);
201 fFiles[fNfiles] = new ifstream(filename,ios::in);
203 if(fFiles[fNfiles]==0){// file open error
204 cout << "Error opening input file " << filename << endl;
208 fNeventsStart[fNfiles] = start;
209 fNeventsEnd[fNfiles] = end;
213 //----------------------------------------------------------------------
214 Int_t AliITSspdTestBeam::Read(Int_t i){
215 // Read in one buffer's worth of the file.
217 // Int_t i Which file from the array of files to be read in.
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);
234 //----------------------------------------------------------------------
235 Int_t AliITSspdTestBeam::Decode(){
236 // Decode the fBuff read in.
242 // sets up the array fData fRH, and fRT
250 Int_t *ivnt,iburst,ip,np,i,j;
251 AliITSspdTestBeamData *d;
252 AliITSspdTestBeamBurst *b;
254 np = GetNumberOfPilots();
255 ivnt = new Int_t[np];
256 for(i=0;i<np;i++) ivnt[i] = 0;
257 fRH = (AliITSspdTestBeamHeader*) &(fBuff[0]); // Sets up the Run Header.
258 fRT = (AliITSspdTestBeamTail*)&(fBuff[fBuffSize-fRT->SizeOf()]);
260 tr = (UInt_t*) &(fBuff[fBuffSize-(fRT->SizeOf())-sizeof(UInt_t)]);
261 if(!(*tr==fTermination)){
262 cout << "Error Termination word not found at "<<tr<<endl;
265 if(fNData)for(i=0;i<np;i++){
266 if(fNData[i]) delete[] fNData[i];
268 if(fNData) {delete[] fNData; fNData = 0;}
269 if(fData)for(i=0;i<np;i++){
270 if(fData[i]) delete[] fData[i];
272 if(fData) {delete[] fData; fData = 0;}
273 if(fHData)for(i=0;i<np;i++){
274 if(fHData[i]) delete[] fHData[i];
276 if(fHData) {delete[] fHData; fHData = 0;}
277 if(fTData)for(i=0;i<np;i++){
278 if(fTData[i]) delete[] fTData[i];
280 if(fTData) {delete[] fTData; fTData = 0;}
281 if(fBrstSize)for(i=0;i<np;i++){
282 if(fBrstSize[i]) delete[] fBrstSize[i];
284 if(fBrstSize) {delete[] fBrstSize; fBrstSize = 0;}
285 fNEvents = fRH->GetNumberOfEvents();
286 fNBrst = fNEvents/fRH->GetBurstSize();
287 fBrst = new AliITSspdTestBeamBurst*[fNBrst];
288 fBrstSize = new Int_t*[np];
289 fNData = new Int_t*[np];
290 fData = new AliITSspdTestBeamData**[np];
291 fHData = new AliITSspdTestBeamData**[np];
292 fTData = new AliITSspdTestBeamData**[np];
294 fBrstSize[i] = new Int_t[fNBrst];
295 fNData[i] = new Int_t[fNEvents];
296 fData[i] = new AliITSspdTestBeamData*[fNEvents];
297 fHData[i] = new AliITSspdTestBeamData*[fNEvents];
298 fTData[i] = new AliITSspdTestBeamData*[fNEvents];
299 for(j=0;j<fNEvents;j++){
306 if(fBrst){delete[] fBrst; fBrst = 0;}
307 size = fRH->SizeOf();
310 for(iburst=0;(*(u.wd) != fTermination)&&(u.wd<tr);iburst++){ // loop over Bursts
311 b = (AliITSspdTestBeamBurst *) u.wd;
313 u.bt += b->SizeOf(); // increment wd byte wise
314 for(ip=0;ip<np;ip++){ // loop over pilots
315 // Get size of data stored for this pilot.
316 fBrstSize[ip][iburst] = (UInt_t) u.wd;
317 u.bt += sizeof(UInt_t); // increment wd byte wise
318 for(i=0;i<fBrstSize[ip][iburst];i++){ // loop over data
319 d = (AliITSspdTestBeamData *) u.wd;
321 case AliITSTestBeamData::kData :
322 fNData[ip][ivnt[ip]]++;
323 // set pointer to first data member
324 if(fData[ip][ivnt[ip]] == 0 ) fData[ip][ivnt[ip]] = d;
326 case AliITSTestBeamData::kHead :
327 fNData[ip][ivnt[ip]] = 0;
328 fData[ip][ivnt[ip]] = 0;
329 fHData[ip][ivnt[ip]++] = d;
331 case AliITSTestBeamData::kTail :
332 case AliITSTestBeamData::kAbort :
333 fTData[ip][ivnt[ip]] = d;
336 cout << "Unknown Data Type: wd="<<hex<<*(u.wd)<<dec<<endl;
339 u.bt += d->SizeOf(); // increment wd byte wise
340 } // end for i (next data word).
341 } // end for loop over pilots (ip).
342 } // end for loop over bursts
346 //============================================================================
347 void AliITSspdTestBeamHeader::Print(ostream *os)const{
348 // print out the header information
350 // ostream *os Pointer to the output stream.
363 #if defined __ICC || defined __ECC
370 *os<<"Version: "<<fUnion.fHead.fVersion<<" Written: "<<fUnion.fHead.fDate;
371 *os<<" " << fUnion.fHead.fTime << endl;
372 *os<<"Buffer Size [0], [1], [2]: " << fUnion.fHead.fBuffSize[0] << ",";
373 *os<<fUnion.fHead.fBuffSize[1]<<"," <<fUnion.fHead.fBuffSize[2] << endl;
374 *os<<"Test Pulse: " << fUnion.fHead.fTestPulse << endl;
375 *os<<"Trigger Mode General, [0], [1], [2]: " << fUnion.fHead.fTriggerMode;
376 *os<<","<<fUnion.fHead.fTrigger[0]<<","<<fUnion.fHead.fTrigger[1]<< ",";
377 *os<<fUnion.fHead.fTrigger[2] << endl;
378 *os<<"Number of Events: " << fUnion.fHead.fNEvents << " Burst Size: ";
379 *os<<fUnion.fHead.fBurstSize << endl;
382 //----------------------------------------------------------------------
383 ostream &operator<<(ostream &os,AliITSspdTestBeamHeader &p){
384 // Standard output operator. See Print
386 // ostream &os the output stream.
387 // AliITSspdTestBeamHeader &p the data to be printed out.
391 // ostream &os pointing now to the end of the present stream.
396 //============================================================================
397 void AliITSspdTestBeamTail::Print(ostream *os)const{
398 // print out the Tail information
400 // ostream *os Pointer to the output stream.
413 #if defined __ICC || defined __ECC
420 *os << "Number of Events: "<< fUnion.fTail.fEvents << " Written: "
421 << fUnion.fTail.fDate;
422 *os << " " << fUnion.fTail.fTime << endl;
423 *os <<"Termination Flag: " << fUnion.fTail.fTermMode << endl;
426 //----------------------------------------------------------------------
427 ostream &operator<<(ostream &os,AliITSspdTestBeamTail &p){
428 // Standard output operator. See Print
430 // ostream &os the output stream.
431 // AliITSspdTestBeamHeader &p the data to be printed out.
435 // ostream &os pointing now to the end of the present stream.
440 //============================================================================
441 void AliITSspdTestBeamBurst::Print(ostream *os)const{
442 // print out the Burst information
444 // ostream *os Pointer to the output stream.
457 #if defined __ICC || defined __ECC
464 *os << "Burst Number: "<< fUnion.fBrst.fNumber << " Transfers: "
465 << fUnion.fBrst.fTransfers << endl;
468 //----------------------------------------------------------------------
469 ostream &operator<<(ostream &os,AliITSspdTestBeamBurst &p){
470 // Standard output operator. See Print
472 // ostream &os the output stream.
473 // AliITSspdTestBeamHeader &p the data to be printed out.
477 // ostream &os pointing now to the end of the present stream.
482 //======================================================================
483 void AliITSspdTestBeamData::Print(ostream *os)const{
484 // print out the the Test Beam Data information
486 // ostream *os Pointer to the output stream.
499 #if defined __ICC || defined __ECC
506 *os << "Word=" << hex << fUnion.fBuf[0] << hex << fUnion.fBuf[1]
507 << hex << fUnion.fBuf[2] << hex << fUnion.fBuf[3] << dec;
508 switch (this->Mode()){
509 case AliITSTestBeamData::kData :
510 *os << " kData chip=" << setw(3) << fUnion.fDataD.fChip;
511 *os << " Row=" << setw(3) << fUnion.fDataD.fRow;
512 *os << " Column=" << setw(3) << fUnion.fDataD.fColm;
514 case AliITSTestBeamData::kHead :
515 *os << " kHead Event Sync =" << fUnion.fDataH.fEventSync;
517 case AliITSTestBeamData::kTail :
518 *os << " kTail Transmitted word count =" << fUnion.fDataT.fTrans;
520 case AliITSTestBeamData::kAbort :
521 *os << " kAbort Transmitted word count =" << fUnion.fDataA.fTrans;
524 *os << " Unknown Data Type";
530 //----------------------------------------------------------------------
531 ostream &operator<<(ostream &os,AliITSspdTestBeamData &p){
532 // Standard output operator. See Print
534 // ostream &os the output stream.
535 // AliITSspdTestBeamHeader &p the data to be printed out.
539 // ostream &os pointing now to the end of the present stream.