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.4.4.4 2002/12/11 10:00:34 hristov
19 Merging with v3-09-04 (P.Skowronski)
21 Revision 1.4.4.3 2002/11/22 14:19:50 hristov
22 Merging NewIO-01 with v3-09-04 (part one) (P.Skowronski)
24 Revision 1.4.4.2 2002/06/18 10:18:32 hristov
25 Important update (P.Skowronski)
27 Revision 1.4.4.1 2002/05/31 09:37:59 hristov
28 First set of changes done by Piotr
30 Revision 1.5 2002/04/09 13:38:47 jchudoba
31 Add const to the filename argument
33 Revision 1.4 2001/12/03 07:10:13 jchudoba
34 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
36 Revision 1.3 2001/10/15 17:31:56 jchudoba
39 Revision 1.2 2001/10/04 15:58:52 jchudoba
40 Option to open the stream in READ or UPDATE mode
42 Revision 1.1 2001/09/19 06:20:50 jchudoba
43 Class to manage input filenames, used by AliRunDigitizer
47 ////////////////////////////////////////////////////////////////////////
51 // - store file names associated with a given stream
52 // - open and close files
53 // - return serial event number of the next event in the stream
54 // and the TFile pointer for a proper file
56 ////////////////////////////////////////////////////////////////////////
58 #include <Riostream.h>
63 #include "AliStream.h"
66 #include "TObjString.h"
68 #include "TClonesArray.h"
70 #include "AliLoader.h"
74 AliStream::AliStream():
75 fLastEventSerialNr(-1),
77 fCurrentFileIndex(-1),
83 // root requires default ctor, where no new objects can be created
84 // do not use this ctor, it is supplied only for root needs
86 //_______________________________________________________________________
88 AliStream::AliStream(const char* foldername,Option_t *option):
89 fLastEventSerialNr(-1),
91 fCurrentFileIndex(-1),
94 fFileNames(new TObjArray(1)),
95 fEventFolderName(foldername)
99 //_______________________________________________________________________
101 AliStream::~AliStream()
104 delete AliRunLoader::GetRunLoader(fEventFolderName); //clear the eventuall session
105 if (fFileNames) delete fFileNames;
107 //_______________________________________________________________________
109 void AliStream::AddFile(const char *fileName)
111 // stores the name of the file
112 TObjString *name = new TObjString(fileName);
113 fFileNames->Add(name);
115 //_______________________________________________________________________
117 Bool_t AliStream::NextEventInStream()
119 // returns kFALSE if no more events
120 // returns kTRUE and the serial nr of the next event
121 // fCurrentFile points to the file containing offered event
124 if (fFileNames->GetLast() < 0) return kFALSE;
126 AliRunLoader* currentloader = AliRunLoader::GetRunLoader(fEventFolderName);
127 if (currentloader == 0x0)
129 Info("NextEventInStream",
130 "Can not get RL from folder named %s. Attempting to open next file",
131 fEventFolderName.Data());
132 Int_t res = OpenNextFile();
133 if ( res == 0) return kFALSE;
134 currentloader = AliRunLoader::GetRunLoader(fEventFolderName);
137 if (fLastEventSerialNr+1 >= fEvents)
139 if (!OpenNextFile()) return kFALSE;
141 Info("NextEventInStream","Trying to get event ",fLastEventSerialNr+1);
142 currentloader->GetEvent(++fLastEventSerialNr);
145 //_______________________________________________________________________
147 void AliStream::ChangeMode(Option_t* option)
148 // set the mode to READ or UPDATE, reopen file with the new mode
149 // only change from UPDATE to READ have sense in the current scheme,
150 // other changes are possible but not usefull
154 AliRunLoader* currentloader = AliRunLoader::GetRunLoader(fEventFolderName);
156 delete currentloader;
161 //_______________________________________________________________________
163 Bool_t AliStream::OpenNextFile()
165 if (++fCurrentFileIndex > fFileNames->GetLast()) {
166 cerr<<"No more files in the stream"<<endl;
170 const char* filename = static_cast<TObjString*>(fFileNames->At(fCurrentFileIndex))->GetName();
172 // check if the file was already opened by some other code
173 TFile *f = (TFile *)(gROOT->GetListOfFiles()->FindObject(filename));
176 AliRunLoader* currentloader = AliRunLoader::GetRunLoader(fEventFolderName);
180 delete currentloader;
183 currentloader = AliRunLoader::Open(filename,fEventFolderName,fMode);
186 if (currentloader == 0x0)
188 // cannot open file specified on input. Do not skip it silently.
189 cerr<<"Cannot open session "<<filename<<endl;
193 // find nr of events in the given file
195 if ( AliLoader::TestFileOption(fMode) )//tests if file is opened in read or update mode
197 Int_t res = currentloader->LoadHeader();
200 Error("OpenNextFile","Problems with loading header");
203 fEvents = static_cast<Int_t>(currentloader->TreeE()->GetEntries());
207 //if it is new, create or recreate there is no chance to find header in file
211 fLastEventSerialNr = -1;
214 //_______________________________________________________________________
216 Bool_t AliStream::ImportgAlice()
218 if (fFileNames->GetLast() < 0) return kFALSE;
220 AliRunLoader* currentloader = AliRunLoader::GetRunLoader(fEventFolderName);
223 if (!OpenNextFile()) return kFALSE;
224 currentloader = AliRunLoader::GetRunLoader(fEventFolderName);
226 currentloader->LoadgAlice();
227 gAlice = currentloader->GetAliRun();
228 if (!gAlice) return kFALSE;
232 //_______________________________________________________________________
233 TString AliStream::GetFileName(const Int_t order) const
234 // returns name of the order-th file
235 // returns empty string if such file does not exist
236 // first file in the input stream is 0
238 TString fileName("");
239 if (order > fFileNames->GetLast()) return fileName;
240 TObjString *fileNameStored = dynamic_cast<TObjString*>(fFileNames->At(order));
241 if (fileNameStored) fileName = fileNameStored->GetString();