]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Class to manage input filenames, used by AliRunDigitizer
authorjchudoba <jchudoba@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 19 Sep 2001 06:20:50 +0000 (06:20 +0000)
committerjchudoba <jchudoba@f7af4fe6-9843-0410-8265-dc069ae4e863>
Wed, 19 Sep 2001 06:20:50 +0000 (06:20 +0000)
STEER/AliStream.cxx [new file with mode: 0644]
STEER/AliStream.h [new file with mode: 0644]

diff --git a/STEER/AliStream.cxx b/STEER/AliStream.cxx
new file mode 100644 (file)
index 0000000..ede7c78
--- /dev/null
@@ -0,0 +1,125 @@
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/*
+$Log$
+*/
+
+////////////////////////////////////////////////////////////////////////
+//
+// AliStream.cxx
+//
+// - store file names associated with a given stream
+// - open and close files
+// - return serial event number of the next event in the stream
+// and the TFile pointer for a proper file
+//
+////////////////////////////////////////////////////////////////////////
+
+#include <iostream.h>
+
+#include "TTree.h"
+
+#include "AliStream.h"
+
+#include "AliRun.h"
+
+ClassImp(AliStream)
+
+AliStream::AliStream()
+{
+// default ctor
+  fLastEventSerialNr = -1;
+  fLastEventNr = 0;
+  fCurrentFileIndex = -1;
+  fCurrentFile = 0;
+  fEvents = 0;
+  fFileNames = new TObjArray(1);
+}
+
+////////////////////////////////////////////////////////////////////////
+AliStream::~AliStream()
+{
+// default dtor
+  if (fFileNames) delete fFileNames;
+}
+
+////////////////////////////////////////////////////////////////////////
+void AliStream::AddFile(char *fileName)
+{
+// stores the name of the file
+  TObjString *name = new TObjString(fileName);
+  fFileNames->Add(name);
+}
+
+////////////////////////////////////////////////////////////////////////
+Bool_t AliStream::NextEventInStream(Int_t &serialNr)
+{
+// returns kFALSE if no more events
+// returns kTRUE and the serial nr of the next event
+// fCurrentFile points to the file containing offered event
+
+// no files given:
+  if (fFileNames->GetLast() < 0) return kFALSE;
+
+  if (!fCurrentFile) {
+    if (!OpenNextFile()) return kFALSE;
+  }
+  
+  if (fLastEventSerialNr+1 >= fEvents) {
+    if (!OpenNextFile()) return kFALSE;
+  }
+  serialNr = ++fLastEventSerialNr;
+  return kTRUE;
+}
+
+////////////////////////////////////////////////////////////////////////
+Bool_t AliStream::OpenNextFile()
+{
+  if (++fCurrentFileIndex > fFileNames->GetLast()) {
+    cerr<<"No more files in the stream"<<endl;
+    return kFALSE;
+  }
+
+  const char * filename = 
+    static_cast<TObjString*>(fFileNames->At(fCurrentFileIndex))->GetName();
+  fCurrentFile = TFile::Open(filename,"READ");
+  if (!fCurrentFile) {
+// cannot open file specified on input. Do not skip it silently.
+    cerr<<"Cannot open file "<<filename<<endl;
+    return kFALSE;
+  }
+// find nr of events in the given file  
+  TTree * te = (TTree *) fCurrentFile->Get("TE") ;
+  if (!te) {
+    Error("OpenNextFile", "input file does not contain TE");
+    return kFALSE;
+  }
+  fEvents = static_cast<Int_t>(te->GetEntries());
+  fLastEventSerialNr = -1;
+  return kTRUE;
+}
+
+////////////////////////////////////////////////////////////////////////
+Bool_t AliStream::ImportgAlice()
+{
+  if (fFileNames->GetLast() < 0) return kFALSE;
+  if (!fCurrentFile) {
+    if (!OpenNextFile()) return kFALSE;
+  }
+  gAlice = (AliRun*)fCurrentFile->Get("gAlice");
+  if (!gAlice)  return kFALSE;
+  return kTRUE;
+}
diff --git a/STEER/AliStream.h b/STEER/AliStream.h
new file mode 100644 (file)
index 0000000..684486f
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef ALISTREAM_H
+#define ALISTREAM_H
+/* Copyright(c) 1998-2000, ALICE Experiment at CERN, All rights reserved. *
+ * See cxx source for full Copyright notice                               */
+
+/* $Id$ */
+
+////////////////////////////////////////////////////////////////////////
+//
+//  Class to handle files on IO
+//                  
+//  Author: Jiri Chudoba (CERN), 2001
+//
+////////////////////////////////////////////////////////////////////////
+
+// --- ROOT system ---
+#include "TNamed.h"
+#include "TObjString.h"
+#include "TArrayI.h"
+#include "TClonesArray.h"
+#include "TFile.h"
+
+// --- AliRoot header files ---
+
+class AliStream: public TNamed {
+
+public:
+  AliStream();
+  virtual ~AliStream();
+  void AddFile(char *fileName);
+  Bool_t NextEventInStream(Int_t &eventNr);
+  Bool_t OpenNextFile();
+  Bool_t ImportgAlice();
+  TFile* CurrentFile() { return fCurrentFile;}
+  
+private:  
+  Int_t fLastEventSerialNr;
+  Int_t fLastEventNr;
+  Int_t fCurrentFileIndex;
+  Int_t fEvents;                //! nr. of events in the current file
+  TFile *fCurrentFile;
+  TObjArray * fFileNames;
+  
+  ClassDef(AliStream,1)
+};
+
+#endif // ALISTREAM_H