iConfig Parameter Set

See also: Description of the cmsRun Python Configuration Syntax for examples in the use of iConfig parameters.

An example of getting from python to CMSSW:

In Python file, define, for example, the string run and the vector xtalid
run = '163796'
xtalid = [155685227, 27, 54, 1]

To pass these to the CMSSW analyzer, HeepAnalyzer, along with an InputTag:
process.demo = cms.EDAnalyzer('HeepAnalyzer',
                runnum = cms.untracked.string(run),
      xtalidcfg = cms.untracked.vint32(xtalid),
                EEuncalibRecHitCollection = cms.InputTag("ecalWeightUncalibRecHit:EcalUncalibRecHitsEE"),
                EEdigiCollection = cms.InputTag("ecalEBunpacker","eeDigis")             
)

In CMSSW, in: 
class HeepAnalyzer : public edm::EDAnalyzer {
   public:
      explicit HeepAnalyzer(const edm::ParameterSet&);
      ~HeepAnalyzer();

      static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
   private:
      virtual void beginJob() ;
      virtual void analyze(const edm::Event&, const edm::EventSetup&);
      virtual void endJob() ;

      virtual void beginRun(edm::Run const&, edm::EventSetup const&);
      virtual void endRun(edm::Run const&, edm::EventSetup const&);
      virtual void beginLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
      virtual void endLuminosityBlock(edm::LuminosityBlock const&, edm::EventSetup const&);
      // ----------member data ---------------------------
     string run;
     std::vector< int > xtalid;
     edm::InputTag EEdigiCollection_;
     edm::InputTag EEuncalibRecHitCollection_;
};

Then get the iConfig info:
HeepAnalyzer::HeepAnalyzer(const edm::ParameterSet& iConfig)
{
     run = iConfig.getUntrackedParameter<string>("runnum");
     xtalid = iConfig.getUntrackedParameter< std::vector < int> >("xtalidcfg");
     EEdigiCollection_ =  iConfig.getParameter<edm::InputTag>("EEdigiCollection");
     EEuncalibRecHitCollection_ = iConfig.getParameter<edm::InputTag>("EEuncalibRecHitCollection");
}

