![]() |
|
|||
File indexing completed on 2025-07-01 08:45:41
0001 //========================================================================== 0002 // AIDA Detector description implementation 0003 //-------------------------------------------------------------------------- 0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) 0005 // All rights reserved. 0006 // 0007 // For the licensing terms see $DD4hepINSTALL/LICENSE. 0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS. 0009 // 0010 // Author : M.Frank 0011 // 0012 //========================================================================== 0013 #ifndef PARSERS_PRINTOUT_H 0014 #define PARSERS_PRINTOUT_H 0015 0016 // Framework include files 0017 #include <Parsers/config.h> 0018 0019 // C/C++ include files 0020 #include <cstdio> 0021 #include <cstdlib> 0022 #include <cstdarg> 0023 #include <string> 0024 #include <sstream> 0025 //#include <iostream> 0026 0027 /// Forward declarations 0028 class TNamed; 0029 0030 /// Namespace for the AIDA detector description toolkit 0031 namespace dd4hep { 0032 0033 // Forward declarations 0034 class Detector; 0035 class NamedObject; 0036 template <typename T> class Handle; 0037 0038 enum PrintLevel { 0039 NOLOG = 0, 0040 VERBOSE = 1, 0041 DEBUG = 2, 0042 INFO = 3, 0043 WARNING = 4, 0044 ERROR = 5, 0045 FATAL = 6, 0046 ALWAYS = 7, 0047 0048 /// Forced printout levels if the output level is handled 0049 /// e.g. by a Geant4Action or DigiAction. These always pass 0050 /// The default DD4hep print level restrictions. 0051 FORCE_LEVEL = 0x10, 0052 FORCE_VERBOSE = FORCE_LEVEL + 1, 0053 FORCE_DEBUG = FORCE_LEVEL + 2, 0054 FORCE_INFO = FORCE_LEVEL + 3, 0055 FORCE_WARNING = FORCE_LEVEL + 4, 0056 FORCE_ERROR = FORCE_LEVEL + 5, 0057 FORCE_FATAL = FORCE_LEVEL + 6, 0058 FORCE_ALWAYS = FORCE_LEVEL + 7 0059 }; 0060 0061 #ifndef __CINT__ 0062 typedef size_t (*output_function1_t)(void*, PrintLevel severity, const char*, const char*); 0063 typedef size_t (*output_function2_t)(void*, PrintLevel severity, const char*, const char*, va_list& args); 0064 0065 namespace detail { 0066 /// Multi-thread save, locked printout to stdout 0067 std::size_t printf(const char* fmt, ...); 0068 /// Multi-thread save, locked printout to stderr 0069 std::size_t errprintf(const char* fmt, ...); 0070 } 0071 0072 /// Helper function to serialize argument list to a single string 0073 /** 0074 * @arg argc [int,read-only] Number of arguments. 0075 * @arg argv [char**,read-only] Argument strings 0076 * @return String containing the concatenated arguments 0077 */ 0078 std::string arguments(int argc, char** argv); 0079 0080 /// Decode printlevel from string to value 0081 /** 0082 * @arg level_as_string [string,read-only] String value of print level 0083 * @return Print level as enumeration 0084 */ 0085 PrintLevel decodePrintLevel(const std::string& level_as_string); 0086 0087 /// Calls the display action with a given severity level 0088 /** 0089 * @arg severity [int,read-only] Display severity flag (see enum) 0090 * @arg src [string,read-only] Information source (component, etc.) 0091 * @arg str [stringstream, RW] string stream containing data to be printed. 0092 * Object is reset after use. 0093 * @return Status code indicating success or failure 0094 */ 0095 int printout(PrintLevel severity, const char* src, std::stringstream& str); 0096 0097 /// Calls the display action with a given severity level 0098 /** 0099 * @arg severity [int,read-only] Display severity flag (see enum) 0100 * @arg src [string,read-only] Information source (component, etc.) 0101 * @arg str [stringstream, RW] string stream containing data to be printed. 0102 * Object is reset after use. 0103 * @return Status code indicating success or failure 0104 */ 0105 int printout(PrintLevel severity, const std::string& src, std::stringstream& str); 0106 0107 /// Calls the display action with a given severity level 0108 /** 0109 * @arg severity [int,read-only] Display severity flag (see enum) 0110 * @arg src [string,read-only] Information source (component, etc.) 0111 * @arg fmt [string,read-only] Format string for ellipsis args 0112 * @return Status code indicating success or failure 0113 */ 0114 int printout(PrintLevel severity, const char* src, const char* fmt, ...); 0115 0116 /// Calls the display action with a given severity level 0117 /** 0118 * @arg severity [int,read-only] Display severity flag (see enum) 0119 * @arg src [string,read-only] Information source (component, etc.) 0120 * @arg fmt [string,read-only] Format string for ellipsis args 0121 * @return Status code indicating success or failure 0122 */ 0123 int printout(PrintLevel severity, const std::string& src, const char* fmt, ...); 0124 0125 /// Calls the display action with a given severity level 0126 /** 0127 * @arg severity [int,read-only] Display severity flag (see enum) 0128 * @arg src [string,read-only] Information source (component, etc.) 0129 * @arg fmt [string,read-only] Format string for ellipsis args 0130 * @return Status code indicating success or failure 0131 */ 0132 int printout(PrintLevel severity, const std::string& src, const std::string& fmt, ...); 0133 0134 /// Calls the display action with a given severity level 0135 /** 0136 * @arg severity [int,read-only] Display severity flag (see enum) 0137 * @arg src [string,read-only] Information source (component, etc.) 0138 * @arg fmt [string,read-only] Format string for ellipsis args 0139 * @return Status code indicating success or failure 0140 */ 0141 int printout(PrintLevel severity, const char* src, const std::string& fmt, ...); 0142 0143 /// Calls the display action with a given severity level 0144 /** 0145 * @arg severity [int,read-only] Display severity flag (see enum) 0146 * @arg src [string,read-only] Information source (component, etc.) 0147 * @arg fmt [string,read-only] Format string for ellipsis args 0148 * @arg args [ap_list,read-only] List with variable number of arguments to fill format string. 0149 * @return Status code indicating success or failure 0150 */ 0151 int printout(PrintLevel severity, const char* src, const char* fmt, va_list& args); 0152 0153 /// Calls the display action with a given severity level 0154 /** 0155 * @arg severity [int,read-only] Display severity flag (see enum) 0156 * @arg src [string,read-only] Information source (component, etc.) 0157 * @arg fmt [string,read-only] Format string for ellipsis args 0158 * @arg args [ap_list,read-only] List with variable number of arguments to fill format string. 0159 * @return Status code indicating success or failure 0160 */ 0161 int printout(PrintLevel severity, const std::string& src, const char* fmt, va_list& args); 0162 0163 /// Calls the display action with a given severity level 0164 /** 0165 * @arg severity [int,read-only] Display severity flag (see enum) 0166 * @arg src [string,read-only] Information source (component, etc.) 0167 * @arg fmt [string,read-only] Format string for ellipsis args 0168 * @arg args [ap_list,read-only] List with variable number of arguments to fill format string. 0169 * @return Status code indicating success or failure 0170 */ 0171 int printout(PrintLevel severity, const std::string& src, const std::string& fmt, va_list& args); 0172 0173 /// Calls the display action with a given severity level 0174 /** 0175 * @arg severity [int,read-only] Display severity flag (see enum) 0176 * @arg src [string,read-only] Information source (component, etc.) 0177 * @arg fmt [string,read-only] Format string for ellipsis args 0178 * @arg args [ap_list,read-only] List with variable number of arguments to fill format string. 0179 * @return Status code indicating success or failure 0180 */ 0181 int printout(PrintLevel severity, const char* src, const std::string& fmt, va_list& args); 0182 0183 /// Calls the display action with ERROR and throws an std::runtime_error exception 0184 /** 0185 * @arg src [string,read-only] Information source (component, etc.) 0186 * @arg fmt [string,read-only] Format string for ellipsis args 0187 * @return Status code indicating success or failure 0188 */ 0189 int except(const std::string& src, const std::string& fmt, ...); 0190 0191 /// Calls the display action with ERROR and throws an std::runtime_error exception 0192 /** 0193 * @arg src [string,read-only] Information source (component, etc.) 0194 * @arg fmt [string,read-only] Format string for ellipsis args 0195 * @return Status code indicating success or failure 0196 */ 0197 int except(const char* src, const char* fmt, ...); 0198 0199 /// Calls the display action with ERROR and throws an std::runtime_error exception 0200 /** 0201 * @arg src [string,read-only] Information source (component, etc.) 0202 * @arg fmt [string,read-only] Format string for ellipsis args 0203 * @arg args [ap_list,read-only] List with variable number of arguments to fill format string. 0204 * @return Status code indicating success or failure 0205 */ 0206 int except(const std::string& src, const std::string& fmt, va_list& args); 0207 0208 /// Calls the display action with ERROR and throws an std::runtime_error exception 0209 /** 0210 * @arg src [string,read-only] Information source (component, etc.) 0211 * @arg fmt [string,read-only] Format string for ellipsis args 0212 * @arg args [ap_list,read-only] List with variable number of arguments to fill format string. 0213 * @return Status code indicating success or failure 0214 */ 0215 int except(const char* src, const char* fmt, va_list& args); 0216 0217 /// Build formatted string 0218 /* 0219 * @arg src [string,read-only] Information source (component, etc.) 0220 * @arg fmt [string,read-only] Format string for ellipsis args 0221 * @return Status code indicating success or failure 0222 */ 0223 std::string format(const std::string& src, const std::string& fmt, ...); 0224 0225 /// Build exception string 0226 /** 0227 * @arg src [string,read-only] Information source (component, etc.) 0228 * @arg fmt [string,read-only] Format string for ellipsis args 0229 * @return Status code indicating success or failure 0230 */ 0231 std::string format(const char* src, const char* fmt, ...); 0232 0233 /// Build formatted string 0234 /** 0235 * @arg src [string,read-only] Information source (component, etc.) 0236 * @arg fmt [string,read-only] Format string for ellipsis args 0237 * @arg args [ap_list,read-only] List with variable number of arguments to fill format string. 0238 * @return Status code indicating success or failure 0239 */ 0240 std::string format(const std::string& src, const std::string& fmt, va_list& args); 0241 0242 /// Build formatted string 0243 /** 0244 * @arg src [string,read-only] Information source (component, etc.) 0245 * @arg fmt [string,read-only] Format string for ellipsis args 0246 * @arg args [ap_list,read-only] List with variable number of arguments to fill format string. 0247 * @return Status code indicating success or failure 0248 */ 0249 std::string format(const char* src, const char* fmt, va_list& args); 0250 0251 /// Customize printer function 0252 void setPrinter(void* print_arg, output_function1_t fcn); 0253 0254 /// Customize printer function 0255 void setPrinter2(void* print_arg, output_function2_t fcn); 0256 0257 #endif // __CINT__ 0258 0259 /// Set new printout format for the 3 fields: source-level-message. All 3 are strings 0260 std::string setPrintFormat(const std::string& new_format); 0261 0262 /// Set new print level. Returns the old print level 0263 PrintLevel setPrintLevel(PrintLevel new_level); 0264 0265 /// Access the current printer level 0266 PrintLevel printLevel(); 0267 0268 /// Translate the printer level from string to value 0269 PrintLevel printLevel(const char* value); 0270 0271 /// Translate the printer level from string to value 0272 PrintLevel printLevel(const std::string& value); 0273 0274 /// Check if this print level would result in some output 0275 bool isActivePrintLevel(int severity); 0276 0277 /// Helper function to print booleans in format YES/NO 0278 inline const char* yes_no(bool value) { 0279 return value ? "YES" : "NO "; 0280 } 0281 /// Helper function to print booleans in format true/false 0282 inline const char* true_false(bool value) { 0283 return value ? "true " : "false"; 0284 } 0285 0286 } /* End namespace dd4hep */ 0287 #endif // PARSERS_PRINTOUT_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |