19
Gaudi Framework Tutorial, April 2006 3 3 Job Options and Printing

Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

Embed Size (px)

Citation preview

Page 1: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

Gaudi Framework Tutorial, April 2006

33

Job Options and PrintingJob Options and Printing

Page 2: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-2 Gaudi Framework Tutorial, April 2006

ObjectivesObjectives

After completing this lesson, you should After completing this lesson, you should be able to:be able to:

• Know how to implement job options in an algorithm.

• Know basic job options.

• Know how to print.

After completing this lesson, you should After completing this lesson, you should be able to:be able to:

• Know how to implement job options in an algorithm.

• Know basic job options.

• Know how to print.

Page 3: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-3 Gaudi Framework Tutorial, April 2006

Job OptionsJob Options

•Job is steered by “cards” fileJob is steered by “cards” file

•Options are not directly accessedOptions are not directly accessed

•Access through Access through IJobOptionsSvcIJobOptionsSvc interface interface

– Details hidden from users by the framework

•Job is steered by “cards” fileJob is steered by “cards” file

•Options are not directly accessedOptions are not directly accessed

•Access through Access through IJobOptionsSvcIJobOptionsSvc interface interface

– Details hidden from users by the framework

Page 4: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-4 Gaudi Framework Tutorial, April 2006

Job Options: Data TypesJob Options: Data Types

PrimitivesPrimitives

– bool, char, short, int, long, long long, float, double, std::string

– And unsigned char, short, int, long, long long

Arrays of primitivesArrays of primitives

– std::vector<bool>, std::vector<double>...

PrimitivesPrimitives

– bool, char, short, int, long, long long, float, double, std::string

– And unsigned char, short, int, long, long long

Arrays of primitivesArrays of primitives

– std::vector<bool>, std::vector<double>...

Page 5: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-5 Gaudi Framework Tutorial, April 2006

