SST  10.1.0
StructuralSimulationToolkit
timeLord.h
1 // -*- c++ -*-
2 
3 // Copyright 2009-2020 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-2020, 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 TimeConverter;
31 class UnitAlgebra;
32 
33  /**
34  Class for creating and managing TimeConverter objects
35  */
36 class TimeLord {
37  typedef std::map<SimTime_t,TimeConverter*> TimeConverterMap_t;
38  typedef std::map<std::string,TimeConverter*> StringToTCMap_t;
39 
40  public:
41  /**
42  Create a new TimeConverter object using specified SI Units. For
43  example, "1 Ghz" (1 Gigahertz), "2.5 ns" (2.5 nanoseconds).
44 
45  @param ts String indicating the base unit for this object. The
46  string should be a floating point number followed by a prefix,
47  and then frequency (i.e. Hz) or time unit (s). Allowable seconds
48  prefixes are: 'f' (fempto), 'p' (pico), 'n' (nano), 'u' (micro),
49  'm' (milli). Allowable frequency prefixes are 'k' (kilo), 'M'
50  (mega), and 'G' (giga).
51  */
52  TimeConverter* getTimeConverter(const std::string& ts);
53  /**
54  * Create a new TimeConverter object using the specified units.
55  *
56  * @param ts UnitAlgebra object indicating the base unit for this object.
57  */
59 
60  /**
61  * Return the Time Base of the TimeLord
62  */
63  UnitAlgebra getTimeBase() const { return timeBase; }
64 
65  /** Return a TimeConverter which represents Nanoseconds */
66  TimeConverter* getNano() {return nano;}
67  /** Return a TimeConverter which represents Microseconds */
68  TimeConverter* getMicro() {return micro;}
69  /** Return a TimeConverter which represents Milliseconds */
70  TimeConverter* getMilli() {return milli;}
71 
72  /** Not a Public API.
73  * Returns the number of raw simulation cycles given by a specified time string
74  */
75  SimTime_t getSimCycles(const std::string& timeString, const std::string& where);
76 
77 
78  private:
79  friend class SST::Simulation;
80  friend int ::main(int argc, char **argv);
81 
82  void init(const std::string& timeBaseString);
83 
84  // Needed by the simulator to turn minPart back into a
85  // TimeConverter object.
86  TimeConverter *getTimeConverter(SimTime_t simCycles);
87 
88  TimeLord() : initialized(false) { }
89  ~TimeLord();
90 
91  TimeLord(TimeLord const&); // Don't Implement
92  void operator=(TimeLord const&); // Don't Implement
93 
94  bool initialized;
95  std::recursive_mutex slock;
96 
97  // Variables that need to be saved when serialized
98  std::string timeBaseString;
99  TimeConverterMap_t tcMap;
100  UnitAlgebra timeBase;
101 
102  // double sec_factor;
103  StringToTCMap_t parseCache;
104 
105  TimeConverter* nano;
106  TimeConverter* micro;
107  TimeConverter* milli;
108 
109 };
110 
111 } // namespace SST
112 
113 #endif //SST_CORE_TIMELORD_H
TimeConverter * getTimeConverter(const std::string &ts)
Create a new TimeConverter object using specified SI Units.
Definition: timeLord.cc:29
Main control class for a SST Simulation.
Definition: simulation.h:73
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:114
TimeConverter * getNano()
Return a TimeConverter which represents Nanoseconds.
Definition: timeLord.h:66
UnitAlgebra getTimeBase() const
Return the Time Base of the TimeLord.
Definition: timeLord.h:63
TimeConverter * getMicro()
Return a TimeConverter which represents Microseconds.
Definition: timeLord.h:68
TimeConverter * getMilli()
Return a TimeConverter which represents Milliseconds.
Definition: timeLord.h:70
Class for creating and managing TimeConverter objects.
Definition: timeLord.h:36
Performs Unit math in full precision.
Definition: unitAlgebra.h:107