FACT++  1.0
void RawDataViewer::openFile ( std::string &  file)

Definition at line 563 of file RawEventsViewer.cc.

References _softwareOrdering, adcCount, boardTime, builderVersion, camera, izstream::close(), creationDate, daq, eventData, eventNum, eventStep, firstDataTime, fits::Get(), fits::GetColumns(), fits::GetFloat(), fits::GetInt(), fits::GetStr(), fits::HasColumn(), fits::HasKey(), inputFile, fits::IsCompressedFITS(), lastDataTime, nbBad, nBoards, nbOk, nbRej, newFileLoaded(), nightInt, nPixels, nRoi, nRoiTM, nRows, nTM, offSetRoi, pcTime, plusEvent(), rawEventData, revision, rowNum, runNumber, runType, selectedPixel, fits::SetPtrAddress(), signalCurrentPixel(), softTrig, startPix, startTM, timeSystem, triggerType, and waveLetArray.

564 {
565  if (inputFile)
566  {
567  inputFile->close();
568  delete inputFile;
569  }
570  try {
571  inputFile = new factfits(file, "Events");
572  }
573  catch (std::runtime_error e)
574  {
575  cout << "Something went wrong while loading fits. Aborting: " << e.what() << endl;
576  return;
577  }
578  if (!*inputFile)
579  {
580  delete inputFile;
581  inputFile = NULL;
582  return;
583  }
584  vector<string> entriesToCheck;
586  entriesToCheck.push_back("ZNAXIS2");
587  else
588  entriesToCheck.push_back("NAXIS2");
589  entriesToCheck.push_back("NROI");
590  entriesToCheck.push_back("REVISION");
591  entriesToCheck.push_back("RUNID");
592  entriesToCheck.push_back("NBOARD");
593  entriesToCheck.push_back("NPIX");
594  entriesToCheck.push_back("NROITM");
595  entriesToCheck.push_back("TIMESYS");
596  entriesToCheck.push_back("DATE");
597  entriesToCheck.push_back("NIGHT");
598  entriesToCheck.push_back("CAMERA");
599  entriesToCheck.push_back("DAQ");
600  entriesToCheck.push_back("TSTART");
601  entriesToCheck.push_back("TSTOP");
602 
603 
604  for (vector<string>::const_iterator it=entriesToCheck.begin(); it != entriesToCheck.end(); it++)
605  {
606  try {
607  if (!inputFile->HasKey(*it)){
608  cout << "Warning: header keyword " << *it << " missing." << endl;
609  }
610  }
611  catch (std::runtime_error e)
612  {
613  cout << e.what() << endl;
614  return;
615  }
616  }
617 
618  nRows = 0;
620  nRows = inputFile->HasKey("ZNAXIS2") ? inputFile->GetInt("ZNAXIS2") : 0;
621  else
622  nRows = inputFile->HasKey("NAXIS2") ? inputFile->GetInt("NAXIS2") : 0;
623  nRoi = inputFile->HasKey("NROI") ? inputFile->GetInt("NROI") : 0;
624  runNumber = inputFile->HasKey("RUNID") ? inputFile->GetInt("RUNID") : -1;
625  nTM = inputFile->HasKey("NTMARK") ? inputFile->GetInt("NTMARK") : 0;
626 
627  runType = "unkown";
628  if (inputFile->HasKey("RUNTYPE"))
629  {
630  runType = inputFile->GetStr("RUNTYPE");
631  if (runType == "")
632  runType = "unkown";
633  }
634  firstDataTime = inputFile->HasKey("TSTART") ? inputFile->GetInt("TSTART") : -1;
635  lastDataTime = inputFile->HasKey("TSTOP") ? inputFile->GetInt("TSTOP"): -1;
636  nRoiTM = inputFile->HasKey("NROITM") ? inputFile->GetInt("NROITM") : 0;
637  revision = inputFile->HasKey("REVISION") ? inputFile->GetInt("REVISION") : -1;
638  builderVersion = inputFile->HasKey("BLDVER") ? inputFile->GetInt("BLDVER") : -1;
639  nBoards = inputFile->HasKey("NBOARD") ? inputFile->GetInt("NBOARD") : 0;
640  nPixels = inputFile->HasKey("NPIX") ? inputFile->GetInt("NPIX") : 0;
641  timeSystem = inputFile->HasKey("TIMESYS") ? inputFile->GetStr("TIMESYS") : "";
642  creationDate = inputFile->HasKey("DATE") ? inputFile->GetStr("DATE") : "";
643  nightInt = inputFile->HasKey("NIGHT") ? inputFile->GetInt("NIGHT") : 0;
644  camera = inputFile->HasKey("CAMERA") ? inputFile->GetStr("CAMERA") : "";
645  daq = inputFile->HasKey("DAQ") ? inputFile->GetStr("DAQ") : "";
646  adcCount = inputFile->HasKey("ADCRANGE") ? inputFile->GetFloat("ADCRANGE") : 2000;
647  if (nPixels == 0)
648  {
649  cout << "could not read num pixels from fits header. Assuming 1440 (FACT)." << endl;
650  nPixels = 1440;
651  }
652  if (nRoi == 0 && !inputFile->HasKey("NROI"))
653  {//let's try to figure out the roi from the column's format
654  const fits::Table::Columns& cols = inputFile->GetColumns();
655  if (cols.find("Data") == cols.end())
656  {
657  cout << "ERROR: Column \"Data\" could not be found. abortin load." << endl;
658  return;
659  }
660  const fits::Table::Columns::const_iterator col = cols.find("Data");
661  if (col->second.type != 'I')
662  {
663  cout << "ERROR: Data Column has type " << col->second.type << " while viewer expects I" << endl;
664  return;
665  }
666  if (col->second.num % nPixels != 0)
667  {
668  cout << "ERROR: Num pixels (" << nPixels << ") does not match Data length (" << col->second.num << "). Aborting" << endl;
669  return;
670  }
671  nRoi = col->second.num/nPixels;
672  cout << "Estimate num samples per pixels to be " << nRoi;
673  _softwareOrdering = true;
674  }
675  else
676  _softwareOrdering = inputFile->Get<string>("ISMC", "F")=="T";
677 
678  if (inputFile->HasKey("OFFSET"))
679  offSetRoi = inputFile->GetInt("OFFSET");
680 
681  nbOk = 0;//inputFile->GetInt("NBEVTOK");
682  nbRej = 0;//inputFile->GetInt("NBEVTREJ");
683  nbBad = 0;//inputFile->GetInt("NBEVTBAD");
684 
685  eventNum = 1;
686 
687  if (eventData != NULL) {
688  delete[] eventData;
689  delete[] rawEventData;
690  delete[] waveLetArray;
691  }
692  eventData = new float[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
693 
694  rawEventData = new int16_t[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
695  waveLetArray = new int16_t[1024*1440];
696  try
697  {
699  if (inputFile->HasColumn("EventNum"))
700  inputFile->SetPtrAddress("EventNum", &eventNum);
701  else
702  cout << "Warning: could not find column \"EventNum\"" << endl;
703  if (inputFile->HasColumn("TriggerType"))
704  inputFile->SetPtrAddress("TriggerType", &triggerType);
705  else
706  cout << "Warning: could not find column \"TriggerType\"" << endl;
707  if (inputFile->HasColumn("SoftTrig"))
708  inputFile->SetPtrAddress("SoftTrig", &softTrig);
709  else
710  cout << "Warning: could not find column \"SoftTrig\"" << endl;
711  if (inputFile->HasColumn("BoardTime"))
712  inputFile->SetPtrAddress("BoardTime", boardTime);
713  else
714  cout << "Warning: could not find column \"BoardTime\"" << endl;
715  if (inputFile->HasColumn("StartCellData"))
716  inputFile->SetPtrAddress("StartCellData", startPix);
717  else
718  cout << "Warning: could not find column \"StartCellData\"" << endl;
719  if (inputFile->HasColumn("StartCellTimeMarker"))
720  inputFile->SetPtrAddress("StartCellTimeMarker", startTM);
721  else
722  cout << "Warning: could not find column \"StartCellTimeMarker\"" << endl;
723  if (inputFile->HasColumn("TimeMarker"))
724  inputFile->SetPtrAddress("TimeMarker", &rawEventData[1440*nRoi]);
725  else
726  cout << "Warning: could not find column \"TimeMarker\"" << endl;
727  }
728  catch (const runtime_error &e)
729  {
730  cout << e.what() << endl;
731  cout << "Loading aborted." << endl;
732 
733  nRoi = nRows = 0;
734 
735  return;
736  }
737 
738  try
739  {
740  pcTime[0] = pcTime[1] = 0;
741  if (inputFile->HasColumn("UnixTimeUTC"))
742  inputFile->SetPtrAddress("UnixTimeUTC", pcTime);
743  }
744  catch (const runtime_error&)
745  {
746  try
747  {
748  if (inputFile->HasColumn("PCTime"))
749  inputFile->SetPtrAddress("PCTime", pcTime);
750  else
751  cout << "Warning: could not find column \"UnixTimeUTC\" nor \"PCTime\"" << endl;
752 
753  }
754  catch (const runtime_error&)
755  {
756 
757  }
758  }
759 
760 
761  int backupStep = eventStep;
762  rowNum = -1;
763  eventStep = 1;
764 
765  plusEvent();
766  eventStep = backupStep;
767  emit newFileLoaded();
769 }
int16_t startTM[NTMARK]
bool HasKey(const std::string &key) const
Definition: fits.h:1002
std::string GetStr(const std::string &key) const
Definition: fits.h:1011
int16_t * rawEventData
void signalCurrentPixel(int pixel)
void * SetPtrAddress(const std::string &name)
Definition: fits.h:886
bool IsCompressedFITS() const
Definition: fits.h:1029
std::map< std::string, Column > Columns
Definition: fits.h:113
std::string daq
std::string runType
void close()
Definition: izstream.h:91
uint32_t boardTime[NBOARDS]
int32_t pcTime[2]
double GetFloat(const std::string &key) const
Definition: fits.h:1010
std::string timeSystem
int64_t GetInt(const std::string &key) const
Definition: fits.h:1008
uint16_t triggerType
int16_t startPix[NPIX]
std::string creationDate
bool HasColumn(const std::string &col) const
Definition: fits.h:1003
void newFileLoaded()
std::string camera
const Table::Columns & GetColumns() const
Definition: fits.h:1004
int16_t * waveLetArray
T Get(const std::string &key) const
Definition: fits.h:962

+ Here is the call graph for this function: