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 **************************************************************************/
16 // Title: Class for ccessing data from STAR NTuples
17 // produces data encapsulated in AliStarEvent and AliStarTrack classes
19 // Origin: Jim Thomas, jhthomas@lbl.gov
20 // Mikolaj Krzewicki, mikolaj.krzewicki@cern.ch
22 #include <Riostream.h>
25 #include <TSystemFile.h>
33 #include "AliStarEventReader.h"
34 #include "AliStarEvent.h"
35 #include "AliStarTrack.h"
37 ClassImp(AliStarEventReader)
39 //______________________________________________________________________________
40 AliStarEventReader::AliStarEventReader():
47 //______________________________________________________________________________
48 AliStarEventReader::AliStarEventReader( const char* inputFileDirectory ):
51 fEvent(new AliStarEvent(1024))
54 MakeFileList ( inputFileDirectory ) ;
57 //______________________________________________________________________________
58 AliStarEventReader::~AliStarEventReader()
65 //______________________________________________________________________________
66 Bool_t AliStarEventReader::GetNextEvent( )
69 static TFile* nextFile = NULL ;
70 static TNtuple* ntData = NULL ;
71 static Int_t doOnce = 0 ;
72 static Long64_t nextEntry = 0 ;
73 static Long64_t entries = 0 ;
74 static Long64_t fileCounter = 0 ;
79 nextFile = (TFile*) fFileList->First() ;
80 if ( nextFile == 0 ) return false ;
81 ntData = (TNtuple*) ( nextFile->Get("NTtracks") ) ;
82 entries = ntData->GetEntriesFast() ;
83 Int_t columns = ntData->GetNvar() ;
86 cout << "Error in reading Ntuple file: no. columns != 15" << endl ;
90 cout << "Start New File " << fileCounter << endl ;
95 while ( nextEntry < entries )
97 Float_t* header = NULL;
98 Int_t numberOfParticles = 0 ; // Number of particle tracks in the next event
99 Long64_t headerEntry = 0 ; // Store position of Header and Set Flag in case of EOF or error
100 Long64_t skipEvent = 0 ; // Flag in case of wrong number of tracks in this event
102 fEvent->Reset(); //reset the event
104 // Search for the first "Event" record
106 for ( Long64_t j = nextEntry ; j < entries ; j++ )
108 Long64_t BytesRead = ntData->GetEntry(j) ;
109 if ( BytesRead < 60 )
111 cout << "Warning: error in file or EOF " << endl ;
115 header = ntData->GetArgs() ;
116 if ( (int) header[10] == -1 && (int) header[11] == -1 && (int) header[12] == -1 &&
117 (int) header[13] == -1 && (int) header[14] == -1 )
119 fEvent->SetParams(header); //set the event params
121 numberOfParticles = (int) header[9] ; // # of particles passing track cuts, thus in ntuple
125 cout << "Warning: no header entries found in this file" << endl ;
129 if ( headerEntry == -1 ) break ; // Break out of main loop if I/O error
131 // Get subsequent "track" data
132 for ( Long64_t j = headerEntry + 1 ; j < headerEntry + 1 + numberOfParticles ; j++ )
134 Long64_t BytesRead = ntData->GetEntry(j) ;
135 if ( BytesRead < 60 )
137 cout << "Warning: error in file sequence or EOF" << endl ;
141 header = ntData->GetArgs() ;
143 if ( TMath::IsNaN(header[10]) == 1 )
145 cout << "IsNan ... dEdx will be zeroed out" << endl ;
151 cout << header[0] << " " << header[1] << " " << header[2] << " " << header[3] << " "
152 << header[4] << " " << header[5] << " " << header[6] << " " << header[7] << " "
153 << header[8] << " " << header[9] << " " << header[10] << " " << header[11] << " "
154 << header[12] << " " << header[13] << " " << header[14] << endl ; // JT test
157 if ( (int) header[10] == -1 && (int) header[11] == -1 && (int) header[12] == -1 &&
158 (int) header[13] == -1 && (int) header[14] == -1 )
160 cout << "Warning: Header in the wrong place, skipping event" << endl ;
162 nextEntry = j ; // Skip event and freeze nextEntry counter
166 fEvent->AddTrack( new AliStarTrack(header) ); //add the new track
170 if ( nextEntry == -1 ) break ; // Bad record in file, go to next file in fFileList
171 if ( skipEvent == 1 ) continue ; // Bad event, go to next event in this file
172 return true ; // Success: Event read OK, note unusual location for a successful return
175 nextEntry = 0 ; // this entry goes before nextFile
176 nextFile = (TFile*) fFileList->After(nextFile) ;
177 if ( nextFile == 0 ) break ;
178 if (ntData) delete ntData;
179 ntData = (TNtuple*) ( nextFile->Get("NTtracks") ) ;
180 entries = ntData->GetEntriesFast() ;
181 Int_t columns = ntData->GetNvar() ;
184 cout << "Error in reading Ntuple file: no. columns != 15" << endl ;
188 cout << "Start New File " << fileCounter << endl ;
191 return false ; // Failure: Error or EOF
194 //______________________________________________________________________________
195 Bool_t AliStarEventReader::MakeFileList ( const char* input )
197 //get the files to process
198 TString inputstring(input);
199 inputstring = inputstring.Strip(TString::kBoth);
200 TSystemFile inputfile(inputstring.Data(),"");
201 if (inputfile.IsDirectory())
202 return MakeFileListFromDir(inputstring.Data());
204 return MakeFileListFromFile(inputstring.Data());
207 //______________________________________________________________________________
208 Bool_t AliStarEventReader::MakeFileListFromDir ( const char* inputFileDirectory )
210 //get the files to process
212 static Int_t doOnce = 0 ;
213 fFileList = new TList() ;
214 void* directory = gSystem->OpenDirectory(inputFileDirectory) ;
215 const char* entry = gSystem->GetDirEntry(directory) ;
219 cout << endl << "Error: \"" << inputFileDirectory << "\" does not exist" << endl << endl ;
226 int len = strlen(entry);
227 if( len >= 5 && strcmp( &entry[len - 5], ".root" ) == 0 )
230 fileName = inputFileDirectory ;
231 if( !fileName.EndsWith("/") ) fileName += "/" ;
233 fFileList->Add ( TFile::Open(fileName) ) ;
236 cout << "Add: " << fileName << endl ;
241 entry = gSystem->GetDirEntry(directory) ;
244 cout << "Add: " << Count-1 << " more file(s) from this directory for a total of " << Count << " files." << endl ;
245 cout << "Finished creating file list ... preparing to open first file." << endl << endl ;
249 //______________________________________________________________________________
250 Bool_t AliStarEventReader::MakeFileListFromFile ( const char* inputFile )
252 //get the files to process, from a text file, one file per line
253 if (!fFileList) fFileList=new TList();
255 filein.open(inputFile);
258 printf("problem reading the file list \"%s\"\n",inputFile);
262 while (filein.good())
264 printf("opening file: ");
265 line.ReadLine(filein);
266 if (line.Length() == 0) continue;
267 TFile* file = TFile::Open(line.Data());
270 printf("problem opening file \"%s\"\n",line.Data());
273 fFileList->Add(file);
274 printf("%s\n",line.Data());
276 if (fFileList->GetEntries()>0) return kTRUE;