gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
logging.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
20 
21 #ifndef __logging_hpp__
22 #define __logging_hpp__
23 
24 // Standard libraries
25 #include <string>
26 #include <set>
27 #include <map>
28 #include <vector>
29 #include <deque>
30 #include <fstream>
31 #include <chrono>
32 #include <omp.h>
33 
34 // Gambit
35 #include "gambit/Logs/logger.hpp" // Minimal declarations needed to use logger -- most code should only need to include this.
36 #include "gambit/Logs/log_tags.hpp"
38 //#include "gambit/Utils/util_functions.hpp"
39 
40 
41 namespace Gambit
42 {
43  // Forward declarations from Utils. Saves including the entire header for a trivial thing
44  namespace Utils
45  {
46  typedef std::chrono::time_point<std::chrono::system_clock> time_point;
48  time_point get_clock_now();
49  }
50 
51  namespace Logging
52  {
53 
54  // Global reference start time. Can only be used in this compile unit.
55  static const Utils::time_point start_time(Utils::get_clock_now());
56 
57  // Function to retrieve the 'msgtypes' set
58  const std::set<LogTag>& msgtypes();
59 
60  // Function to retrieve the 'flags' set
61  const std::set<LogTag>& flags();
62 
63  // Function to retrieve the 'echoes' set
64  const std::set<LogTag>& echoes();
65 
66  // Function to return the next unused tag index
67  // (needed by module and backend macros so they can determine what tag they are allowed to use)
68  int getfreetag();
69 
71  void checktags();
72 
74  struct Message
75  {
76  std::string message;
77  std::set<int> tags;
80  Message(const std::string& msgIN,
81  const std::set<int>& tagsIN)
82  : message(msgIN),
83  tags(tagsIN),
84  received_at(Utils::get_clock_now())
85  {}
86  };
87 
90  {
91  const std::string& message; //lives on in original Message object, so can be a reference safely I think
93  // couldn't figure out how to nicely initialise these in the constructor list, so not const
94  // now happens in body of constructor
95  std::set<LogTag> type_tags; //message types
96  std::set<int> component_tags; //gambit components, modules, and backends
97  std::set<LogTag> flag_tags; //extra message flags
98  std::set<LogTag> echo_tags; //message echo flags
99  // Constructor (does the sorting of the tags)
100  SortedMessage(const Message& mail);
101  };
102 
103 
104  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105  //% Logger class declarations %
106  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 
110  {
111  public:
113  virtual ~BaseLogger();
114 
116  virtual void write(const SortedMessage&) = 0;
117 
119  virtual void flush() = 0;
120  };
121 
123  class StdLogger : public BaseLogger
124  {
125  public:
127  // Attach logger object to an existing stream
128  StdLogger(std::ostream&);
129 
131  // Opens a file and takes care of the stream itself
132  StdLogger(const std::string&);
133 
135  virtual ~StdLogger();
136 
138  virtual void write(const SortedMessage&);
139 
141  virtual void flush();
142 
144  void writetags(const std::set<LogTag>&);
145  void writetags(const std::set<int>&);
146 
147  private:
148  std::ofstream my_own_fstream; //Don't use this except in constructor
149  std::ostream& my_stream;
150 
152  int MPIrank;
153  int MPIsize;
154  };
155 
156  } //end namespace Logging
157 
158 } // end namespace Gambit
159 
160 #endif
std::set< LogTag > flag_tags
Definition: logging.hpp:97
structure for storing log messages and metadata after tags are sorted
Definition: logging.hpp:89
int getfreetag()
Definition: logging.cpp:138
std::set< LogTag > type_tags
Definition: logging.hpp:95
const std::set< LogTag > & echoes()
Definition: logging.cpp:73
const std::string & message
Definition: logging.hpp:91
std::set< int > tags
Definition: logging.hpp:77
structure for storing log messages and metadata
Definition: logging.hpp:74
std::chrono::time_point< std::chrono::system_clock > time_point
Definition: logging.hpp:46
std::ofstream my_own_fstream
Definition: logging.hpp:148
GAMBIT file locking functions Use these to block access to sensitive parts of the code by other proce...
Logger virtual base class.
Definition: logging.hpp:109
Logging access header for GAMBIT.
std::ostream & my_stream
Definition: logging.hpp:149
Message(const std::string &msgIN, const std::set< int > &tagsIN)
Constructor.
Definition: logging.hpp:80
Headeer for logging classes.
void checktags()
Function to inspect tags and their associated strings. For testing purposes only. ...
Definition: logging.cpp:163
int MPIrank
MPI variables.
Definition: logging.hpp:152
const Utils::time_point & received_at
Definition: logging.hpp:92
Utils::time_point received_at
Definition: logging.hpp:78
std::set< int > component_tags
Definition: logging.hpp:96
const std::set< LogTag > & flags()
Definition: logging.cpp:65
Logger for &#39;standard&#39; messages.
Definition: logging.hpp:123
std::set< LogTag > echo_tags
Definition: logging.hpp:98
TODO: see if we can use this one:
Definition: Analysis.hpp:33
const std::set< LogTag > & msgtypes()
Definition: logging.cpp:57
time_point get_clock_now()
Get clock time.