Gaudi Framework, version v25r0

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

Generated at Mon Feb 17 2014 14:37:41 for Gaudi Framework, version v25r0 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004