SLIC  6.1.1
Simulation for the Linear Collider (SLIC) - Geant4 simulation application
EventSourceWithInputFile.cc
Go to the documentation of this file.
1 // $Header: /nfs/slac/g/lcd/cvs/lcdroot/slic/src/EventSourceWithInputFile.cc,v 1.10 2012-11-27 19:32:19 jeremy Exp $
3 
4 // SLIC
5 #include "EventSourceManager.hh"
6 
7 namespace slic {
8 void EventSourceWithInputFile::setFilename(const std::string& s) {
9  if (s != std::string("")) {
10 
11  if (FileUtil::fileExists(s)) {
12  m_filename = s;
13 
14  m_fileIsSet = true;
15  m_fileIsNew = true;
16  }
17 #ifdef SLIC_LOG
18  else {
19  log() << LOG::error << "Ignoring nonexistant input file <" << s << ">." << LOG::done;
20  }
21 #endif
22  }
23 #ifdef SLIC_LOG
24  else {
25  log() << LOG::error << "Ignoring blank filename." << LOG::done;
26  }
27 #endif
28 }
29 
31  return m_filename;
32 }
33 
35  // close if open
36  if (m_fileIsOpen) {
37  close();
38  }
39 
40  // (re)open
41  open();
42 
43  // should not be EOF now (maybe on next read)
44  m_eof = false;
45 }
46 
47 unsigned int EventSourceWithInputFile::skipEvents(unsigned int nevents) {
48  unsigned int i;
49  for (i = 0; i < nevents; i++) {
50 
51  if (isEOF()) {
52  break;
53  }
54 
55  readNextEvent();
56  }
57  return i;
58 }
59 
61  return m_eof;
62 }
63 
65  readNextEvent();
66 }
67 
69  // attempt to setup filename from mgr if got a new filename
70  if (EventSourceManager::instance()->isNewFilename()) {
72  }
73 
74  // check if filename is setup correctly
75  if (!m_fileIsSet) {
76  G4Exception("", "", FatalException, "Generator filename was not set.");
77  }
78 
79  // reset if new file
80  if (m_fileIsNew) {
81 
82  // close and open (possibly with new file)
83  reset();
84 
85  /* Set state variables. */
86  m_fileIsNew = false;
87  m_fileIsOpen = true;
88  }
89 
90  // get num events to skip from mgr
91  int nskip = EventSourceManager::instance()->getSkipEvents();
92 
93  if (nskip) {
94 
95 #ifdef SLIC_LOG
96  log() << LOG::okay << "Skipping <" << nskip << "> events ..." << LOG::done;
97 #endif
98 
99  // skip events according to current mgr val
100  int actualskipped = skipEvents(nskip);
101 
102 #ifdef SLIC_LOG
103  log() << LOG::okay << "Skipped <" << actualskipped << "> events." << LOG::done;
104 
105  if (actualskipped < nskip) {
106  log() << LOG::warning << "Ran out of records to skip on event file!" << LOG::done;
107  }
108 #endif
109 
110  // reset skip events
111  EventSourceManager::instance()->setSkipEvents(0);
112  }
113 }
114 }
static EventSourceManager * instance()
void setFilename(const std::string &filename)
void beginEvent(const G4Event *event)
virtual void readNextEvent()=0
unsigned int skipEvents(unsigned int nevents)
static bool fileExists(const char *filename)
Definition: FileUtil.cc:22
LogStream & log()
Definition: Module.hh:99
@ okay
Definition: LogStream.hh:33
@ warning
Definition: LogStream.hh:33
@ error
Definition: LogStream.hh:33
@ done
Definition: LogStream.hh:26