FACT++  1.0
bool EventBuilderWrapper::InitRunNumber ( const string &  path = "")
inlineprotected

Definition at line 119 of file EventBuilderWrapper.h.

References DimWriteStatistics::DoesPathExist(), MessageImp::Error(), DataProcessorImp::FormFileName(), Time::GetAsStr(), Time::GetPrevSunRise(), MessageImp::Info(), MessageImp::Message(), Time::NightAsInt(), DimWriteStatistics::SetCurrentFolder(), str, and MessageImp::Warn().

120  {
121  if (!path.empty())
122  {
124  {
125  fMsg.Error("Data path "+path+" does not exist!");
126  return false;
127  }
128 
129  fPath = path;
131 
132  fMsg.Info("Data path set to "+path+".");
133  }
134 
135  // Get current night
136  const Time now;
137 
138  const uint32_t night = now.NightAsInt();
139  if (night==fNightAsInt)
140  return true;
141 
142  const string crosscheck = now.GetPrevSunRise().GetAsStr("%Y%m%d");
143  if (crosscheck!=to_string(night))
144  {
145  fMsg.Warn("The crosscheck for the night failed. "+crosscheck+" is not equal to "+to_string(night)+"... keeping old one.");
146  fMsg.Warn("This is a severe error. Please restart fadctrl.");
147  return true;
148  }
149 
150  // In some circumstances, I do not understand yet (but I guess it can happen
151  // when the shared objects are re-compiled while the program is not
152  // re-started), it can happen that the returned value is wrong by one day.
153  // So this is just another check to avoid problems.
154  const uint32_t night_test = Time(now-boost::posix_time::seconds(1)).NightAsInt();
155  if (night_test != night)
156  return true;
157 
158  // And another check. Let's read the clock again.
159  // In both cases a false condition is no error and can happen. But if it happens,
160  // the bahaviour will change a fraction of a second later and the conditon
161  // will be true. No run should be taken just around that moment and if one
162  // is taken, then the date doesn't matter.
163  if (Time().NightAsInt() != night)
164  return true;
165 
166  if (night<fNightAsInt)
167  {
168  fMsg.Warn("New night "+to_string(night)+" ["+now.GetAsStr()+"] before current night "+to_string(night)+"... keeping old one.");
169  fMsg.Warn("Please check the system clock.");
170  return true;
171  }
172 
173  // Check for run numbers
174  fRunNumber = 1000;
175 
176  while (--fRunNumber>0)
177  {
178  const string name = DataProcessorImp::FormFileName(fPath, night, fRunNumber, "");
179 
180  if (access((name+"bin").c_str(), F_OK) == 0)
181  break;
182  if (access((name+"fits").c_str(), F_OK) == 0)
183  break;
184  if (access((name+"fits.fz").c_str(), F_OK) == 0)
185  break;
186  if (access((name+"fits.gz").c_str(), F_OK) == 0)
187  break;
188  if (access((name+"drs.fits").c_str(), F_OK) == 0)
189  break;
190  }
191 
192  // This is now the first file which does not exist
193  fRunNumber++;
194  fLastOpened = 0;
195 
196  // Check if we have exceeded the maximum
197  if (fRunNumber==1000)
198  {
199  fMsg.Error("You have a file with run-number 1000 in "+fPath+" ["+to_string(night)+"]");
200  return false;
201  }
202 
203  ostringstream str;
204  if (fNightAsInt==0)
205  str << "First night...";
206  else
207  str << "Night has changed from " << fNightAsInt << " [" << now << "]... ";
208  str << " next run-number is " << night << "-" << setfill('0') << setw(3) << fRunNumber << " [" << (fPath.empty()?".":fPath) << "]";
209  fMsg.Message(str);
210 
211  fNightAsInt = night;
212 
213  return true;
214  }
Time GetPrevSunRise(double horizon) const
Definition: Time.cc:313
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
char str[80]
Definition: test_client.c:7
uint32_t NightAsInt() const
Definition: Time.cc:397
static bool DoesPathExist(std::string path, MessageImp &log)
int Error(const std::string &str)
Definition: MessageImp.h:49
int Warn(const std::string &str)
Definition: MessageImp.h:48
DimWriteStatistics fDimWriteStats
bool SetCurrentFolder(const std::string &folder)
Configures that current folder where files are written to.
int Info(const std::string &str)
Definition: MessageImp.h:47
int Message(const std::string &str)
Definition: MessageImp.h:46
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
Definition: Time.cc:240
static std::string FormFileName(const std::string &path, uint64_t night, uint32_t runid, const std::string &extension)

+ Here is the call graph for this function: