Example #1
0
void Engine::initialize(std::string profile) {
  //don't allow this twice?
  profile_path_ = profile;

  PL_DBG << "Engine will attempt to initialize with profile at " << profile_path_;

  pugi::xml_document doc;
  if (!doc.load_file(profile_path_.c_str()))
    return;
  PL_DBG << "<Engine> Loading device settings " << profile_path_;

  pugi::xml_node root = doc.child(Qpx::Setting().xml_element_name().c_str());
  if (!root)
    return;

  Qpx::Setting tree(root);

  //tree.metadata.setting_type = Qpx::SettingType::stem;
  tree.metadata.saveworthy = true;

  Qpx::Setting descr = tree.get_setting(Qpx::Setting("Profile description"), Qpx::Match::id);
  descr.metadata.setting_type = Qpx::SettingType::text;
  descr.metadata.writable = true;
  tree.branches.replace(descr);

  boost::filesystem::path dir(profile_path_);
  dir.make_preferred();
  boost::filesystem::path path = dir.remove_filename();

//  if (!boost::filesystem::is_directory(path)) {
//    PL_DBG << "<Engine> Bad profile root directory. Will not proceed with loading device settings";
//    return;
//  }

  for (auto &q : tree.branches.my_data_) {
    if (q.id_ != "Detectors") {
      boost::filesystem::path dev_settings = path / q.value_text;
      DaqDevice* device = DeviceFactory::getInstance().create_type(q.id_, dev_settings.string());
      if (device != nullptr) {
        PL_DBG << "<Engine> Success loading " << device->device_name();
        devices_[q.id_] = std::unique_ptr<DaqDevice>(device);
      }
    }
  }

  push_settings(tree);
  get_all_settings();
  save_optimization();

  PL_INFO << "<Engine> Welcome to " << descr.value_text;
}
Example #2
0
Engine::~Engine() {
  if (die()) {
    get_all_settings();
    save_optimization();
  }

  if (!profile_path_.empty()) {
    get_all_settings();

    Qpx::Setting dev_settings = pull_settings();
    dev_settings.condense();
    dev_settings.strip_metadata();

    pugi::xml_document doc;
    dev_settings.to_xml(doc);

    if (doc.save_file(profile_path_.c_str()))
      PL_ERR << "<Engine> Saved settings to " << profile_path_;
    else
      PL_ERR << "<Engine> Failed to save device settings";
  }

}
Example #3
0
bool Engine::die() {
  bool success = false;
  for (auto &q : devices_)
    if ((q.second != nullptr) && (q.second->status() & DeviceStatus::booted)) {
      success |= q.second->die();
      //PL_DBG << "die > " << q.second->device_name();
    }

  if (success) {
    //settings_tree_.value_int = 0;
    get_all_settings();
  }

  return success;
}
Example #4
0
bool Engine::boot() {
  PL_INFO << "<Engine> Booting system...";

  bool success = false;
  for (auto &q : devices_)
    if ((q.second != nullptr) && (q.second->status() & DeviceStatus::can_boot)) {
      success |= q.second->boot();
      //PL_DBG << "daq_start > " << q.second->device_name();
    }

  if (success) {
    PL_INFO << "<Engine> Boot successful.";
    //settings_tree_.value_int = 2;
    get_all_settings();
  }

  return success;
}
Example #5
0
ListData* Engine::getList(uint64_t timeout, boost::atomic<bool>& interruptor) {

  boost::unique_lock<boost::mutex> lock(mutex_);

  if (!(aggregate_status_ & DeviceStatus::can_run)) {
    PL_WARN << "<Engine> No devices exist that can perform acquisition";
    return nullptr;
  }

  Spill* one_spill;
  ListData* result = new ListData;

  PL_INFO << "<Engine> Multithreaded list mode acquisition scheduled for " << timeout << " seconds";

  CustomTimer *anouncement_timer = nullptr;
  double secs_between_anouncements = 5;

  get_all_settings();
  save_optimization();
  result->run.state = pull_settings();
  result->run.detectors = get_detectors();
  result->run.time = boost::posix_time::microsec_clock::universal_time();

  SynchronizedQueue<Spill*> parsedQueue;

  if (daq_start(&parsedQueue))
    PL_DBG << "<Engine> Started device daq threads";

  CustomTimer total_timer(timeout, true);
  anouncement_timer = new CustomTimer(true);

  while (daq_running()) {
    wait_ms(1000);
    if (anouncement_timer->s() > secs_between_anouncements) {
      PL_INFO << "  RUNNING Elapsed: " << total_timer.done()
              << "  ETA: " << total_timer.ETA();
      delete anouncement_timer;
      anouncement_timer = new CustomTimer(true);
    }
    if (interruptor.load() || (timeout && total_timer.timeout())) {
      if (daq_stop())
        PL_DBG << "<Engine> Stopped device daq threads successfully";
      else
        PL_ERR << "<Engine> Failed to stop device daq threads";
    }
  }

  delete anouncement_timer;

  result->run.time = boost::posix_time::microsec_clock::universal_time();

  wait_ms(500);

  while (parsedQueue.size() > 0) {
    one_spill = parsedQueue.dequeue();
    for (auto &q : one_spill->hits)
      result->hits.push_back(q);
    delete one_spill;
  }

  parsedQueue.stop();
  return result;
}
Example #6
0
void Engine::getMca(uint64_t timeout, SpectraSet& spectra, boost::atomic<bool>& interruptor) {

  boost::unique_lock<boost::mutex> lock(mutex_);

  if (!(aggregate_status_ & DeviceStatus::can_run)) {
    PL_WARN << "<Engine> No devices exist that can perform acquisition";
    return;
  }

  PL_INFO << "<Engine> Multithreaded spectra acquisition scheduled for " << timeout << " seconds";

  CustomTimer *anouncement_timer = nullptr;
  double secs_between_anouncements = 5;

  SynchronizedQueue<Spill*> parsedQueue;

  boost::thread builder(boost::bind(&Qpx::Engine::worker_MCA, this, &parsedQueue, &spectra));

  Spill* spill = new Spill;
  get_all_settings();
  save_optimization();
  spill->run.state = pull_settings();
  spill->run.detectors = get_detectors();
  spill->run.time = boost::posix_time::microsec_clock::universal_time();
  parsedQueue.enqueue(spill);

  if (daq_start(&parsedQueue))
    PL_DBG << "<Engine> Started device daq threads";

  CustomTimer total_timer(timeout, true);
  anouncement_timer = new CustomTimer(true);

  while (daq_running()) {
    wait_ms(1000);
    if (anouncement_timer->s() > secs_between_anouncements) {
      if (timeout > 0)
        PL_INFO << "  RUNNING Elapsed: " << total_timer.done()
                << "  ETA: " << total_timer.ETA();
      else
        PL_INFO << "  RUNNING Elapsed: " << total_timer.done();

      delete anouncement_timer;
      anouncement_timer = new CustomTimer(true);
    }
    if (interruptor.load() || (timeout && total_timer.timeout())) {
      if (daq_stop())
        PL_DBG << "<Engine> Stopped device daq threads successfully";
      else
        PL_ERR << "<Engine> Failed to stop device daq threads";
    }
  }

  delete anouncement_timer;

  spill = new Spill;
  get_all_settings();
  save_optimization();
  spill->run.state = pull_settings();
  spill->run.detectors = get_detectors();
  spill->run.time = boost::posix_time::microsec_clock::universal_time();
  parsedQueue.enqueue(spill);

  wait_ms(500);
  while (parsedQueue.size() > 0)
    wait_ms(1000);
  wait_ms(500);
  parsedQueue.stop();
  wait_ms(500);

  builder.join();
}
Example #7
0
void settings_editor::on_interface_loaded() {
  get_all_settings();
  process_port_list();
}