Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:44

0001 // -*- C++ -*-
0002 //
0003 // Package:     MessageLogger
0004 // Class  :     MessageDrop
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  M. Fischler and Jim Kowalkowsi
0010 //         Created:  Tues Feb 14 16:38:19 CST 2006
0011 //
0012 
0013 // system include files
0014 #include <cstring>
0015 #include <limits>
0016 
0017 // user include files
0018 #include "FWCore/MessageLogger/interface/MessageDrop.h"
0019 #include "FWCore/Utilities/interface/thread_safety_macros.h"
0020 
0021 using namespace edm;
0022 
0023 // The following are false at initialization (in case configure is not done)
0024 // and are set true at the start of configure_ordinary_destinations,
0025 // but are set false once a destination is thresholded to react to the
0026 // corresponding severity:
0027 bool MessageDrop::debugAlwaysSuppressed = false;
0028 bool MessageDrop::infoAlwaysSuppressed = false;
0029 bool MessageDrop::fwkInfoAlwaysSuppressed = false;
0030 bool MessageDrop::warningAlwaysSuppressed = false;
0031 std::string MessageDrop::jobMode{};
0032 
0033 MessageDrop* MessageDrop::instance() {
0034   thread_local static MessageDrop s_drop{};
0035   return &s_drop;
0036 }
0037 namespace {
0038   const std::string kBlankString{" "};
0039 }
0040 
0041 namespace edm {
0042   namespace messagedrop {
0043 
0044     class StringProducer {
0045     public:
0046       virtual ~StringProducer() {}
0047       virtual std::string theContext() const = 0;
0048     };
0049 
0050     class StringProducerWithPhase : public StringProducer {
0051     public:
0052       StringProducerWithPhase()
0053           : name_(&kBlankString),
0054             label_(&kBlankString),
0055             phasePtr_("(Startup)"),
0056             moduleID_(std::numeric_limits<unsigned int>::max()),
0057             cache_(),
0058             idLabelMap_() {}
0059 
0060       std::string theContext() const override {
0061         if (cache_.empty()) {
0062           if (moduleID_ != std::numeric_limits<unsigned int>::max()) {
0063             auto nameLableIter = idLabelMap_.find(moduleID_);
0064             if (nameLableIter != idLabelMap_.end()) {
0065               cache_.assign(nameLableIter->second);
0066               cache_.append(phasePtr_);
0067               return cache_;
0068             }
0069           }
0070           cache_.assign(*name_);
0071           cache_.append(":");
0072           cache_.append(*label_);
0073           idLabelMap_[moduleID_] = cache_;
0074           cache_.append(phasePtr_);
0075         }
0076         return cache_;
0077       }
0078       void set(std::string const& name, std::string const& label, unsigned int moduleID, const char* phase) {
0079         name_ = &name;
0080         label_ = &label;
0081         moduleID_ = moduleID;
0082         phasePtr_ = phase;
0083         cache_.clear();
0084       }
0085 
0086     private:
0087       std::string const* name_;
0088       std::string const* label_;
0089       const char* phasePtr_;
0090       unsigned int moduleID_;
0091 
0092       //This class is only used within a thread local object
0093       CMS_SA_ALLOW mutable std::string cache_;
0094       CMS_SA_ALLOW mutable std::map<unsigned int, std::string> idLabelMap_;
0095     };
0096 
0097     class StringProducerPath : public StringProducer {
0098     public:
0099       StringProducerPath()
0100           : typePtr_("PathNotYetEstablished")  // change log 4
0101             ,
0102             path_(" "),
0103             cache_() {}
0104       std::string theContext() const override {
0105         if (cache_.empty()) {
0106           cache_.assign(typePtr_);
0107           cache_.append(path_);
0108         }
0109         return cache_;
0110       }
0111       void set(const char* type, std::string const& pathname) {
0112         typePtr_ = type;
0113         path_ = pathname;
0114         cache_.clear();
0115       }
0116 
0117     private:
0118       const char* typePtr_;
0119       std::string path_;
0120       //This class is only used within a thread local object
0121       CMS_SA_ALLOW mutable std::string cache_;
0122     };
0123 
0124     class StringProducerSinglet : public StringProducer {
0125     public:
0126       StringProducerSinglet() : singlet_("(NoModuleName)") {}
0127       std::string theContext() const override { return singlet_; }
0128       void set(const char* sing) { singlet_ = sing; }
0129 
0130     private:
0131       const char* singlet_;
0132     };
0133 
0134   }  // namespace messagedrop
0135 
0136   MessageDrop::MessageDrop()
0137       : runEvent("pre-events"),
0138         streamID(std::numeric_limits<unsigned int>::max()),
0139         debugEnabled(true),
0140         infoEnabled(true),
0141         fwkInfoEnabled(true),
0142         warningEnabled(true),
0143         errorEnabled(true),
0144         spWithPhase(new messagedrop::StringProducerWithPhase),
0145         spPath(new messagedrop::StringProducerPath),
0146         spSinglet(new messagedrop::StringProducerSinglet),
0147         moduleNameProducer(spSinglet) {}
0148 
0149   MessageDrop::~MessageDrop() {
0150     delete spSinglet.get();
0151     delete spPath.get();
0152     delete spWithPhase.get();
0153   }
0154 
0155   void MessageDrop::setModuleWithPhase(std::string const& name,
0156                                        std::string const& label,
0157                                        unsigned int moduleID,
0158                                        const char* phase) {
0159     spWithPhase->set(name, label, moduleID, phase);
0160     moduleNameProducer = spWithPhase;
0161   }
0162 
0163   void MessageDrop::setPath(const char* type, std::string const& pathname) {
0164     spPath->set(type, pathname);
0165     moduleNameProducer = spPath;
0166   }
0167 
0168   void MessageDrop::setSinglet(const char* sing) {
0169     spSinglet->set(sing);
0170     moduleNameProducer = spSinglet;
0171   }
0172 
0173   std::string MessageDrop::moduleContext() { return moduleNameProducer->theContext(); }
0174   void MessageDrop::clear() { setSinglet(""); }
0175 }  // namespace edm
0176 
0177 unsigned char MessageDrop::messageLoggerScribeIsRunning = 0;