gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
logmaster.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
20 
21 #ifndef __logmaster_hpp__
22 #define __logmaster_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"
36 #include "gambit/Logs/log_tags.hpp"
37 
38 namespace Gambit
39 {
40 
41  namespace Logging
42  {
44  struct Message;
45  class BaseLogger;
46 
49  class LogMaster
50  {
51  public:
53  LogMaster();
54 
57  LogMaster(std::map<std::set<int>,BaseLogger*>&);
58 
62  ~LogMaster();
63 
65  void init_memory();
66 
68  // This is the function that yaml_parser.hpp uses. You provide tags as a set of strings, and the filename as a string. We then construct the logger objects in here.
69  // This needs to be a vector of pairs rather than a map in case people want duplicate output streams of certain logs. In this case there will be duplicate keys, which a map cannot allow.
70  void initialise(std::vector<std::pair< std::set<std::string>, std::string>>&);
71 
72  // Overload to allow using maps as input
73  void initialise(std::map<std::set<std::string>, std::string>&);
74 
75  // Overload of initialise function to allow easier manual initialisation in standalone modules
76  void initialise(std::map<std::string, std::string>&);
77 
78  // Function to silence all log messages
79  void disable();
80  // Function to check if all log messages are silenced
81  bool disabled();
82  // Turn logs back on
83  void enable();
84 
86  void emit_backlog(bool verbose);
87 
89  void input(const std::string&);
90  void input(const LogTag&);
91  void input(const endofmessage&);
92  // Overloads for stream manipulators (typedefs in logger.hpp)
93  void input(const manip1);
94  void input(const manip2);
95  void input(const manip3);
96 
98  // Need a bunch of overloads of this to deal with
99  void send(const std::string&);
100  void send(const std::string&,LogTag);
101  void send(const std::string&,LogTag,LogTag);
102  void send(const std::string&,LogTag,LogTag,LogTag);
103  void send(const std::string&,LogTag,LogTag,LogTag,LogTag);
104  void send(const std::string&,LogTag,LogTag,LogTag,LogTag,LogTag);
105  //...add more as needed
106 
107  // stringstream versions of the above
108  void send(const std::ostringstream&);
109  void send(const std::ostringstream&,LogTag);
110  void send(const std::ostringstream&,LogTag,LogTag);
111  void send(const std::ostringstream&,LogTag,LogTag,LogTag);
112  void send(const std::ostringstream&,LogTag,LogTag,LogTag,LogTag);
113  void send(const std::ostringstream&,LogTag,LogTag,LogTag,LogTag,LogTag);
114  //...add more as needed
115 
117  void send(const std::string&, std::set<LogTag>&);
118  void send(const std::string&, std::set<int>&);
119  void finalsend(const Message&);
120 
121  // stringstream versions...
122  void send(const std::ostringstream&, std::set<LogTag>&);
123  void send(const std::ostringstream&, std::set<int>&);
124 
126  void entering_module(int);
127  void leaving_module();
128  void entering_backend(int);
129  void leaving_backend();
130 
136 
139 
141 
142  private:
144  void empty_backlog();
145 
147  std::map<std::set<int>,BaseLogger*> loggers;
148 
150  std::set<int> ignore;
151 
154 
156  bool silenced;
157 
160 
163 
165  int MPIrank;
166  int MPIsize;
167 
170 
172 
174  int* current_module; // index -1 means "not in any module"
175  int* current_backend; // index -1 means "not in any backend"
176 
178  std::ostringstream* stream;
179  std::set<int>* streamtags;
180 
183  std::deque<Message>* backlog;
184 
186  };
187 
188  } //end namespace Logging
189 
190 } // end namespace Gambit
191 
192 #endif
std::deque< Message > * backlog
Messages sent before logger objects are created will be buffered Same for messages sent while inside ...
Definition: logmaster.hpp:183
void init_memory()
Initialise dynamic memory required for thread safety.
Definition: logmaster.cpp:93
bool log_debug_messages
Flag to ignore Debug tagged messages.
Definition: logmaster.hpp:162
bool loggers_readyQ
Flag to set whether loggers have been initialised not.
Definition: logmaster.hpp:153
void send(const std::string &)
Main logging function (user-friendly overloaded version)
Definition: logmaster.cpp:403
structure for storing log messages and metadata
Definition: logging.hpp:74
Logger virtual base class.
Definition: logging.hpp:109
std::map< std::set< int >, BaseLogger * > loggers
Map to identify loggers.
Definition: logmaster.hpp:147
void entering_module(int)
Set the internal variables tracking which module and/or backend is currently running.
Definition: logmaster.cpp:616
Logging access header for GAMBIT.
void emit_backlog(bool verbose)
Print the backlogs to the default log file.
Definition: logmaster.cpp:137
~LogMaster()
Destructor If errors happen before the inifile is loaded, we need to dump the log messages (that have...
Definition: logmaster.cpp:167
Headeer for logging classes.
LogMaster()
Default constructor.
Definition: logmaster.cpp:55
void empty_backlog()
Empty the backlog buffer to the &#39;send&#39; function.
Definition: logmaster.cpp:378
std::ostream &(* manip1)(std::ostream &)
Definition: logger.hpp:56
int * current_module
Variables that need to be threadsafe.
Definition: logmaster.hpp:174
void set_log_debug_messages(bool flag)
Choose whether "Debug" tagged log messages will be ignored (i.e. not logged)
Definition: logmaster.hpp:138
const bool verbose
Definition: logging.cpp:52
std::ostringstream * stream
Buffer variables needed for stream logging.
Definition: logmaster.hpp:178
Logging "controller" object Keeps track of the various "Logger" objects.
Definition: logmaster.hpp:49
std::set< int > ignore
Global ignore set; if these tags/integers are seen, ignore messages containing them.
Definition: logmaster.hpp:150
void initialise(std::vector< std::pair< std::set< std::string >, std::string >> &)
Function to construct loggers according to blueprint.
Definition: logmaster.cpp:223
Special (empty) struct for signalling end of message to LogMaster stream.
Definition: logger.hpp:43
bool separate_file_per_process
Flag to store log messages for different processes in separate files.
Definition: logmaster.hpp:159
int MPIrank
MPI variables.
Definition: logmaster.hpp:165
bool silenced
Flag to silence logger.
Definition: logmaster.hpp:156
std::set< int > * streamtags
Definition: logmaster.hpp:179
void input(const std::string &)
Functions for stream input (actual stream operators which use these are defined in logger...
Definition: logmaster.cpp:667
int globlMaxThreads
Max number of threads that could potentially be running.
Definition: logmaster.hpp:169
TODO: see if we can use this one:
Definition: Analysis.hpp:33
std::ios_base &(* manip3)(std::ios_base &)
Definition: logger.hpp:59
void finalsend(const Message &)
Version of send function used by buffer dump; skips all the tag modification stuff.
Definition: logmaster.cpp:570
ios_type &(* manip2)(ios_type &)
Definition: logger.hpp:58