How to Use a Service

Complete: 4

Configuring a Service

Services are configured in the configuration file similar to how modules and sources are configured. The syntax for configuring a service is shown below. For example

process.Foo = cms.Service('Foo',
    whatsIt  = cms.untracked.string("blah"),
    bar = cms.untracked.int32(10)
)

In this example, the name of the service is Foo. The service name appears twice (for those interested in the details, the first is the label given to the object in the python Process class and the second is the name of the plugin, these must match). The service may or may not have parameters that can be used to configure it. In this example, the service 'Foo' has two parameters named 'whatsIt' and 'bar'.

Accessing a Service

From within your C++ code, you access a service by using the Service<> handle template. The Service<> operates like a smart pointer to the requested service.

Service<Foo> foo; foo->bar();

or

Service<Foo>()->bar();

If the service is not available, an edm::Exception will be thrown when you attempt to dereference the Service<> smart pointer.

If you want to check to see if a particular service is available, you can either call the isAvailable() method or just use the handle instance in a comparison

if( Service<Foo>().isAvailable() )

or

if( Service<Foo>() )

Review Status

Reviewer/Editor and Date (copy from screen) Comments
ChrisDJones - 11 Sep 2005 page author
ChrisDJones - 04 Oct 2005 page content last edited
JennyWilliams - 07 Feb 2007 editing to include in SWGuide
WilliamTanenbaum - 11 Oct 2008 editing to add python configuration

Responsible: ChrisDJones
Last reviewed by: Reviewer

Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r7 - 2013-07-18 - DavidDagenhart



 
    • 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-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback