17#include "GaudiKernel/IRegistry.h"
18#include "GaudiKernel/ThreadLocalContext.h"
21#include "eformat/Issue.h"
22#include "eformat/SourceIdentifier.h"
31 AthMessaging(msgSvc(),
"L1TriggerResultByteStreamCnv") {}
46 const bool doMuon = not serviceLocator()->getOptsSvc().get(
"ToolSvc.L1MuonBSEncoderTool.ROBIDs").empty();
47 ATH_MSG_DEBUG(
"MUCTPI BS encoding is " << (doMuon ?
"enabled" :
"disabled"));
50 const bool doMuonDaq = not serviceLocator()->getOptsSvc().get(
"ToolSvc.L1MuonBSEncoderToolDAQ.ROBIDs").empty();
51 ATH_MSG_DEBUG(
"MUCTPI DAQ ROB encoding is " << (doMuonDaq ?
"enabled" :
"disabled"));
54 const bool doCTP = not serviceLocator()->getOptsSvc().get(
"ToolSvc.CTPResultBSEncoderTool.ROBIDs").empty();
55 ATH_MSG_DEBUG(
"CTP BS encoding is " << (doCTP ?
"enabled" :
"disabled"));
58 const bool doEfex = not serviceLocator()->getOptsSvc().get(
"ToolSvc.eFexBSEncoderTool.ROBIDs").empty();
59 ATH_MSG_DEBUG(
"eFex BS encoding is " << (doEfex ?
"enabled" :
"disabled"));
62 const bool doJfex = not serviceLocator()->getOptsSvc().get(
"ToolSvc.jFexBSEncoderTool.ROBIDs").empty();
63 ATH_MSG_DEBUG(
"jFex BS encoding is " << (doJfex ?
"enabled" :
"disabled"));
66 const bool doGfex = not serviceLocator()->getOptsSvc().get(
"ToolSvc.gFexBSEncoderTool.ROBIDs").empty();
67 ATH_MSG_DEBUG(
"gFex BS encoding is " << (doGfex ?
"enabled" :
"disabled"));
71 return StatusCode::SUCCESS;
94 return StatusCode::SUCCESS;
101 ATH_MSG_ERROR(
"L1TriggerResult cannot be created directly from ByteStream!"
102 <<
" Use the L1TriggerResultMaker algorithm instead");
103 return StatusCode::FAILURE;
112 const EventContext& ctx = Gaudi::Hive::currentContext();
117 if (!castSuccessful || !l1TriggerResult) {
118 ATH_MSG_ERROR(
"Failed to convert DataObject to xAOD::TrigCompositeContainer for L1TriggerResult");
119 return StatusCode::FAILURE;
125 ATH_MSG_ERROR(
"Failed to obtain a pointer to RawEventWrite");
126 return StatusCode::FAILURE;
138 l1tr->
getDetail<std::string>(
"CTPResultKey", ctpKey);
145 auto wordsToBitset = [](
const std::vector<uint32_t>& words) {
146 std::bitset<512> out;
147 for (
size_t i = 0; i < words.size(); ++i) {
148 uint32_t w = words[i];
149 for (
size_t b = 0; b < 32; ++b) {
158 std::bitset<512> tbp = wordsToBitset(result->getTBPWords());
159 std::bitset<512> tap = wordsToBitset(result->getTAPWords());
160 std::bitset<512> tav = wordsToBitset(result->getTAVWords());
163 constexpr size_t wordSize = 32;
164 constexpr size_t wordsPerSet = 512 / wordSize;
165 constexpr size_t numWords = 3 * wordsPerSet;
168 std::vector<uint32_t> l1BitsData(numWords, 0);
172 for (
const std::bitset<512>& bset : {tbp, tap, tav}) {
173 const std::string
sbits = bset.to_string();
174 const size_t iWordOutputStart = wordsPerSet * iset;
175 for (
size_t iWordInSet = 0; iWordInSet < wordsPerSet; ++iWordInSet) {
176 const size_t bwordPos = 512 - (iWordInSet + 1) * wordSize;
177 std::bitset<wordSize> bword{
sbits.substr(bwordPos, wordSize)};
178 l1BitsData[iWordOutputStart + iWordInSet] =
static_cast<uint32_t
>(bword.to_ulong());
182 const uint32_t triggerType = result->triggerType();
185 re->lvl1_trigger_info(l1BitsData.size(), l1BitsData.data());
186 re->lvl1_trigger_type(
static_cast<uint8_t
>(triggerType & 0xFF));
192 if (l1tr->
getDetail<std::string>(
"CTPResultKey", ctpKey)) {
193 ATH_MSG_WARNING(
"L1TriggerResult contains CTPResult ReadHandleKey but CTP bytestream encoding tool is not enabled");
200 if (not tool.isEnabled()) {
continue;}
201 std::vector<WROBF*> muon_robs;
202 ATH_CHECK(tool->convertToBS(muon_robs, l1TriggerResult, ctx));
203 ATH_MSG_DEBUG(tool.name() <<
" created " << muon_robs.size() <<
" L1Muon ROB Fragments");
204 for (
WROBF* rob : muon_robs) {
207 rob->rod_lvl1_type(
re->lvl1_trigger_type());
209 rob->rod_lvl1_id(
re->lvl1_id());
212 ATH_MSG_DEBUG(
"Added ROB fragment 0x" << MSG::hex << rob->source_id() << MSG::dec <<
" to the output raw event");
219 if ( pAddr !=
nullptr ) pAddr->release();
221 pAddr =
static_cast<IOpaqueAddress*
>(bsAddr);
225 return StatusCode::SUCCESS;
232 if (not
msgLvl(MSG::DEBUG)) {
return;}
233 const uint32_t ndata = rob.rod_ndata();
234 const uint32_t*
data = rob.rod_data();
236 for (uint32_t i=0; i<ndata; ++i, ++
data) {
const boost::regex re(r_e)
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
uint32_t CLID
The Class ID type.
char data[hepevt_bytes_allocation_ATLAS]
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::FullEventFragment RawEventWrite
data type for writing raw event
convert to and from a SG storable
#define sbits(u, n)
Intrinsic functions which do not work correctly due to differences in byte ordering.
bool msgLvl(const MSG::Level lvl) const
Test the output level.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
IOpaqueAddress for ByteStreamCnvSvc, with ROB ids.
static constexpr long storageType()
const T * at(size_type n) const
Access an element, as an rvalue.
static CLID classID()
CLID of the class of the L1TriggerResult converted by this converter (xAOD::TrigCompositeContainer).
void printRob(const OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment &rob) const
Helper method for debug printouts.
ToolHandle< IL1TriggerByteStreamTool > m_ctpResultEncoderTool
Encoder tool for CTP result.
virtual StatusCode createRep(DataObject *pObj, IOpaqueAddress *&pAddr) override
Create ByteStream from xAOD (L1TriggerResult).
static long storageType()
Storage type used by this converter.
ToolHandle< IL1TriggerByteStreamTool > m_efexEncoderTool
eFEX tool
virtual StatusCode finalize() override
ToolHandle< IL1TriggerByteStreamTool > m_muonEncoderTool
Encoder tools for L1Muon RoIs (one writing RoIB ROB, one writing DAQ ROB).
ToolHandle< IL1TriggerByteStreamTool > m_jfexEncoderTool
jFEX tool
ServiceHandle< IByteStreamEventAccess > m_ByteStreamEventAccess
Helper to obtain the RawEvent pointer.
virtual ~L1TriggerResultByteStreamCnv()
Standard destructor.
virtual StatusCode initialize() override
ToolHandle< IL1TriggerByteStreamTool > m_gfexEncoderTool
gFEX tool
ToolHandle< IL1TriggerByteStreamTool > m_muonEncoderToolDaq
L1TriggerResultByteStreamCnv(ISvcLocator *svcLoc)
Standard constructor.
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj) override
Create xAOD (L1TriggerResult) from ByteStream.
bool getDetail(const std::string &name, TYPE &value) const
Get an TYPE detail from the object.
eformat::write::ROBFragment ROBFragment
bool fromStorable(DataObject *pDObj, T *&pTrans, bool quiet=false, IRegisterTransient *irt=0, bool isConst=true)
TrigCompositeContainer_v1 TrigCompositeContainer
Declare the latest version of the container.
TrigComposite_v1 TrigComposite
Declare the latest version of the class.
static constexpr CLID ID()