MessageLogger Tutorial Examples

Contents

Sending Warnings and Error Messages to a File

# warningsToMyOutputFile.py
# -------------------------------

import FWCore.ParameterSet.Config as cms
process.MessageLogger = cms.Service("MessageLogger",
        destinations = cms.untracked.vstring(                           #1
                'myOutputFile'                                          #2
        ),
        myOutputFile = cms.untracked.PSet(                              #3
                threshold = cms.untracked.string( 'WARNINGS' )          #4
        ),
)                                                                       #5

# set the number of events
process.maxEvents = cms.untracked.PSet(
    input = cms.untracked.int32(200)
)
 
process.myAnalysisModule = cms.EDAnalyzer('ModuleThatIssuesMessages')
process.p = cms.Path(process.myAnalysisModule)

Explanation:

In the above example, one file, named myOutputFile.log, would be produced.

On line 1, we define a vstring named destinations=cms.untracked.vstring(... . Every confugration file should have this vstring defined; the name destinations is a keyword telling the logger that one or more files for output are going to be created.

On line 2, we name a file destination. In this example, this is the only destination we name. Two special names could have been used here: cerr or cout. Those would not produce files; they would route the output to cerr or cout.

On line 3, we start a PSet with a name matching one of the destinations we had specified. In this case, that name is myOutputFile. The contents of this PSet will control the behavior of just that destination. The name of the file produced will be taken from the name of the destination; by default, the logger adds the extension .log. (A later example will explain how to get an extension other than .log, or a file name other than the name of the destination PSet, if you want.)

On line 4, we are controlling the behavior of this destination. In this case, we are saying that the threshold for responding to messages issues is at the level of WARNING. This means that this destination will respond to (and output) message issued via edm::LogWarning and anything at least that serious. (For example, edm::LogPrint, edm::LogError, edm::LogProblem, and edm::LogImportant will lead to output.) But levels less severe than WARNING will not appear. For example, edm::LogInfo and edm::LogVerbatim will have no effect on this destination.

Line 5 completes the configuration of the MessageLogger. The other lines of this example are generic lines to tell cmsRun how many events to process, which modules to use, and so forth.

-- MarkFischler - 12-Aug-2010

Topic attachments
I Attachment History Action Size Date Who Comment
Cascading Style Sheet filecss tutorial.css r1 manage 0.2 K 2011-08-30 - 03:19 SudhirMalik  
Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r9 - 2013-10-23 - AndreaBocci
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright &© 2008-2023 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback