FACT++  1.0
bool DataWriteFits2::Open ( const RUN_HEAD h,
const FAD::RunDescription &  d 
)
virtual

DataWriteFits constructor. This is the one that should be used, not the default one (parameter-less)

Parameters
runidThis parameter should probably be removed. I first thought it was the run number, but apparently it is not
ha pointer to the RUN_HEAD structure that contains the informations relative to this run

Implements DataProcessorImp.

Definition at line 171 of file DataWriteFits2.cc.

References zofits::DefaultMaxNumTiles(), zofits::DefaultNumRowsPerTile(), MessageImp::Error(), fFile, DataProcessorImp::fFileName, DataProcessorImp::FormFileName(), zofits::SetNumTiles(), str, and WriteHeader().

Referenced by GetDrsStep(), and DataCalib::Open().

172 {
173  //Form filename, based on runid and run-type
174  fFileName = FormFileName(dynamic_pointer_cast<factofits>(fFile)?"fits.fz":"fits");
175 
176  if (boost::filesystem::exists(fFileName))
177  {
178  Error("ofits - file '"+fFileName+"' already exists.");
179  return false;
180  }
181 
182  zofits *fits = dynamic_cast<zofits*>(fFile.get());
183  if (fits)
184  {
185  const uint32_t nrpt = zofits::DefaultNumRowsPerTile();
186 
187  // Maximum number of events if taken with 100Hz
188  // (If no limit requested, maxtime is 24*60*60)
189  const uint32_t ntime = d.maxtime*100/nrpt;
190 
191  // Maximum number of events if taken as number
192  // (If no limit requested, maxevts is INT32_MAX)
193  const uint32_t nevts = d.maxevt/nrpt+1;
194 
195  // get the minimum of all three
196  uint32_t num = zofits::DefaultMaxNumTiles();
197  if (ntime<num)
198  num = ntime;
199  if (nevts<num)
200  num = nevts;
201 
202  fits->SetNumTiles(num);
203  }
204 
205  try
206  {
207  fFile->open(fFileName.c_str());
208  }
209  catch (const exception &e)
210  {
211  Error("ofits::open() failed for '"+fFileName+"': "+e.what());
212  return false;
213  }
214 
215  if (!(*fFile))
216  {
217  ostringstream str;
218  str << "ofstream::open() failed for '" << fFileName << "': " << strerror(errno) << " [errno=" << errno << "]";
219  Error(str);
220  return false;
221  }
222 
223  try
224  {
225  WriteHeader(h, d);
226  }
227  catch (const exception &e)
228  {
229  Error("ofits - Writing header failed for '"+fFileName+"': "+e.what());
230  return false;
231  }
232 
233  if (!(*fFile))
234  {
235  ostringstream str;
236  str << "ofstream::write() failed for '" << fFileName << "': " << strerror(errno) << " [errno=" << errno << "]";
237  Error(str);
238  return false;
239  }
240 
241  return true;
242 }
char str[80]
Definition: test_client.c:7
std::shared_ptr< ofits > fFile
static uint32_t DefaultMaxNumTiles(const uint32_t &_n=0)
Definition: zofits.h:94
void WriteHeader(const RUN_HEAD &h, const FAD::RunDescription &d)
std::string fFileName
Definition: fits.h:54
int Error(const std::string &str)
Definition: MessageImp.h:49
void SetNumTiles(uint32_t num)
Definition: zofits.h:635
static uint32_t DefaultNumRowsPerTile(const uint32_t &_n=0)
Definition: zofits.h:95
Definition: zofits.h:28
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:

+ Here is the caller graph for this function: