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 **************************************************************************/
20 ////////////////////////////////////////////////////////////////////////
24 // - store file names associated with a given stream
25 // - open and close files
26 // - return serial event number of the next event in the stream
27 // and the TFile pointer for a proper file
29 ////////////////////////////////////////////////////////////////////////
35 #include "AliStream.h"
41 AliStream::AliStream()
44 fLastEventSerialNr = -1;
46 fCurrentFileIndex = -1;
49 fFileNames = new TObjArray(1);
52 ////////////////////////////////////////////////////////////////////////
53 AliStream::~AliStream()
56 if (fFileNames) delete fFileNames;
59 ////////////////////////////////////////////////////////////////////////
60 void AliStream::AddFile(char *fileName)
62 // stores the name of the file
63 TObjString *name = new TObjString(fileName);
64 fFileNames->Add(name);
67 ////////////////////////////////////////////////////////////////////////
68 Bool_t AliStream::NextEventInStream(Int_t &serialNr)
70 // returns kFALSE if no more events
71 // returns kTRUE and the serial nr of the next event
72 // fCurrentFile points to the file containing offered event
75 if (fFileNames->GetLast() < 0) return kFALSE;
78 if (!OpenNextFile()) return kFALSE;
81 if (fLastEventSerialNr+1 >= fEvents) {
82 if (!OpenNextFile()) return kFALSE;
84 serialNr = ++fLastEventSerialNr;
88 ////////////////////////////////////////////////////////////////////////
89 Bool_t AliStream::OpenNextFile()
91 if (++fCurrentFileIndex > fFileNames->GetLast()) {
92 cerr<<"No more files in the stream"<<endl;
96 const char * filename =
97 static_cast<TObjString*>(fFileNames->At(fCurrentFileIndex))->GetName();
98 fCurrentFile = TFile::Open(filename,"READ");
100 // cannot open file specified on input. Do not skip it silently.
101 cerr<<"Cannot open file "<<filename<<endl;
104 // find nr of events in the given file
105 TTree * te = (TTree *) fCurrentFile->Get("TE") ;
107 Error("OpenNextFile", "input file does not contain TE");
110 fEvents = static_cast<Int_t>(te->GetEntries());
111 fLastEventSerialNr = -1;
115 ////////////////////////////////////////////////////////////////////////
116 Bool_t AliStream::ImportgAlice()
118 if (fFileNames->GetLast() < 0) return kFALSE;
120 if (!OpenNextFile()) return kFALSE;
122 gAlice = (AliRun*)fCurrentFile->Get("gAlice");
123 if (!gAlice) return kFALSE;