EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fun4AllInputManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Fun4AllInputManager.cc
1 #include "Fun4AllInputManager.h"
2 
3 #include "Fun4AllServer.h"
4 #include "SubsysReco.h"
5 
6 #include <phool/phool.h>
7 
8 #include <boost/filesystem.hpp>
9 
10 #include <cstdint> // for uintmax_t
11 #include <fstream>
12 #include <iostream>
13 
14 using namespace std;
15 
16 Fun4AllInputManager::Fun4AllInputManager(const string &name, const string &nodename, const string &topnodename)
17  : Fun4AllBase(name)
18  , m_MySyncManager(nullptr)
19  , m_IsOpen(0)
20  , m_Repeat(0)
21  , m_MyRunNumber(0)
22  , m_InitRun(0)
23  , m_InputNode(nodename)
24  , m_TopNodeName(topnodename)
25 {
26  return;
27 }
28 
30 {
31  while (m_SubsystemsVector.begin() != m_SubsystemsVector.end())
32  {
33  if (Verbosity())
34  {
35  m_SubsystemsVector.back()->Verbosity(Verbosity());
36  }
37  delete m_SubsystemsVector.back();
38  m_SubsystemsVector.pop_back();
39  }
40 }
41 
43 {
44  if (Verbosity() > 0)
45  {
46  cout << "Adding " << filename << " to list of input files for "
47  << Name() << endl;
48  }
49  m_FileList.push_back(filename);
50  m_FileListCopy.push_back(filename);
51  return 0;
52 }
53 
54 int Fun4AllInputManager::AddListFile(const string &filename, const int do_it)
55 {
56  // checking filesize to see if we have a text file
57  if (boost::filesystem::exists(filename.c_str()))
58  {
59  if (boost::filesystem::is_regular_file(filename.c_str()))
60  {
61  uintmax_t fsize = boost::filesystem::file_size(filename.c_str());
62  if (fsize > 1000000 && !do_it)
63  {
64  cout << "size of " << filename
65  << " is suspiciously large for a text file: "
66  << fsize << " bytes" << endl;
67  cout << "if you really want to use " << filename
68  << " as list file (it will be used as a text file containing a list of input files), use AddListFile(\""
69  << filename << "\",1)" << endl;
70  return -1;
71  }
72  }
73  else
74  {
75  cout << filename << " is not a regular file" << endl;
76  return -1;
77  }
78  }
79  else
80  {
81  cout << PHWHERE << "Could not open " << filename << endl;
82  return -1;
83  }
84  ifstream infile;
85  infile.open(filename.c_str(), ios_base::in);
86  if (!infile)
87  {
88  cout << PHWHERE << "Could not open " << filename << endl;
89  return -1;
90  }
91  string FullLine;
92  getline(infile, FullLine);
93  while (!infile.eof())
94  {
95  if (FullLine.size() && FullLine[0] != '#') // remove comments
96  {
97  AddFile(FullLine);
98  }
99  else if (FullLine.size())
100  {
101  if (Verbosity() > 0)
102  {
103  cout << "Found Comment: " << FullLine << endl;
104  }
105  }
106 
107  getline(infile, FullLine);
108  }
109  infile.close();
110  return 0;
111 }
112 
113 void Fun4AllInputManager::Print(const string &what) const
114 {
115  if (what == "ALL" || what == "FILELIST")
116  {
117  cout << "--------------------------------------" << endl
118  << endl;
119  cout << "List of input files in Fun4AllInputManager " << Name() << ":" << endl;
120 
121  for (string file : m_FileList)
122  {
123  cout << file << endl;
124  }
125  }
126  if (what == "ALL" || what == "SUBSYSTEMS")
127  {
128  // loop over the map and print out the content (name and location in memory)
129  cout << "--------------------------------------" << endl
130  << endl;
131  cout << "List of SubsysRecos in Fun4AllInputManager " << Name() << ":" << endl;
132 
133  for (SubsysReco *subsys : m_SubsystemsVector)
134  {
135  cout << subsys->Name() << endl;
136  }
137  cout << endl;
138  }
139  return;
140 }
141 
143 {
145  int iret = subsystem->Init(se->topNode(m_TopNodeName));
146  if (iret)
147  {
148  cout << PHWHERE << " Error initializing subsystem "
149  << subsystem->Name() << ", return code: " << iret << endl;
150  return iret;
151  }
152  if (Verbosity() > 0)
153  {
154  cout << "Registering Subsystem " << subsystem->Name() << endl;
155  }
156  m_SubsystemsVector.push_back(subsystem);
157  return 0;
158 }
159 
161 {
162  if (!m_SubsystemsVector.empty())
163  {
165  for (SubsysReco *subsys : m_SubsystemsVector)
166  {
167  if (!m_InitRun)
168  {
169  subsys->InitRun(se->topNode(m_TopNodeName));
170  m_InitRun = 1;
171  }
172  if (Verbosity() > 0)
173  {
174  cout << Name() << ": Fun4AllInpuManager::EventReject processing " << subsys->Name() << endl;
175  }
176  if (subsys->process_event(se->topNode(m_TopNodeName)) != Fun4AllReturnCodes::EVENT_OK)
177  {
179  }
180  }
181  }
183 }
184 
186 {
187  if (m_FileListCopy.empty())
188  {
189  cout << Name() << ": ResetFileList can only be used with filelists" << endl;
190  return -1;
191  }
192  m_FileList.clear();
194  return 0;
195 }
196 
198 {
199  if (!m_FileList.empty())
200  {
201  if (m_Repeat)
202  {
203  m_FileList.push_back(*(m_FileList.begin()));
204  if (m_Repeat > 0)
205  {
206  m_Repeat--;
207  }
208  }
209  m_FileList.pop_front();
210  }
211  return;
212 }
213 
215 {
216  while (!m_FileList.empty())
217  {
218  list<string>::const_iterator iter = m_FileList.begin();
219  if (Verbosity())
220  {
221  cout << PHWHERE << " opening next file: " << *iter << endl;
222  }
223  if (fileopen(*iter))
224  {
225  cout << PHWHERE << " could not open file: " << *iter << endl;
226  m_FileList.pop_front();
227  }
228  else
229  {
230  return 0;
231  }
232  }
233  return -1;
234 }