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.2 2001/10/04 15:58:52 jchudoba
19 Option to open the stream in READ or UPDATE mode
21 Revision 1.1 2001/09/19 06:20:50 jchudoba
22 Class to manage input filenames, used by AliRunDigitizer
26 ////////////////////////////////////////////////////////////////////////
30 // - store file names associated with a given stream
31 // - open and close files
32 // - return serial event number of the next event in the stream
33 // and the TFile pointer for a proper file
35 ////////////////////////////////////////////////////////////////////////
41 #include "AliStream.h"
47 AliStream::AliStream()
50 fLastEventSerialNr = -1;
52 fCurrentFileIndex = -1;
55 fFileNames = new TObjArray(1);
59 ////////////////////////////////////////////////////////////////////////
60 AliStream::AliStream(Option_t *option)
63 fLastEventSerialNr = -1;
65 fCurrentFileIndex = -1;
68 fFileNames = new TObjArray(1);
72 ////////////////////////////////////////////////////////////////////////
73 AliStream::~AliStream()
76 if (fFileNames) delete fFileNames;
79 ////////////////////////////////////////////////////////////////////////
80 void AliStream::AddFile(char *fileName)
82 // stores the name of the file
83 TObjString *name = new TObjString(fileName);
84 fFileNames->Add(name);
87 ////////////////////////////////////////////////////////////////////////
88 Bool_t AliStream::NextEventInStream(Int_t &serialNr)
90 // returns kFALSE if no more events
91 // returns kTRUE and the serial nr of the next event
92 // fCurrentFile points to the file containing offered event
95 if (fFileNames->GetLast() < 0) return kFALSE;
98 if (!OpenNextFile()) return kFALSE;
101 if (fLastEventSerialNr+1 >= fEvents) {
102 if (!OpenNextFile()) return kFALSE;
104 serialNr = ++fLastEventSerialNr;
108 ////////////////////////////////////////////////////////////////////////
109 void AliStream::ChangeMode(Option_t* option)
110 // set the mode to READ or UPDATE, reopen file with the new mode
111 // only change from UPDATE to READ have sense in the current scheme,
112 // other changes are possible but not usefull
116 fCurrentFile->Close();
122 ////////////////////////////////////////////////////////////////////////
123 Bool_t AliStream::OpenNextFile()
125 if (++fCurrentFileIndex > fFileNames->GetLast()) {
126 cerr<<"No more files in the stream"<<endl;
131 if (fCurrentFile->IsOpen()) {
132 fCurrentFile->Close();
136 const char * filename =
137 static_cast<TObjString*>(fFileNames->At(fCurrentFileIndex))->GetName();
138 fCurrentFile = TFile::Open(filename,fMode.Data());
140 // cannot open file specified on input. Do not skip it silently.
141 cerr<<"Cannot open file "<<filename<<endl;
144 // find nr of events in the given file
145 TTree * te = (TTree *) fCurrentFile->Get("TE") ;
147 Error("OpenNextFile", "input file does not contain TE");
150 fEvents = static_cast<Int_t>(te->GetEntries());
151 fLastEventSerialNr = -1;
155 ////////////////////////////////////////////////////////////////////////
156 Bool_t AliStream::ImportgAlice()
158 if (fFileNames->GetLast() < 0) return kFALSE;
160 if (!OpenNextFile()) return kFALSE;
162 gAlice = (AliRun*)fCurrentFile->Get("gAlice");
163 if (!gAlice) return kFALSE;