gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
baseprinter.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
21 
22 #ifndef __base_printer_hpp__
23 #define __base_printer_hpp__
24 
25 // Standard libraries
26 #include <vector>
27 
28 // Gambit
36 
38 
39 // Boost
40 #include <boost/preprocessor/seq/for_each_i.hpp>
41 
42 // Printable types
43 #ifndef SCANNER_STANDALONE
44  // If we are in a main gambit executable, we need to know all the GAMBIT printable types
46 #else
47  // Otherwise, we are in the ScannerBit standalone executable and need only a limited set.
49 
50  // Already dealt with in basebaseprinter? Can possibly do this to deal with
51  // lack of new types, rest will be inherited anyway.
52  #define PRINTABLE_TYPES SCANNER_PRINTABLE_TYPES
53  #define RETRIEVABLE_TYPES SCANNER_RETRIEVABLE_TYPES
54 #endif
55 
56 // This macro registers each printer so that they can be constructed automatically from inifile instructions
57 #define LOAD_PRINTER(tag, ...) REGISTER(printer_creators, tag, __VA_ARGS__)
58 
59 // This macro registers each reader so that they can be constructed automatically from inifile instructions
60 #define LOAD_READER(tag, ...) REGISTER(reader_creators, tag, __VA_ARGS__)
61 
62 // Code!
63 namespace Gambit
64 {
65  namespace Printers
66  {
67 
68  // Helper function for parsing ModelParameters label strings.
69  bool parse_label_for_ModelParameters(const std::string& fulllabel, const std::string& modelname, std::string& out, std::string& rest, bool case_sensitive=true);
70 
72  bool parse_label_for_spectrum_entry(const std::string& fulllabel, const std::string& req_capability, const std::string& req_module, const std::string& req_function, std::string& outname, std::string& outtag, std::string& labelroot, bool case_sensitive=true);
73 
75  void printAllTypeIDs(void);
76 
78  #define DECLARE_GETTYPEID(r,data,i,elem) \
79  template<> \
80  EXPORT_SYMBOLS std::size_t getTypeID<elem>(void);
82  #undef DECLARE_GETTYPEID
83 
84  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85  //% Printer class declarations %
86  //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87 
89  class BasePrinter: public BaseBasePrinter
90  {
91  private:
92  BasePrinter* primary_printer;
93  bool is_aux;
94 
95  public:
96  BasePrinter()
97  : primary_printer(NULL)
98  , is_aux(false)
99  {}
100 
101  BasePrinter(BasePrinter* const primary, bool is_aux_IN)
102  : primary_printer(primary)
103  , is_aux(is_aux_IN)
104  {}
105 
107  virtual ~BasePrinter() {}
108 
110  // Run by dependency resolver, which supplies the functors with a vector of VertexIDs whose requiresPrinting flags are set to true. (TODO: probably extend this to be a list of functors THIS printer is supposed to print, since we may want several printers handling different functors, for SLHA output or some such perhaps).
111  virtual void initialise(const std::vector<int>&) = 0;
112 
116  virtual void flush() = 0;
117 
118  // Get options required to construct a reader object that can read
119  // the previous output of this printer.
120  virtual Options resume_reader_options() = 0;
121 
123  void set_as_aux() { is_aux = true; }
124 
129  virtual void auxilliary_init() {};
130 
131  BasePrinter* get_primary_printer()
132  {
133  if(not is_aux)
134  {
135  std::ostringstream err;
136  err << "Error! Tried to retrieve pointer to primary printer from a "
137  << "printer object not flagged as auxilliary!";
138  printer_error().raise(LOCAL_INFO,err.str());
139  }
140  else if(primary_printer==NULL)
141  {
142  std::ostringstream err;
143  err << "Error! Tried to retrieve pointer to primary printer, but it "
144  << "is NULL! Something has gone wrong in the initialisation of "
145  << "the printer system.";
146  printer_error().raise(LOCAL_INFO,err.str());
147  }
148  return primary_printer;
149  }
150  bool is_auxilliary_printer() { return is_aux; }
151 
152 
153  // Printer dispatch function. This is defined already
154  // in the BaseBasePrinter class, but I think I need it
155  // here as well so that that BasePrinter version can
156  // detect the new virtual function overloads which exist
157  // in this class.
158  template<typename T>
159  void print(T const& in, const std::string& label,
160  const int vertexID, const uint rank,
161  const ulong pointID)
162  {
163  if(printer_enabled) _print(in, label, vertexID, rank, pointID);
164  }
165 
166  // Overload which automatically determines a unique ID code
167  // based on the label.
168  template<typename T>
169  void print(T const& in, const std::string& label,
170  const uint rank,
171  const ulong pointID)
172  {
173  if(printer_enabled) _print(in, label, rank, pointID);
174  }
175 
176  protected:
177  using BaseBasePrinter::_print; //unhide the default function in the base class
178 
179  // We need to have a virtual print method for every type that we want to
180  // be able to print. The list of these types is maintained in
181  // "gambit/Elements/printable_types.hpp"
182  // Run the macro; add all the print functions
184 
185  };
186 
189  {
190  public:
192 
194  virtual ~BaseReader() {}
195 
197  // Need to do this because otherwise we end up using the scanner-only templates for the retrieves,
198  // rather than the full set available here.
199  template<typename T>
200  bool retrieve(T& out, const std::string& label)
201  {
202  PPIDpair pt = get_current_point();
203  return retrieve(out, label, pt.rank, pt.pointID);
204  }
205 
206  // retrieve function dispatch
207  template<typename T>
208  bool retrieve(T& out, const std::string& label, const uint rank, const ulong pointID)
209  {
210  return _retrieve(out, label, rank, pointID);
211  }
212 
214  bool retrieve_and_print(const std::string& in_label, const std::string& out_label, BaseBasePrinter& printer, const uint rank, const ulong pointID);
215 
216  protected:
217  using BaseBaseReader::_retrieve; //unhide the default function in the base class
218 
219  // We need to have a virtual 'retrieve' method for every type that we want to
220  // be able to retrieve. The list of these types is maintained in
221  // "gambit/Elements/printable_types.hpp"
222  // Run the macro; add all the print functions
224 
225  };
226 
227 
230  // (uses the same machinery as in priors.hpp)
231  // Note: Arguments to e.g printer_creators need to match constructor for printer object
232  // e.g. printer_creators.at(tag)(args...)
233  // (this is set up by the typedef)
235  {
236  typedef BasePrinter* create_printer_function(const Options&, BasePrinter* const&);
238 
241  }
242 
243  } //end namespace Printers
244 } // end namespace Gambit
245 
246 
247 #endif //ifndef __base_printer_hpp__
void print(MixMatrix A)
Helper function to print a matrix.
Utility functions used by ScannerBit and the GAMBIT printers to register available scanners and print...
bool _retrieve(T &, const std::string &label, const uint, const ulong)
Default _retrieve function.
unsigned long long int pointID
EXPORT_SYMBOLS error & printer_error()
Printer errors.
virtual ~BaseReader()
Destructor.
Header for logging classes.
reg_elem< create_printer_function > printer_creators
#define LOCAL_INFO
Definition: local_info.hpp:34
BOOST_PP_SEQ_FOR_EACH_I(GETTYPEID, _, PRINTABLE_TYPES) void printAllTypeIDs(void)
For debugging; print to stdout all the typeIDs for all types.
Definition: baseprinter.cpp:36
BaseReader * create_reader_function(const Options &)
Declarations for the YAML options class.
#define PRINTABLE_TYPES
#define ADD_VIRTUAL_RETRIEVALS(TYPES)
#define ADD_VIRTUAL_PRINTS(TYPES)
Printers::BaseBasePrinter printer
Type of the printer objects.
#define RETRIEVABLE_TYPES
Copies of boost headers that are required but that may be too recent to be present on the user&#39;s mach...
BASE PRINTER CLASS.
void printAllTypeIDs(void)
For debugging; print to stdout all the typeIDs for all types.
reg_elem< create_reader_function > reader_creators
bool retrieve(T &out, const std::string &label)
Reimplement overload for &#39;retrieve&#39; that uses the current point as the input for rank/pointID.
unsigned long int ulong
#define DECLARE_GETTYPEID(r, data, i, elem)
Declare specialisations of type ID getters.
Definition: baseprinter.hpp:78
List of types printable by GAMBIT printers.
Exception objects required for standalone compilation.
void _print(T const &, const std::string &label, const int vertexID, const uint, const ulong)
Default _print function.
Preprocessor sequence of functor types that should be allowed to print when using ScannerBit in stand...
Class for holding model parameters.
This is a minimal (pure virtual) precursor to the printer base class, for use only in ScannerBit...
gambit_registry
Maps in which to keep factory functions for the printers (printer_creators) and readers (reader_creat...
Helper macro for controlling symbol visibility in shared libraries.
bool parse_label_for_spectrum_entry(const std::string &fulllabel, const std::string &req_capability, const std::string &req_module, const std::string &req_function, std::string &outname, std::string &outtag, std::string &labelroot, bool case_sensitive=true)
Helper function for parsing Spectrum label strings.
pointID / process number pair Used to identify a single parameter space point
TODO: see if we can use this one:
Definition: Analysis.hpp:33
A small wrapper object for &#39;options&#39; nodes.
bool parse_label_for_ModelParameters(const std::string &fulllabel, const std::string &modelname, std::string &out, std::string &rest, bool case_sensitive=true)
Helper function for the ModelParameters &#39;_retrieve&#39; functions Parses a printer label and checks if it...
Definition: baseprinter.cpp:81
bool retrieve(T &out, const std::string &label, const uint rank, const ulong pointID)