]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliStream.cxx
commented out classes that are not yet available
[u/mrichter/AliRoot.git] / STEER / AliStream.cxx
CommitLineData
77843484 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*
17$Log$
314558d7 18Revision 1.3 2001/10/15 17:31:56 jchudoba
19Bug correction
20
fb0b99cb 21Revision 1.2 2001/10/04 15:58:52 jchudoba
22Option to open the stream in READ or UPDATE mode
23
6873edea 24Revision 1.1 2001/09/19 06:20:50 jchudoba
25Class to manage input filenames, used by AliRunDigitizer
26
77843484 27*/
28
29////////////////////////////////////////////////////////////////////////
30//
31// AliStream.cxx
32//
33// - store file names associated with a given stream
34// - open and close files
35// - return serial event number of the next event in the stream
36// and the TFile pointer for a proper file
37//
38////////////////////////////////////////////////////////////////////////
39
40#include <iostream.h>
41
42#include "TTree.h"
43
44#include "AliStream.h"
45
46#include "AliRun.h"
47
48ClassImp(AliStream)
49
50AliStream::AliStream()
51{
314558d7 52// root requires default ctor, where no new objects can be created
53// do not use this ctor, it is supplied only for root needs
77843484 54 fCurrentFile = 0;
55 fEvents = 0;
314558d7 56 fFileNames = 0;
6873edea 57}
58
59////////////////////////////////////////////////////////////////////////
60AliStream::AliStream(Option_t *option)
61{
62// ctor
63 fLastEventSerialNr = -1;
64 fLastEventNr = 0;
65 fCurrentFileIndex = -1;
66 fCurrentFile = 0;
67 fEvents = 0;
68 fFileNames = new TObjArray(1);
69 fMode = option;
77843484 70}
71
72////////////////////////////////////////////////////////////////////////
73AliStream::~AliStream()
74{
75// default dtor
76 if (fFileNames) delete fFileNames;
77}
78
79////////////////////////////////////////////////////////////////////////
80void AliStream::AddFile(char *fileName)
81{
82// stores the name of the file
83 TObjString *name = new TObjString(fileName);
84 fFileNames->Add(name);
85}
86
87////////////////////////////////////////////////////////////////////////
88Bool_t AliStream::NextEventInStream(Int_t &serialNr)
89{
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
93
94// no files given:
95 if (fFileNames->GetLast() < 0) return kFALSE;
96
97 if (!fCurrentFile) {
98 if (!OpenNextFile()) return kFALSE;
99 }
100
101 if (fLastEventSerialNr+1 >= fEvents) {
102 if (!OpenNextFile()) return kFALSE;
103 }
104 serialNr = ++fLastEventSerialNr;
105 return kTRUE;
106}
107
6873edea 108////////////////////////////////////////////////////////////////////////
109void 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
113{
114 fMode = option;
115 if (fCurrentFile) {
116 fCurrentFile->Close();
117 fCurrentFileIndex--;
118 OpenNextFile();
119 }
120}
121
77843484 122////////////////////////////////////////////////////////////////////////
123Bool_t AliStream::OpenNextFile()
124{
fb0b99cb 125 if (++fCurrentFileIndex > fFileNames->GetLast()) {
126 cerr<<"No more files in the stream"<<endl;
127 return kFALSE;
128 }
129
6873edea 130 if (fCurrentFile) {
131 if (fCurrentFile->IsOpen()) {
132 fCurrentFile->Close();
133 }
134 }
135
77843484 136 const char * filename =
137 static_cast<TObjString*>(fFileNames->At(fCurrentFileIndex))->GetName();
6873edea 138 fCurrentFile = TFile::Open(filename,fMode.Data());
77843484 139 if (!fCurrentFile) {
140// cannot open file specified on input. Do not skip it silently.
141 cerr<<"Cannot open file "<<filename<<endl;
142 return kFALSE;
143 }
144// find nr of events in the given file
145 TTree * te = (TTree *) fCurrentFile->Get("TE") ;
146 if (!te) {
147 Error("OpenNextFile", "input file does not contain TE");
148 return kFALSE;
149 }
150 fEvents = static_cast<Int_t>(te->GetEntries());
151 fLastEventSerialNr = -1;
152 return kTRUE;
153}
154
155////////////////////////////////////////////////////////////////////////
156Bool_t AliStream::ImportgAlice()
157{
158 if (fFileNames->GetLast() < 0) return kFALSE;
159 if (!fCurrentFile) {
160 if (!OpenNextFile()) return kFALSE;
161 }
162 gAlice = (AliRun*)fCurrentFile->Get("gAlice");
163 if (!gAlice) return kFALSE;
164 return kTRUE;
165}