Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:17:43

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 
0014 // Framework include files
0015 #include "XML/Printout.h"
0016 #include <stdexcept>
0017 
0018 // Disable some diagnostics for ROOT dictionaries
0019 #ifdef __GNUC__
0020 #pragma GCC diagnostic ignored "-Wvarargs"
0021 #endif
0022 
0023 using namespace std;
0024 
0025 namespace {
0026   string print_fmt = "%-16s %5s %s";
0027   dd4hep::PrintLevel print_lvl = dd4hep::INFO;
0028   const char* print_level(dd4hep::PrintLevel lvl)   {
0029     switch(lvl)   {
0030     case dd4hep::NOLOG:     return "NOLOG";
0031     case dd4hep::VERBOSE:   return "VERB ";
0032     case dd4hep::DEBUG:     return "DEBUG";
0033     case dd4hep::INFO:      return "INFO ";
0034     case dd4hep::WARNING:   return "WARN ";
0035     case dd4hep::ERROR:     return "ERROR";
0036     case dd4hep::FATAL:     return "FATAL";
0037     case dd4hep::ALWAYS:    return "     ";
0038     default:
0039       if ( lvl> dd4hep::ALWAYS )
0040         return print_level(dd4hep::ALWAYS);
0041       return print_level(dd4hep::NOLOG);
0042     }
0043   }
0044   size_t print_out(dd4hep::PrintLevel lvl, const char* src, const char* fmt, va_list& args) {
0045     char text[4096];
0046     ::snprintf(text,sizeof(text),print_fmt.c_str(),src,print_level(lvl),fmt);
0047     size_t len = ::vfprintf(stdout, text, args);
0048     ::fputc('\n',stdout);
0049     return len;
0050   }
0051 }
0052 
0053 /// Set new print level. Returns the old print level
0054 dd4hep::PrintLevel dd4hep::setPrintLevel(PrintLevel new_level) {
0055   PrintLevel old = print_lvl;
0056   print_lvl = new_level;
0057   return old;
0058 }
0059 
0060 /// Access the current printer level
0061 dd4hep::PrintLevel dd4hep::printLevel()  {
0062   return print_lvl;
0063 }
0064 
0065 
0066 /** Calls the display action
0067  *  \arg severity   [int,read-only]      Display severity flag
0068  *  \arg src        [string,read-only]   Information source (component, etc.)
0069  *  \arg fmt        [string,read-only]   Format string for ellipsis args
0070  *  \return Status code indicating success or failure
0071  */
0072 int dd4hep::printout(PrintLevel severity, const char* src, const char* fmt, ...) {
0073   if (severity >= print_lvl) {
0074     va_list args;
0075     va_start(args, fmt);
0076     print_out(severity, src, fmt, args);
0077     va_end(args);
0078   }
0079   return 1;
0080 }
0081 
0082 /** Calls the display action
0083  *  \arg severity   [int,read-only]      Display severity flag
0084  *  \arg src        [string,read-only]   Information source (component, etc.)
0085  *  \arg fmt        [string,read-only]   Format string for ellipsis args
0086  *  \return Status code indicating success or failure
0087  */
0088 int dd4hep::printout(PrintLevel severity, const string& src, const char* fmt, ...) {
0089   if (severity >= print_lvl) {
0090     va_list args;
0091     va_start(args, fmt);
0092     print_out(severity, src.c_str(), fmt, args);
0093     va_end(args);
0094   }
0095   return 1;
0096 }
0097 
0098 /** Calls the display action with ERROR and throws an std::runtime_error exception
0099  *  \arg src        [string,read-only]   Information source (component, etc.)
0100  *  \arg fmt        [string,read-only]   Format string for ellipsis args
0101  *  \return Status code indicating success or failure
0102  */
0103 int dd4hep::except(const char* src, const char* fmt, ...) {
0104   char str[4096];
0105   va_list args;
0106   va_start(args, fmt);
0107   size_t len1 = ::snprintf(str, sizeof(str), "%s: ", src);
0108   size_t len2 = ::vsnprintf(str + len1, sizeof(str) - len1, fmt, args);
0109   if ( len2 > sizeof(str) - len1 )  {
0110     len2 = sizeof(str) - len1 - 1;
0111     str[sizeof(str)-1] = 0;
0112   }
0113   printout(FATAL,src,fmt,args);
0114   va_end(args);
0115   throw runtime_error(str);
0116 }