Gaudi Framework, version v24r2

Home   Generated: Wed Dec 4 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
JobOptionsSvc.cpp
Go to the documentation of this file.
1 // ============================================================================
2 // Boost:
3 // ============================================================================
4 #include <boost/foreach.hpp>
5 // ============================================================================
6 // Local:
7 // ============================================================================
8 #include "JobOptionsSvc.h"
9 #include "Analyzer.h"
10 #include "Messages.h"
11 #include "Catalog.h"
12 #include "Units.h"
13 #include "PragmaOptions.h"
14 #include "Node.h"
15 // ============================================================================
16 // Gaudi:
17 // ============================================================================
18 #include "GaudiKernel/IProperty.h"
19 #include "GaudiKernel/Property.h"
20 
21 #include "GaudiKernel/SvcFactory.h"
22 #include "GaudiKernel/MsgStream.h"
23 #include "GaudiKernel/System.h"
24 // ============================================================================
26 // ============================================================================
27 // Namespace aliases:
28 // ============================================================================
29 namespace gp = Gaudi::Parsers;
30 // ============================================================================
31 JobOptionsSvc::JobOptionsSvc(const std::string& name,ISvcLocator* svc):
32 base_class(name,svc),
33 m_pmgr()
34 , m_source_path()
35 , m_source_type()
36 , m_dir_search_path()
37 , m_dump()
38 {
39  std::string tmp ;
40  tmp = System::getEnv ( "JOBOPTSEARCHPATH" ) ;
41  if ( !tmp.empty() && ("UNKNOWN" != tmp) ) { m_dir_search_path = tmp ; }
42  tmp = System::getEnv ( "JOBOPTSDUMPFILE" ) ;
43  if ( !tmp.empty() && ("UNKNOWN" != tmp) ) { m_dump = tmp ; }
44 
45  m_pmgr.declareProperty( "TYPE" , m_source_type ) ;
46  m_pmgr.declareProperty( "PATH" , m_source_path ) ;
47  m_pmgr.declareProperty( "SEARCHPATH" , m_dir_search_path ) ;
48  m_pmgr.declareProperty( "DUMPFILE" , m_dump ) ;
49 }
50 // ============================================================================
52 {
53  return m_pmgr.setProperty( p );
54 }
55 // ============================================================================
57 {
58 
59  return m_pmgr.getProperty( p );
60 }
61 // ============================================================================
63 {
64  // Call base class initializer
66  if( !sc.isSuccess() ) return sc;
67  // Read the job options if needed
68  if ( this->m_source_type == "NONE" ) {
70  }
71  else {
73  }
74  return sc;
75 }
76 
78 {
79  // finalize the base class
80  return Service::finalize();
81 }
82 // ============================================================================
84 ( const std::string& client,
85  const Property& property )
86 {
87  Property* p = new StringProperty ( property.name(), "" ) ;
88  if ( !property.load( *p ) ) { delete p ; return StatusCode::FAILURE ; }
89  return m_svc_catalog.addProperty( client , p );
90 }
91 // ============================================================================
94 ( const std::string& client,
95  const std::string& name )
96 {
97  return m_svc_catalog.removeProperty(client,name);
98 }
99 // ============================================================================
102 {
103  return m_svc_catalog.getProperties(client);
104 }
105 // ============================================================================
107  IProperty* myInt )
108 {
109  const SvcCatalog::PropertiesT* props =
111 
112  if ( NULL == props ){ return StatusCode::SUCCESS; }
113 
114  bool fail = false;
116  cur != props->end(); cur++)
117  {
118  StatusCode sc = myInt->setProperty (**cur ) ;
119  if ( sc.isFailure() )
120  {
121  MsgStream my_log( this->msgSvc(), this->name() );
122  my_log
123  << MSG::ERROR
124  << "Unable to set the property '" << (*cur)->name() << "'"
125  << " of '" << client << "'. "
126  << "Check option and algorithm names, type and bounds."
127  << endmsg;
128  fail = true;
129  }
130  }
131  return fail ? StatusCode::FAILURE : StatusCode::SUCCESS ;
132 }
133 
136  return m_svc_catalog.getClients();
137 }
138 
139 
141  const gp::Catalog& catalog) const {
142  MsgStream log ( msgSvc() , name() ) ;
143  std::ofstream out
144  ( file.c_str() , std::ios_base::out | std::ios_base::trunc ) ;
145  // perform the actual dumping
146  if ( !out ) {
147  log << MSG::ERROR << "Unable to open dump-file \""+file+"\"" << endmsg ;
148  return ; // RETURN
149  }
150  else {
151  log << MSG::INFO << "Properties are dumped into \""+file+"\"" << endmsg ;
152  }
153  // perform the actual dump:
154  out << catalog;
155 }
156 
157 void JobOptionsSvc::fillServiceCatalog(const gp::Catalog& catalog) {
158  BOOST_FOREACH(const gp::Catalog::value_type& client, catalog) {
159  for (gp::Catalog::CatalogSet::mapped_type::const_iterator current
160  = client.second.begin(); current != client.second.end();
161  ++current) {
162  StringProperty tmp (current->NameInClient(), current->ValueAsString()) ;
163  addPropertyToCatalogue ( client.first , tmp ) ;
164  }
165  }
166 }
167 
169  const std::string& path) {
170  std::string search_path = path;
171  if ( search_path.empty() && !m_dir_search_path.empty() )
172  { search_path = m_dir_search_path ; }
173  //
174  MsgStream my_log( this->msgSvc(), this->name() );
175  if (UNLIKELY(outputLevel() <= MSG::DEBUG))
176  my_log << MSG::DEBUG // debug
177  << "Reading options from the file "
178  << "'" << file << "'" << endmsg;
179  gp::Messages messages(my_log);
180  gp::Catalog catalog;
181  gp::Units units;
182  gp::PragmaOptions pragma;
183  gp::Node ast;
184  StatusCode sc = gp::ReadOptions(file, path, &messages, &catalog, &units,
185  &pragma, &ast);
186 
187  // --------------------------------------------------------------------------
188  if ( sc.isSuccess() )
189  {
190  if (pragma.IsPrintOptions()) {
191  my_log << MSG::INFO << "Print options" << std::endl << catalog
192  << endmsg;
193  }
194  if (pragma.IsPrintTree()) {
195  my_log << MSG::INFO << "Print tree:" << std::endl << ast.ToString()
196  << endmsg;
197  }
198  if (pragma.HasDumpFile()) {
199  dump(pragma.dumpFile(), catalog);
200  }
201  my_log << MSG::INFO
202  << "Job options successfully read in from " << file << endmsg;
203  fillServiceCatalog(catalog);
204  }
205  else
206  {
207  my_log << MSG::FATAL << "Job options errors."<< endmsg;
208  }
209  // ----------------------------------------------------------------------------
210  return sc;
211 }
212 

Generated at Wed Dec 4 2013 14:33:08 for Gaudi Framework, version v24r2 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004