Configures the framework.
79{
80 psc::Utils::ScopeTimer
timer(
"Psc configuration");
81
82 ROOT::EnableThreadSafety();
83
84 ERS_DEBUG(1,
"psc::Psc::configure ptree:\n" <<
to_string(config));
85 try
86 {
87 m_config = std::make_unique<Config>(config);
88 }
89 catch(const std::exception& e)
90 {
92 return false;
93 }
94
95
96 ERS_LOG(
"---> Dump of config cache: \n" <<
m_config->dumpOptions() );
97 ERS_LOG(
"---> Pesa JobOptions file is = " <<
m_config->getOption(
"JOBOPTIONSPATH") );
98
99
100
101
102 ERS_DEBUG(1,"---> Create Pesa Application Manager");
105
108 return false;
109 }
110
111
112 ERS_DEBUG(1,"---> Configure Pesa Property Manager");
114 if( !propMgr.isValid() ) {
115 ERS_PSC_ERROR(
"Error retrieving IProperty interface of ApplicationMgr");
116 return false;
117 }
118
119
121 sc = propMgr->setProperty(
"JobOptionsSvcType",
m_config->getOption(
"JOBOPTIONSSVCTYPE"));
122 if (
sc.isFailure()) {
124 return false;
125 }
126
127
128 sc = propMgr->setProperty(
"JobOptionsType",
m_config->getOption(
"JOBOPTIONSTYPE"));
129 if (
sc.isFailure()) {
131 return false;
132 }
133
134
135 sc = propMgr->setProperty(
"JobOptionsPath",
m_config->getOption(
"JOBOPTIONSPATH") );
136 if (
sc.isFailure()) {
138 return false;
139 }
140
141
142 sc = propMgr->setProperty(
"MessageSvcType",
m_config->getOption(
"MESSAGESVCTYPE"));
143 if (
sc.isFailure()) {
145 return false;
146 }
147
148
149
150
151
152 bool jobOptConfig, needPython;
153 if (
m_config->getOption(
"JOBOPTIONSTYPE") ==
"NONE" ) {
154 jobOptConfig = needPython = true;
155 }
156 else if (
m_config->getOption(
"JOBOPTIONSTYPE") ==
"DB" ||
157 m_config->getOption(
"JOBOPTIONSTYPE") ==
"FILE") {
158 jobOptConfig = needPython = false;
159 if ( (
m_config->getOption(
"PRECOMMAND")!=
"") || (
m_config->getOption(
"POSTCOMMAND")!=
"") ) {
160 needPython = true;
161 }
162 if (
m_config->didUserSetLogLevel()) {
163 needPython = true;
164 }
165 }
166 else {
167 ERS_PSC_ERROR(
"Unsupported configuration method \"" <<
m_config->getOption(
"JOBOPTIONSTYPE") <<
"\"");
168 return false;
169 }
170
171
172 if ( jobOptConfig || needPython ) {
173
174
175
176
177
178 if ( ! Py_IsInitialized() ) {
179 ERS_DEBUG(1,"Initializing Python interpreter");
180
182 PyConfig_InitPythonConfig (&config);
183 PyStatus
status = PyConfig_SetBytesArgv (&config, System::argc(), System::argv());
184 if (PyStatus_Exception (status)) {
185 PyConfig_Clear (&config);
187 return false;
188 }
189 status = Py_InitializeFromConfig (&config);
190 if (PyStatus_Exception (status)) {
191 PyConfig_Clear (&config);
193 return false;
194 }
195
196
197
198
199
200
201 if ( ! Py_IsInitialized() ) {
203 return false;
204 }
205
206 }
207 else {
208 ERS_DEBUG(1,"Python interpreter already initialized");
209 }
210
211
212
213 PyObject* pModule = PyImport_ImportModule(
"TrigPSC.PscConfig");
214 if ( pModule ) {
216 if ( optmap ) {
217 std::map<std::string,std::string>::const_iterator
iter;
220 std::vector<char> writable(
iter->first.size() + 1);
221 std::copy(
iter->first.begin(),
iter->first.end(), writable.begin());
222 PyMapping_SetItemString(optmap, &writable[0], v);
223 }
224 Py_DECREF(optmap);
225 }
226 else {
227 ERS_DEBUG(1, "Could not import TrigPSC.PscConfig.optmap");
228 }
229 Py_DECREF(pModule);
230 }
231 }
232
233 if ( jobOptConfig ) {
234
235 std::string pyBasicFile =
m_config->getOption(
"PYTHONSETUPFILE") ;
238 return false;
239 }
240 }
241
242 if ( !jobOptConfig ) {
243
244
245
246
247
248 std::string
cmd =
m_config->getOption(
"PRECOMMAND");
249 if ( cmd != "" ) {
250 ERS_LOG("Running pre-configure command '" << cmd << "'");
253 return false;
254 }
255 }
256
257
258 ERS_DEBUG(1,"Configure ApplicationMgr from database.");
260 if(
sc.isFailure() ) {
262 return false;
263 }
264
265
266 if ( needPython ) {
267
268 std::string pyBasicFile =
m_config->getOption(
"PYTHONSETUPFILE",
true) ;
269 if ( !pyBasicFile.empty() ) {
272 return false;
273 }
274 }
275 }
276 }
277
278
279
280 if ( needPython ) {
281 PyObject* pModule = PyImport_ImportModule(
"TrigPSC.PscConfig");
282 if ( pModule ) {
283 PyObject* pInteractive = PyObject_GetAttrString(pModule,
"interactive");
284 if ( pInteractive && PyBool_Check(pInteractive) ) {
286 ERS_DEBUG(1,
"TrigPSC.PscConfig.interactive = " <<
m_interactive);
287 Py_DECREF(pInteractive);
288 }
289 else {
290 ERS_DEBUG(1, "Could not read TrigPSC.PscConfig.interactive");
291 }
292 Py_DECREF(pModule);
293 }
294 else {
295 ERS_DEBUG(1, "Could not import TrigPSC.PscConfig");
296 }
297 }
298
300
301 ERS_DEBUG(1,
"Configured ApplicationMgr in state: " <<
m_pesaAppMgr->FSMState());
302
303 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> jobOptionSvc("JobOptionsSvc","psc::Psc");
304 SmartIF<IProperty> jos_propif{&(*jobOptionSvc)};
306 jos_propif->setProperty(
"OutputLevel",
m_config->getLogLevelAsNumStr()).ignore();
307
308
309
310
311 auto props = std::map<std::string,std::string>{
312 {"DF_PartitionName", "DF_PARTITION_NAME"},
313 {"DF_ApplicationName", "DF_APPLICATIONNAME"},
314 {"DF_MachineName", "DF_MACHINE_NAME"},
315 {"DF_Ppid", "DF_PPID"},
316 {"DF_Pid", "DF_PID"},
317 {"DF_HostId", "DF_HOST_ID"},
318 {"DF_RandomSeed", "DF_RANDOM_SEED"},
319 {"DF_NumberOfWorkers", "NPROCS"}
320 };
322 return false;
323
324
325 if (
m_config->enabled_robs.size() != 0 ) {
326 jobOptionSvc->set("DataFlowConfig.DF_Enabled_ROB_IDs",
327 Gaudi::Utils::toString<std::vector<uint32_t>>(
m_config->enabled_robs));
328 ERS_DEBUG(1,"psc::Psc::configure: Wrote configuration for enabled ROBs in JobOptions Catalogue: "
329 <<
" number of ROB IDs read from OKS = " <<
m_config->enabled_robs.size());
330 }
331
332
333 if (
m_config->enabled_SubDets.size() != 0 ) {
334 jobOptionSvc->set("DataFlowConfig.DF_Enabled_SubDet_IDs",
335 Gaudi::Utils::toString<std::vector<uint32_t>>(
m_config->enabled_SubDets));
336 ERS_DEBUG(1,"psc::Psc::configure: Wrote configuration for enabled sub detectors in JobOptions Catalogue: "
337 <<
" number of Sub Det IDs read from OKS = " <<
m_config->enabled_SubDets.size());
338 }
339
340
341 if (std::string opt =
m_config->getOption(
"MAXEVENTSIZEMB"); !
opt.empty()) {
342 jobOptionSvc->set("DataFlowConfig.DF_MaxEventSizeMB", opt);
343 ERS_DEBUG(1,"psc::Psc::configure: Wrote DF_MaxEventSizeMB=" << opt << " in JobOptions Catalogue");
344 }
345
346
347 if ( (
m_config->getOption(
"MUONCALBUFFERNAME") !=
"NONE") && (
m_config->getOption(
"MUONCALBUFFERNAME") !=
"") ) {
348 jobOptionSvc->set(
"MuonHltCalibrationConfig.MuonCalBufferName",
m_config->getOption(
"MUONCALBUFFERNAME"));
349 jobOptionSvc->set(
"MuonHltCalibrationConfig.MuonCalBufferSize",
m_config->getOption(
"MUONCALBUFFERSIZE"));
350
351 ERS_DEBUG(1,"psc::Psc::configure: Wrote configuration for HLT Muon Calibration in JobOptions Catalogue: "
352 <<
" MuonCalBufferName = " <<
m_config->getOption(
"MUONCALBUFFERNAME")
353 <<
" MuonCalBufferSize = " <<
m_config->getOption(
"MUONCALBUFFERSIZE") );
354 }
355
356
358
359 if ( !jobOptConfig ) {
360
361 std::string
cmd =
m_config->getOption(
"POSTCOMMAND");
362 if ( cmd != "" ) {
363 ERS_LOG("Running post-configure command '" << cmd << "'");
366 return false;
367 }
368 }
369 }
370
373 }
374
375 return true;
376}
bool setAthenaProperties()
bool setDFProperties(const std::map< std::string, std::string > &name_tr_table)
bool m_interactive
Running in interactive mode (athenaHLT)
bool doAppMgrInit()
Initialize the application manager.
std::unique_ptr< psc::Config > m_config
Config derived from ptree.
bool execFile(const std::string &pyFileName)
Execute a python file (via include or import)
bool execPython(const std::string &pyCmd)
Execute a python command in the python interpreter.
dict optmap
string:string map equivalent to TrigPsc/Config.h (filled in TrigPsc.cxx)
timer(name, disabled=False)