13#include "eformat/eformat.h"
14#include "eformat/SourceIdentifier.h"
21#include "CLHEP/Random/RandomEngine.h"
22#include "CLHEP/Random/RandFlat.h"
34 const std::string& name,
35 const IInterface* parent )
62 ATH_MSG_DEBUG(
"Creating trigger configuration maps from run-3-style menu");
64 std::vector<unsigned int> bg{1};
65 std::vector<unsigned int> bgEmpty{1};
68 for (
size_t i = 0; i < 16; ++i) {
74 for(
int rndmIdx = 0; rndmIdx<4; rndmIdx++) {
85 return StatusCode::SUCCESS;
90 std::vector<uint32_t> & tip )
const
94 for(
auto & entry : thrMultiMap ) {
95 const std::string & thrName = entry.first;
96 size_t multiplicity = entry.second;
108 size_t posWithinWord =
x->second->pitPos() % 32;
110 tip[wordNr] |= ( 1L << posWithinWord );
117 size_t nBits = ctpTT.
endBit() - startBit + 1;
120 if(multiplicity >= (1U<<nBits)) {
121 multiplicity = (1U<<nBits)-1;
124 size_t wordNr = startBit / 32;
125 size_t posWithinWord = startBit % 32;
127 uint64_t
result = multiplicity;
130 tip[wordNr] |=
result & 0xFFFFFFFF;
132 tip[wordNr+1] |= uint32_t((
result & 0xFFFFFFFF00000000) >> 32);
138 for( uint32_t word : tip ) {
139 ATH_MSG_DEBUG(
"REGTEST - " <<
"TIP word #" << std::dec << wrdNr++
140 <<
" is: 0x" << std::hex << std::setw( 8 ) << std::setfill(
'0' ) << word );
143 return StatusCode::SUCCESS;
150 std::map<std::string, unsigned int> & itemDecisionMap,
151 CLHEP::HepRandomEngine* rndmEngine )
const
154 itemDecisionMap.clear();
160 bool pass_beforePrescale = ctpItem->evaluate(thrMultiMap);
161 bool pass_afterPrescale =
false;
162 bool pass_afterVeto =
false;
164 if ( pass_beforePrescale ) {
165 long random = CLHEP::RandFlat::shootInt( rndmEngine,
pow(2,24) );
167 pass_afterPrescale = (random >= cut) && (cut > 0);
168 pass_afterVeto = pass_afterPrescale;
171 unsigned int result = (pass_beforePrescale ?
TBP : 0) + (pass_afterPrescale ?
TAP : 0) + (pass_afterVeto ?
TAV : 0);
173 itemDecisionMap[itemName] =
result;
177 return StatusCode::FAILURE;
179 return StatusCode::SUCCESS;
184 std::vector<uint32_t> & tbp, std::vector<uint32_t> & tap, std::vector<uint32_t> & tav,
185 unsigned char & triggerType )
const
192 for(
auto & entry : itemDecisionMap ) {
193 const std::string & itemName = entry.first;
194 unsigned int result = entry.second;
205 triggerType |= l1Item->triggerType();
208 auto ctpId = l1Item->ctpId();
209 unsigned int wordNr = ctpId / 32;
210 unsigned int posWithinWord = ctpId % 32;
212 if( passBP ) { tbp[wordNr] |= 1L << posWithinWord; }
213 if( passAP ) { tap[wordNr] |= 1L << posWithinWord; }
214 if( passAV ) { tav[wordNr] |= 1L << posWithinWord; }
217 " is " << ( !passBP ?
"INACTIVE" : ( passAV ?
"ACTIVE" :
"ACTIVE (but PRESCALED)" ) ) );
219 ATH_MSG_DEBUG(
"REGTEST - " <<
"TriggerType byte is: 0x" << std::setw( 2 ) << std::setfill(
'0' ) << std::hex <<
int(triggerType) );
221 return StatusCode::SUCCESS;
227std::unique_ptr<LVL1CTP::CTPSLink>
229 const std::vector<uint32_t> & tbp,
230 const std::vector<uint32_t> & tap,
231 const std::vector<uint32_t> & tav,
232 const std::vector<uint32_t> & tip,
233 const std::vector<uint32_t> & extra,
234 const unsigned char triggerType )
const
239 std::vector<uint32_t> roi_vector;
240 roi_vector.push_back( eventID.time_stamp_ns_offset() );
241 roi_vector.push_back( eventID.time_stamp() );
243 roi_vector.insert(roi_vector.end(), tip.begin(), tip.end());
244 roi_vector.insert(roi_vector.end(), tbp.begin(), tbp.end());
245 roi_vector.insert(roi_vector.end(), tap.begin(), tap.end());
246 roi_vector.insert(roi_vector.end(), tav.begin(), tav.end());
247 roi_vector.insert(roi_vector.end(), extra.begin(), extra.end());
256 roi_vector.insert(roi_vector.end(), trailer.begin(), trailer.end());
264 const uint32_t source_id{eformat::helper::SourceIdentifier(eformat::TDAQ_CTP, 1).code()};
267 uint32_t version_word = eformat::DEFAULT_ROD_VERSION;
268 const uint32_t l1a_pos{0};
277 helperHeader.
setBCID( eventID.bunch_crossing_id());
281 std::vector<unsigned int>
header(helperHeader.
header());
282 roi_vector.insert(roi_vector.begin(),
header.begin(),
header.end());
296 if(
msgLvl(MSG::VERBOSE) ) {
298 ATH_MSG_VERBOSE(
"REGTEST - Items fired before prescale: " << itemName );
301 ATH_MSG_VERBOSE(
"REGTEST - Items fired after prescale: " << itemName );
313std::unique_ptr<CTP_RDO>
315 const std::vector<uint32_t> & tbp,
316 const std::vector<uint32_t> & tap,
317 const std::vector<uint32_t> & tav,
318 const std::vector<uint32_t> & tip,
319 const std::vector<uint32_t> & extra )
const
321 auto wrongSize = [
this](
const std::vector<uint32_t> &
vec, uint32_t exp, std::string_view name) {
322 if (
vec.size() == exp) {
return false;}
323 ATH_MSG_ERROR(
"Wrong " << name <<
" vector size passed to constructRDOResult, " <<
vec.size() <<
" instead of " << exp);
333 std::vector<uint32_t>
data(
static_cast<size_t>(
m_ctpDataFormat->getNumberTimeWords()), uint32_t{0});
335 data.insert(
data.end(),tip.begin(),tip.end());
336 data.insert(
data.end(),tbp.begin(),tbp.end());
337 data.insert(
data.end(),tap.begin(),tap.end());
338 data.insert(
data.end(),tav.begin(),tav.end());
339 data.insert(
data.end(),extra.begin(),extra.end());
342 result->setTimeSec(eventID.time_stamp());
343 result->setTimeNanoSec(eventID.time_stamp_ns_offset());
351std::pair< std::unique_ptr<xAOD::CTPResult>, std::unique_ptr<xAOD::CTPResultAuxInfo> >
353 const std::vector<uint32_t> & tbp,
354 const std::vector<uint32_t> & tap,
355 const std::vector<uint32_t> & tav,
356 const std::vector<uint32_t> & tip,
357 const std::vector<uint32_t> & extra,
358 const unsigned char triggerType )
const
360 auto wrongSize = [
this](
const std::vector<uint32_t> &
vec, uint32_t exp, std::string_view name) {
361 if (
vec.size() == exp) {
return false;}
362 ATH_MSG_ERROR(
"Wrong " << name <<
" vector size passed to constructCTPResult, " <<
vec.size() <<
" instead of " << exp);
369 return {
nullptr,
nullptr};
372 std::vector<uint32_t>
data(
static_cast<size_t>(
m_ctpDataFormat->getNumberTimeWords()), uint32_t{0});
376 data.insert(
data.end(),tip.begin(),tip.end());
377 data.insert(
data.end(),tbp.begin(),tbp.end());
378 data.insert(
data.end(),tap.begin(),tap.end());
379 data.insert(
data.end(),tav.begin(),tav.end());
380 data.insert(
data.end(),extra.begin(),extra.end());
383 const uint32_t source_id{eformat::helper::SourceIdentifier(eformat::TDAQ_CTP, 1).code()};
386 uint32_t version_word = eformat::DEFAULT_ROD_VERSION;
387 const uint32_t l1a_pos{0};
393 auto result = std::make_unique<xAOD::CTPResult>();
394 auto resultAux = std::make_unique<xAOD::CTPResultAuxInfo>();
395 result->setStore(resultAux.get());
397 result->setHeader(eformat::ROD, version_word, source_id, 0, eventID.run_number(), eventID.bunch_crossing_id(), triggerType, 0);
399 result->setL1AcceptBunchPosition(l1a_pos);
402 return std::make_pair(std::move(
result), std::move(resultAux));
406std::vector<std::string>
408 std::vector<std::string> passedItems;
411 size_t idx = item->ctpId() / 32;
412 size_t bit = item->ctpId() % 32;
413 if ( triggerWords[idx] % (1L << bit) ) {
414 passedItems.push_back(item->name());
417 std::sort(passedItems.begin(), passedItems.end());
#define ATH_MSG_VERBOSE(x)
std::vector< size_t > vec
char data[hepevt_bytes_allocation_ATLAS]
constexpr int pow(int base, int exp) noexcept
bool msgLvl(const MSG::Level lvl) const
Class for simulating the internal bunch group trigger.
Helper class holding trigger threshold multiplicity.
unsigned int endBit() const
Get the end position of the threshold.
unsigned int startBit() const
Get the start position of the threshold.
StatusCode createTriggerConfigMaps(const TrigConf::L1Menu &l1menu)
ResultBuilder(const std::string &type, const std::string &name, const IInterface *parent)
StatusCode setConfiguration(const TrigConf::L1Menu &l1menu)
StatusCode constructResultVectors(const std::map< std::string, unsigned int > &itemDecisionMap, std::vector< uint32_t > &tbp, std::vector< uint32_t > &tap, std::vector< uint32_t > &tav, unsigned char &triggerType) const
std::pair< std::unique_ptr< xAOD::CTPResult >, std::unique_ptr< xAOD::CTPResultAuxInfo > > constructCTPResult(const EventIDBase &eventID, const std::vector< uint32_t > &tbp, const std::vector< uint32_t > &tap, const std::vector< uint32_t > &tav, const std::vector< uint32_t > &tip, const std::vector< uint32_t > &extra, const unsigned char triggerType) const
build RDO result (CTPResult)
StatusCode constructTIPVector(const std::map< std::string, unsigned int > &thrMultiMap, std::vector< uint32_t > &tip) const
InternalTriggerMap m_internalTrigger
internal triggers BGRP and RNDM
std::unique_ptr< ItemMap > m_itemConfigMap
Map between item objects and their CTP-internal description.
CTPdataformatVersion * m_ctpDataFormat
CTP data format details.
StatusCode buildItemDecision(const std::map< std::string, unsigned int > &thrMultiMap, std::map< std::string, unsigned int > &itemDecisionMap, CLHEP::HepRandomEngine *rndmEngine) const
std::vector< std::string > firedItems(const std::vector< uint32_t > &triggerWords) const
build list of fired items and dump to string
unsigned int m_ctpVersionNumber
CTP data format version (4 in most of Run 2 and in Run 3)
std::unique_ptr< CTP_RDO > constructRDOResult(const EventIDBase &eventID, const std::vector< uint32_t > &tbp, const std::vector< uint32_t > &tap, const std::vector< uint32_t > &tav, const std::vector< uint32_t > &tip, const std::vector< uint32_t > &extra) const
build RDO result (CTP_RDO) - TODO obsolete it in favor of xAOD::CTPResult
std::unique_ptr< CTPSLink > constructRoIResult(const EventIDBase &eventID, const std::vector< uint32_t > &tbp, const std::vector< uint32_t > &tap, const std::vector< uint32_t > &tav, const std::vector< uint32_t > &tip, const std::vector< uint32_t > &extra, const unsigned char triggerType) const
build RoI result (LVL1CTP::CTPSLink)
std::unique_ptr< ThresholdMap > m_thrConfigMap
Map between threshold objects and their CTP-internal description.
ROIB::Trailer models the LVL1 ROD Trailer.
const std::vector< uint32_t > & trailer() const
get full trailer
const std::string & msg() const
static int32_t getCutFromPrescale(double prescale)
calculate cut value for hardware configuration cut = 2*24/prescale - 1
void initialize(xAOD::CTPResult &ctpRes, const uint32_t ctpVersionNumber, std::vector< uint32_t > &data, const uint32_t nExtraWords)
Initialize the object using xAOD::Header, xAOD::Trailer, and the payload data.
void dumpData(xAOD::CTPResult &ctpRes)
Print object content to default message stream.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.