Modules

From Mu2eWiki
Revision as of 15:14, 23 March 2017 by Rlc (talk | contribs) (Created page with "==Module Names== Consider a class named <font color=red>MyClass</font> that you wish to make into a module that can be manipulated by the framework. First, your class must i...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Module Names

Consider a class named MyClass that you wish to make into a module that can be manipulated by the framework. First, your class must inherit from one of the module base classes, EDAnalyzer, EDProducer or EDFilter. Second it must follow the following rules, all of which are case sensitive.

  1. It must be in a file named MyClass_module.cc.
  2. The build system will make this into a file named lib/libMyClass_module.so.
  3. The module source file must look like:
  4. namespace mu2e { class MyClass : public art::EDAnalyzer { public: explicit MyClass(fhicl::ParameterSet const& pset); // Compiler generated d'tor is OK. void analyze( art::Event const& event ); }; MyClass::MyClass(fhicl::ParameterSet const& pset){ // Body of the constructor. You can access information in the parameter set here. } void MyClass::analyze(art::Event const& event){ mf::LogVerbatim("test") << "Hello, world. From analyze. " << event.id(); } } // end namespace mu2e using mu2e::MyClass; DEFINE_ART_MODULE(MyClass); This example is for an analyzer. To create a producer or a filter module, you must inherit from either art::EDProducer or art::EDFilter. The last line invokes a macro that inserts additional code into the .so file ( for the experts: it inserts a factory method to produce an instance of the class and it inserts and auto-registration object that registers the factory method with art's module registry ).
  5. To declare this module to the framework you need to have a fragment like the following in your .fcl file:
  6. physics : { analyzers: { looseCuts : { module_type  : MyClass } # Other analyzer modules listed here ... } } The string looseCuts is called a module label and is defined below .
  7. The previous item was for the case that your module is an analyzer. If it is a producer or filter, then the text in green needs to be either producers or filters.
  8. When you put a data product into an event, the data provenance system records the module label of the module that did the put.

Module Labels

Consider the following fragment from a .fcl file,

physics: {
  producers: {
    looseCuts: { module_type   : MyClass }
  }
}
  1. The string looseCuts is refered to as the module module label; I have sometimes called this module "instance name" but the code refers to it as ModuleLabel.
  2. The above fragment may be expaned to include additional arguments, that will be treated as the definition of a parameter set to be given to the object. For example,
  3. physics : { analyzers: { looseCuts : { module_type  : MyClass cutLevel : 1 } tightCuts : { module_type  : MyClass cutLevel : 2 } } } The parameter cutLevel is available to the contructor of MyClass via the fhicl::ParameterSet argument.
  4. In this example two modules are defined, both are of type EDAnalzer and both are instances of the class MyClass. They are distinguished by having different values in the parameter sets and by having different module labels. The name cutLevel has no meaning to the framework: presumably it has meaning within MyClass.