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 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////
22 // - store file names associated with a given stream
23 // - open and close files
24 // - return serial event number of the next event in the stream
25 // and the TFile pointer for a proper file
27 ////////////////////////////////////////////////////////////////////////
29 #include <Riostream.h>
32 #include "TObjString.h"
37 #include "AliStream.h"
41 //_______________________________________________________________________
42 AliStream::AliStream():
43 fLastEventSerialNr(0),
52 // root requires default ctor, where no new objects can be created
53 // do not use this ctor, it is supplied only for root needs
57 //_______________________________________________________________________
58 AliStream::AliStream(Option_t *option):
59 fLastEventSerialNr(-1),
61 fCurrentFileIndex(-1),
65 fFileNames(new TObjArray(1))
72 //_______________________________________________________________________
73 AliStream::AliStream(const AliStream& str):
75 fLastEventSerialNr(0),
89 //_______________________________________________________________________
90 void AliStream::Copy(AliStream& ) const
92 Fatal("Copy","Not implemented\n");
95 //_______________________________________________________________________
96 AliStream::~AliStream()
100 fFileNames->Delete();
105 //_______________________________________________________________________
106 void AliStream::AddFile(const char *fileName)
108 // stores the name of the file
109 TObjString *name = new TObjString(fileName);
110 fFileNames->Add(name);
113 //_______________________________________________________________________
114 Bool_t AliStream::NextEventInStream(Int_t &serialNr)
116 // returns kFALSE if no more events
117 // returns kTRUE and the serial nr of the next event
118 // fCurrentFile points to the file containing offered event
121 if (fFileNames->GetLast() < 0) return kFALSE;
124 if (!OpenNextFile()) return kFALSE;
127 if (fLastEventSerialNr+1 >= fEvents) {
128 if (!OpenNextFile()) return kFALSE;
130 serialNr = ++fLastEventSerialNr;
134 //_______________________________________________________________________
135 void AliStream::ChangeMode(Option_t* option)
137 // set the mode to READ or UPDATE, reopen file with the new mode
138 // only change from UPDATE to READ have sense in the current scheme,
139 // other changes are possible but not usefull
142 fCurrentFile->Close();
148 //_______________________________________________________________________
149 Bool_t AliStream::OpenNextFile()
152 // Open the next file in the series
154 if (++fCurrentFileIndex > fFileNames->GetLast()) {
155 cerr<<"No more files in the stream"<<endl;
159 const char * filename =
160 static_cast<TObjString*>(fFileNames->At(fCurrentFileIndex))->GetName();
162 // check if the file was already opened by some other code
163 TFile *f = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->FindObject(filename));
167 if (fCurrentFile->IsOpen()) {
168 fCurrentFile->Close();
172 fCurrentFile = TFile::Open(filename,fMode.Data());
174 // cannot open file specified on input. Do not skip it silently.
175 cerr<<"Cannot open file "<<filename<<endl;
178 // find nr of events in the given file
179 TTree * te = dynamic_cast<TTree *>(fCurrentFile->Get("TE"));
181 Error("OpenNextFile", "input file does not contain TE");
184 fEvents = static_cast<Int_t>(te->GetEntries());
185 fLastEventSerialNr = -1;
189 //_______________________________________________________________________
190 Bool_t AliStream::ImportgAlice()
193 // Import AliRun object pointed from gAlice
195 if (fFileNames->GetLast() < 0) return kFALSE;
197 if (!OpenNextFile()) return kFALSE;
199 gAlice = dynamic_cast<AliRun*>(fCurrentFile->Get("gAlice"));
200 if (!gAlice) return kFALSE;
204 //_______________________________________________________________________
205 TString AliStream::GetFileName(const Int_t order) const
207 // returns name of the order-th file
208 // returns empty string if such file does not exist
209 // first file in the input stream is 0
210 TString fileName("");
211 if (order > fFileNames->GetLast()) return fileName;
212 TObjString *fileNameStored = dynamic_cast<TObjString*>(fFileNames->At(order));
213 if (fileNameStored) fileName = fileNameStored->GetString();