NCBI C++ ToolKit
incr_time.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: incr_time.cpp 63636 2014-07-16 15:38:41Z vasilche $
2 * ===========================================================================
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 * ===========================================================================
23 *
24 * Author: Eugene Vasilchenko
25 *
26 * File Description: Support for configurable increasing timeout
27 *
28 */
29 
30 #include <ncbi_pch.hpp>
32 #include <corelib/ncbi_config.hpp>
33 #include <cmath>
34 
37 
38 /////////////////////////////////////////////////////////////////////////////
39 // CIncreasingTime
40 /////////////////////////////////////////////////////////////////////////////
41 
42 
44  const string& driver_name,
45  const SAllParams& params)
46 {
47  m_InitTime = x_GetDoubleParam(conf, driver_name, params.m_Initial);
48  m_MaxTime = x_GetDoubleParam(conf, driver_name, params.m_Maximal);
49  m_Multiplier = x_GetDoubleParam(conf, driver_name, params.m_Multiplier);
50  m_Increment = x_GetDoubleParam(conf, driver_name, params.m_Increment);
51 }
52 
53 
55  const string& driver_name,
56  const SParam& param)
57 {
58  string value = conf.GetString(driver_name,
59  param.m_ParamName,
61  "");
62  if ( value.empty() && param.m_ParamName2 ) {
63  value = conf.GetString(driver_name,
64  param.m_ParamName2,
66  "");
67  }
68  if ( value.empty() ) {
69  return param.m_DefaultValue;
70  }
72 }
73 
74 
75 double CIncreasingTime::GetTime(int step) const
76 {
77  double time = m_InitTime;
78  if ( step > 0 ) {
79  if ( m_Multiplier <= 0 ) {
80  time += step * m_Increment;
81  }
82  else {
83  double p = pow(m_Multiplier, step);
84  time = time * p + m_Increment * (p - 1) / (m_Multiplier - 1);
85  }
86  }
87  return min(time, m_MaxTime);
88 }
89 
90 
double GetTime(int step) const
Definition: incr_time.cpp:75
double m_MaxTime
Definition: incr_time.hpp:78
static double x_GetDoubleParam(CConfig &conf, const string &driver_name, const SParam &param)
Definition: incr_time.cpp:54
double m_InitTime
Definition: incr_time.hpp:78
double m_Multiplier
Definition: incr_time.hpp:78
double m_Increment
Definition: incr_time.hpp:78
char value[7]
Definition: config.c:431
static void Init(void)
Definition: cursor6.c:76
string GetString(const string &driver_name, const string &param_name, EErrAction on_error, const string &default_value, const list< string > *synonyms=NULL)
Utility function to get an element of parameter tree Throws an exception when mandatory parameter is ...
@ eErr_NoThrow
Return default value on error.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
static double StringToDouble(const CTempStringEx str, TStringToNumFlags flags=0)
Convert string to double.
Definition: ncbistr.cpp:1387
@ fDecimalPosixOrLocal
StringToDouble*(): For decimal point, try both C and current locale.
Definition: ncbistr.hpp:301
Parameters initialization model.
T min(T x_, T y_)
const char * m_ParamName2
Definition: incr_time.hpp:47
const char * m_ParamName
Definition: incr_time.hpp:46
#define const
Definition: zconf.h:230
Modified on Wed Feb 21 09:56:13 2024 by modify_doxy.py rev. 669887