17#include "GaudiKernel/IRegistry.h"
18#include "GaudiKernel/ThreadLocalContext.h"
21#include "eformat/Issue.h"
22#include "eformat/SourceIdentifier.h"
31 AthMessaging(msgSvc(),
"L1TriggerResultByteStreamCnv") {}
49 const bool doMuon = not serviceLocator()->getOptsSvc().get(
"ToolSvc.L1MuonBSEncoderTool.ROBIDs").empty();
50 ATH_MSG_DEBUG(
"MUCTPI BS encoding is " << (doMuon ?
"enabled" :
"disabled"));
53 const bool doMuonDaq = not serviceLocator()->getOptsSvc().get(
"ToolSvc.L1MuonBSEncoderToolDAQ.ROBIDs").empty();
54 ATH_MSG_DEBUG(
"MUCTPI DAQ ROB encoding is " << (doMuonDaq ?
"enabled" :
"disabled"));
57 const bool doCTP = not serviceLocator()->getOptsSvc().get(
"ToolSvc.CTPResultBSEncoderTool.ROBIDs").empty();
58 ATH_MSG_DEBUG(
"CTP BS encoding is " << (doCTP ?
"enabled" :
"disabled"));
62 return StatusCode::SUCCESS;
79 return StatusCode::SUCCESS;
86 ATH_MSG_ERROR(
"L1TriggerResult cannot be created directly from ByteStream!"
87 <<
" Use the L1TriggerResultMaker algorithm instead");
88 return StatusCode::FAILURE;
97 const EventContext& ctx = Gaudi::Hive::currentContext();
102 if (!castSuccessful || !l1TriggerResult) {
103 ATH_MSG_ERROR(
"Failed to convert DataObject to xAOD::TrigCompositeContainer for L1TriggerResult");
104 return StatusCode::FAILURE;
110 ATH_MSG_ERROR(
"Failed to obtain a pointer to RawEventWrite");
111 return StatusCode::FAILURE;
126 auto wordsToBitset = [](
const std::vector<uint32_t>& words) {
127 std::bitset<512> out;
128 for (
size_t i = 0; i < words.size(); ++i) {
129 uint32_t w = words[i];
130 for (
size_t b = 0; b < 32; ++b) {
139 std::bitset<512> tbp = wordsToBitset(
result->getTBPWords());
140 std::bitset<512> tap = wordsToBitset(
result->getTAPWords());
141 std::bitset<512> tav = wordsToBitset(
result->getTAVWords());
144 constexpr size_t wordSize = 32;
145 constexpr size_t wordsPerSet = 512 / wordSize;
146 constexpr size_t numWords = 3 * wordsPerSet;
149 std::vector<uint32_t> l1BitsData(numWords, 0);
153 for (
const std::bitset<512>& bset : {tbp, tap, tav}) {
154 const std::string
sbits = bset.to_string();
155 const size_t iWordOutputStart = wordsPerSet * iset;
156 for (
size_t iWordInSet = 0; iWordInSet < wordsPerSet; ++iWordInSet) {
157 const size_t bwordPos = 512 - (iWordInSet + 1) * wordSize;
158 std::bitset<wordSize> bword{
sbits.substr(bwordPos, wordSize)};
159 l1BitsData[iWordOutputStart + iWordInSet] =
static_cast<uint32_t
>(bword.to_ulong());
163 const uint32_t triggerType =
result->triggerType();
166 re->lvl1_trigger_info(l1BitsData.size(), l1BitsData.data());
167 re->lvl1_trigger_type(
static_cast<uint8_t
>(triggerType & 0xFF));
170 std::vector<WROBF*> ctpResultROBs;
173 for (
WROBF* rob : ctpResultROBs) {
176 rob->rod_lvl1_type(
re->lvl1_trigger_type());
178 rob->rod_lvl1_id(
re->lvl1_id());
181 ATH_MSG_DEBUG(
"Added ROB fragment 0x" << MSG::hex << rob->source_id() << MSG::dec <<
" to the output raw event");
188 if (not tool.isEnabled()) {
continue;}
189 std::vector<WROBF*> muon_robs;
190 ATH_CHECK(tool->convertToBS(muon_robs, ctx));
191 ATH_MSG_DEBUG(tool.name() <<
" created " << muon_robs.size() <<
" L1Muon ROB Fragments");
192 for (
WROBF* rob : muon_robs) {
195 rob->rod_lvl1_type(
re->lvl1_trigger_type());
197 rob->rod_lvl1_id(
re->lvl1_id());
200 ATH_MSG_DEBUG(
"Added ROB fragment 0x" << MSG::hex << rob->source_id() << MSG::dec <<
" to the output raw event");
207 if ( pAddr !=
nullptr ) pAddr->release();
209 pAddr =
static_cast<IOpaqueAddress*
>(bsAddr);
213 return StatusCode::SUCCESS;
220 if (not
msgLvl(MSG::DEBUG)) {
return;}
221 const uint32_t ndata = rob.rod_ndata();
222 const uint32_t*
data = rob.rod_data();
224 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()
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.
SG::ReadHandleKey< xAOD::CTPResult > m_inKeyCTPResult
virtual StatusCode finalize() override
ToolHandle< IL1TriggerByteStreamTool > m_muonEncoderTool
Encoder tools for L1Muon RoIs (one writing RoIB ROB, one writing DAQ ROB)
ServiceHandle< IByteStreamEventAccess > m_ByteStreamEventAccess
Helper to obtain the RawEvent pointer.
virtual ~L1TriggerResultByteStreamCnv()
Standard destructor.
virtual StatusCode initialize() override
ToolHandle< IL1TriggerByteStreamTool > m_muonEncoderToolDaq
L1TriggerResultByteStreamCnv(ISvcLocator *svcLoc)
Standard constructor.
virtual StatusCode createObj(IOpaqueAddress *pAddr, DataObject *&pObj) override
Create xAOD (L1TriggerResult) from ByteStream.
static const CLID & classID()
CLID of the class of the L1TriggerResult converted by this converter (xAOD::TrigCompositeContainer)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type get() const
Dereference the pointer, but don't cache anything.
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.
CTPResult_v1 CTPResult
Define the latest version of the CTPResult class.