FACT++  1.0
std::string DrsCalibration::ReadFitsImp ( const std::string &  str,
std::vector< float > &  vec 
)
inline

Definition at line 1390 of file DrsCalib.h.

References fits::GetInt(), fits::GetNextRow(), fits::GetNumRows(), fits::GetStr(), fits::GetUInt(), fits::HasKey(), i, and fits::SetPtrAddress().

Referenced by RawDataViewer::openCalibFile().

1391  {
1392  fits file(str);
1393  if (!file)
1394  {
1395  std::ostringstream msg;
1396  msg << "Could not open file '" << str << "': " << strerror(errno);
1397  return msg.str();
1398  }
1399 
1400  if (file.GetStr("TELESCOP")!="FACT")
1401  {
1402  std::ostringstream msg;
1403  msg << "Reading '" << str << "' failed: Not a valid FACT file (TELESCOP not FACT in header)";
1404  return msg.str();
1405  }
1406 
1407  if (!file.HasKey("STEP"))
1408  {
1409  std::ostringstream msg;
1410  msg << "Reading '" << str << "' failed: Is not a DRS calib file (STEP not found in header)";
1411  return msg.str();
1412  }
1413 
1414  if (file.GetNumRows()!=1)
1415  {
1416  std::ostringstream msg;
1417  msg << "Reading '" << str << "' failed: Number of rows in table is not 1.";
1418  return msg.str();
1419  }
1420 
1421  fStep = file.GetUInt("STEP");
1422  fNumOffset = file.GetInt("NBOFFSET");
1423  fNumGain = file.GetInt("NBGAIN");
1424  fNumTrgOff = file.GetInt("NBTRGOFF");
1425  fRoi = file.GetUInt("NROI");
1426  fNumTm = file.HasKey("NTM") ? file.GetUInt("NTM") : 0;
1427 
1428  if (file.HasKey("DATE-OBS"))
1429  fDateObs = file.GetStr("DATE-OBS");
1430  if (file.HasKey("DATE-END"))
1431  fDateEnd = file.GetStr("DATE-END");
1432 
1433  if (file.HasKey("RUN0-BEG"))
1434  fDateRunBeg[0]= file.GetStr("RUN0-BEG");
1435  if (file.HasKey("RUN1-BEG"))
1436  fDateRunBeg[1]= file.GetStr("RUN1-BEG");
1437  if (file.HasKey("RUN2-BEG"))
1438  fDateRunBeg[2]= file.GetStr("RUN2-BEG");
1439  if (file.HasKey("RUN0-END"))
1440  fDateRunEnd[0]= file.GetStr("RUN0-END");
1441  if (file.HasKey("RUN1-END"))
1442  fDateRunEnd[1]= file.GetStr("RUN1-END");
1443  if (file.HasKey("RUN2-END"))
1444  fDateRunEnd[2]= file.GetStr("RUN2-END");
1445 /*
1446  fDAC[0] = file.GetUInt("DAC_A");
1447  fDAC[1] = file.GetUInt("DAC_B");
1448  fDAC[4] = file.GetUInt("DAC_C");
1449 */
1450  vec.resize(1440*1024*4 + (1440+fNumTm)*fRoi*2 + 4);
1451 
1452  float *base = vec.data();
1453 
1454  reinterpret_cast<uint32_t*>(base)[0] = fRoi;
1455 
1456  file.SetPtrAddress("RunNumberBaseline", base+1, 1);
1457  file.SetPtrAddress("RunNumberGain", base+2, 1);
1458  file.SetPtrAddress("RunNumberTriggerOffset", base+3, 1);
1459  file.SetPtrAddress("BaselineMean", base+4+0*1024*1440, 1024*1440);
1460  file.SetPtrAddress("BaselineRms", base+4+1*1024*1440, 1024*1440);
1461  file.SetPtrAddress("GainMean", base+4+2*1024*1440, 1024*1440);
1462  file.SetPtrAddress("GainRms", base+4+3*1024*1440, 1024*1440);
1463  file.SetPtrAddress("TriggerOffsetMean", base+4+4*1024*1440, fRoi*1440);
1464  file.SetPtrAddress("TriggerOffsetRms", base+4+4*1024*1440+fRoi*1440, fRoi*1440);
1465  if (fNumTm>0)
1466  {
1467  file.SetPtrAddress("TriggerOffsetTMMean", base+4+4*1024*1440+ 2*fRoi*1440, fRoi*fNumTm);
1468  file.SetPtrAddress("TriggerOffsetTMRms", base+4+4*1024*1440+ 2*fRoi*1440+ fRoi*fNumTm, fRoi*fNumTm);
1469  }
1470 
1471  if (!file.GetNextRow())
1472  {
1473  std::ostringstream msg;
1474  msg << "Reading data from " << str << " failed.";
1475  return msg.str();
1476  }
1477 /*
1478  fDAC[2] = fDAC[1];
1479  fDAC[4] = fDAC[1];
1480 
1481  fDAC[5] = fDAC[4];
1482  fDAC[6] = fDAC[4];
1483  fDAC[7] = fDAC[4];
1484 */
1485  fOffset.resize(1024*1440);
1486  fGain.resize(1024*1440);
1487 
1488  fTrgOff.resize(fRoi*(1440+fNumTm));
1489 
1490  // Convert back to ADC counts: 256/125 = 4096/2000
1491  // Convert back to sum (mean * num_entries)
1492  for (int i=0; i<1024*1440; i++)
1493  {
1494  fOffset[i] = fNumOffset *256*base[i+1024*1440*0+4]/125;
1495  fGain[i] = fNumOffset*fNumGain*256*base[i+1024*1440*2+4]/125;
1496  }
1497 
1498  for (int i=0; i<fRoi*1440; i++)
1499  fTrgOff[i] = fNumOffset*fNumTrgOff*256*base[i+1024*1440*4+4]/125;
1500 
1501  for (int i=0; i<fRoi*fNumTm; i++)
1502  fTrgOff[i+1440*fRoi] = fNumOffset*fNumTrgOff*256*base[i+1024*1440*4+2*fRoi*1440+4]/125;
1503 
1504 
1505  // DAC: 0..2.5V == 0..65535
1506  // V-mV: 1000
1507  //fNumGain *= 2500*50000;
1508  //for (int i=0; i<1024*1440; i++)
1509  // fGain[i] *= 65536;
1510  if (fStep==0)
1511  {
1512  for (int i=0; i<1024*1440; i++)
1513  fGain[i] = fNumOffset*4096;
1514  }
1515  else
1516  {
1517  fNumGain *= 1953125;
1518  for (int i=0; i<1024*1440; i++)
1519  fGain[i] *= 1024;
1520  }
1521 
1522  // Now mark the stored DRS data as "officially valid"
1523  // However, this is not thread safe. It only ensures that
1524  // this data is not used before it is completely and correctly
1525  // read.
1526  fStep++;
1527 
1528  return std::string();
1529  }
std::vector< int32_t > fOffset
Definition: DrsCalib.h:1309
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
char str[80]
Definition: test_client.c:7
uint16_t fRoi
Definition: DrsCalib.h:1318
uint16_t fNumTm
Definition: DrsCalib.h:1319
std::vector< int64_t > fGain
Definition: DrsCalib.h:1310
Definition: fits.h:54
std::string fDateRunBeg[3]
Definition: DrsCalib.h:1322
std::string fDateRunEnd[3]
Definition: DrsCalib.h:1323
uint32_t fStep
Definition: DrsCalib.h:1317
std::vector< int64_t > fTrgOff
Definition: DrsCalib.h:1311
std::string fDateObs
Definition: DrsCalib.h:1321
int64_t fNumOffset
Definition: DrsCalib.h:1313

+ Here is the call graph for this function:

+ Here is the caller graph for this function: