Analysis Software
Documentation for sPHENIX simulation 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 
15  : Fun4AllBase(name)
16  , m_InputNode(nodename)
17  , m_TopNodeName(topnodename)
18 {
19  return;
20 }
21 
23 {
24  while (m_SubsystemsVector.begin() != m_SubsystemsVector.end())
25  {
26  if (Verbosity())
27  {
28  m_SubsystemsVector.back()->Verbosity(Verbosity());
29  }
30  delete m_SubsystemsVector.back();
31  m_SubsystemsVector.pop_back();
32  }
33 }
34 
36 {
37  if (Verbosity() > 0)
38  {
39  std::cout << "Adding " << filename << " to list of input files for "
40  << Name() << std::endl;
41  }
42  m_FileList.push_back(filename);
43  m_FileListCopy.push_back(filename);
44  return 0;
45 }
46 
48 {
49  // checking filesize to see if we have a text file
50  if (boost::filesystem::exists(filename.c_str()))
51  {
52  if (boost::filesystem::is_regular_file(filename.c_str()))
53  {
54  uintmax_t fsize = boost::filesystem::file_size(filename.c_str());
55  if (fsize > 1000000 && !do_it)
56  {
57  std::cout << "size of " << filename
58  << " is suspiciously large for a text file: "
59  << fsize << " bytes" << std::endl;
60  std::cout << "if you really want to use " << filename
61  << " as list file (it will be used as a text file containing a list of input files), use AddListFile(\""
62  << filename << "\",1)" << std::endl;
63  return -1;
64  }
65  }
66  else
67  {
68  std::cout << filename << " is not a regular file" << std::endl;
69  return -1;
70  }
71  }
72  else
73  {
74  std::cout << PHWHERE << "Could not open " << filename << std::endl;
75  return -1;
76  }
77  std::ifstream infile;
78  infile.open(filename, std::ios_base::in);
79  if (!infile)
80  {
81  std::cout << PHWHERE << "Could not open " << filename << std::endl;
82  return -1;
83  }
84  std::string FullLine;
85  int nfiles = 0;
86  getline(infile, FullLine);
87  while (!infile.eof())
88  {
89  if (FullLine.size() && FullLine[0] != '#') // remove comments
90  {
91  AddFile(FullLine);
92  nfiles++;
93  }
94  else if (FullLine.size())
95  {
96  if (Verbosity() > 0)
97  {
98  std::cout << "Found Comment: " << FullLine << std::endl;
99  }
100  }
101  getline(infile, FullLine);
102  }
103  infile.close();
104  if (nfiles == 0)
105  {
106  std::cout << Name() << " listfile " << filename << " does not contain filenames "
107  << "if this is the only list you load into this Input Manager your code will exit very soon" << std::endl;
108  }
109  return 0;
110 }
111 
113 {
114  if (what == "ALL" || what == "FILELIST")
115  {
116  std::cout << "--------------------------------------" << std::endl
117  << std::endl;
118  std::cout << "List of input files in Fun4AllInputManager " << Name() << ":" << std::endl;
119 
120  for (const std::string &file : m_FileList)
121  {
122  std::cout << file << std::endl;
123  }
124  }
125  if (what == "ALL" || what == "SUBSYSTEMS")
126  {
127  // loop over the map and print out the content (name and location in memory)
128  std::cout << "--------------------------------------" << std::endl
129  << std::endl;
130  std::cout << "List of SubsysRecos in Fun4AllInputManager " << Name() << ":" << std::endl;
131 
132  for (SubsysReco *subsys : m_SubsystemsVector)
133  {
134  std::cout << subsys->Name() << std::endl;
135  }
136  std::cout << std::endl;
137  }
138  return;
139 }
140 
142 {
144  int iret = subsystem->Init(se->topNode(m_TopNodeName));
145  if (iret)
146  {
147  std::cout << PHWHERE << " Error initializing subsystem "
148  << subsystem->Name() << ", return code: " << iret << std::endl;
149  return iret;
150  }
151  if (Verbosity() > 0)
152  {
153  std::cout << "Registering Subsystem " << subsystem->Name() << std::endl;
154  }
155  m_SubsystemsVector.push_back(subsystem);
156  return 0;
157 }
158 
160 {
161  if (!m_SubsystemsVector.empty())
162  {
164  for (SubsysReco *subsys : m_SubsystemsVector)
165  {
166  if (!m_InitRun)
167  {
168  subsys->InitRun(se->topNode(m_TopNodeName));
169  m_InitRun = 1;
170  }
171  if (Verbosity() > 0)
172  {
173  std::cout << Name() << ": Fun4AllInpuManager::EventReject processing " << subsys->Name() << std::endl;
174  }
175  if (subsys->process_event(se->topNode(m_TopNodeName)) != Fun4AllReturnCodes::EVENT_OK)
176  {
178  }
179  }
180  }
182 }
183 
185 {
186  if (m_FileListCopy.empty())
187  {
188  std::cout << Name() << ": ResetFileList can only be used with filelists" << std::endl;
189  return -1;
190  }
191  m_FileList.clear();
193  return 0;
194 }
195 
197 {
198  if (!m_FileList.empty())
199  {
200  if (m_Repeat)
201  {
202  m_FileList.push_back(*(m_FileList.begin()));
203  if (m_Repeat > 0)
204  {
205  m_Repeat--;
206  }
207  }
208  m_FileList.pop_front();
209  }
210  return;
211 }
212 
214 {
215  while (!m_FileList.empty())
216  {
217  std::list<std::string>::const_iterator iter = m_FileList.begin();
218  if (Verbosity())
219  {
220  std::cout << PHWHERE << " opening next file: " << *iter << std::endl;
221  }
222  if (fileopen(*iter))
223  {
224  std::cout << PHWHERE << " could not open file: " << *iter << std::endl;
225  m_FileList.pop_front();
226  }
227  else
228  {
229  return 0;
230  }
231  }
232  return -1;
233 }