otbConfigurationManager.cxx 2.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
20 21 22

#include "otbConfigurationManager.h"

23
#include "otbMacro.h"
24
#include "otbLogger.h"
25

26
#include "itkMultiThreader.h"
27 28
#include "itksys/SystemTools.hxx"

29 30 31 32
#ifdef _OPENMP
#include <omp.h>
#endif

Christophe Palmann's avatar
Christophe Palmann committed
33
#include <cstdlib>
34 35
#include <algorithm>
#include <string>
Christophe Palmann's avatar
Christophe Palmann committed
36

37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
namespace otb
{

std::string ConfigurationManager::GetDEMDirectory()
{
  std::string svalue;
  itksys::SystemTools::GetEnv("OTB_DEM_DIRECTORY",svalue);
  return svalue;
}

std::string ConfigurationManager::GetGeoidFile()
{
  std::string svalue;
  itksys::SystemTools::GetEnv("OTB_GEOID_FILE",svalue);
  return svalue;
}

ConfigurationManager::RAMValueType ConfigurationManager::GetMaxRAMHint()
{
56 57 58 59 60 61 62 63 64 65
  std::string max_ram_hint;
  if (itksys::SystemTools::GetEnv("OTB_MAX_RAM_HINT", max_ram_hint))
  {
    return std::stoul(max_ram_hint);
  }
  else
  {
    // Default value
    return 256;
  }
66 67 68 69 70 71
}

itk::LoggerBase::PriorityLevelType ConfigurationManager::GetLoggerLevel()
{
  std::string svalue;

72
  // Default value is INFO
73
  itk::LoggerBase::PriorityLevelType level = itk::LoggerBase::INFO;
74 75 76
  
  if(itksys::SystemTools::GetEnv("OTB_LOGGER_LEVEL",svalue))
    {
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
    if(svalue.compare("DEBUG") == 0)
      {
      level = itk::LoggerBase::DEBUG;
      }
    else if(svalue.compare("INFO") == 0)
      {
      level = itk::LoggerBase::INFO;
      }
    else if(svalue.compare("WARNING") == 0)
      {
      level = itk::LoggerBase::WARNING;
      }
    else if(svalue.compare("CRITICAL") == 0)
      {
      level = itk::LoggerBase::CRITICAL;
      }
    else
      {
      otbLogMacro(Error,<<"Unknown value for OTB_LOGGER_LEVEL_MACRO. Possible values are DEBUG, INFO, WARNING, CRITICAL.");
      }
97 98
    }
  return level;
99
}
100

101 102 103 104 105 106 107 108 109 110
int ConfigurationManager::InitOpenMPThreads()
{
  int ret = 1;
#ifdef _OPENMP
  ret = itk::MultiThreader::GetGlobalDefaultNumberOfThreads();
  omp_set_num_threads(ret);
#endif
  return ret;
}

111
}