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 2001/12/03 07:10:13 jchudoba
19 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
21 Revision 1.3 2001/10/15 17:31:56 jchudoba
24 Revision 1.2 2001/10/04 15:58:52 jchudoba
25 Option to open the stream in READ or UPDATE mode
27 Revision 1.1 2001/09/19 06:20:50 jchudoba
28 Class to manage input filenames, used by AliRunDigitizer
32 ////////////////////////////////////////////////////////////////////////
36 // - store file names associated with a given stream
37 // - open and close files
38 // - return serial event number of the next event in the stream
39 // and the TFile pointer for a proper file
41 ////////////////////////////////////////////////////////////////////////
48 #include "AliStream.h"
54 AliStream::AliStream()
56 // root requires default ctor, where no new objects can be created
57 // do not use this ctor, it is supplied only for root needs
63 ////////////////////////////////////////////////////////////////////////
64 AliStream::AliStream(Option_t *option)
67 fLastEventSerialNr = -1;
69 fCurrentFileIndex = -1;
72 fFileNames = new TObjArray(1);
76 ////////////////////////////////////////////////////////////////////////
77 AliStream::~AliStream()
80 if (fFileNames) delete fFileNames;
83 ////////////////////////////////////////////////////////////////////////
84 void AliStream::AddFile(const char *fileName)
86 // stores the name of the file
87 TObjString *name = new TObjString(fileName);
88 fFileNames->Add(name);
91 ////////////////////////////////////////////////////////////////////////
92 Bool_t AliStream::NextEventInStream(Int_t &serialNr)
94 // returns kFALSE if no more events
95 // returns kTRUE and the serial nr of the next event
96 // fCurrentFile points to the file containing offered event
99 if (fFileNames->GetLast() < 0) return kFALSE;
102 if (!OpenNextFile()) return kFALSE;
105 if (fLastEventSerialNr+1 >= fEvents) {
106 if (!OpenNextFile()) return kFALSE;
108 serialNr = ++fLastEventSerialNr;
112 ////////////////////////////////////////////////////////////////////////
113 void AliStream::ChangeMode(Option_t* option)
114 // set the mode to READ or UPDATE, reopen file with the new mode
115 // only change from UPDATE to READ have sense in the current scheme,
116 // other changes are possible but not usefull
120 fCurrentFile->Close();
126 ////////////////////////////////////////////////////////////////////////
127 Bool_t AliStream::OpenNextFile()
129 if (++fCurrentFileIndex > fFileNames->GetLast()) {
130 cerr<<"No more files in the stream"<<endl;
134 const char * filename =
135 static_cast<TObjString*>(fFileNames->At(fCurrentFileIndex))->GetName();
137 // check if the file was already opened by some other code
138 TFile *f = (TFile *)(gROOT->GetListOfFiles()->FindObject(filename));
142 if (fCurrentFile->IsOpen()) {
143 fCurrentFile->Close();
147 fCurrentFile = TFile::Open(filename,fMode.Data());
149 // cannot open file specified on input. Do not skip it silently.
150 cerr<<"Cannot open file "<<filename<<endl;
153 // find nr of events in the given file
154 TTree * te = (TTree *) fCurrentFile->Get("TE") ;
156 Error("OpenNextFile", "input file does not contain TE");
159 fEvents = static_cast<Int_t>(te->GetEntries());
160 fLastEventSerialNr = -1;
164 ////////////////////////////////////////////////////////////////////////
165 Bool_t AliStream::ImportgAlice()
167 if (fFileNames->GetLast() < 0) return kFALSE;
169 if (!OpenNextFile()) return kFALSE;
171 gAlice = (AliRun*)fCurrentFile->Get("gAlice");
172 if (!gAlice) return kFALSE;