ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
listEventiterator.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file listEventiterator.cc
1 //
2 // listEventIterator mlp 4/19/1997
3 //
4 // this iterator reads events froma data file.
5 
6 
7 #include "listEventiterator.h"
8 #include <stddef.h>
9 #include <string.h>
10 
11 // there are two similar constructors, one with just the
12 // filename, the other with an additional status value
13 // which is non-zero on return if anything goes wrong.
14 
15 
17 {
18  if (it) delete it;
19  if (liststream) delete liststream;
20  if ( listfilename ) delete [] listfilename;
21 }
22 
23 
25 {
26  listfilename = new char[strlen(filename)+1];
27  strcpy (listfilename, filename);
28 
29  liststream = new std::ifstream(filename);
30  finished = 0;
31  defunct = 0;
32 #ifdef OSF1
33  if (liststream)
34 #else
35  if (!liststream->is_open() )
36 #endif
37  {
38  defunct = 1;
39  finished = 1;
40  }
41  it = 0;
42  strcpy(thefilename, " ");
43 }
44 
45 
47 {
48  listfilename = new char[strlen(filename)+1];
49  strcpy (listfilename, filename);
50 
51  liststream = new std::ifstream(filename);
52  finished = 0;
53  defunct = 0;
54  status = 0;
55 #ifdef OSF1
56  if (liststream)
57 #else
58  if (!liststream->is_open() )
59 #endif
60  {
61  status = 1;
62  defunct = 1;
63  finished = 1;
64  }
65  it = 0;
66  strcpy(thefilename, " ");
67 }
68 
69 
70 
72 {
73  os << "listEventiterator from list " << listfilename << ", current from " << thefilename << std::endl;
74 
75 };
76 
77 
79 {
80  static char namestr[512];
81 
82  strcpy (namestr, thefilename);
83  return namestr;
84 
85 };
86 
87 
88 const char * listEventiterator::getIdTag () const
89 {
90  // sprintf (idline, " -- listEventiterator reading from %s", thefilename);
91  return "listEventiterator";
92 };
93 
94 
95 
96 // and, finally, the only non-constructor member function to
97 // retrieve events from the iterator.
98 
100 {
101 
102  Eventiterator *fit;
103  int status = 0;
104 
105  if (finished) return 0;
106 
107  if (it) return it; //protect against overwriting our own.
108 
109  while ( liststream->getline(thefilename,FEMAXFILENAMELENGTH) )
110  {
111  fit = new fileEventiterator(thefilename,status);
112  if (! status)
113  {
114  std::cout << "opened file " << thefilename << std::endl;
115  return fit;
116  }
117  }
118  finished = 1;
119  delete liststream;
120  liststream = 0;
121  return 0;
122 }
123 
124 
126 {
127  while ( ! finished) // we still have more file to process
128  {
129  if (it ==0 ) // if we don't have one open...
130  {
131  it = getNextIterator(); // try to open it
132  if (! it) // no more there, done
133  {
134  return 0;
135  }
136  }
137  Event *e = it->getNextEvent(); // get the nexct event
138  if (e) return e; // and if we got it, we're done
139  delete it; // if that prdf was exhausted, try the next one
140  it = 0;
141  }
142  return 0;
143 }