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 Revision 1.5 2002/04/09 13:38:47 jchudoba
19 Add const to the filename argument
21 Revision 1.4 2001/12/03 07:10:13 jchudoba
22 Default ctor cannot create new objects, create dummy default ctor which leaves object in not well defined state - to be used only by root for I/O
24 Revision 1.3 2001/10/15 17:31:56 jchudoba
27 Revision 1.2 2001/10/04 15:58:52 jchudoba
28 Option to open the stream in READ or UPDATE mode
30 Revision 1.1 2001/09/19 06:20:50 jchudoba
31 Class to manage input filenames, used by AliRunDigitizer
35 ////////////////////////////////////////////////////////////////////////
39 // - store file names associated with a given stream
40 // - open and close files
41 // - return serial event number of the next event in the stream
42 // and the TFile pointer for a proper file
44 ////////////////////////////////////////////////////////////////////////
51 #include "AliStream.h"
57 AliStream::AliStream()
59 // root requires default ctor, where no new objects can be created
60 // do not use this ctor, it is supplied only for root needs
66 ////////////////////////////////////////////////////////////////////////
67 AliStream::AliStream(Option_t *option)
70 fLastEventSerialNr = -1;
72 fCurrentFileIndex = -1;
75 fFileNames = new TObjArray(1);
79 ////////////////////////////////////////////////////////////////////////
80 AliStream::~AliStream()
89 ////////////////////////////////////////////////////////////////////////
90 void AliStream::AddFile(const char *fileName)
92 // stores the name of the file
93 TObjString *name = new TObjString(fileName);
94 fFileNames->Add(name);
97 ////////////////////////////////////////////////////////////////////////
98 Bool_t AliStream::NextEventInStream(Int_t &serialNr)
100 // returns kFALSE if no more events
101 // returns kTRUE and the serial nr of the next event
102 // fCurrentFile points to the file containing offered event
105 if (fFileNames->GetLast() < 0) return kFALSE;
108 if (!OpenNextFile()) return kFALSE;
111 if (fLastEventSerialNr+1 >= fEvents) {
112 if (!OpenNextFile()) return kFALSE;
114 serialNr = ++fLastEventSerialNr;
118 ////////////////////////////////////////////////////////////////////////
119 void AliStream::ChangeMode(Option_t* option)
120 // set the mode to READ or UPDATE, reopen file with the new mode
121 // only change from UPDATE to READ have sense in the current scheme,
122 // other changes are possible but not usefull
126 fCurrentFile->Close();
132 ////////////////////////////////////////////////////////////////////////
133 Bool_t AliStream::OpenNextFile()
135 if (++fCurrentFileIndex > fFileNames->GetLast()) {
136 cerr<<"No more files in the stream"<<endl;
140 const char * filename =
141 static_cast<TObjString*>(fFileNames->At(fCurrentFileIndex))->GetName();
143 // check if the file was already opened by some other code
144 TFile *f = (TFile *)(gROOT->GetListOfFiles()->FindObject(filename));
148 if (fCurrentFile->IsOpen()) {
149 fCurrentFile->Close();
153 fCurrentFile = TFile::Open(filename,fMode.Data());
155 // cannot open file specified on input. Do not skip it silently.
156 cerr<<"Cannot open file "<<filename<<endl;
159 // find nr of events in the given file
160 TTree * te = (TTree *) fCurrentFile->Get("TE") ;
162 Error("OpenNextFile", "input file does not contain TE");
165 fEvents = static_cast<Int_t>(te->GetEntries());
166 fLastEventSerialNr = -1;
170 ////////////////////////////////////////////////////////////////////////
171 Bool_t AliStream::ImportgAlice()
173 if (fFileNames->GetLast() < 0) return kFALSE;
175 if (!OpenNextFile()) return kFALSE;
177 gAlice = (AliRun*)fCurrentFile->Get("gAlice");
178 if (!gAlice) return kFALSE;
181 ////////////////////////////////////////////////////////////////////////
182 TString AliStream::GetFileName(const Int_t order) const
183 // returns name of the order-th file
184 // returns empty string if such file does not exist
185 // first file in the input stream is 0
187 TString fileName("");
188 if (order > fFileNames->GetLast()) return fileName;
189 TObjString *fileNameStored = dynamic_cast<TObjString*>(fFileNames->At(order));
190 if (fileNameStored) fileName = fileNameStored->GetString();
193 ////////////////////////////////////////////////////////////////////////