Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:13:38

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   /// Helper function to serialize argument list to a single string
0066   /**
0067    *  @arg argc       [int,read-only]      Number of arguments.
0068    *  @arg argv       [char**,read-only]   Argument strings
0069    *  @return String containing the concatenated arguments
0070    */
0071   std::string arguments(int argc, char** argv);
0072 
0073   /// Decode printlevel from string to value
0074   /**
0075    *  @arg level_as_string       [string,read-only]      String value of print level
0076    *  @return Print level as enumeration
0077    */
0078   PrintLevel decodePrintLevel(const std::string& level_as_string);
0079   
0080   /// Calls the display action with a given severity level
0081   /**
0082    *  @arg severity   [int,read-only]      Display severity flag (see enum)
0083    *  @arg src        [string,read-only]   Information source (component, etc.)
0084    *  @arg str        [stringstream, RW]   string stream containing data to be printed.
0085    *                                       Object is reset after use.
0086    *  @return Status code indicating success or failure
0087    */
0088   int printout(PrintLevel severity, const char* src, std::stringstream& str);
0089 
0090   /// Calls the display action with a given severity level
0091   /**
0092    *  @arg severity   [int,read-only]      Display severity flag (see enum)
0093    *  @arg src        [string,read-only]   Information source (component, etc.)
0094    *  @arg str        [stringstream, RW]   string stream containing data to be printed.
0095    *                                       Object is reset after use.
0096    *  @return Status code indicating success or failure
0097    */
0098   int printout(PrintLevel severity, const std::string& src, std::stringstream& str);
0099 
0100   /// Calls the display action with a given severity level
0101   /**
0102    *  @arg severity   [int,read-only]      Display severity flag (see enum)
0103    *  @arg src        [string,read-only]   Information source (component, etc.)
0104    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0105    *  @return Status code indicating success or failure
0106    */
0107   int printout(PrintLevel severity, const char* src, const char* fmt, ...);
0108 
0109   /// Calls the display action with a given severity level
0110   /**
0111    *  @arg severity   [int,read-only]      Display severity flag (see enum)
0112    *  @arg src        [string,read-only]   Information source (component, etc.)
0113    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0114    *  @return Status code indicating success or failure
0115    */
0116   int printout(PrintLevel severity, const std::string& src, const char* fmt, ...);
0117 
0118   /// Calls the display action with a given severity level
0119   /**
0120    *  @arg severity   [int,read-only]      Display severity flag (see enum)
0121    *  @arg src        [string,read-only]   Information source (component, etc.)
0122    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0123    *  @return Status code indicating success or failure
0124    */
0125   int printout(PrintLevel severity, const std::string& src, const std::string& fmt, ...);
0126 
0127   /// Calls the display action with a given severity level
0128   /**
0129    *  @arg severity   [int,read-only]      Display severity flag (see enum)
0130    *  @arg src        [string,read-only]   Information source (component, etc.)
0131    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0132    *  @return Status code indicating success or failure
0133    */
0134   int printout(PrintLevel severity, const char* src, const std::string& fmt, ...);
0135 
0136   /// Calls the display action with a given severity level
0137   /**
0138    *  @arg severity   [int,read-only]      Display severity flag (see enum)
0139    *  @arg src        [string,read-only]   Information source (component, etc.)
0140    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0141    *  @arg args       [ap_list,read-only]  List with variable number of arguments to fill format string.
0142    *  @return Status code indicating success or failure
0143    */
0144   int printout(PrintLevel severity, const char* src, const char* fmt, va_list& args);
0145 
0146   /// Calls the display action with a given severity level
0147   /**
0148    *  @arg severity   [int,read-only]      Display severity flag (see enum)
0149    *  @arg src        [string,read-only]   Information source (component, etc.)
0150    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0151    *  @arg args       [ap_list,read-only]  List with variable number of arguments to fill format string.
0152    *  @return Status code indicating success or failure
0153    */
0154   int printout(PrintLevel severity, const std::string& src, const char* fmt, va_list& args);
0155 
0156   /// Calls the display action with a given severity level
0157   /**
0158    *  @arg severity   [int,read-only]      Display severity flag (see enum)
0159    *  @arg src        [string,read-only]   Information source (component, etc.)
0160    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0161    *  @arg args       [ap_list,read-only]  List with variable number of arguments to fill format string.
0162    *  @return Status code indicating success or failure
0163    */
0164   int printout(PrintLevel severity, const std::string& src, const std::string& fmt, va_list& args);
0165 
0166   /// Calls the display action with a given severity level
0167   /**
0168    *  @arg severity   [int,read-only]      Display severity flag (see enum)
0169    *  @arg src        [string,read-only]   Information source (component, etc.)
0170    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0171    *  @arg args       [ap_list,read-only]  List with variable number of arguments to fill format string.
0172    *  @return Status code indicating success or failure
0173    */
0174   int printout(PrintLevel severity, const char* src, const std::string& fmt, va_list& args);
0175 
0176   /// Calls the display action with ERROR and throws an std::runtime_error exception
0177   /**
0178    *  @arg src        [string,read-only]   Information source (component, etc.)
0179    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0180    *  @return Status code indicating success or failure
0181    */
0182   int except(const std::string& src, const std::string& fmt, ...);
0183 
0184   /// Calls the display action with ERROR and throws an std::runtime_error exception
0185   /**
0186    *  @arg src        [string,read-only]   Information source (component, etc.)
0187    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0188    *  @return Status code indicating success or failure
0189    */
0190   int except(const char* src, const char* fmt, ...);
0191 
0192   /// Calls the display action with ERROR and throws an std::runtime_error exception
0193   /**
0194    *  @arg src        [string,read-only]   Information source (component, etc.)
0195    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0196    *  @arg args       [ap_list,read-only]  List with variable number of arguments to fill format string.
0197    *  @return Status code indicating success or failure
0198    */
0199   int except(const std::string& src, const std::string& fmt, va_list& args);
0200 
0201   /// Calls the display action with ERROR and throws an std::runtime_error exception
0202   /**
0203    *  @arg src        [string,read-only]   Information source (component, etc.)
0204    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0205    *  @arg args       [ap_list,read-only]  List with variable number of arguments to fill format string.
0206    *  @return Status code indicating success or failure
0207    */
0208   int except(const char* src, const char* fmt, va_list& args);
0209 
0210   /// Build formatted string
0211   /*
0212    *  @arg src        [string,read-only]   Information source (component, etc.)
0213    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0214    *  @return Status code indicating success or failure
0215    */
0216   std::string format(const std::string& src, const std::string& fmt, ...);
0217 
0218   /// Build exception string
0219   /**
0220    *  @arg src        [string,read-only]   Information source (component, etc.)
0221    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0222    *  @return Status code indicating success or failure
0223    */
0224   std::string format(const char* src, const char* fmt, ...);
0225 
0226   /// Build formatted string
0227   /**
0228    *  @arg src        [string,read-only]   Information source (component, etc.)
0229    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0230    *  @arg args       [ap_list,read-only]  List with variable number of arguments to fill format string.
0231    *  @return Status code indicating success or failure
0232    */
0233   std::string format(const std::string& src, const std::string& fmt, va_list& args);
0234 
0235   /// Build formatted string
0236   /**
0237    *  @arg src        [string,read-only]   Information source (component, etc.)
0238    *  @arg fmt        [string,read-only]   Format string for ellipsis args
0239    *  @arg args       [ap_list,read-only]  List with variable number of arguments to fill format string.
0240    *  @return Status code indicating success or failure
0241    */
0242   std::string format(const char* src, const char* fmt, va_list& args);
0243 
0244   /// Customize printer function
0245   void setPrinter(void* print_arg, output_function1_t fcn);
0246 
0247   /// Customize printer function
0248   void setPrinter2(void* print_arg, output_function2_t fcn);
0249 
0250 #endif // __CINT__
0251 
0252   /// Set new printout format for the 3 fields: source-level-message. All 3 are strings
0253   std::string setPrintFormat(const std::string& new_format);
0254 
0255   /// Set new print level. Returns the old print level
0256   PrintLevel setPrintLevel(PrintLevel new_level);
0257 
0258   /// Access the current printer level
0259   PrintLevel printLevel();
0260 
0261   /// Translate the printer level from string to value
0262   PrintLevel printLevel(const char* value);
0263 
0264   /// Translate the printer level from string to value
0265   PrintLevel printLevel(const std::string& value);
0266 
0267   /// Check if this print level would result in some output
0268   bool isActivePrintLevel(int severity);
0269 
0270   /// Helper function to print booleans in format YES/NO
0271   inline const char* yes_no(bool value) {
0272     return value ? "YES" : "NO ";
0273   }
0274   /// Helper function to print booleans in format true/false
0275   inline const char* true_false(bool value) {
0276     return value ? "true " : "false";
0277   }
0278 
0279 }         /* End namespace dd4hep              */
0280 #endif // PARSERS_PRINTOUT_H