FACT++  1.0
bool DataCalib::Close ( const EVT_CTRL2 evt)
virtual

Implements DataProcessorImp.

Definition at line 278 of file DataCalib.cc.

References DataWriteFits2::Close(), end, Error(), fData, i, and str.

279 {
280  if (fNumEntries==0)
281  {
282  ostringstream str;
283  str << "DRS calibration run (run=" << GetRunId() << ", step=" << fData.fStep << ", roi=" << fData.fRoi << ") has 0 events.";
284  Warn(str);
285  }
286 
287  if (fData.fStep==0)
288  {
289  fData.fOffset.assign(fSum.begin(), fSum.end());
291 
292  for (int i=0; i<1024*1440; i++)
293  fData.fGain[i] = 4096*fNumEntries;
294 
295  // Scale ADC data from 12bit to 2000mV
296  GetSampleStats(fStats.data()+4, 2000./4096);
297  reinterpret_cast<uint32_t*>(fStats.data())[1] = GetRunId();;
298  }
299  if (fData.fStep==1)
300  {
301  fData.fGain.assign(fSum.begin(), fSum.end());
303 
304  // DAC: 0..2.5V == 0..65535 2500*50000 625*50000 625*3125
305  // V-mV: 1000 ---------- --------- --------
306  //fNumGain *= 2500*50000; 65536 16384 1024
307  //for (int i=0; i<1024*1440; i++)
308  // fGain[i] *= 65536;
309  fData.fNumGain *= 1953125;
310  for (int i=0; i<1024*1440; i++)
311  fData.fGain[i] *= 1024;
312 
313  // Scale ADC data from 12bit to 2000mV
314  GetSampleStats(fStats.data()+1024*1440*2+4, 2000./4096/fData.fNumOffset);//0.5);
315  reinterpret_cast<uint32_t*>(fStats.data())[2] = GetRunId();;
316  }
317  if (fData.fStep==2)
318  {
319  fData.fTrgOff.assign(fSum.begin(), fSum.end());
321 
322  // Scale ADC data from 12bit to 2000mV
323  GetSampleStats(fStats.data()+1024*1440*4+4, 2000./4096/fData.fNumOffset);//0.5);
324  reinterpret_cast<uint32_t*>(fStats.data())[0] = fNumSamples;
325  reinterpret_cast<uint32_t*>(fStats.data())[3] = GetRunId();
326  }
327 
328  const string beg = GetTstart().Iso();
329  const string end = GetTstop().Iso();
330 
331  if (fData.fStep==0)
332  fData.fDateObs = beg;
333  fData.fDateEnd = end;
334 
335  fData.fDateRunBeg[fData.fStep] = beg;
337 
338  if (fData.fStep<=2)
339  {
340  const string filename = FormFileName("drs.fits");
341  try
342  {
343  fData.WriteFitsImp(filename, fStats, GetNight());
344 
345  ostringstream str;
346  str << "Wrote DRS calibration data (run=" << GetRunId() << ", step=" << fData.fStep << ", roi=" << fData.fRoi << ") to '" << filename << "'";
347  Info(str);
348  }
349  catch (const exception &e)
350  {
351  Error("Exception writing run "+to_string(GetRunId())+" '"+filename+"': "+e.what());
352  }
353  }
354 
355  Update(fDim, fDimRuns);
356 
357  fData.fStep++;
358 
359  fProcessing = false;
360 
361  return DataWriteFits2::Close(evt);
362 }
std::vector< int32_t > fOffset
Definition: DrsCalib.h:1309
static std::vector< float > fStats
Definition: DataCalib.h:15
std::vector< int64_t > fSum
Definition: DrsCalib.h:23
std::string WriteFitsImp(const std::string &filename, const std::vector< float > &vec, uint32_t night=0) const
Definition: DrsCalib.h:1531
int64_t fNumGain
Definition: DrsCalib.h:1314
std::string fDateEnd
Definition: DrsCalib.h:1324
int i
Definition: db_dim_client.c:21
int64_t fNumTrgOff
Definition: DrsCalib.h:1315
std::string Iso() const
Definition: Time.cc:253
std::pair< std::vector< double >, std::vector< double > > GetSampleStats() const
Definition: DrsCalib.h:796
char str[80]
Definition: test_client.c:7
uint32_t GetRunId() const
uint16_t fRoi
Definition: DrsCalib.h:1318
std::vector< int64_t > fGain
Definition: DrsCalib.h:1310
size_t fNumSamples
Definition: DrsCalib.h:20
int Error(const std::string &str)
Definition: MessageImp.h:49
static DrsCalibration fData
Definition: DataCalib.h:13
std::string fDateRunBeg[3]
Definition: DrsCalib.h:1322
std::string fDateRunEnd[3]
Definition: DrsCalib.h:1323
int Warn(const std::string &str)
Definition: MessageImp.h:48
double end
DimDescribedService & fDim
Definition: DataCalib.h:21
uint32_t GetNight() const
Time GetTstop() const
uint32_t fStep
Definition: DrsCalib.h:1317
int Info(const std::string &str)
Definition: MessageImp.h:47
std::vector< int64_t > fTrgOff
Definition: DrsCalib.h:1311
static bool fProcessing
Storage for mean and rms values.
Definition: DataCalib.h:19
std::string fDateObs
Definition: DrsCalib.h:1321
DimDescribedService & fDimRuns
Definition: DataCalib.h:22
bool Close(const EVT_CTRL2 &)
int64_t fNumOffset
Definition: DrsCalib.h:1313
static void Update(DimDescribedService &dim, DimDescribedService &runs)
Definition: DataCalib.cc:56
static std::string FormFileName(const std::string &path, uint64_t night, uint32_t runid, const std::string &extension)
Time GetTstart() const
int64_t fNumEntries
Definition: DrsCalib.h:18

+ Here is the call graph for this function: