]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliStream.cxx
Class to manage input filenames, used by AliRunDigitizer
[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$
18*/
19
20////////////////////////////////////////////////////////////////////////
21//
22// AliStream.cxx
23//
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
28//
29////////////////////////////////////////////////////////////////////////
30
31#include <iostream.h>
32
33#include "TTree.h"
34
35#include "AliStream.h"
36
37#include "AliRun.h"
38
39ClassImp(AliStream)
40
41AliStream::AliStream()
42{
43// default ctor
44 fLastEventSerialNr = -1;
45 fLastEventNr = 0;
46 fCurrentFileIndex = -1;
47 fCurrentFile = 0;
48 fEvents = 0;
49 fFileNames = new TObjArray(1);
50}
51
52////////////////////////////////////////////////////////////////////////
53AliStream::~AliStream()
54{
55// default dtor
56 if (fFileNames) delete fFileNames;
57}
58
59////////////////////////////////////////////////////////////////////////
60void AliStream::AddFile(char *fileName)
61{
62// stores the name of the file
63 TObjString *name = new TObjString(fileName);
64 fFileNames->Add(name);
65}
66
67////////////////////////////////////////////////////////////////////////
68Bool_t AliStream::NextEventInStream(Int_t &serialNr)
69{
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
73
74// no files given:
75 if (fFileNames->GetLast() < 0) return kFALSE;
76
77 if (!fCurrentFile) {
78 if (!OpenNextFile()) return kFALSE;
79 }
80
81 if (fLastEventSerialNr+1 >= fEvents) {
82 if (!OpenNextFile()) return kFALSE;
83 }
84 serialNr = ++fLastEventSerialNr;
85 return kTRUE;
86}
87
88////////////////////////////////////////////////////////////////////////
89Bool_t AliStream::OpenNextFile()
90{
91 if (++fCurrentFileIndex > fFileNames->GetLast()) {
92 cerr<<"No more files in the stream"<<endl;
93 return kFALSE;
94 }
95
96 const char * filename =
97 static_cast<TObjString*>(fFileNames->At(fCurrentFileIndex))->GetName();
98 fCurrentFile = TFile::Open(filename,"READ");
99 if (!fCurrentFile) {
100// cannot open file specified on input. Do not skip it silently.
101 cerr<<"Cannot open file "<<filename<<endl;
102 return kFALSE;
103 }
104// find nr of events in the given file
105 TTree * te = (TTree *) fCurrentFile->Get("TE") ;
106 if (!te) {
107 Error("OpenNextFile", "input file does not contain TE");
108 return kFALSE;
109 }
110 fEvents = static_cast<Int_t>(te->GetEntries());
111 fLastEventSerialNr = -1;
112 return kTRUE;
113}
114
115////////////////////////////////////////////////////////////////////////
116Bool_t AliStream::ImportgAlice()
117{
118 if (fFileNames->GetLast() < 0) return kFALSE;
119 if (!fCurrentFile) {
120 if (!OpenNextFile()) return kFALSE;
121 }
122 gAlice = (AliRun*)fCurrentFile->Get("gAlice");
123 if (!gAlice) return kFALSE;
124 return kTRUE;
125}