Declare the property in the Constructor, and Declare the property in the Constructor, and initialize it with a default valueinitialize it with a default value DecayTreeAlgorithm:: DecayTreeAlgorithm( <args> ) DecayTreeAlgorithm:: DecayTreeAlgorithm( <args> ) <initialization> <initialization> { { declareProperty( declareProperty( "DecayParticle", m_partName = "B0"); }

Declare the property in the Constructor, and Declare the property in the Constructor, and initialize it with a default valueinitialize it with a default value DecayTreeAlgorithm:: DecayTreeAlgorithm( <args> ) DecayTreeAlgorithm:: DecayTreeAlgorithm( <args> ) <initialization> <initialization> { { declareProperty( declareProperty( "DecayParticle", m_partName = "B0"); }

Declare property variable as data memberDeclare property variable as data member class DecayTreeAlgorithm : public GaudiAlgorithm { class DecayTreeAlgorithm : public GaudiAlgorithm { private: private: std::string std::string m_m_partName;partName; ...... }; };

Declare property variable as data memberDeclare property variable as data member class DecayTreeAlgorithm : public GaudiAlgorithm { class DecayTreeAlgorithm : public GaudiAlgorithm { private: private: std::string std::string m_m_partName;partName; ...... }; };

Using Job OptionsUsing Job Options

LHCb conventionLHCb convention

Page 6: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-6 Gaudi Framework Tutorial, April 2006

Set options in job options fileSet options in job options file– File path is first argument of executable

../$CMTDEB/Main.exe ../options/jobOptions.opts

– C++ like syntax– Example

B0_Decays.DecayParticle = “B0”;D0_Decays.DecayParticle = “D0”;

Set options in job options fileSet options in job options file– File path is first argument of executable

../$CMTDEB/Main.exe ../options/jobOptions.opts

– C++ like syntax– Example

B0_Decays.DecayParticle = “B0”;D0_Decays.DecayParticle = “D0”;

– Object name (Instance not class)– Object name (Instance not class)

Set Job OptionsSet Job Options

– Property name– Property name– Property value– Property value

Page 7: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-7 Gaudi Framework Tutorial, April 2006

Job Options: ConventionsJob Options: Conventions

Many algorithms need many optionsMany algorithms need many options

– Options go along with code– New code release may need different options– Must be configurable with cmt

– Need for conventions

Many algorithms need many optionsMany algorithms need many options

– Options go along with code– New code release may need different options– Must be configurable with cmt

– Need for conventions

Page 8: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-8 Gaudi Framework Tutorial, April 2006

ApplicationMgr.DLLs += { “STAlgorithms" };

ApplicationMgr.TopAlg += {

"MCSTDepositCreator/MCITDepositCreator" };

#include "$STALGORITHMSROOT/options/itDigi.opts“

ApplicationMgr.DLLs += { “STAlgorithms" };

ApplicationMgr.TopAlg += {

"MCSTDepositCreator/MCITDepositCreator" };

#include "$STALGORITHMSROOT/options/itDigi.opts“

LHCb conventionsLHCb conventionsLHCb applications organize sequencing of LHCb applications organize sequencing of algorithms, then take specific options algorithms, then take specific options from corresponding algorithms packagefrom corresponding algorithms package

LHCb applications organize sequencing of LHCb applications organize sequencing of algorithms, then take specific options algorithms, then take specific options from corresponding algorithms packagefrom corresponding algorithms package

MCITDepositCreator.tofVector = {25.9, 28.3, 30.5};

ToolSvc.STSignalToNoiseToolIT.conversionToADC = 0.0015;

MCITDepositCreator.tofVector = {25.9, 28.3, 30.5};

ToolSvc.STSignalToNoiseToolIT.conversionToADC = 0.0015;

Default values for the options should be Default values for the options should be hard-coded. Included options files modify hard-coded. Included options files modify these defaults.these defaults.

Default values for the options should be Default values for the options should be hard-coded. Included options files modify hard-coded. Included options files modify these defaults.these defaults.

Page 9: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-9 Gaudi Framework Tutorial, April 2006

ApplicationMgr.EvtMax <integer>

ApplicationMgr.DLLs <Array of string>

ApplicationMgr.TopAlg <Array of string>

ApplicationMgr.EvtMax <integer>

ApplicationMgr.DLLs <Array of string>

ApplicationMgr.TopAlg <Array of string>

Job Options You Must KnowJob Options You Must Know

• Maximal number of events to execute• Maximal number of events to execute• Component libraries to be loaded• Component libraries to be loaded• Top level algorithms: “Type/Name”

“DecayTreeAlgorithm/B0_Decays”This also defines the execution schedule

• Top level algorithms: “Type/Name”“DecayTreeAlgorithm/B0_Decays”This also defines the execution schedule

Page 10: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-10 Gaudi Framework Tutorial, April 2006

Job options printoutJob options printout

Contents of job options files is printed out Contents of job options files is printed out when Gaudi starts.when Gaudi starts.

- Control printing during processing:- Control printing during processing:

Contents of job options files is printed out Contents of job options files is printed out when Gaudi starts.when Gaudi starts.

- Control printing during processing:- Control printing during processing:

#pragma print off // Do not print options defined after this

#pragma print on // Switch back on

#pragma print off // Do not print options defined after this

#pragma print on // Switch back on

#printOptions#printOptions

- Print a single sorted list of all modified - Print a single sorted list of all modified options:options:- Print a single sorted list of all modified - Print a single sorted list of all modified options:options:

Page 11: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-11 Gaudi Framework Tutorial, April 2006

PrintingPrinting

Why not use std::cout, std::cerr, ... ?Why not use std::cout, std::cerr, ... ?

• Yes, it prints, but– Do you always want to print to the log file?

– How can you connect std::cout to the message window of an event display?

– You may want to switch on/off printing at several levels just for one given algorithm, service etc.

Why not use std::cout, std::cerr, ... ?Why not use std::cout, std::cerr, ... ?

• Yes, it prints, but– Do you always want to print to the log file?

– How can you connect std::cout to the message window of an event display?

– You may want to switch on/off printing at several levels just for one given algorithm, service etc.

Page 12: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-12 Gaudi Framework Tutorial, April 2006

Printing - MsgStreamPrinting - MsgStream

Using the Using the MsgStreamMsgStream class class• Usable like std::cout• Allows for different levels of printing

– MSG::VERBOSE (=1)– MSG::DEBUG (=2)– MSG::INFO (=3)– MSG::WARNING (=4)– MSG::ERROR (=5)– MSG::FATAL (=6)– MSG::ALWAYS (=7)

• Record oriented• Allows to define severity level per

object instance

Using the Using the MsgStreamMsgStream class class• Usable like std::cout• Allows for different levels of printing

– MSG::VERBOSE (=1)– MSG::DEBUG (=2)– MSG::INFO (=3)– MSG::WARNING (=4)– MSG::ERROR (=5)– MSG::FATAL (=6)– MSG::ALWAYS (=7)

• Record oriented• Allows to define severity level per

object instance

Page 13: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-13 Gaudi Framework Tutorial, April 2006

MsgStream - UsageMsgStream - Usage

Print error and return bad statusPrint error and return bad statusreturn Error("Cannot retrieve particle properties");return Error("Cannot retrieve particle properties");

Print error and return bad statusPrint error and return bad statusreturn Error("Cannot retrieve particle properties");return Error("Cannot retrieve particle properties");

Set printlevel in job optionsSet printlevel in job optionsMessageSvc.OutputLevel = 5; // MSG::ERRORMessageSvc.OutputLevel = 5; // MSG::ERROR MySvc.OutputLevel = 4; // MSG::WARNINGMySvc.OutputLevel = 4; // MSG::WARNINGMyAlgorithm.OutputLevel = 3; // MSG::INFOMyAlgorithm.OutputLevel = 3; // MSG::INFO

Set printlevel in job optionsSet printlevel in job optionsMessageSvc.OutputLevel = 5; // MSG::ERRORMessageSvc.OutputLevel = 5; // MSG::ERROR MySvc.OutputLevel = 4; // MSG::WARNINGMySvc.OutputLevel = 4; // MSG::WARNINGMyAlgorithm.OutputLevel = 3; // MSG::INFOMyAlgorithm.OutputLevel = 3; // MSG::INFO

Send to predefined message streamSend to predefined message streaminfo() << "PDG particle ID of " << m_partNameinfo() << "PDG particle ID of " << m_partName << " is " << m_partID << endmsg; << " is " << m_partID << endmsg;

err() << "Cannot retrieve properties for particle " err() << "Cannot retrieve properties for particle " << m_partName << endmsg; << m_partName << endmsg;

Send to predefined message streamSend to predefined message streaminfo() << "PDG particle ID of " << m_partNameinfo() << "PDG particle ID of " << m_partName << " is " << m_partID << endmsg; << " is " << m_partID << endmsg;

err() << "Cannot retrieve properties for particle " err() << "Cannot retrieve properties for particle " << m_partName << endmsg; << m_partName << endmsg;

Formatting with format( “string”, vars )Formatting with format( “string”, vars )debug() << format("E: %8.3f GeV", energy ) << endmsg;debug() << format("E: %8.3f GeV", energy ) << endmsg;Formatting with format( “string”, vars )Formatting with format( “string”, vars )debug() << format("E: %8.3f GeV", energy ) << endmsg;debug() << format("E: %8.3f GeV", energy ) << endmsg;

Page 14: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-14 Gaudi Framework Tutorial, April 2006

Hands On: DecayTreeAlgorithmHands On: DecayTreeAlgorithm

Introduce a propertyIntroduce a property– std::string called “DecayParticle”

– long called “DecayDepth”

Print value in DecayTreeAlgorithm usingPrint value in DecayTreeAlgorithm using– accessors to MsgStream class

– several severity levels

Add algorithm instance to top alg listAdd algorithm instance to top alg list– Name: B0_Decays

Introduce a propertyIntroduce a property– std::string called “DecayParticle”

– long called “DecayDepth”

Print value in DecayTreeAlgorithm usingPrint value in DecayTreeAlgorithm using– accessors to MsgStream class

– several severity levels

Add algorithm instance to top alg listAdd algorithm instance to top alg list– Name: B0_Decays

Page 15: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-15 Gaudi Framework Tutorial, April 2006

Hands On: If you have time left...Hands On: If you have time left...

Extend for printout of DExtend for printout of D00 decays decays

• Re-use the existing implementationRe-use the existing implementation

Play with printing directives:Play with printing directives:

#pragma print off#pragma print off

#pragma print on#pragma print on

#printOptions#printOptions

Extend for printout of DExtend for printout of D00 decays decays

• Re-use the existing implementationRe-use the existing implementation

Play with printing directives:Play with printing directives:

#pragma print off#pragma print off

#pragma print on#pragma print on

#printOptions#printOptions

Page 16: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-16 Gaudi Framework Tutorial, April 2006

Hands On: DecayTreeAlgorithm.hHands On: DecayTreeAlgorithm.h

class DecayTreeAlgorithm : public GaudiAlgorithm {

private:

/// Name of the particle to be analysed

std::string m_partName;

/// Integer property to set the depth of printout

long m_depth;

...

};

class DecayTreeAlgorithm : public GaudiAlgorithm {

private:

/// Name of the particle to be analysed

std::string m_partName;

/// Integer property to set the depth of printout

long m_depth;

...

};

Page 17: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-17 Gaudi Framework Tutorial, April 2006

Hands On: DecayTreeAlgorithm.cppHands On: DecayTreeAlgorithm.cpp

StatusCode DecayTreeAlgorithm::initialize() { debug() << “Decay Particle:” << m_partName << “Number of daughter generations in printout:” << m_depth << endmsg;}

StatusCode DecayTreeAlgorithm::initialize() { debug() << “Decay Particle:” << m_partName << “Number of daughter generations in printout:” << m_depth << endmsg;}

DecayTreeAlgorithm::DecayTreeAlgorithm( const std::string& name, ISvcLocator* pSvcLocator) : GaudiAlgorithm(name, pSvcLocator){ declareProperty( "DecayParticle", m_partName = "B0” ); declareProperty( "DecayDepth", m_depth = 2 );}

DecayTreeAlgorithm::DecayTreeAlgorithm( const std::string& name, ISvcLocator* pSvcLocator) : GaudiAlgorithm(name, pSvcLocator){ declareProperty( "DecayParticle", m_partName = "B0” ); declareProperty( "DecayDepth", m_depth = 2 );}

Page 18: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-18 Gaudi Framework Tutorial, April 2006

Hands On: B0DecayTree.optsHands On: B0DecayTree.opts

// Add B0 decay algorithm to list of top level algorithms

ApplicationMgr.TopAlg += {"DecayTreeAlgorithm/B0_Decays"};

// Setup of B0 decay algorithm

B0_Decays.DecayParticle = "B0";

B0_Decays.DecayDepth = 3;

// Add B0 decay algorithm to list of top level algorithms

ApplicationMgr.TopAlg += {"DecayTreeAlgorithm/B0_Decays"};

// Setup of B0 decay algorithm

B0_Decays.DecayParticle = "B0";

B0_Decays.DecayDepth = 3;

Page 19: Gaudi Framework Tutorial, April 2006 3 Job Options and Printing

3-19 Gaudi Framework Tutorial, April 2006

Hands On: add D0 decaysHands On: add D0 decays

// Add B0 decay algorithm to list of top level algorithms

ApplicationMgr.TopAlg += {"DecayTreeAlgorithm/B0_Decays"};

// Setup of B0 decay algorithm

B0_Decays.DecayParticle = "B0";

B0_Decays.DecayDepth = 3;

// Add B0 decay algorithm to list of top level algorithms

ApplicationMgr.TopAlg += {"DecayTreeAlgorithm/B0_Decays"};

// Setup of B0 decay algorithm

B0_Decays.DecayParticle = "B0";

B0_Decays.DecayDepth = 3;

// Add D0 decay algorithm to list of top level algorithms

ApplicationMgr.TopAlg += {"DecayTreeAlgorithm/D0_Decays"};

// Setup of D0 decay algorithm

D0_Decays.DecayParticle = “D0";

// Add D0 decay algorithm to list of top level algorithms

ApplicationMgr.TopAlg += {"DecayTreeAlgorithm/D0_Decays"};

// Setup of D0 decay algorithm

D0_Decays.DecayParticle = “D0";