StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StStreamFile.cxx
1 // $Id: StStreamFile.cxx,v 1.4 2010/01/07 17:37:59 fine Exp $
2 //
3 // $Log: StStreamFile.cxx,v $
4 // Revision 1.4 2010/01/07 17:37:59 fine
5 // introduce closeFileSignal to process several DAT files at once. RT # 1794
6 //
7 // Revision 1.3 2010/01/06 20:42:26 fine
8 // Fix type EventNumber shoould be RunNumber . Thanks Akio
9 //
10 // Revision 1.2 2009/10/13 15:44:59 fine
11 // add the method to provide the error message
12 //
13 // Revision 1.1 2009/10/12 04:21:06 fine
14 // Add abstract STAR iostream-base file interface
15 //
16 //
17 
18 /***************************************************************************
19  * \Author: Valeri Fine (fine@bnl.gov)
20  \date 10-Oct-2009
21  * Description: Trigger Data file (run*.*.dat) reader
22  **************************************************************************/
23 
24 #include "StStreamFile.h"
25 #include <iostream>
26 
27 //__________________________________________________________________________
28 StStreamFile::~StStreamFile() { close(); }
29 //__________________________________________________________________________
30 void StStreamFile::open(const char *fileName, ios_base::openmode mode)
31 {
32  if (fFilename==fileName && is_open() ) {
33  fStream.clear();
34  fStream.seekg (0, ios::beg);
35  } else {
36  close();
37  fFilename=fileName;
38  fStream.clear();
39  fStream.open(fFilename.c_str(),mode);
40  }
41  if (Debug()) Perror("StStreamFile::open");
42 }
43 
44 //__________________________________________________________________________
45 void StStreamFile::close()
46 {
47  if (is_open()) {
48  fStream.clear();
49  fStream.close();
50  fFilename.erase();
51  closeFileSignal();
52  }
53 }
54 //__________________________________________________________________________
55 istream &StStreamFile::read(char *s, streamsize n)
56 {
57  fStream.clear();
58  fStream.read(s,n);
59  if (Debug()) Perror("StStreamFile::read");
60  return fStream;
61 }
62 //__________________________________________________________________________
63 void StStreamFile::Perror(const char *header) const
64 {
65  if (!good()) {
66  if (header && header[0]) std::cerr << header << ": ";
67  std::cerr << " StStreamFile I/O error: "
68  << " fail=" << fail()
69  << "; bad=" << bad()
70  << "; eof=" << eof()
71  << " for <" << fFilename <<"> "
72  << " open=" << ((StStreamFile *)this)->is_open()
73  << std::endl;
74  } else if (Debug()) {
75  if (header && header[0]) std::cerr << header << ": ";
76  std::cerr << "There was no I/O Error"
77  << " for <" << fFilename <<"> "
78  << std::endl;
79  }
80 }