Skip to content

Commit

Permalink
Issue #165 - port to unified format 2.x
Browse files Browse the repository at this point in the history
Fix CAENParser allow for fact that fragmentindex body pointer points to
the body header.
  • Loading branch information
Ron Fox committed Sep 3, 2024
1 parent 7422427 commit 8200bfb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
9 changes: 7 additions & 2 deletions main/Core/CAENParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ CAENParser::~CAENParser()
* The first long is the size of the event body.
* The event body is assumed to be, and better be,
* an event built event.
*
* NOTE: In ufmt s_itembody points to the body header.
*/
void
CAENParser::operator()(void* pEventBody)
{

ufmt::FragmentIndex frags(static_cast<uint16_t*>(pEventBody));
for (int i =0; i < frags.getNumberFragments(); i++) {
ufmt::FragmentInfo info = frags.getFragment(i);

const uint8_t* pBody = reinterpret_cast<const uint8_t*>(info.s_itembody);
const uint32_t* pBhSize = reinterpret_cast<const uint32_t*>(info.s_itembody);
pBody += *pBhSize; // Skip the body headeer.
int sid = info.s_sourceId; // That's what we care about.

// If there's a module in the map we ask it to
Expand All @@ -63,7 +68,7 @@ CAENParser::operator()(void* pEventBody)
auto p = m_modules.find(sid);
if (p != m_modules.end()) {
CAENHit* pHit = makeHit(p->second);
pHit->unpack(const_cast<uint16_t*>(info.s_itembody));
pHit->unpack(const_cast<uint16_t*>(reinterpret_cast<const uint16_t*>(pBody)));
if (p->second.s_module.getHits().size() == 0) {
// First hit:

Expand Down
26 changes: 13 additions & 13 deletions main/Core/caenevptests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
#include <Histogrammer.h>
#include <Globals.h>
#include <stdint.h>
#include <DataFormat.h>
#include <v11/DataFormat.h>
#include <fragment.h>
#include <memory.h>
#include <stdint.h>


using namespace ufmt;
using namespace ufmt::v11;
class CAnalyzer;
class CBufferDecoder;

Expand Down Expand Up @@ -142,11 +142,11 @@ CPPUNIT_TEST_SUITE_REGISTRATION(caenevptest);
size_t
caenevptest::makeFragment(void* pDest, void* pItem)
{
ufmt::pRingItemHeader pSrc = reinterpret_cast<ufmt::pRingItemHeader>(pItem);
ufmt::pBodyHeader pBh = reinterpret_cast<ufmt::pBodyHeader>(pSrc+1);
pRingItemHeader pSrc = reinterpret_cast<pRingItemHeader>(pItem);
pBodyHeader pBh = reinterpret_cast<pBodyHeader>(pSrc+1);

ufmt::EVB::pFragmentHeader pFrag = reinterpret_cast<ufmt::EVB::pFragmentHeader>(pDest);
ufmt::EVB::pFragmentHeader pBody = pFrag+1;
EVB::pFragmentHeader pFrag = reinterpret_cast<EVB::pFragmentHeader>(pDest);
EVB::pFragmentHeader pBody = pFrag+1;

// Fill in the fragment header; we get the info from the body header
// and ring item header.
Expand All @@ -157,7 +157,7 @@ caenevptest::makeFragment(void* pDest, void* pItem)
pFrag->s_barrier = pBh->s_barrier;
memcpy(pBody, pSrc, pSrc->s_size);

return pSrc->s_size + sizeof(ufmt::EVB::FragmentHeader);
return pSrc->s_size + sizeof(EVB::FragmentHeader);

}
/**
Expand All @@ -176,16 +176,16 @@ caenevptest::makeRingItem(
{
// Build pointers to the chunks of the ring item:

ufmt::pRingItemHeader pItemHeader = reinterpret_cast<ufmt::pRingItemHeader>(p);
ufmt::pBodyHeader pBHeader = reinterpret_cast<ufmt::pBodyHeader>(pItemHeader+1);
pRingItemHeader pItemHeader = reinterpret_cast<pRingItemHeader>(p);
pBodyHeader pBHeader = reinterpret_cast<pBodyHeader>(pItemHeader+1);
uint32_t* pBody = reinterpret_cast<uint32_t*>(pBHeader+1);

// Fill in the body header:

pBHeader->s_timestamp = time;
pBHeader->s_sourceId = sid;
pBHeader->s_barrier = 0;
pBHeader->s_size = sizeof(ufmt::BodyHeader);
pBHeader->s_size = sizeof(BodyHeader);

// Fill in the data:

Expand All @@ -194,9 +194,9 @@ caenevptest::makeRingItem(

// Fill in the ring item header:

size_t totalSize = sizeof(uint32_t)+payloadSize + sizeof(ufmt::BodyHeader) + sizeof(ufmt::RingItemHeader);
size_t totalSize = sizeof(uint32_t)+payloadSize + sizeof(BodyHeader) + sizeof(RingItemHeader);
pItemHeader->s_size = totalSize;
pItemHeader->s_type = ufmt::PHYSICS_EVENT;
pItemHeader->s_type = PHYSICS_EVENT;

return totalSize;
}
Expand Down
21 changes: 12 additions & 9 deletions main/Core/parsertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@
#undef private
#include "CAENHit.h"
#include "CAENModuleHits.h"
#include <DataFormat.h>
#include <v11/DataFormat.h>

#include <fragment.h>
#include <stdint.h>
#include <string.h>

using namespace ufmt::v11;
using namespace ufmt;

/**
* The struct type below is used to compose 'events'.
*/
Expand Down Expand Up @@ -63,17 +66,17 @@ FakeEvent::putFragment(
size_t nBytes, uint64_t timestamp, uint32_t sid, void* pData
)
{
ufmt::EVB::pFragmentHeader p =
reinterpret_cast<ufmt::EVB::pFragmentHeader>(m_pCursor);
EVB::pFragmentHeader p =
reinterpret_cast<EVB::pFragmentHeader>(m_pCursor);
p->s_timestamp = timestamp;
p->s_sourceId = sid;
p->s_size = nBytes + sizeof(ufmt::RingItemHeader) + sizeof(ufmt::BodyHeader);
p->s_size = nBytes + sizeof(RingItemHeader) + sizeof(BodyHeader);
p->s_barrier = 0;
ufmt::pRingItemHeader pRHeader = reinterpret_cast<ufmt::pRingItemHeader>(p+1);
pRingItemHeader pRHeader = reinterpret_cast<pRingItemHeader>(p+1);
pRHeader->s_size = p->s_size;
pRHeader->s_type = ufmt::PHYSICS_EVENT;
ufmt::pBodyHeader pBHeader = reinterpret_cast<ufmt::pBodyHeader>(pRHeader+1);
pBHeader->s_size = sizeof(ufmt::BodyHeader);
pRHeader->s_type = PHYSICS_EVENT;
pBodyHeader pBHeader = reinterpret_cast<pBodyHeader>(pRHeader+1);
pBHeader->s_size = sizeof(BodyHeader);
pBHeader->s_timestamp = timestamp;
pBHeader->s_sourceId = sid;
pBHeader->s_barrier = 0;
Expand Down Expand Up @@ -248,7 +251,7 @@ void parsertest::parse_2()

uint16_t data[0x11] = {
0x0011, 0x0000, // Word count.
0x001e, 0x0000, // Byte count.
32, 0x0000, // Byte count.
0x1, 0x0000, // Channel #
0x1234, 0x5678, 0x9abc, 0xef, // timestamp.
100, // energy.
Expand Down

0 comments on commit 8200bfb

Please sign in to comment.