The method to prescale chains.
If the prescale set input key is not defined or the chain does not exist in the prescale set, then the chains (or all chains) are kept according to the property KeepUnknownChains
96 {
97 if ( initiallyActive.empty() ) {
98 return StatusCode::SUCCESS;
99 }
100
101
102 remainActive.clear();
103
105
107 remainActive.reserve( initiallyActive.size() );
108 for( const auto & ch : initiallyActive ) {
109 remainActive.push_back(ch);
110 }
111 }
112 return StatusCode::SUCCESS;
113 }
114
117
118
120 auto mon_lb = Monitored::Scalar<int>("LB", [&](){ return ctx.eventID().lumi_block(); });
121 auto mon_psk = Monitored::Scalar<std::string>("HLTPSK", [&](){ return std::to_string(hltPrescaleSet->psk()); });
122 auto mon = Monitored::Group(
m_monTool, mon_lb, mon_psk);
123
124
125 remainActive.reserve( initiallyActive.size() );
126
127
135 CHECK( eventInfoHandle.isValid() );
136 size_t seed = eventInfoHandle->timeStamp() ^ eventInfoHandle->timeStampNSOffset();
137
139 engine->setSeed( seed, 0 );
140
141 auto getPrescale = [&](
const HLT::Identifier&
ch) ->
const TrigConf::HLTPrescalesSet::HLTPrescale& {
142 try {
143 if (forExpressStream) {
144 return hltPrescaleSet->prescale_express(
ch.numeric() );
145 } else {
146 return hltPrescaleSet->prescale(
ch.numeric() );
147 }
148 } catch(const std::out_of_range & ex) {
149
151 ATH_MSG_DEBUG(
"No prescale value for chain " << ch <<
", keeping it because "
153 } else {
155 }
156 }
158 };
159
160 auto decisionPerChain = [&](
const HLT::Identifier&
ch,
double prescaleValue ) ->
bool {
161 auto flat =
engine->flat();
163 auto mon_rndm = Monitored::Scalar<double>("Random", flat);
165 }
166 return flat < 1./ prescaleValue;
167 };
168
169 struct ChainAndPrescale {
171 TrigConf::HLTPrescalesSet::HLTPrescale
ps;
172 double relativePrescale{};
173 };
174
176
177
178 if ( forExpressStream || std::find(initiallyActive.begin(), initiallyActive.end(), chainIDs.front()) != initiallyActive.end() ) {
179 std::vector<ChainAndPrescale> psValueSorted;
180 for ( const HLT::Identifier& ch: chainIDs ) {
181
182
183 if ( forExpressStream && std::find(initiallyActive.begin(), initiallyActive.end(), ch) == initiallyActive.end() ) {
184 continue;
185 }
186 auto ps = getPrescale(ch);
188 psValueSorted.emplace_back( ChainAndPrescale({
ch,
ps}) );
189 }
190 if ( psValueSorted.empty() ) {
191 continue;
192 }
193 std::sort(psValueSorted.begin(), psValueSorted.end(), [](
const ChainAndPrescale&
a,
const ChainAndPrescale& b){
194 return a.ps.prescale < b.ps.prescale;
195 });
196
197
198 psValueSorted.front().relativePrescale = psValueSorted.front().ps.prescale;
199 if ( psValueSorted.size() > 1 ) {
200 for ( auto i = psValueSorted.begin()+1; i < psValueSorted.end(); ++i ) {
201 i->relativePrescale =
i->ps.prescale / (
i-1)->
ps.prescale ;
202 }
203 }
204 if (msgLvl(MSG::DEBUG)) {
205 ATH_MSG_DEBUG(
"Chains in CPS group '"<< groupName <<
"' sorted by PS : ");
206 for ( const ChainAndPrescale& ch: psValueSorted ) {
208 "prescale relative to the above " + std::to_string(
ch.relativePrescale) :
209 "disabled"));
210 }
211 }
212
213 for ( const ChainAndPrescale& ch: psValueSorted ) {
214 const bool decision = decisionPerChain(
ch.id,
ch.relativePrescale);
215 if ( not decision ) {break;}
216 remainActive.push_back(
ch.id );
217 }
218 }
219 }
220
221
223 if ( std::find( initiallyActive.begin(), initiallyActive.end(), ch ) != initiallyActive.end() ) {
224 auto prescale = getPrescale(ch);
225 if ( prescale.enabled ) {
226 const bool decision = decisionPerChain(ch, prescale.prescale);
227 if ( decision ) {
228 remainActive.push_back( ch );
229 }
230 ATH_MSG_DEBUG(
"Prescaling decision for chain " << ch <<
" " << decision);
231 } else {
232 ATH_MSG_DEBUG(
"Chain " << ch <<
" is disabled, won't keep" );
233 }
234 }
235 }
236
237 return StatusCode::SUCCESS;
238}
#define CHECK(...)
Evaluate an expression and check for errors.
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.