DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Printout.h
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation for LCD
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DD4HEP_PRINTOUT_H
14 #define DD4HEP_PRINTOUT_H
15 
16 // Framework include files
17 
18 // C/C++ include files
19 #include <cstdio>
20 #include <cstdlib>
21 #include <cstdarg>
22 #include <map>
23 #include <string>
24 #include <iostream>
25 
27 class TNamed;
28 
30 namespace DD4hep {
31 
32  // Forward declarations
33  class NamedObject;
34  template <typename T> class Handle;
35  typedef Handle<NamedObject> Ref_t;
36 
38  namespace Geometry {
39 
40  // Forward declarations
41  class LCDD;
42  class VisAttr;
43  class DetElement;
44  class PlacedVolume;
45  }
46 
47  enum PrintLevel {
48  NOLOG = 0,
49  VERBOSE = 1,
50  DEBUG = 2,
51  INFO = 3,
52  WARNING = 4,
53  ERROR = 5,
54  FATAL = 6,
55  ALWAYS = 7
56  };
57 
58 #ifndef __CINT__
59  typedef size_t (*output_function1_t)(void*, PrintLevel severity, const char*, const char*);
60  typedef size_t (*output_function2_t)(void*, PrintLevel severity, const char*, const char*, va_list& args);
61 
63 
68  std::string arguments(int argc, char** argv);
69 
71 
77  int printout(PrintLevel severity, const char* src, const char* fmt, ...);
78 
80 
86  int printout(PrintLevel severity, const std::string& src, const char* fmt, ...);
87 
89 
95  int printout(PrintLevel severity, const std::string& src, const std::string& fmt, ...);
96 
98 
104  int printout(PrintLevel severity, const char* src, const std::string& fmt, ...);
105 
107 
114  int printout(PrintLevel severity, const char* src, const char* fmt, va_list& args);
115 
117 
124  int printout(PrintLevel severity, const std::string& src, const char* fmt, va_list& args);
125 
127 
134  int printout(PrintLevel severity, const std::string& src, const std::string& fmt, va_list& args);
135 
137 
144  int printout(PrintLevel severity, const char* src, const std::string& fmt, va_list& args);
145 
147 
152  int except(const std::string& src, const std::string& fmt, ...);
153 
155 
160  int except(const char* src, const char* fmt, ...);
161 
163 
169  int except(const std::string& src, const std::string& fmt, va_list& args);
170 
172 
178  int except(const char* src, const char* fmt, va_list& args);
179 
181  /*
182  * @arg src [string,read-only] Information source (component, etc.)
183  * @arg fmt [string,read-only] Format string for ellipsis args
184  * @return Status code indicating success or failure
185  */
186  std::string format(const std::string& src, const std::string& fmt, ...);
187 
189 
194  std::string format(const char* src, const char* fmt, ...);
195 
197 
203  std::string format(const std::string& src, const std::string& fmt, va_list& args);
204 
206 
212  std::string format(const char* src, const char* fmt, va_list& args);
213 
215  void setPrinter(void* print_arg, output_function1_t fcn);
216 
218  void setPrinter2(void* print_arg, output_function2_t fcn);
219 
220 #endif // __CINT__
221 
223  std::string setPrintFormat(const std::string& new_format);
224 
227 
230 
232  PrintLevel printLevel(const char* value);
233 
235  PrintLevel printLevel(const std::string& value);
236 
238 
245  template <typename T> struct Printer {
249  std::ostream& os;
251  std::string prefix;
253  Printer(const Geometry::LCDD* l, std::ostream& stream, const std::string& p = "")
254  : lcdd(l), os(stream), prefix(p) {
255  }
257  void operator()(const T& value) const;
258  };
259 
260  template <typename T> inline std::ostream& print(const T& object, std::ostream& os = std::cout,
261  const std::string& indent = "") {
262  Printer<T>(0, os, indent)(object);
263  return os;
264  }
265 
267 
274  template <typename T> struct PrintMap {
275  typedef T item_type;
276  typedef const std::map<std::string, Ref_t> cont_type;
277 
281  std::ostream& os;
283  std::string text;
287  PrintMap(const Geometry::LCDD* l, std::ostream& stream, cont_type& c, const std::string& t = "")
288  : lcdd(l), os(stream), text(t), cont(c) {
289  }
291  void operator()() const;
292  };
293 
295  inline const char* yes_no(bool value) {
296  return value ? "YES" : "NO ";
297  }
299  inline const char* true_false(bool value) {
300  return value ? "true " : "false";
301  }
302 
303 } /* End namespace DD4hep */
304 #endif /* DD4HEP_PRINTOUT_H */
void operator()() const
Callback operator to be specialized depending on the element type.
Printer(const Geometry::LCDD *l, std::ostream &stream, const std::string &p="")
Initializing constructor of the functor.
Definition: Printout.h:253
void setPrinter2(void *print_arg, output_function2_t fcn)
Customize printer function.
Definition: Printout.cpp:371
Helper class template to implement ASCII dumps of named objects maps.
Definition: Printout.h:274
const char * true_false(bool value)
Helper function to print booleans in format true/false.
Definition: Printout.h:299
const char * yes_no(bool value)
Helper function to print booleans in format YES/NO.
Definition: Printout.h:295
cont_type & cont
Reference to the container data of the map.
Definition: Printout.h:285
Helper class template to implement ASCII object dumps.
Definition: Printout.h:245
const Geometry::LCDD * lcdd
Reference to the detector description object.
Definition: Printout.h:247
void operator()(const T &value) const
Callback operator to be specialized depending on the element type.
PrintLevel printLevel()
Access the current printer level.
Definition: Printout.cpp:323
int except(const std::string &src, const std::string &fmt,...)
Calls the display action with ERROR and throws an std::runtime_error exception.
Definition: Printout.cpp:217
std::ostream & os
Reference to the output stream object, the Printer object should write.
Definition: Printout.h:281
PrintLevel
Definition: Printout.h:47
DD4hep::Geometry::DetElement DetElement
std::string format(const std::string &src, const std::string &fmt,...)
Build formatted string.
Definition: Printout.cpp:267
size_t(* output_function1_t)(void *, PrintLevel severity, const char *, const char *)
Definition: Printout.h:59
const std::map< std::string, Ref_t > cont_type
Definition: Printout.h:276
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:34
std::string text
Optional text prefix when formatting the output.
Definition: Printout.h:283
void setPrinter(void *print_arg, output_function1_t fcn)
Customize printer function.
Definition: Printout.cpp:365
size_t(* output_function2_t)(void *, PrintLevel severity, const char *, const char *, va_list &args)
Definition: Printout.h:60
std::string setPrintFormat(const std::string &new_format)
Set new printout format for the 3 fields: source-level-message. All 3 are strings.
Definition: Printout.cpp:358
Handle< NamedObject > Ref_t
Default Ref_t definition describing named objects.
Definition: Handle.h:176
std::ostream & os
Reference to the output stream object, the Printer object should write.
Definition: Printout.h:249
The main interface to the DD4hep detector description package.
Definition: LCDD.h:82
std::string prefix
Optional text prefix when formatting the output.
Definition: Printout.h:251
PrintMap(const Geometry::LCDD *l, std::ostream &stream, cont_type &c, const std::string &t="")
Initializing constructor of the functor.
Definition: Printout.h:287
const Geometry::LCDD * lcdd
Reference to the detector description object.
Definition: Printout.h:279
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111
PrintLevel setPrintLevel(PrintLevel new_level)
Set new print level. Returns the old print level.
Definition: Printout.cpp:316
std::ostream & print(const T &object, std::ostream &os=std::cout, const std::string &indent="")
Definition: Printout.h:260
std::string arguments(int argc, char **argv)
Helper function to serialize argument list to a single string.
Definition: Printout.cpp:96