SST  12.0.1
StructuralSimulationToolkit
timeLord.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2022 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-2022, 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 #include "sst/core/threadsafe.h"
19 #include "sst/core/unitAlgebra.h"
20 
21 #include <map>
22 #include <string>
23 
24 extern int main(int argc, char** argv);
25 
26 namespace SST {
27 
28 class Link;
29 class Simulation;
30 class Simulation_impl;
31 class TimeConverter;
32 class UnitAlgebra;
33 
34 /**
35  Class for creating and managing TimeConverter objects
36  */
37 class TimeLord
38 {
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 class SST::Link;
84 
85  friend int ::main(int argc, char** argv);
86 
87  void init(const std::string& timeBaseString);
88 
89  // Needed by the simulator to turn minPart back into a
90  // TimeConverter object.
91  TimeConverter* getTimeConverter(SimTime_t simCycles);
92 
93  TimeLord() : initialized(false) {}
94  ~TimeLord();
95 
96  TimeLord(TimeLord const&); // Don't Implement
97  void operator=(TimeLord const&); // Don't Implement
98 
99  bool initialized;
100  std::recursive_mutex slock;
101 
102  // Variables that need to be saved when serialized
103  std::string timeBaseString;
104  TimeConverterMap_t tcMap;
105  UnitAlgebra timeBase;
106 
107  // double sec_factor;
108  StringToTCMap_t parseCache;
109 
110  TimeConverter* nano;
111  TimeConverter* micro;
112  TimeConverter* milli;
113 };
114 
115 } // namespace SST
116 
117 #endif // SST_CORE_TIMELORD_H
TimeConverter * getTimeConverter(const std::string &ts)
Create a new TimeConverter object using specified SI Units.
Definition: timeLord.cc:31
Main control class for a SST Simulation.
Definition: simulation.h:34
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:26
SimTime_t getSimCycles(const std::string &timeString, const std::string &where)
Not a Public API.
Definition: timeLord.cc:165
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:75
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:37
Performs Unit math in full precision.
Definition: unitAlgebra.h:106