Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
int main (int argc, char *argv[]){

    // VERIFICAR SE O USUARIO
    // CONTINUA OU SAI DO PROGRAMA
    char op=NULL;
    do {

        PPMImageParams* imageParams;

        imageParams = (PPMImageParams *)malloc(sizeof(PPMImageParams));

        // CARREGA O MENU OU SETA AS OPCOES
        // CASO INSERIDAS NA LINHA DE COMANDO
        initialParams* ct = (initialParams *)calloc(1,sizeof(initialParams));

        ct->DIRIMGIN = "images_in/";
        ct->DIRIMGOUT = "images_out/";
        ct->DIRRES = "resultados/";
        ct->typeAlg = 'S'; // SEQUENCIAL
        menu(ct, argc, argv);

        sprintf((char*) &imageParams->fileOut, "%s%s", ct->DIRIMGOUT, ct->filePath);
        sprintf((char*) &imageParams->fileIn, "%s%s", ct->DIRIMGIN, ct->filePath);

        if (ct->filePath != NULL) {
            // RELOGIO
            tempo* relogio = (tempo* )malloc(sizeof(tempo)*2);

            //CARREGA O RELOGIO
            timer* tempoA = (timer *)malloc(sizeof(timer));
            timer* tempoR = (timer *)malloc(sizeof(timer));
            timer* tempoF = (timer *)malloc(sizeof(timer));
            timer* tempoW = (timer *)malloc(sizeof(timer));

            start_timer(tempoA);

            sequencial(imageParams, ct, tempoR, tempoF, tempoW);

            //PARA O RELOGIO
            stop_timer(tempoA);

            relogio[0].tempoA = total_timer(tempoA);
            relogio[1].tempoR = total_timer(tempoR);
            relogio[1].tempoF = total_timer(tempoF);
            relogio[1].tempoW = total_timer(tempoW);

            show_timer(relogio, 1);

            // ESCREVENDO OS RESULTADOS
            // NO ARQUIVO /resultados/
            writeFile(ct, imageParams, relogio);

            // LIMPANDO A MEMORIA
            cleanMemory(ct, imageParams, NULL, relogio, tempoA, tempoR, tempoF, tempoW);

        } else {
            printf("\nOpcao invalida!\n\n");
        }

        if (!argv[1]) {
            printf("\nPressione 's' para voltar ao menu ou 'n' para sair...\n");
            int ret = scanf(" %c", &op);
            if (ct->debug >= 1) printf("\nRet OP: %d", ret);
        } else {
            op = 'n';
        }

    } while (op != 'n');

    return 0;
}
Ejemplo n.º 3
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();
}