SST  11.0.0
StructuralSimulationToolkit
timeLord.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2021 NTESS. Under the terms
4 // of Contract DE-NA0003525 with NTESS, the U.S.
5 // Government retains certain rights in this software.
6 //
7 // Copyright (c) 2009-2021, NTESS
8 // All rights reserved.
9 //
10 // This file is part of the SST software package. For license
11 // information, see the LICENSE file in the top level directory of the
12 // distribution.
13 
14 #ifndef SST_CORE_TIMELORD_H
15 #define SST_CORE_TIMELORD_H
16 
17 #include "sst/core/sst_types.h"
18 
19 #include <map>
20 #include <string>
21 
22 //#include "sst/core/simulation.h"
23 #include "sst/core/unitAlgebra.h"
24 #include "sst/core/threadsafe.h"
25 
26 extern int main(int argc, char **argv);
27 
28 namespace SST {
29 
30 class Simulation;
31 class Simulation_impl;
32 class TimeConverter;
33 class UnitAlgebra;
34 
35  /**
36  Class for creating and managing TimeConverter objects
37  */
38 class TimeLord {
39  typedef std::map<SimTime_t,TimeConverter*> TimeConverterMap_t;
40  typedef std::map<std::string,TimeConverter*> StringToTCMap_t;
41 
42  public:
43  /**
44  Create a new TimeConverter object using specified SI Units. For
45  example, "1 Ghz" (1 Gigahertz), "2.5 ns" (2.5 nanoseconds).
46 
47  @param ts String indicating the base unit for this object. The
48  string should be a floating point number followed by a prefix,
49  and then frequency (i.e. Hz) or time unit (s). Allowable seconds
50  prefixes are: 'f' (fempto), 'p' (pico), 'n' (nano), 'u' (micro),
51  'm' (milli). Allowable frequency prefixes are 'k' (kilo), 'M'
52  (mega), and 'G' (giga).
53  */
54  TimeConverter* getTimeConverter(const std::string& ts);
55  /**
56  * Create a new TimeConverter object using the specified units.
57  *
58  * @param ts UnitAlgebra object indicating the base unit for this object.
59  */
61 
62  /**
63  * Return the Time Base of the TimeLord
64  */
65  UnitAlgebra getTimeBase() const { return timeBase; }
66 
67  /** Return a TimeConverter which represents Nanoseconds */
68  TimeConverter* getNano() {return nano;}
69  /** Return a TimeConverter which represents Microseconds */
70  TimeConverter* getMicro() {return micro;}
71  /** Return a TimeConverter which represents Milliseconds */
72  TimeConverter* getMilli() {return milli;}
73 
74  /** Not a Public API.
75  * Returns the number of raw simulation cycles given by a specified time string
76  */
77  SimTime_t getSimCycles(const std::string& timeString, const std::string& where);
78 
79 
80  private:
81  friend class SST::Simulation;
82  friend class SST::Simulation_impl;
83  friend int ::main(int argc, char **argv);
84 
85  void init(const std::string& timeBaseString);
86 
87  // Needed by the simulator to turn minPart back into a
88  // TimeConverter object.
89  TimeConverter *getTimeConverter(SimTime_t simCycles);
90 
91  TimeLord() : initialized(false) { }
92  ~TimeLord();
93 
94  TimeLord(TimeLord const&); // Don't Implement
95  void operator=(TimeLord const&); // Don't Implement
96 
97  bool initialized;
98  std::recursive_mutex slock;
99 
100  // Variables that need to be saved when serialized
101  std::string timeBaseString;
102  TimeConverterMap_t tcMap;
103  UnitAlgebra timeBase;
104 
105  // double sec_factor;
106  StringToTCMap_t parseCache;
107 
108  TimeConverter* nano;
109  TimeConverter* micro;
110  TimeConverter* milli;
111 
112 };
113 
114 } // namespace SST
115 
116 #endif //SST_CORE_TIMELORD_H
TimeConverter * getTimeConverter(const std::string &ts)
Create a new TimeConverter object using specified SI Units.
Definition: timeLord.cc:30
Main control class for a SST Simulation.
Definition: simulation.h:38
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:25
SimTime_t getSimCycles(const std::string &timeString, const std::string &where)
Not a Public API.
Definition: timeLord.cc:115
TimeConverter * getNano()
Return a TimeConverter which represents Nanoseconds.
Definition: timeLord.h:68
UnitAlgebra getTimeBase() const
Return the Time Base of the TimeLord.
Definition: timeLord.h:65
TimeConverter * getMicro()
Return a TimeConverter which represents Microseconds.
Definition: timeLord.h:70
TimeConverter * getMilli()
Return a TimeConverter which represents Milliseconds.
Definition: timeLord.h:72
Main control class for a SST Simulation.
Definition: simulation_impl.h:72
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:38
Performs Unit math in full precision.
Definition: unitAlgebra.h:107