Then loop over events and use the passed variables in:
void HeepAnalyzer::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {

Parameters

Each C++ class that gets created from a Python object can be configured via its associated ParameterSet. For most of the types of objects the framework actually creates a ParameterSet object used to configure the related component of the executable. Each such object can contain any, or all, of the following types of named parameters, in any number or combination. NOTE: the examples assume one has done import ParameterSet.Config as cms so we can use the short name cms rather than the verbose name FWCore.ParameterSet.Config when refering to the Python objects.

Keyword C++ type Example
bool bool b = cms.bool(False)
int32 int i = cms.int32(-234)
uint32 unsigned i = cms.uint32(2112)
vint32 std::vector<int> v = cms.vint32( 1, -3, 5 )
vuint32 std::vector<unsigned> v =cms.vuint32( 0, 1, 0 )
int64 boost::int64_t i = cms.int64(-234)
uint64 boost::uint64_t i = cms.uint64(2112)
vint64 std::vector<boost::int64_t> v = cms.vint64( 1, -3, 5 )
vuint64 std::vector<boost::uint64_t> v =cms.vuint64( 0, 1, 0 )
string std::string s = cms.string("spaces are allowed")
s = cms.string('single quotes allowed')
vstring std::vector<std::string> v = cms.vstring( 'thing one', "thing two")
double double d = cms.double(-3.43e-34)
vdouble std::vector<double> v = cms.vdouble(1.2, 3, 4.5e-100, -inf)
FileInPath edm::FileInPath particleFile = cms.FileInPath("SimGeneral/HepPDTESSource/data/particle.tbl")
InputTag edm::InputTag inputTag = cms.InputTag("simrec","jets")
VInputTag std::vector<edm::InputTag> jetTags = cms.VInputTag( cms.InputTag("simrec","jets"), cms.InputTag("cone5CMS.CaloJets"))
EventID edm::EventID e = cms.EventID(1,1,1)
CmsRange None yet r = cms.CmsRange(1,1,5,999)
VCmsRange std::vector<None yet> ranges = cms.VCmsRange( (1,1,5,0), (8,1,9,10),) (0 corresponds to MAX)
PSet edm::ParameterSet see below
VPSet std::vector<edm::ParameterSet> see below

Note that empty vectors are legal; e.g.,

    c = cms.vint32( )
creates an empty integer vector named "c".

The system keeps track of what parameters are used to create each data item in the Event. This can be used later to help understand how the data was made. However, sometimes a parameter will have no effect on the final objects created, e.g., the parameter just sets how much debugging information should be printed to the log. Such parameters are 'untracked'.

To see how parameters are defined, here is a sample :

import FWCore.ParameterSet.Config as cms
source = cms.Source("FlatRandomEGunSource",     
    # Here we define a parameter set (PSet) to be used by the source, 
    # and give it the name PGunParameters:
    PGunParameters =cms.PSet(
         # you can request more than one particle, e.g.:
         # PartID = cms.vint32(211,11)   # but we just request one this time:
         PartID = cms.vint32(211),
         MinEta = cms.double(-3.5),
         MaxEta =  cms.double(3.5),
         MinPhi = cms.double(-3.14159265358979323846), # in radians
         MaxPhi =  cms.double(3.14159265358979323846),
         MinE   =  cms.double(9.99),
         MaxE   = cms.double(10.01)
      ),
      Verbosity = cms.untracked.int32(0) # set to 1 (or greater)  for printouts
   )

For modules with many parameters, it can be painful to have to write every single one of them in a job's configuration program. Instead, you may consult the module's "configuration fragment include" ( cfi) file which specifies the module's parameters and their default values. The cfi file is used as the default configuration; you only need to specify (replace) parameters in your configuration ( cfg) program whose values differ from the default values. The cfi files are located in the data directory of the package which contains the module. The name of the file should match the 'module label' assigned to the module from within the cfi file, and should end with the suffix _cfi.py.

For example, in SimG4Core/Application/test/runP-WithPythiaAndQGSP.cfg, see the "include" statement, followed by a "replace" statement:

   from IOMC/GeneratorInterface/data/PythiaSourceMinBias_cfi import source
   source.pythiaVerbosity = True

This reads in the specified cfi file which starts with this contents:

import FWCore.ParameterSet.Config as cms
import IOMC.GeneratorInterface.pythiaDefault_cff as defaults

source = cms.ESSource("PythiaSource",  
  pythiaVerbosity = cms.untracked.bool(False)
This parameter gets replaced in the cfg file. Further along in the cfi file:
  • a parameter set (PSet) is defined whose parameters refer to the card file and the vstring parameters (discussed below)
  PythiaParameters = cms.PSet(
    # This is a vector of ParameterSet names to be read, in this order
    # The first two are in the include files below
    # The last one are simply my additional parameters
    parameterSets = cms.vstring(
      "pythiaDefault", 
      "pythiaMinBias", 
      "myParameters"
    )
  • two vstring parameters are defined (pythiaMinBias and myParameters)
    pythiaMinBias = cms.vstring(
      'MSEL=0         ! User defined processes',
      'MSUB(11)=1     ! Min bias process',
       ...
      'MSTJ(11)=3     ! Choice of the fragmentation function',
      'MSTJ(22)=2     ! Decay those unstable particles',
      'PARJ(71)=10 .  ! for which ctau  10 mm',
      'MSTP(2)=1      ! which order running alphaS',
      'MSTP(33)=0     ! no K factors in hard cross sections',
       ... (many more parameter definitions follow)
      )
    myParameters = cms.vstring(
    #  'MRPY(1)= 123456789 ! Automatically random if -1')
  • add the contents of the pythiaDefault_cff file,
    ).extend(defaults)

-- DavidCockerill - 08-Apr-2011

Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r2 - 2011-08-03 - DavidCockerill
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright &© 2008-2024 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