Declaring Plugins

Complete: 5
Detailed Review status

Authors: J. Mans and P. Dudero

To allow cmsRun to load your analyzer, producer, filter, or output module, it must be declared to the PluginManager. This takes two steps. First add the following line to the CMS.BuildFile:

<flags EDM_PLUGIN=1>

Second add the following 2 lines to your source file (the file with the .cc suffix). Usually, the second line is placed at the bottom of the file.

#include "FWCore/Framework/interface/MakerMacros.h"

That is all you need to do and it is simple, but there are a couple pitfalls to be aware of. First, the DEFINE_FWK_MODULE macro does not usually handle namespaces very well. So if your module is defined in a namespace, you will want to declare it like this:

#include "FWCore/Framework/interface/MakerMacros.h"
using mynamespace::MyAnalyzer;

Second, there is some flexibility in which source file you place the DEFINE_FWK_MODULE macro and this determines which BuildFile needs to contain the line declaring the EDM_PLUGIN. You can find examples of many of the different possibilities in CMSSW code. The most simple case is when the package contains only one plug-in module and the code implementing this module is only used as a plugin. In this case, you can simply add the DEFINE_FWK MODULE macro to the bottom of your file. Then the EDM_PLUGIN line goes in the BuildFile in the top directory of the package as described in WorkBookBuildFilesIntro (put it just before declaring any exports).

Here is the second pitfall. If another package depends on code that is compiled into the same library as the plug-in, then this will not work. The other package will fail, because a library cannot be used both as a plug-in and also be directly used by some other package. In this case, you must create a directory named plugins. You can place the source file (the .cc file) containing the DEFINE_FWK_MODULE macro in the plugins directory instead of the src directory. Alternately, you can create a new file named in the plugins directory. Either case will work when there are multiple plug-in modules however moving the source files to the plugins directory is the recommended behavior. If you create a file you must put all the DEFINE_FWK_MODULE macros in this new file. This new file would look something like this:

#include "MyAnalysis/Analysis1/interface/MyAnalyzer1.h"
#include "MyAnalysis/Analysis1/interface/MyAnalyzer2.h"
#include "FWCore/Framework/interface/MakerMacros.h"


Then create a CMS.BuildFile in the plugins directory that contains the following:

<library name=MySystemMyPackagePlugins>
<flags EDM_PLUGIN=1>

If you put the DEFINE_FWK_MODULE macros in the file, then you have a choice whether to leave the main module source files in the src directory or put them in the plugins directory (does not matter). If you put them in the plugins directory, then you will also include the names of those files along with when declaring the library. Alternately, if you decide to leave them in the src directory you will need to declare a dependency to the library that includes them with a "use" statement in the CMS.BuildFile. There are more variations than this, but they all follow these basic rules. The library containing the code with the DEFINE_FWK_MODULE macro can only be used as a plug-in library. No other package can depend on that library. The CMS.BuildFile that defines the library which contains the DEFINE_FWK_MODULE macro must contain the EDM_PLUGIN declaration and the proper dependencies.

There can also be plug-in modules defined in a test subdirectory in the same manner as they are defined in the plugins directory.

Review status

Reviewer/Editor and Date (copy from screen) Comments
WilliamTanenbaum - 27 Nov 2008 generalized analyzer to module
ChrisDJones - 17 Sep 2008 clarified preferred behavior
DavidDagenhart - 25 Feb 2008 rewritten to correspond the current plugin manager
ChrisDJones - 02 Mar 2007 removed include and macros that will not work when CMS switches to new PluginManager
Last reviewed by: ChrisDJones - 13 Nov 2006 content was fine but I added the 'Important Note'
AnneHeavey - 06 Apr 2006 moved to WorkBook, fixed links, no content change
AnneHeavey - 17 Feb 2006 new page

Responsible: ChrisDJones
Last reviewed by: DavidDagenhart - 25 Feb 2008

Edit | Attach | Watch | Print version | History: r20 < r19 < r18 < r17 < r16 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r20 - 2009-11-25 - KatiLassilaPerini

    • 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