- Possibility for vertex distribution truncation.
[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$
6873edea 18Revision 1.1 2001/09/19 06:20:50 jchudoba
19Class to manage input filenames, used by AliRunDigitizer
20
77843484 21*/
22
23////////////////////////////////////////////////////////////////////////
24//
25// AliStream.cxx
26//
27// - store file names associated with a given stream
28// - open and close files
29// - return serial event number of the next event in the stream
30// and the TFile pointer for a proper file
31//
32////////////////////////////////////////////////////////////////////////
33
34#include <iostream.h>
35
36#include "TTree.h"
37
38#include "AliStream.h"
39
40#include "AliRun.h"
41
42ClassImp(AliStream)
43
44AliStream::AliStream()
45{
46// default ctor
47 fLastEventSerialNr = -1;
48 fLastEventNr = 0;
49 fCurrentFileIndex = -1;
50 fCurrentFile = 0;
51 fEvents = 0;
52 fFileNames = new TObjArray(1);
6873edea 53 fMode = "READ";
54}
55
56////////////////////////////////////////////////////////////////////////
57AliStream::AliStream(Option_t *option)
58{
59// ctor
60 fLastEventSerialNr = -1;
61 fLastEventNr = 0;
62 fCurrentFileIndex = -1;
63 fCurrentFile = 0;
64 fEvents = 0;
65 fFileNames = new TObjArray(1);
66 fMode = option;
77843484 67}
68
69////////////////////////////////////////////////////////////////////////
70AliStream::~AliStream()
71{
72// default dtor
73 if (fFileNames) delete fFileNames;
74}
75
76////////////////////////////////////////////////////////////////////////
77void AliStream::AddFile(char *fileName)
78{
79// stores the name of the file
80 TObjString *name = new TObjString(fileName);
81 fFileNames->Add(name);
82}
83
84////////////////////////////////////////////////////////////////////////
85Bool_t AliStream::NextEventInStream(Int_t &serialNr)
86{
87// returns kFALSE if no more events
88// returns kTRUE and the serial nr of the next event
89// fCurrentFile points to the file containing offered event
90
91// no files given:
92 if (fFileNames->GetLast() < 0) return kFALSE;
93
94 if (!fCurrentFile) {
95 if (!OpenNextFile()) return kFALSE;
96 }
97
98 if (fLastEventSerialNr+1 >= fEvents) {
99 if (!OpenNextFile()) return kFALSE;
100 }
101 serialNr = ++fLastEventSerialNr;
102 return kTRUE;
103}
104
6873edea 105////////////////////////////////////////////////////////////////////////
106void AliStream::ChangeMode(Option_t* option)
107// set the mode to READ or UPDATE, reopen file with the new mode
108// only change from UPDATE to READ have sense in the current scheme,
109// other changes are possible but not usefull
110{
111 fMode = option;
112 if (fCurrentFile) {
113 fCurrentFile->Close();
114 fCurrentFileIndex--;
115 OpenNextFile();
116 }
117}
118
77843484 119////////////////////////////////////////////////////////////////////////
120Bool_t AliStream::OpenNextFile()
121{
6873edea 122 if (fCurrentFile) {
123 if (fCurrentFile->IsOpen()) {
124 fCurrentFile->Close();
125 }
126 }
127
77843484 128 if (++fCurrentFileIndex > fFileNames->GetLast()) {
129 cerr<<"No more files in the stream"<<endl;
130 return kFALSE;
131 }
132
133 const char * filename =
134 static_cast<TObjString*>(fFileNames->At(fCurrentFileIndex))->GetName();
6873edea 135 fCurrentFile = TFile::Open(filename,fMode.Data());
77843484 136 if (!fCurrentFile) {
137// cannot open file specified on input. Do not skip it silently.
138 cerr<<"Cannot open file "<<filename<<endl;
139 return kFALSE;
140 }
141// find nr of events in the given file
142 TTree * te = (TTree *) fCurrentFile->Get("TE") ;
143 if (!te) {
144 Error("OpenNextFile", "input file does not contain TE");
145 return kFALSE;
146 }
147 fEvents = static_cast<Int_t>(te->GetEntries());
148 fLastEventSerialNr = -1;
149 return kTRUE;
150}
151
152////////////////////////////////////////////////////////////////////////
153Bool_t AliStream::ImportgAlice()
154{
155 if (fFileNames->GetLast() < 0) return kFALSE;
156 if (!fCurrentFile) {
157 if (!OpenNextFile()) return kFALSE;
158 }
159 gAlice = (AliRun*)fCurrentFile->Get("gAlice");
160 if (!gAlice) return kFALSE;
161 return kTRUE;
162}