6 #include <GaudiKernel/DataIncident.h>
7 #include <GaudiKernel/IEvtSelector.h>
8 #include <GaudiKernel/IIncidentSvc.h>
10 #include <boost/core/typeinfo.hpp>
11 #include <range/v3/to_container.hpp>
12 #include <range/v3/view.hpp>
18 using namespace std::literals;
19 namespace rv = ranges::views;
22 template <
typename propType,
typename T>
23 const Gaudi::Property<propType>&
24 getProp(SmartIF<T>& iface,
const std::string&
name)
26 auto prop_iface = iface.template as<IProperty>();
27 const auto& prop = prop_iface->getProperty(
name);
29 const auto& conv_prop =
30 dynamic_cast<const Gaudi::Property<propType>&
>(prop);
32 }
catch (
const std::bad_cast&) {
33 std::string if_name =
"UNKNOWN";
35 if_name = iface.template as<INamedInterface>()->name();
39 "The {} object's {} property has type {} not Gaudi::Property<{}>",
40 if_name,
name, boost::core::demangled_name(
typeid(prop)),
41 boost::core::demangled_name(
typeid(propType)));
42 throw std::logic_error(
what);
48 const std::string&
val) {
49 auto prop_iface = iface.template as<IProperty>();
50 return prop_iface->setProperty(
name,
val);
61 SmartIF<IProperty> propMgr(serviceLocator());
62 std::string evt_sel_name{};
63 ATH_CHECK(propMgr->getProperty(
"EvtSel", evt_sel_name));
64 if (evt_sel_name.empty()) {
69 return StatusCode::SUCCESS;
71 auto sg = serviceLocator()->service<
StoreGateSvc>(
"StoreGateSvc/StoreGateSvc",
73 auto evtSel = serviceLocator()->service<IEvtSelector>(evt_sel_name,
false);
74 if (!sg.isValid() || !evtSel.isValid()) {
76 return StatusCode::FAILURE;
80 "EvtIdModifierSvc/EvtIdModifierSvc",
false);
82 std::vector<EvtId> modifier_evts{};
83 if (modSvc.isValid()) {
86 evts_skipped_before_mod =
87 getProp<std::uint64_t&>(modSvc,
"SkipEvents").value();
89 <<
" events before modifying");
90 std::vector<std::uint64_t> lst =
91 getProp<std::vector<std::uint64_t>&>(modSvc,
"Modifiers").
value();
93 << lst.size() / 6 <<
" entries.");
94 std::string config_str{};
95 auto config_str_iter = std::back_inserter(config_str);
98 rv::for_each([&config_str_iter](
const auto& rec) {
99 const int mod_bitset = rec[5];
100 const bool mod_run_num = mod_bitset & 1;
101 const bool mod_evt_num = mod_bitset & (1 << 1);
102 const bool mod_lb_num = mod_bitset & (1 << 3);
109 fmt::format_to(config_str_iter,
110 "Run: {} [{:c}] LB: {} [{:c}] EVT: {} [{:c}] "
112 runNum, mod_run_num ?
'Y' :
'N', lbNum,
113 mod_lb_num ?
'Y' :
'N', evtNum,
114 mod_evt_num ?
'Y' :
'N', numEvts);
115 return ranges::yield_from(
117 static_cast<uint32_t>(lbNum), evtNum},
122 }
catch (
const std::bad_cast&) {
123 ATH_MSG_ERROR(
"Wrong type for property of EvtIdModifierSvc.");
130 ATH_CHECK(setProp(evtSel,
"SkipEvents",
"0"));
131 IEvtSelector::Context* ctx =
nullptr;
136 ATH_CHECK(
dynamic_cast<Service*
>(evtSel.get())->start());
137 while (evtSel->next(*ctx).isSuccess()) {
140 IOpaqueAddress* addr =
nullptr;
141 ATH_CHECK(evtSel->createAddress(*ctx, addr));
148 std::vector<std::string> attr_lists;
152 const auto* attr_list_p =
154 if (attr_list_p !=
nullptr && attr_list_p->size() > 6) {
157 const auto runNum = attr_list[
"RunNumber"].data<
unsigned>();
158 const auto evtNum = attr_list[
"EventNumber"].data<
unsigned long long>();
159 const auto lbNum = attr_list[
"LumiBlockN"].data<
unsigned>();
160 evt_id = EvtId{
runNum, lbNum, evtNum};
165 if (
idx >= evts_skipped_before_mod && !modifier_evts.empty()) {
166 const std::size_t mod_idx =
167 (
idx - evts_skipped_before_mod) % modifier_evts.size();
168 evt_id.runNum = modifier_evts[mod_idx].runNum != 0U
169 ? modifier_evts[mod_idx].runNum
171 evt_id.lbNum = modifier_evts[mod_idx].lbNum != 0U
172 ? modifier_evts[mod_idx].lbNum
174 evt_id.evtNum = modifier_evts[mod_idx].evtNum != 0U
175 ? modifier_evts[mod_idx].evtNum
185 <<
" and rewinding");
194 incident_svc->addListener(
this,
"BeginRun");
195 incident_svc->addListener(
this,
"SkipEvents");
196 return StatusCode::SUCCESS;
208 return StatusCode::SUCCESS;
222 return StatusCode::SUCCESS;
226 if (inc.type() !=
"BeginRun"s && inc.type() !=
"SkipEvents"s) {
229 ATH_MSG_DEBUG(
"Received incident of type " << inc.type() <<
" from "
231 if (inc.type() ==
"SkipEvents"s) {
234 dynamic_cast<const ContextIncident<std::tuple<int, int>
>&>(inc);
236 auto end =
m_events.cbegin() + std::get<1>(cInc.tag()) +
239 if (!std::invoke(
fn,
begin,
end).isSuccess()) {
240 throw std::runtime_error(
241 "A skipEvent callback returned a failure error code!");