1 / 14

Job Options file (HelloWorldOptions.py)

Job Options file (HelloWorldOptions.py). Application Configuration options. # Full job is a list of algorithms from AthenaCommon.AlgSequence import AlgSequence job = AlgSequence() # Add top algorithms to be run from AthExHelloWorld.AthExHelloWorldConf import HelloAlg

dinos
Download Presentation

Job Options file (HelloWorldOptions.py)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Job Options file (HelloWorldOptions.py) • Application Configuration options # Full job is a list of algorithms from AthenaCommon.AlgSequence import AlgSequence job = AlgSequence() # Add top algorithms to be run from AthExHelloWorld.AthExHelloWorldConf import HelloAlg job += HelloAlg( "HelloWorld" ) # 1 alg, named "HelloWorld" # Set output level threshold (DEBUG, INFO, WARNING, ERROR, FATAL) # Output level for HelloAlg only (note name: instance, not type) job.HelloWorld.OutputLevel = 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) theApp.EvtMax = 10

  2. Algorithms Private Options (all optional) # For convenience, get a reference to the HelloAlg Algorithm # named "HelloWorld" in the job HelloWorld = job.HelloWorld # Set an int property HelloWorld.MyInt = 42 # Set a boolean property (False, True, 0, 1) HelloWorld.MyBool = True # Set a double property HelloWorld.MyDouble = 3.14159 # Set a vector of strings property ... HelloWorld.MyStringVec = [ "Welcome", "to", "Athena", "Framework", "Tutorial" ] # ... and add one more: HelloWorld.MyStringVec += [ "!" ]

  3. … more Algorithms Private Options # Set a map of strings to strings property ... HelloWorld.MyDict = { 'Bonjour' : 'Guten Tag', 'Good Morning' : 'Bonjour' , 'one' : 'uno' } # ... and add one more: HelloWorld.MyDict[ "Goeiedag" ] = "Ni Hao" # Set a table (a vector of pairs of doubles) ... HelloWorld.MyTable = [ ( 1 , 1 ) , ( 2 , 4 ) , ( 3 , 9 ) ] # ... and one more: HelloWorld.MyTable += [ ( 4, 16 ) ] # Set a matrix (a vector of vectors) ... HelloWorld.MyMatrix = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ] # ... and some more: HelloWorld.MyMatrix += [ [ 7, 8, 9 ] ]

  4. Algorithms Tool Usage Private Options (advanced and optional) # Import configurable for using our HelloTool from AthExHelloWorld.AthExHelloWorldConf import HelloTool # Setup a public tool so that it can be used (again, note name) ToolSvc += HelloTool( "PublicHello" ) ToolSvc.PublicHello.MyMessage ="A Public Message!" # Tell "HelloWorld" to use this tool ("MyPublicHelloTool" is a # ToolHandle property of HelloAlg) HelloWorld.MyPublicHelloTool = ToolSvc.PublicHello # Hand "HelloWorld" a private HelloTool ("MyPrivateHelloTool" is # a ToolHandler property of HelloAlg) HelloWorld.MyPrivateHelloTool = HelloTool( "HelloTool" ) HelloWorld.MyPrivateHelloTool.MyMessage = "A Private Message!"

  5. Header file (HelloAlg.h) • Include basic features // -*- C++ -*- #ifndef ATHEXHELLOWORLD_HELLOALG_H #define ATHEXHELLOWORLD_HELLOALG_H #include "GaudiKernel/ToolHandle.h" #include "AthenaBaseComps/AthAlgorithm.h" #include <string> #include <vector> #include <utility> #include <map> • Specify tool template class IHelloTool;

  6. Declare class HelloAlg as a descendent of AthAlgorithm class HelloAlg : public AthAlgorithm { • Declare its public methods public: HelloAlg( const std::string& name, ISvcLocator* pSvcLocator ); StatusCode initialize(); StatusCode execute(); StatusCode finalize(); StatusCode beginRun(); StatusCode endRun();

  7. Declare its private variables and methods private: int m_myInt; bool m_myBool; double m_myDouble; std::vector< std::string > m_myStringVec; ToolHandle< IHelloTool > m_myPrivateHelloTool; ToolHandle< IHelloTool > m_myPublicHelloTool; typedef std::map<std::string, std::string> Dict_t; Dict_t m_myDict; typedef std::vector<std::pair<double, double> > Table_t; Table_t m_myTable; typedef std::vector<std::vector<double> > Matrix_t; Matrix_t m_myMatrix; };

  8. Source file(HelloAlg.cxx) • Include basic features #include <iterator> • Include headers for tool #include "AthExHelloWorld/IHelloTool.h" #include "HelloAlg.h" • Algorithm Constructor HelloAlg::HelloAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthAlgorithm(name, pSvcLocator), m_myInt(0), m_myBool(0), m_myDouble(0), m_myPrivateHelloTool("HelloTool",this), m_myPublicHelloTool("HelloTool"), m_myDict(), m_myTable(), m_myMatrix() {

  9. Declare properties declareProperty("MyInt", m_myInt); declareProperty("MyBool", m_myBool); declareProperty("MyDouble", m_myDouble); declareProperty("MyStringVec",m_myStringVec, "an entire vector of strings!"); declareProperty("MyPrivateHelloTool", m_myPrivateHelloTool, "private IHelloTool"); declareProperty("MyPublicHelloTool", m_myPublicHelloTool, "public, shared IHelloTool"); declareProperty("MyDict", m_myDict, "A little dictionary" ); // some default values; m_myDict["Bonjour"] = "Guten Tag"; m_myDict["Good Morning"] = "Bonjour"; m_myDict["one"] = "uno"; declareProperty("MyTable", m_myTable, "A table of <double,double>" ); // some default values m_myTable.push_back( std::make_pair( 1., 1. ) ); m_myTable.push_back( std::make_pair( 2., 2.*2. ) ); m_myTable.push_back( std::make_pair( 3., 3.*3. ) ); declareProperty("MyMatrix", m_myMatrix, "A matrix of doubles" );

  10. StatusCode HelloAlg::initialize() { • Print where you are ATH_MSG_INFO ("HelloAlg initialize()"); • Print out the property values ATH_MSG_INFO ( " This is MyInt = " << m_myInt << endreq << " MyBool = " << (int)m_myBool << endreq << " MyDouble = " << m_myDouble); for (unsigned int i=0; i<m_myStringVec.size(); i++) { ATH_MSG_INFO (" MyStringVec[" << i << "] = " << m_myStringVec[i]); } for ( Dict_t::const_iterator itr = m_myDict.begin(); itr != m_myDict.end(); ++itr ) { ATH_MSG_INFO (" MyDict['" << itr->first << "'] = '" << itr->second << "'"); }

  11. for ( Table_t::const_iterator itr = m_myTable.begin(); itr != m_myTable.end(); ++itr ) { ATH_MSG_INFO (" MyTable['" << itr->first << "'] = '" << itr->second << "'"); } for (unsigned int i=0; i<m_myMatrix.size(); i++) { msg(MSG::INFO) << " MyMatrix[" << i << "] = [ "; std::copy( m_myMatrix[i].begin(), m_myMatrix[i].end(), std::ostream_iterator<double>(msg().stream(), " ") ); msg() << "]" << endreq; } ATH_MSG_INFO (" " << m_myPrivateHelloTool.propertyName() << " = " << m_myPrivateHelloTool.type() << endreq << " " << m_myPublicHelloTool.propertyName() << " = " << m_myPublicHelloTool.type());

  12. Retrive the tools using the ToolHandles if ( m_myPrivateHelloTool.retrieve().isFailure() ) { ATH_MSG_FATAL (m_myPrivateHelloTool.propertyName() << ": Failed to retrieve tool " << m_myPrivateHelloTool.type()); return StatusCode::FAILURE; } else { ATH_MSG_INFO (m_myPrivateHelloTool.propertyName() << ": Retrieved tool " << m_myPrivateHelloTool.type()); } if ( m_myPublicHelloTool.retrieve().isFailure() ) { ATH_MSG_FATAL (m_myPublicHelloTool.propertyName() << ": Failed to retrieve tool " << m_myPublicHelloTool); return StatusCode::FAILURE; } else { ATH_MSG_INFO (m_myPublicHelloTool.propertyName() << ": Retrieved tool " << m_myPublicHelloTool.type()); }

  13. StatusCode HelloAlg::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 1a: Let publicly declared tool say something ATH_MSG_INFO ("Let the tool " << m_myPublicHelloTool.propertyName() << " say something:"); StatusCode sc1 = m_myPublicHelloTool->saySomething(); // Part 1b: Let privately declared tool say something ATH_MSG_INFO ("Let the tool " << m_myPrivateHelloTool.propertyName() << " say something:"); StatusCode sc2 = m_myPrivateHelloTool->saySomething(); if ( sc1.isFailure() || sc2.isFailure() ) { return StatusCode::FAILURE; } return StatusCode::SUCCESS; }

  14. StatusCode HelloAlg::finalize() { // Part 1: print where you are ATH_MSG_INFO ("finalize()"); return StatusCode::SUCCESS; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * StatusCode HelloAlg::beginRun() { // Part 1: print where you are ATH_MSG_INFO ("beginRun()"); return StatusCode::SUCCESS; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * StatusCode HelloAlg::endRun() { // Part 1: print where you are ATH_MSG_INFO ("endRun()"); return StatusCode::SUCCESS; }

More Related