SST  14.1.0
StructuralSimulationToolkit
timeLord.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2024 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-2024, 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 Time Base of the TimeLord
64  */
65  UnitAlgebra getTimeBase() const { return timeBase; }
66 
67  /** @return TimeConverter which represents Nanoseconds */
68  TimeConverter* getNano() { return nano; }
69  /** @return TimeConverter which represents Microseconds */
70  TimeConverter* getMicro() { return micro; }
71  /** @return 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 private:
80  friend class SST::Simulation;
81  friend class SST::Simulation_impl;
82  friend class SST::Link;
83 
84  friend int ::main(int argc, char** argv);
85 
86  void init(const std::string& timeBaseString);
87 
88  // Needed by the simulator to turn minPart back into a
89  // TimeConverter object.
90  TimeConverter* getTimeConverter(SimTime_t simCycles);
91 
92  TimeLord() : initialized(false) {}
93  ~TimeLord();
94 
95  TimeLord(TimeLord const&); // Don't Implement
96  void operator=(TimeLord const&); // Don't Implement
97 
98  bool initialized;
99  std::recursive_mutex slock;
100 
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 } // namespace SST
114 
115 #endif // SST_CORE_TIMELORD_H
TimeConverter * getTimeConverter(const std::string &ts)
Create a new TimeConverter object using specified SI Units.
Definition: timeLord.cc:33
UnitAlgebra getTimeBase() const
Definition: timeLord.h:65
A class to convert between a component&#39;s view of time and the core&#39;s view of time.
Definition: timeConverter.h:27
SimTime_t getSimCycles(const std::string &timeString, const std::string &where)
Not a Public API.
Definition: timeLord.cc:167
TimeConverter * getNano()
Definition: timeLord.h:68
Definition: action.cc:18
TimeConverter * getMicro()
Definition: timeLord.h:70
TimeConverter * getMilli()
Definition: timeLord.h:72
Main control class for a SST Simulation.
Definition: simulation_impl.h:76
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:37
Performs Unit math in full precision.
Definition: unitAlgebra.h:106