18#include <boost/python.hpp>
19#include <boost/property_tree/ptree.hpp>
21#include "GaudiKernel/ISvcLocator.h"
22#include "GaudiKernel/IProperty.h"
23#include "GaudiKernel/SmartIF.h"
24#include "GaudiKernel/Bootstrap.h"
25#include "Gaudi/Interfaces/IOptionsSvc.h"
34boost::property_tree::ptree buildPrepareForStartPtree(
36 const std::string& det_mask,
37 const std::string& sor_time,
41 float toroids_current,
42 float solenoid_current,
43 const std::string& run_type,
44 uint32_t trigger_type,
45 bool recording_enabled)
47 boost::property_tree::ptree
pt;
50 boost::property_tree::ptree& runParams =
pt.add_child(
"RunParams", boost::property_tree::ptree());
51 runParams.put(
"run_number", run_number);
52 runParams.put(
"max_events", 0);
53 runParams.put(
"recording_enabled", recording_enabled ? 1 : 0);
54 runParams.put(
"trigger_type", trigger_type);
55 runParams.put(
"run_type", run_type);
56 runParams.put(
"det_mask", det_mask);
57 runParams.put(
"beam_type", beam_type);
58 runParams.put(
"beam_energy", beam_energy);
59 runParams.put(
"stream",
"");
60 runParams.put(
"lumiblock", lb_number);
61 runParams.put(
"filename_tag",
"");
62 runParams.put(
"T0_project_tag",
"");
63 runParams.put(
"timeSOR", sor_time);
64 runParams.put(
"timeEOR",
"1/1/70 01:00:00");
65 runParams.put(
"totalTime", 0);
68 boost::property_tree::ptree& magnets =
pt.add_child(
"Magnets", boost::property_tree::ptree());
70 boost::property_tree::ptree& toroidsCurrent = magnets.add_child(
"ToroidsCurrent", boost::property_tree::ptree());
71 toroidsCurrent.put(
"value", toroids_current);
72 toroidsCurrent.put(
"ts", sor_time);
74 boost::property_tree::ptree& solenoidCurrent = magnets.add_child(
"SolenoidCurrent", boost::property_tree::ptree());
75 solenoidCurrent.put(
"value", solenoid_current);
76 solenoidCurrent.put(
"ts", sor_time);
109 const std::string& det_mask,
110 const std::string& sor_time,
111 uint32_t lb_number = 0,
112 uint32_t beam_type = 0,
113 uint32_t beam_energy = 0,
114 float toroids_current = 20400.0f,
115 float solenoid_current = 7730.0f,
116 const std::string& run_type =
"Physics",
117 uint32_t trigger_type = 0,
118 bool recording_enabled =
false,
119 const std::string& event_loop_name =
"HltEventLoopMgr")
122 boost::property_tree::ptree pt = buildPrepareForStartPtree(
123 run_number, det_mask, sor_time, lb_number,
124 beam_type, beam_energy, toroids_current, solenoid_current,
125 run_type, trigger_type, recording_enabled);
128 ISvcLocator* svcLoc = Gaudi::svcLocator();
130 std::cerr <<
"TrigServicesHelper: Failed to get ISvcLocator" << std::endl;
137 std::cerr <<
"TrigServicesHelper: Failed to retrieve ITrigEventLoopMgr '"
138 << event_loop_name <<
"'" << std::endl;
143 std::cout <<
"TrigServicesHelper: Calling prepareForStart on " << event_loop_name << std::endl;
144 StatusCode
sc = evtLoopMgr->prepareForStart(pt);
146 if (
sc.isFailure()) {
147 std::cerr <<
"TrigServicesHelper: prepareForStart failed" << std::endl;
151 std::cout <<
"TrigServicesHelper: prepareForStart completed successfully" << std::endl;
167 ISvcLocator* svcLoc = Gaudi::svcLocator();
169 std::cerr <<
"TrigServicesHelper: Failed to get ISvcLocator" << std::endl;
176 std::cerr <<
"TrigServicesHelper: Failed to retrieve ITrigEventLoopMgr '"
177 << event_loop_name <<
"'" << std::endl;
182 boost::property_tree::ptree pt;
185 std::cout <<
"TrigServicesHelper: Calling prepareForRun on " << event_loop_name << std::endl;
186 StatusCode
sc = evtLoopMgr->prepareForRun(pt);
188 if (
sc.isFailure()) {
189 std::cerr <<
"TrigServicesHelper: prepareForRun failed" << std::endl;
193 std::cout <<
"TrigServicesHelper: prepareForRun completed successfully" << std::endl;
211 const std::string& event_loop_name =
"HltEventLoopMgr")
214 if (worker_pid < 0) {
215 worker_pid = getpid();
219 ISvcLocator* svcLoc = Gaudi::svcLocator();
221 std::cerr <<
"TrigServicesHelper: Failed to get ISvcLocator" << std::endl;
227 auto jobOptSvc = svcLoc->service<Gaudi::Interfaces::IOptionsSvc>(
"JobOptionsSvc");
229 std::cerr <<
"TrigServicesHelper: Failed to get JobOptionsSvc" << std::endl;
234 jobOptSvc->set(
"DataFlowConfig.DF_WorkerId", std::to_string(worker_id));
235 jobOptSvc->set(
"DataFlowConfig.DF_Pid", std::to_string(worker_pid));
236 jobOptSvc->set(
"DataFlowConfig.DF_ApplicationName",
"athenaEF");
238 std::cout <<
"TrigServicesHelper: Set DataFlowConfig properties (WorkerId="
239 << worker_id <<
", Pid=" << worker_pid <<
")" << std::endl;
242 boost::property_tree::ptree pt;
247 std::cerr <<
"TrigServicesHelper: Failed to retrieve ITrigEventLoopMgr '"
248 << event_loop_name <<
"'" << std::endl;
253 std::cout <<
"TrigServicesHelper: Calling hltUpdateAfterFork on " << event_loop_name << std::endl;
254 StatusCode
sc = evtLoopMgr->hltUpdateAfterFork(pt);
256 if (
sc.isFailure()) {
257 std::cerr <<
"TrigServicesHelper: hltUpdateAfterFork failed" << std::endl;
261 std::cout <<
"TrigServicesHelper: hltUpdateAfterFork completed successfully" << std::endl;
270 using namespace boost::python;
272 class_<TrigServicesHelper>(
"TrigServicesHelper")
277 arg(
"lb_number") = 0,
278 arg(
"beam_type") = 0,
279 arg(
"beam_energy") = 0,
280 arg(
"toroids_current") = 20400.0f,
281 arg(
"solenoid_current") = 7730.0f,
282 arg(
"run_type") =
"Physics",
283 arg(
"trigger_type") = 0,
284 arg(
"recording_enabled") =
false,
285 arg(
"event_loop_name") =
"HltEventLoopMgr"),
286 "Call prepareForStart on HltEventLoopMgr with individual parameters")
288 (arg(
"event_loop_name") =
"HltEventLoopMgr"),
289 "Call prepareForRun on HltEventLoopMgr to initialize COOL folder helper and fire BeginRun incident. "
290 "Must be called after start() and before hltUpdateAfterFork().")
292 (arg(
"worker_id") = 1,
293 arg(
"worker_pid") = -1,
294 arg(
"event_loop_name") =
"HltEventLoopMgr"),
295 "Call hltUpdateAfterFork on HltEventLoopMgr to initialize the scheduler. "
296 "worker_id must be > 0 to avoid mother process behavior during stop().");
BOOST_PYTHON_MODULE(libTrigServicesHelper)
EventLoopMgr interface implemented by the HLT event loop manager.
bool hltUpdateAfterFork(int worker_id=1, int worker_pid=-1, const std::string &event_loop_name="HltEventLoopMgr")
Call hltUpdateAfterFork on the HltEventLoopMgr.
bool prepareForStart(uint32_t run_number, const std::string &det_mask, const std::string &sor_time, uint32_t lb_number=0, uint32_t beam_type=0, uint32_t beam_energy=0, float toroids_current=20400.0f, float solenoid_current=7730.0f, const std::string &run_type="Physics", uint32_t trigger_type=0, bool recording_enabled=false, const std::string &event_loop_name="HltEventLoopMgr")
Call prepareForStart on the HltEventLoopMgr.
TrigServicesHelper()=default
~TrigServicesHelper()=default
bool prepareForRun(const std::string &event_loop_name="HltEventLoopMgr")
Call prepareForRun on the HltEventLoopMgr.