Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 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 , m_dumped( false )
39 {
40  std::string tmp ;
41  tmp = System::getEnv ( "JOBOPTSEARCHPATH" ) ;
42  if ( !tmp.empty() && ("UNKNOWN" != tmp) ) { m_dir_search_path = tmp ; }
43  tmp = System::getEnv ( "JOBOPTSDUMPFILE" ) ;
44  if ( !tmp.empty() && ("UNKNOWN" != tmp) ) { m_dump = tmp ; }
45 
46  m_pmgr.declareProperty( "TYPE" , m_source_type ) ;
47  m_pmgr.declareProperty( "PATH" , m_source_path ) ;
48  m_pmgr.declareProperty( "SEARCHPATH" , m_dir_search_path ) ;
49  m_pmgr.declareProperty( "DUMPFILE" , m_dump ) ;
50 }
51 // ============================================================================
53 {
54  return m_pmgr.setProperty( p );
55 }
56 // ============================================================================
58 {
59 
60  return m_pmgr.getProperty( p );
61 }
62 // ============================================================================
64 {
65  // Call base class initializer
67  if( !sc.isSuccess() ) return sc;
68  // Read the job options if needed
69  if ( this->m_source_type == "NONE" ) {
71  }
72  else {
74  }
75  return sc;
76 }
77 
79 {
80  // finalize the base class
81  return Service::finalize();
82 }
83 // ============================================================================
85 ( const std::string& client,
86  const Property& property )
87 {
88  Property* p = new StringProperty ( property.name(), "" ) ;
89  if ( !property.load( *p ) ) { delete p ; return StatusCode::FAILURE ; }
90  return m_svc_catalog.addProperty( client , p );
91 }
92 // ============================================================================
95 ( const std::string& client,
96  const std::string& name )
97 {
98  return m_svc_catalog.removeProperty(client,name);
99 }
100 // ============================================================================
103 {
104  return m_svc_catalog.getProperties(client);
105 }
106 // ============================================================================
108  IProperty* myInt )
109 {
110  const SvcCatalog::PropertiesT* props =
112 
113  if ( NULL == props ){ return StatusCode::SUCCESS; }
114 
115  bool fail = false;
117  cur != props->end(); cur++)
118  {
119  StatusCode sc = myInt->setProperty (**cur ) ;
120  if ( sc.isFailure() )
121  {
122  MsgStream my_log( this->msgSvc(), this->name() );
123  my_log
124  << MSG::ERROR
125  << "Unable to set the property '" << (*cur)->name() << "'"
126  << " of '" << client << "'. "
127  << "Check option and algorithm names, type and bounds."
128  << endmsg;
129  fail = true;
130  }
131  }
132  return fail ? StatusCode::FAILURE : StatusCode::SUCCESS ;
133 }
134 
137  return m_svc_catalog.getClients();
138 }
139 
140 
142  const gp::Catalog& catalog) const {
143  MsgStream log ( msgSvc() , name() ) ;
144  std::ofstream out
145  ( file.c_str() , std::ios_base::out | std::ios_base::trunc ) ;
146  // perform the actual dumping
147  if ( !out ) {
148  log << MSG::ERROR << "Unable to open dump-file \""+file+"\"" << endmsg ;
149  return ; // RETURN
150  }
151  else {
152  log << MSG::INFO << "Properties are dumped into \""+file+"\"" << endmsg ;
153  }
154  // perform the actual dump:
155  out << catalog;
156 }
157 
158 void JobOptionsSvc::fillServiceCatalog(const gp::Catalog& catalog) {
159  BOOST_FOREACH(const gp::Catalog::value_type& client, catalog) {
160  for (gp::Catalog::CatalogSet::mapped_type::const_iterator current
161  = client.second.begin(); current != client.second.end();
162  ++current) {
163  StringProperty tmp (current->NameInClient(), current->ValueAsString()) ;
164  addPropertyToCatalogue ( client.first , tmp ) ;
165  }
166  }
167 }
168 
170  const std::string& path) {
171  std::string search_path = path;
172  if ( search_path.empty() && !m_dir_search_path.empty() )
173  { search_path = m_dir_search_path ; }
174  //
175  MsgStream my_log( this->msgSvc(), this->name() );
176  if (UNLIKELY(outputLevel() <= MSG::DEBUG))
177  my_log << MSG::DEBUG // debug
178  << "Reading options from the file "
179  << "'" << file << "'" << endmsg;
180  gp::Messages messages(my_log);
181  gp::Catalog catalog;
182  gp::Units units;
183  gp::PragmaOptions pragma;
184  gp::Node ast;
185  StatusCode sc = gp::ReadOptions(file, path, &messages, &catalog, &units,
186  &pragma, &ast);
187 
188  // --------------------------------------------------------------------------
189  if ( sc.isSuccess() )
190  {
191  if (pragma.IsPrintOptions()) {
192  my_log << MSG::INFO << "Print options" << std::endl << catalog
193  << endmsg;
194  }
195  if (pragma.IsPrintTree()) {
196  my_log << MSG::INFO << "Print tree:" << std::endl << ast.ToString()
197  << endmsg;
198  }
199  if (pragma.HasDumpFile()) {
200  dump(pragma.dumpFile(), catalog);
201  }
202  my_log << MSG::INFO
203  << "Job options successfully read in from " << file << endmsg;
204  fillServiceCatalog(catalog);
205  }
206  else
207  {
208  my_log << MSG::FATAL << "Job options errors."<< endmsg;
209  }
210  // ----------------------------------------------------------------------------
211  return sc;
212 }
213 

Generated at Wed Jan 30 2013 17:13:38 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004