Job Options file Hello World Options py Application
Job Options file (Hello. World. Options. py) Application Configuration options # Full job is a list of algorithms from Athena. Common. Alg. Sequence import Alg. Sequence job = Alg. Sequence() # Add top algorithms to be run from Ath. Ex. Hello. World. Conf import Hello. Alg job += Hello. Alg( "Hello. World" ) # 1 alg, named "Hello. World" # Set output level threshold (DEBUG, INFO, WARNING, ERROR, FATAL) # Output level for Hello. Alg only (note name: instance, not type) job. Hello. World. Output. Level = INFO Event related parameters # Number of events to be processed (default is until the end of input, or -1, # if we have no input, a limit needs to be set explicitly, here, choose 10) the. App. Evt. Max = 10
Algorithms Private Options (all optional) # For convenience, get a reference to the Hello. Algorithm # named "Hello. World" in the job Hello. World = job. Hello. World # Set an int property Hello. World. My. Int = 42 # Set a boolean property (False, True, 0, 1) Hello. World. My. Bool = True # Set a double property Hello. World. My. Double = 3. 14159 # Set a vector of strings property. . . Hello. World. My. String. Vec = [ "Welcome", "to", "Athena", "Framework", "Tutorial" ] #. . . and add one more: Hello. World. My. String. Vec += [ "!" ]
… more Algorithms Private Options # Set a map of strings to strings property. . . Hello. World. My. Dict = { 'Bonjour' : 'Guten Tag', 'Good Morning' : 'Bonjour' , 'one' : 'uno' } #. . . and add one more: Hello. World. My. Dict[ "Goeiedag" ] = "Ni Hao" # Set a table (a vector of pairs of doubles). . . Hello. World. My. Table = [ ( 1 , 1 ) , ( 2 , 4 ) , ( 3 , 9 ) ] #. . . and one more: Hello. World. My. Table += [ ( 4, 16 ) ] # Set a matrix (a vector of vectors). . . Hello. World. My. Matrix = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] #. . . and some more: Hello. World. My. Matrix += [ [ 7, 8, 9 ] ]
Algorithms Tool Usage Private Options (advanced and optional) # Import configurable for using our Hello. Tool from Ath. Ex. Hello. World. Conf import Hello. Tool # Setup a public tool so that it can be used (again, note name) Tool. Svc += Hello. Tool( "Public. Hello" ) Tool. Svc. Public. Hello. My. Message = "A Public Message!" # Tell "Hello. World" to use this tool ("My. Public. Hello. Tool" is a # Tool. Handle property of Hello. Alg) Hello. World. My. Public. Hello. Tool = Tool. Svc. Public. Hello # Hand "Hello. World" a private Hello. Tool ("My. Private. Hello. Tool" is # a Tool. Handler property of Hello. Alg) Hello. World. My. Private. Hello. Tool = Hello. Tool( "Hello. Tool" ) Hello. World. My. Private. Hello. Tool. My. Message = "A Private Message!"
Header file (Hello. Alg. h) Include basic features // -*- C++ -*#ifndef ATHEXHELLOWORLD_HELLOALG_H #define ATHEXHELLOWORLD_HELLOALG_H #include "Gaudi. Kernel/Tool. Handle. h" #include "Athena. Base. Comps/Ath. Algorithm. h" #include <string> #include <vector> #include <utility> #include <map> Specify tool template class IHello. Tool;
Declare class Hello. Alg as a descendent of Ath. Algorithm class Hello. Alg : public Ath. Algorithm { Declare its public methods public: Hello. Alg( const std: : string& name, ISvc. Locator* p. Svc. Locator ); Status. Code initialize(); Status. Code execute(); Status. Code finalize(); Status. Code begin. Run(); Status. Code end. Run();
Declare its private variables and methods private: int m_my. Int; bool m_my. Bool; double m_my. Double; std: : vector< std: : string > m_my. String. Vec; Tool. Handle< IHello. Tool > m_my. Private. Hello. Tool; Tool. Handle< IHello. Tool > m_my. Public. Hello. Tool; typedef std: : map<std: : string, std: : string> Dict_t; Dict_t m_my. Dict; typedef std: : vector<std: : pair<double, double> > Table_t; Table_t m_my. Table; typedef std: : vector<double> > Matrix_t; Matrix_t m_my. Matrix; };
Source file (Hello. Alg. cxx) Include basic features #include <iterator> Include headers for tool #include "Ath. Ex. Hello. World/IHello. Tool. h" #include "Hello. Alg. h" Algorithm Constructor Hello. Alg: : Hello. Alg(const std: : string& name, ISvc. Locator* p. Svc. Locator) : Ath. Algorithm(name, p. Svc. Locator), m_my. Int(0), m_my. Bool(0), m_my. Double(0), m_my. Private. Hello. Tool("Hello. Tool", this), m_my. Public. Hello. Tool("Hello. Tool"), m_my. Dict(), m_my. Table(), m_my. Matrix() {
Declare properties declare. Property("My. Int", m_my. Int); declare. Property("My. Bool", m_my. Bool); declare. Property("My. Double", m_my. Double); declare. Property("My. String. Vec", m_my. String. Vec, "an entire vector of strings!"); declare. Property("My. Private. Hello. Tool", m_my. Private. Hello. Tool, "private IHello. Tool"); declare. Property("My. Public. Hello. Tool", m_my. Public. Hello. Tool, "public, shared IHello. Tool"); declare. Property("My. Dict", m_my. Dict, "A little dictionary" ); // some default values; m_my. Dict["Bonjour"] = "Guten Tag"; m_my. Dict["Good Morning"] = "Bonjour"; m_my. Dict["one"] = "uno"; declare. Property("My. Table", m_my. Table, "A table of <double, double>" ); // some default values m_my. Table. push_back( std: : make_pair( 1. , 1. ) ); m_my. Table. push_back( std: : make_pair( 2. , 2. *2. ) ); m_my. Table. push_back( std: : make_pair( 3. , 3. *3. ) ); declare. Property("My. Matrix", m_my. Matrix, "A matrix of doubles" );
Status. Code Hello. Alg: : initialize() { Print where you are ATH_MSG_INFO ("Hello. Alg initialize()"); Print out the property values ATH_MSG_INFO ( " This is My. Int = " << m_my. Int << endreq << " My. Bool = " << (int)m_my. Bool << endreq << " My. Double = " << m_my. Double); for (unsigned int i=0; i<m_my. String. Vec. size(); i++) { ATH_MSG_INFO (" My. String. Vec[" << i << "] = " << m_my. String. Vec[i]); } for ( Dict_t: : const_iterator itr = m_my. Dict. begin(); itr != m_my. Dict. end(); ++itr ) { ATH_MSG_INFO (" My. Dict['" << itr->first << "'] = '" << itr->second << "'"); }
for ( Table_t: : const_iterator itr = m_my. Table. begin(); itr != m_my. Table. end(); ++itr ) { ATH_MSG_INFO (" My. Table['" << itr->first << "'] = '" << itr->second << "'"); } for (unsigned int i=0; i<m_my. Matrix. size(); i++) { msg(MSG: : INFO) << " My. Matrix[" << i << "] = [ "; std: : copy( m_my. Matrix[i]. begin(), m_my. Matrix[i]. end(), std: : ostream_iterator<double>(msg(). stream(), " ") ); msg() << "]" << endreq; } ATH_MSG_INFO (" " << m_my. Private. Hello. Tool. property. Name() << " = " << m_my. Private. Hello. Tool. type() << endreq << " " << m_my. Public. Hello. Tool. property. Name() << " = " << m_my. Public. Hello. Tool. type());
Retrive the tools using the Tool. Handles if ( m_my. Private. Hello. Tool. retrieve(). is. Failure() ) { ATH_MSG_FATAL (m_my. Private. Hello. Tool. property. Name() << ": Failed to retrieve tool " << m_my. Private. Hello. Tool. type()); return Status. Code: : FAILURE; } else { ATH_MSG_INFO (m_my. Private. Hello. Tool. property. Name() << ": Retrieved tool " << m_my. Private. Hello. Tool. type()); } if ( m_my. Public. Hello. Tool. retrieve(). is. Failure() ) { ATH_MSG_FATAL (m_my. Public. Hello. Tool. property. Name() << ": Failed to retrieve tool " << m_my. Public. Hello. Tool); return Status. Code: : FAILURE; } else { ATH_MSG_INFO (m_my. Public. Hello. Tool. property. Name() << ": Retrieved tool " << m_my. Public. Hello. Tool. type()); }
Status. Code Hello. Alg: : execute() { // Part 1: print where you are ATH_MSG_INFO ("execute()"); // Part 1: Print out the different levels of messages ATH_MSG_DEBUG ("A DEBUG message"); ATH_MSG_INFO ("An INFO message"); ATH_MSG_WARNING ("A WARNING message"); ATH_MSG_ERROR ("An ERROR message"); ATH_MSG_FATAL ("A FATAL error message"); // Part 1 a: Let publicly declared tool say something ATH_MSG_INFO ("Let the tool " << m_my. Public. Hello. Tool. property. Name() << " say something: "); Status. Code sc 1 = m_my. Public. Hello. Tool->say. Something(); // Part 1 b: Let privately declared tool say something ATH_MSG_INFO ("Let the tool " << m_my. Private. Hello. Tool. property. Name() << " say something: "); Status. Code sc 2 = m_my. Private. Hello. Tool->say. Something(); if ( sc 1. is. Failure() || sc 2. is. Failure() ) { return Status. Code: : FAILURE; } return Status. Code: : SUCCESS; }
Status. Code Hello. Alg: : finalize() { // Part 1: print where you are ATH_MSG_INFO ("finalize()"); return Status. Code: : SUCCESS; } // * * * * * * * * * * Status. Code Hello. Alg: : begin. Run() { // Part 1: print where you are ATH_MSG_INFO ("begin. Run()"); return Status. Code: : SUCCESS; } // * * * * * * * * * * Status. Code Hello. Alg: : end. Run() { // Part 1: print where you are ATH_MSG_INFO ("end. Run()"); return Status. Code: : SUCCESS; }
- Slides: 14