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.
202 fFiles[fNfiles] = new ifstream(filename,ios::in|ios::binary);
204 fFiles[fNfiles] = new ifstream(filename,ios::in);
206 if(fFiles[fNfiles]==0){// file open error
207 cout << "Error opening input file " << filename << endl;
211 fNeventsStart[fNfiles] = start;
212 fNeventsEnd[fNfiles] = end;
216 //----------------------------------------------------------------------
217 Int_t AliITSspdTestBeam::Read(Int_t i){
218 // Read in one buffer's worth of the file.
220 // Int_t i Which file from the array of files to be read in.
227 fFiles[i]->seekg(0,ios::end);
228 filesize = fFiles[i]->tellg();
229 fFiles[i]->seekg(0,ios::beg);
230 if(fBuff) delete[] fBuff;
231 fBuffSize = filesize;
232 fBuff = new UChar_t[fBuffSize];
233 fFiles[i]->read((Char_t*)fBuff,fBuffSize);
237 //----------------------------------------------------------------------
238 Int_t AliITSspdTestBeam::Decode(){
239 // Decode the fBuff read in.
245 // sets up the array fData fRH, and fRT
253 Int_t *ivnt,iburst,ip,np,i,j;
254 AliITSspdTestBeamData *d;
255 AliITSspdTestBeamBurst *b;
257 np = GetNumberOfPilots();
258 ivnt = new Int_t[np];
259 for(i=0;i<np;i++) ivnt[i] = 0;
260 fRH = (AliITSspdTestBeamHeader*) &(fBuff[0]); // Sets up the Run Header.
261 fRT = (AliITSspdTestBeamTail*)&(fBuff[fBuffSize-fRT->SizeOf()]);
263 tr = (UInt_t*) &(fBuff[fBuffSize-(fRT->SizeOf())-sizeof(UInt_t)]);
264 if(!(*tr==fTermination)){
265 cout << "Error Termination word not found at "<<tr<<endl;
268 if(fNData)for(i=0;i<np;i++){
269 if(fNData[i]) delete[] fNData[i];
271 if(fNData) {delete[] fNData; fNData = 0;}
272 if(fData)for(i=0;i<np;i++){
273 if(fData[i]) delete[] fData[i];
275 if(fData) {delete[] fData; fData = 0;}
276 if(fHData)for(i=0;i<np;i++){
277 if(fHData[i]) delete[] fHData[i];
279 if(fHData) {delete[] fHData; fHData = 0;}
280 if(fTData)for(i=0;i<np;i++){
281 if(fTData[i]) delete[] fTData[i];
283 if(fTData) {delete[] fTData; fTData = 0;}
284 if(fBrstSize)for(i=0;i<np;i++){
285 if(fBrstSize[i]) delete[] fBrstSize[i];
287 if(fBrstSize) {delete[] fBrstSize; fBrstSize = 0;}
288 fNEvents = fRH->GetNumberOfEvents();
289 fNBrst = fNEvents/fRH->GetBurstSize();
290 fBrst = new AliITSspdTestBeamBurst*[fNBrst];
291 fBrstSize = new Int_t*[np];
292 fNData = new Int_t*[np];
293 fData = new AliITSspdTestBeamData**[np];
294 fHData = new AliITSspdTestBeamData**[np];
295 fTData = new AliITSspdTestBeamData**[np];
297 fBrstSize[i] = new Int_t[fNBrst];
298 fNData[i] = new Int_t[fNEvents];
299 fData[i] = new AliITSspdTestBeamData*[fNEvents];
300 fHData[i] = new AliITSspdTestBeamData*[fNEvents];
301 fTData[i] = new AliITSspdTestBeamData*[fNEvents];
302 for(j=0;j<fNEvents;j++){
309 if(fBrst){delete[] fBrst; fBrst = 0;}
310 size = fRH->SizeOf();
313 for(iburst=0;(*(u.wd) != fTermination)&&(u.wd<tr);iburst++){ // loop over Bursts
314 b = (AliITSspdTestBeamBurst *) u.wd;
316 u.bt += b->SizeOf(); // increment wd byte wise
317 for(ip=0;ip<np;ip++){ // loop over pilots
318 // Get size of data stored for this pilot.
319 fBrstSize[ip][iburst] = (UInt_t) u.wd;
320 u.bt += sizeof(UInt_t); // increment wd byte wise
321 for(i=0;i<fBrstSize[ip][iburst];i++){ // loop over data
322 d = (AliITSspdTestBeamData *) u.wd;
324 case AliITSTestBeamData::kData :
325 fNData[ip][ivnt[ip]]++;
326 // set pointer to first data member
327 if(fData[ip][ivnt[ip]] == 0 ) fData[ip][ivnt[ip]] = d;
329 case AliITSTestBeamData::kHead :
330 fNData[ip][ivnt[ip]] = 0;
331 fData[ip][ivnt[ip]] = 0;
332 fHData[ip][ivnt[ip]++] = d;
334 case AliITSTestBeamData::kTail :
335 case AliITSTestBeamData::kAbort :
336 fTData[ip][ivnt[ip]] = d;
339 cout << "Unknown Data Type: wd="<<hex<<*(u.wd)<<dec<<endl;
342 u.bt += d->SizeOf(); // increment wd byte wise
343 } // end for i (next data word).
344 } // end for loop over pilots (ip).
345 } // end for loop over bursts
349 //============================================================================
350 void AliITSspdTestBeamHeader::Print(ostream *os)const{
351 // print out the header information
353 // ostream *os Pointer to the output stream.
366 #if defined __ICC || defined __ECC
373 *os<<"Version: "<<fUnion.fHead.fVersion<<" Written: "<<fUnion.fHead.fDate;
374 *os<<" " << fUnion.fHead.fTime << endl;
375 *os<<"Buffer Size [0], [1], [2]: " << fUnion.fHead.fBuffSize[0] << ",";
376 *os<<fUnion.fHead.fBuffSize[1]<<"," <<fUnion.fHead.fBuffSize[2] << endl;
377 *os<<"Test Pulse: " << fUnion.fHead.fTestPulse << endl;
378 *os<<"Trigger Mode General, [0], [1], [2]: " << fUnion.fHead.fTriggerMode;
379 *os<<","<<fUnion.fHead.fTrigger[0]<<","<<fUnion.fHead.fTrigger[1]<< ",";
380 *os<<fUnion.fHead.fTrigger[2] << endl;
381 *os<<"Number of Events: " << fUnion.fHead.fNEvents << " Burst Size: ";
382 *os<<fUnion.fHead.fBurstSize << endl;
385 //----------------------------------------------------------------------
386 ostream &operator<<(ostream &os,AliITSspdTestBeamHeader &p){
387 // Standard output operator. See Print
389 // ostream &os the output stream.
390 // AliITSspdTestBeamHeader &p the data to be printed out.
394 // ostream &os pointing now to the end of the present stream.
399 //============================================================================
400 void AliITSspdTestBeamTail::Print(ostream *os)const{
401 // print out the Tail information
403 // ostream *os Pointer to the output stream.
416 #if defined __ICC || defined __ECC
423 *os << "Number of Events: "<< fUnion.fTail.fEvents << " Written: "
424 << fUnion.fTail.fDate;
425 *os << " " << fUnion.fTail.fTime << endl;
426 *os <<"Termination Flag: " << fUnion.fTail.fTermMode << endl;
429 //----------------------------------------------------------------------
430 ostream &operator<<(ostream &os,AliITSspdTestBeamTail &p){
431 // Standard output operator. See Print
433 // ostream &os the output stream.
434 // AliITSspdTestBeamHeader &p the data to be printed out.
438 // ostream &os pointing now to the end of the present stream.
443 //============================================================================
444 void AliITSspdTestBeamBurst::Print(ostream *os)const{
445 // print out the Burst information
447 // ostream *os Pointer to the output stream.
460 #if defined __ICC || defined __ECC
467 *os << "Burst Number: "<< fUnion.fBrst.fNumber << " Transfers: "
468 << fUnion.fBrst.fTransfers << endl;
471 //----------------------------------------------------------------------
472 ostream &operator<<(ostream &os,AliITSspdTestBeamBurst &p){
473 // Standard output operator. See Print
475 // ostream &os the output stream.
476 // AliITSspdTestBeamHeader &p the data to be printed out.
480 // ostream &os pointing now to the end of the present stream.
485 //======================================================================
486 void AliITSspdTestBeamData::Print(ostream *os)const{
487 // print out the the Test Beam Data information
489 // ostream *os Pointer to the output stream.
502 #if defined __ICC || defined __ECC
509 *os << "Word=" << hex << fUnion.fBuf[0] << hex << fUnion.fBuf[1]
510 << hex << fUnion.fBuf[2] << hex << fUnion.fBuf[3] << dec;
511 switch (this->Mode()){
512 case AliITSTestBeamData::kData :
513 *os << " kData chip=" << setw(3) << fUnion.fDataD.fChip;
514 *os << " Row=" << setw(3) << fUnion.fDataD.fRow;
515 *os << " Column=" << setw(3) << fUnion.fDataD.fColm;
517 case AliITSTestBeamData::kHead :
518 *os << " kHead Event Sync =" << fUnion.fDataH.fEventSync;
520 case AliITSTestBeamData::kTail :
521 *os << " kTail Transmitted word count =" << fUnion.fDataT.fTrans;
523 case AliITSTestBeamData::kAbort :
524 *os << " kAbort Transmitted word count =" << fUnion.fDataA.fTrans;
527 *os << " Unknown Data Type";
533 //----------------------------------------------------------------------
534 ostream &operator<<(ostream &os,AliITSspdTestBeamData &p){
535 // Standard output operator. See Print
537 // ostream &os the output stream.
538 // AliITSspdTestBeamHeader &p the data to be printed out.
542 // ostream &os pointing now to the end of the present stream.