From fe8ae689a5e8895d9354add76f96465dda6dad61 Mon Sep 17 00:00:00 2001 From: Ron Fox Date: Fri, 30 Aug 2024 10:58:22 -0400 Subject: [PATCH 1/8] Issue # 166 - Use unified format's fragment index stuff. Removed FragmentIndex and fragment.h from the build and the directory tree. --- main/Core/FragmentIndex.cpp | 124 ------------------------------------ main/Core/FragmentIndex.h | 119 ---------------------------------- main/Core/fragment.h | 111 -------------------------------- 3 files changed, 354 deletions(-) delete mode 100644 main/Core/FragmentIndex.cpp delete mode 100644 main/Core/FragmentIndex.h delete mode 100755 main/Core/fragment.h diff --git a/main/Core/FragmentIndex.cpp b/main/Core/FragmentIndex.cpp deleted file mode 100644 index 7b170a652..000000000 --- a/main/Core/FragmentIndex.cpp +++ /dev/null @@ -1,124 +0,0 @@ - -#include "FragmentIndex.h" -#include -#include -#include -#include -#include -#include -#include - - -FragmentIndex::FragmentIndex() - : m_frags() -{ -} - -/**! Given the body pointer, index all of the fragments -* @param a pointer to the first word in the body (this is b/4 the first fragment) -* -*/ -FragmentIndex::FragmentIndex(uint16_t* data) - : m_frags() -{ - - uint32_t max_bytes=0, temp; - - max_bytes = *(reinterpret_cast(data)); - - indexFragments( - data+sizeof(uint32_t)/sizeof(uint16_t), - max_bytes-sizeof(uint32_t) - ); //note that this indexFragments is defined in FragmentsIndex.h --JP -} - - -/**! Indexes all of the fragments - @param data a pointer to the first fragment - @param nbytes the number of bytes from start of first fragment to end of the body -*/ -void FragmentIndex::indexFragments(uint16_t* begin, uint16_t* end) -{ - - if (begin==0) { - throw std::runtime_error("Null pointer passed as argument, cannot proceed"); - } - - // clear what we have already found so we have a fresh search - m_frags.clear(); - - // if we have no data to process, then do nothing! - if (begin == end ) return; - - uint16_t* data = begin; - - size_t dist = 0; - do { - - dist = computeWordsToNextFragment(data); - - if ((data + dist) > end) { - throw std::runtime_error("FragmentIndex::indexFragments() insufficient data in buffer for next fragment!"); - } - - EVB::FlatFragment* frag = reinterpret_cast(data); - - // Store the body of the fragment in a condensed version - FragmentInfo info; - info.s_timestamp = frag->s_header.s_timestamp; - info.s_sourceId = frag->s_header.s_sourceId; - info.s_size = frag->s_header.s_size; - info.s_barrier = frag->s_header.s_barrier; - info.s_itemhdr = reinterpret_cast(frag->s_body); - - - //daqdev/SpecTcl#378 - Compute the size of the header in - // words and fill in info.s_itembody with a pointer to the final - // body. The header consists of a fixed part (ring item header) - // and a variable sized body header. When Fox chose the - // body header representation, like an idiot, he - // chose a size of 0, rather than sizeof(uint32_t) to mean - // no body header (R. Fox writing this), so theat results - // in a special case. - - size_t headerBytes = sizeof(RingItemHeader); - uint32_t* pBodyHeader = reinterpret_cast( - info.s_itemhdr + sizeof(RingItemHeader)/sizeof(uint16_t) - ); - if (*pBodyHeader == 0) { - headerBytes += sizeof(uint32_t); - } else { - headerBytes += *pBodyHeader; - } - // Now all this has to be in uint16_t scale: - - info.s_itembody = info.s_itemhdr + (headerBytes/sizeof(uint16_t)); - - m_frags.push_back(info); //Add current fragment to m_frags list --JP - - data += dist; - - } while (data < end); - -} - -size_t FragmentIndex::computeWordsToNextFragment(uint16_t* data) //This gives the total size of the fragment --JP -{ - // For reference, a fragment looks like this: - // struct EVB::FlatFragment { - // uint64_t tstamp; - // uint32_t sourceId; - // uint32_t payload_size; - // uint32_t barrier_type; - // char* body; - // } - // - - EVB::FlatFragment* frag = reinterpret_cast(data); - uint32_t payload_size = frag->s_header.s_size; // in bytes - uint32_t fraghdr_size = sizeof(EVB::FragmentHeader); // in bytes - - return (payload_size + fraghdr_size)/sizeof(uint16_t); - -} - diff --git a/main/Core/FragmentIndex.h b/main/Core/FragmentIndex.h deleted file mode 100644 index eae133ea5..000000000 --- a/main/Core/FragmentIndex.h +++ /dev/null @@ -1,119 +0,0 @@ -// FragmentIndex.h -// -// Author : Jeromy Tompkins -// Date : 3/2014 -// - -#ifndef FRAGMENTINDEX_H -#define FRAGMENTINDEX_H - -#include -#include -#include - -/**! A convenient, copiable piece formatting of -* a fragment. Similar to a EVB::FlatFragment but -* it can be copied safely. Similar to a EVB::Fragment -* but you don't need to typecast the body to use it. -*/ -struct FragmentInfo // A structure containting basic info from the Fragment header --JP -{ - uint64_t s_timestamp; - uint32_t s_sourceId; - uint32_t s_size; - uint32_t s_barrier; - uint16_t* s_itemhdr; - uint16_t* s_itembody; - - FragmentInfo() : - s_timestamp(0), s_sourceId(0), s_size(0), s_barrier(0), - s_itemhdr(0), s_itembody(0) {} -}; - - -/**! FragmentIndex -* -* A class that finds the start of every fragment in a built ring item. -* -*/ -class FragmentIndex -{ - private: - typedef std::vector Container; - - public: - typedef Container::iterator iterator; - typedef Container::const_iterator const_iterator; - - private: - Container m_frags; ///< The list of fragment locations - - public: - - /**! Default constructor - * Does nothing besides initialize the empty list of fragments - */ - FragmentIndex(); - - /**! Given the body pointer, index all of the fragmentsa - * @param a pointer to the first word in the body (this is b/4 the first fragment) - * - */ - FragmentIndex(uint16_t* data); - - /**! Get a fragment - * Checks whether the index provided is valid. If index is out of range, - * returns a null pointer. Otherwise, it returns the ith pointer. - * - * @param i is the index of the fragment in the body (starting at 0) - * - * @return the pointer to the ith fragment or null if ith index doesn't exist - */ - FragmentInfo getFragment(size_t i) - { - if (i=0) { - return m_frags.at(i); //pointer to ith fragment in the m_frags list --JP - } else { - FragmentInfo null; - null.s_itembody = static_cast(0); - return null; - } - } - - size_t getNumberFragments() const { return m_frags.size(); } - - /**! The indexing algorithm - * This will traverse the range of data in addresses [begin, end] - * and find all of the complete fragments. Every fragment found will be appended to the - * list of fragments m_frags. This is very similar to the constructor but differs in the arguments. - * The constructor expects that the first word of the body is passed, this expects that the - * pointer to the first fragment is passed. There should be a difference of 32-bits between - * the two arguments. - * - * @param begin a pointer to the first fragment - * @param end pointer just beyond the last fragment - */ - void indexFragments(uint16_t* begin, uint16_t* end); - - /**! The indexing algorithm - * @param data a pointer to the first fragment - * @param nbytes the number of bytes from start of first fragment to end of the body - */ - void indexFragments(uint16_t* data, size_t max_bytes) { - indexFragments(data, data+max_bytes/sizeof(uint16_t) ); - } - - private: - size_t computeWordsToNextFragment(uint16_t* data); - - - public: - // Implement an iterator interface - iterator begin() { return m_frags.begin(); } - const_iterator begin() const { return m_frags.begin(); } - - iterator end() { return m_frags.end(); } - const_iterator end() const { return m_frags.end(); } -}; - -#endif diff --git a/main/Core/fragment.h b/main/Core/fragment.h deleted file mode 100755 index a4056ce8c..000000000 --- a/main/Core/fragment.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - This software is Copyright by the Board of Trustees of Michigan - State University (c) Copyright 2009. - - You may use this software under the terms of the GNU public license - (GPL). The terms of this license are described at: - - http://www.gnu.org/licenses/gpl.txt - - Author: - Ron Fox - NSCL - Michigan State University - East Lansing, MI 48824-1321 -*/ - -#ifndef FRAGMENT_H -#define FRAGMENT_H - -#include -#include -#include - -/** - * The conditional directives in this file are for two reasons: - * - In C++ sources, the headers will qualify the type and function - * definitions with the ::EVB:: namepsace. - * - The implementations of the support functions are in C - * - * All of this is to support C programmers as well as C++. - */ - -#ifdef __cplusplus -namespace EVB { -#endif - /* - * Below are valid barrier types. - * These are #defines rather than enums so that the - * known width data types are used to make data transportable - * between 32/64 bit system. - */ - -#define BARRIER_NOTBARRIER 0 /* Not a barrier event. */ -#define BARRIER_START 1 /* Data taking starting (BEGIN/RESUME) */ -#define BARRIER_END 2 /* Data taking endng (END/PAUSE) */ -#define BARRIER_SYNCH 3 /* time synchronization barrier */ - - - /* Define the null timestamp as a 64 bits with all bits set */ - - static const uint64_t NULL_TIMESTAMP = 0xffffffffffffffff; - - /** - * The typedef below defines a fragment header. - */ - - typedef struct __attribute__((__packed__))_FragmentHeader { - uint64_t s_timestamp; //< Fragment time relative to globally synchronized clock. - uint32_t s_sourceId ; //< Unique source identifier. - uint32_t s_size; // Bytes in fragment payload. - uint32_t s_barrier; // Non zero for barrier events - the barrier type. - } FragmentHeader, *pFragmentHeader; - - - - /** - * Within the event builder fragments and payloads get bundled - * together into something that looks like: - */ - typedef struct __attribute__((__packed__)) _Fragment { - FragmentHeader s_header; - uint8_t* s_pBody; - } Fragment, *pFragment; - - - /** - * Linked list of fragments: - */ - typedef struct __attribute__((__packed__)) _FragmentChain { - struct _FragmentChain* s_pNext; - pFragment s_pFragment; - } FragmentChain, *pFragmentChain; - - typedef struct __attribute__((__packed__)) _FlatFragment { - FragmentHeader s_header; - uint8_t s_body[0]; - } FlatFragment, *pFlatFragment; -#ifdef __cplusplus -} -#endif - /** - * Below are convenience functions for fragments: - */ - -#ifdef __cplusplus - extern "C" { -#define NS(type) EVB::type -#else -#define NS(type) type -#endif - void freeFragment(NS(pFragment) p); - NS(pFragment) allocateFragment(NS(pFragmentHeader) pHeader); - NS(pFragment) newFragment(uint64_t timestamp, uint32_t sourceId, uint32_t size); - - size_t fragmentChainLength(NS(pFragmentChain) p); -#ifdef __cplusplus - } -#endif - #undef NS - -#endif From 7e8fe154cbf303732fffb8d5c7d8ec43491b209c Mon Sep 17 00:00:00 2001 From: Ron Fox Date: Fri, 30 Aug 2024 11:01:11 -0400 Subject: [PATCH 2/8] Issue # 166 - Use unified format's fragment index stuff. Also remove the fragment index tests from sourcdes/build --- main/Core/fragidxtests.cpp | 323 ------------------------------------- 1 file changed, 323 deletions(-) delete mode 100644 main/Core/fragidxtests.cpp diff --git a/main/Core/fragidxtests.cpp b/main/Core/fragidxtests.cpp deleted file mode 100644 index 22463af9b..000000000 --- a/main/Core/fragidxtests.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/* - This software is Copyright by the Board of Trustees of Michigan - State University (c) Copyright 2017. - - You may use this software under the terms of the GNU public license - (GPL). The terms of this license are described at: - - http://www.gnu.org/licenses/gpl.txt - - Authors: - Ron Fox - Giordano Cerriza - NSCL - Michigan State University - East Lansing, MI 48824-1321 -*/ - -/** @file: fragidxtst.cpp - * @brief: daqdev/SpecTcl#378 - Tests for FragmentIndex class. - */ -#include -#include -#include "Asserts.h" -#include "FragmentIndex.h" - -#include - -#include -#include -#include - -class fragidxTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(fragidxTest); - CPPUNIT_TEST(empty); - CPPUNIT_TEST(frag1_1); - CPPUNIT_TEST(frag1_2); - CPPUNIT_TEST(frag2_1); - CPPUNIT_TEST(frag2_2); - CPPUNIT_TEST_SUITE_END(); - -private: - -public: - void setUp() { - - } - void tearDown() { - - } -protected: - void empty(); - - void frag1_1(); - void frag1_2(); - - void frag2_1(); - void frag2_2(); -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(fragidxTest); - -void fragidxTest::empty() -{ - uint32_t event(sizeof(uint32_t)); // empty event built data. - FragmentIndex frags(reinterpret_cast(&event)); - EQ(size_t(0), frags.getNumberFragments()); -} - -void fragidxTest::frag1_1() -{ - // Single fragment, no body header. - - uint16_t event[1024]; // Probably too big. - - - // The Ring item. - - uint8_t frag[100]; - pRingItem pFrag = reinterpret_cast(frag); - pFrag->s_header.s_type = PHYSICS_EVENT; - pFrag->s_header.s_size = sizeof(RingItemHeader) + 2*sizeof(uint32_t); - pFrag->s_body.u_noBodyHeader.s_mbz = 0; - uint32_t *pData = - reinterpret_cast(pFrag->s_body.u_noBodyHeader.s_body); - *pData = 0xaaaaaaaa; // Nice signature. - - - // The fragment header. - - EVB::FragmentHeader fh; - fh.s_timestamp = 0x12345678; - fh.s_sourceId = 1; - fh.s_size = pFrag->s_header.s_size; - fh.s_barrier = 0; - - // Fill in event: - - uint32_t nBytes = sizeof(uint32_t) + sizeof(fh) + pFrag->s_header.s_size; - uint8_t* p = reinterpret_cast(event); - memcpy(p, &nBytes, sizeof(uint32_t)); - p += sizeof(uint32_t); - memcpy(p, &fh, sizeof(fh)); - p += sizeof(fh); - memcpy(p, pFrag, pFrag->s_header.s_size); - - FragmentIndex f(event); - EQ(size_t(1), f.getNumberFragments()); - FragmentInfo info = f.getFragment(0); - - EQ(uint64_t(0x12345678), info.s_timestamp); - EQ(uint32_t(1), info.s_sourceId); - EQ(fh.s_size, info.s_size); - EQ(fh.s_barrier, info.s_barrier); - - // The header should point to ring item header: - - pRingItemHeader pH = reinterpret_cast(info.s_itemhdr); - EQ(uint32_t(PHYSICS_EVENT), pH->s_type); - EQ(pFrag->s_header.s_size, pH->s_size); - - uint32_t* pMbz = reinterpret_cast(pH+1); - EQ(uint32_t(0), *pMbz); - - pMbz++; - uint32_t* body = reinterpret_cast(info.s_itembody); - EQ(pMbz, body); - EQ(uint32_t(0xaaaaaaaa), *body); - - - - -} -void fragidxTest::frag1_2() -{ - // One fragment with a 'standard' body header. - - // Single fragment, with body header. - - uint16_t event[1024]; // Probably too big. - - - // The Ring item. - - uint8_t frag[100]; - pRingItem pFrag = reinterpret_cast(frag); - pFrag->s_header.s_type = PHYSICS_EVENT; - pFrag->s_header.s_size = sizeof(RingItemHeader) + sizeof(uint32_t) + sizeof(BodyHeader); - pFrag->s_body.u_hasBodyHeader.s_bodyHeader.s_size = sizeof(BodyHeader); - pFrag->s_body.u_hasBodyHeader.s_bodyHeader.s_timestamp = 0x12345678; - pFrag->s_body.u_hasBodyHeader.s_bodyHeader.s_sourceId = 1; - pFrag->s_body.u_hasBodyHeader.s_bodyHeader.s_barrier = 0; - uint32_t *pData = - reinterpret_cast(pFrag->s_body.u_hasBodyHeader.s_body); - *pData = 0xaaaaaaaa; // Nice signature. - - // Fragment header: - - // The fragment header. - - EVB::FragmentHeader fh; - fh.s_timestamp = 0x12345678; - fh.s_sourceId = 1; - fh.s_size = pFrag->s_header.s_size; - fh.s_barrier = 0; - - - // Fill in event: - - uint32_t nBytes = sizeof(uint32_t) + sizeof(fh) + pFrag->s_header.s_size; - uint8_t* p = reinterpret_cast(event); - memcpy(p, &nBytes, sizeof(uint32_t)); - p += sizeof(uint32_t); - memcpy(p, &fh, sizeof(fh)); - p += sizeof(fh); - memcpy(p, pFrag, pFrag->s_header.s_size); - - FragmentIndex f(event); - EQ(size_t(1), f.getNumberFragments()); - - - FragmentInfo info = f.getFragment(0); - - EQ(uint64_t(0x12345678), info.s_timestamp); - EQ(uint32_t(1), info.s_sourceId); - EQ(fh.s_size, info.s_size); - EQ(fh.s_barrier, info.s_barrier); - - // The header should point to ring item header: - - pRingItemHeader pH = reinterpret_cast(info.s_itemhdr); - EQ(uint32_t(PHYSICS_EVENT), pH->s_type); - EQ(pFrag->s_header.s_size, pH->s_size); - - // The body should point to the signature word: - - uint32_t* pBody = reinterpret_cast(info.s_itembody); - EQ(uint32_t(0xaaaaaaaa), *pBody); - -} -void fragidxTest::frag2_1() -{ - // Two fragments - first has no body header. - // We can get to the second one ok. -uint16_t event[1024]; // Probably too big. - - - // The Ring item. - - uint8_t frag[100]; - pRingItem pFrag = reinterpret_cast(frag); - pFrag->s_header.s_type = PHYSICS_EVENT; - pFrag->s_header.s_size = sizeof(RingItemHeader) + 2*sizeof(uint32_t); - pFrag->s_body.u_noBodyHeader.s_mbz = 0; - uint32_t *pData = - reinterpret_cast(pFrag->s_body.u_noBodyHeader.s_body); - *pData = 0xaaaaaaaa; // Nice signature. - - - // The fragment header. - - EVB::FragmentHeader fh; - fh.s_timestamp = 0x12345678; - fh.s_sourceId = 1; - fh.s_size = pFrag->s_header.s_size; - fh.s_barrier = 0; - - // Fill in event: - - uint32_t nBytes = sizeof(uint32_t) + 2*(sizeof(fh) + pFrag->s_header.s_size); - uint8_t* p = reinterpret_cast(event); - memcpy(p, &nBytes, sizeof(uint32_t)); - p += sizeof(uint32_t); - memcpy(p, &fh, sizeof(fh)); - p += sizeof(fh); - memcpy(p, pFrag, pFrag->s_header.s_size); - p += pFrag->s_header.s_size; - - // Second event we just change the timestamp and pattern: - - *pData = 0x55555555; - fh.s_timestamp = 0x87654321; // Can't happen in real life but... - - memcpy(p, &fh, sizeof(fh)); - p += sizeof(fh); - memcpy(p, pFrag, pFrag->s_header.s_size); - - FragmentIndex f(event); - EQ(size_t(2), f.getNumberFragments()); - auto info = f.getFragment(1); // Second frag. - - EQ(uint64_t(0x87654321), info.s_timestamp); - uint32_t* pBody = reinterpret_cast(info.s_itembody); - EQ(uint32_t(0x55555555), *pBody); - - -} - -void fragidxTest::frag2_2() -{ - // Two fragments first has a body header, - // we can get to the second one ok. - - uint16_t event[1024]; // Probably too big. - - - // The Ring item. - - uint8_t frag[100]; - pRingItem pFrag = reinterpret_cast(frag); - pFrag->s_header.s_type = PHYSICS_EVENT; - pFrag->s_header.s_size = sizeof(RingItemHeader) + sizeof(uint32_t) + sizeof(BodyHeader); - pFrag->s_body.u_hasBodyHeader.s_bodyHeader.s_size = sizeof(BodyHeader); - pFrag->s_body.u_hasBodyHeader.s_bodyHeader.s_timestamp = 0x12345678; - pFrag->s_body.u_hasBodyHeader.s_bodyHeader.s_sourceId = 1; - pFrag->s_body.u_hasBodyHeader.s_bodyHeader.s_barrier = 0; - uint32_t *pData = - reinterpret_cast(pFrag->s_body.u_hasBodyHeader.s_body); - *pData = 0xaaaaaaaa; // Nice signature. - - // Fragment header: - - // The fragment header. - - EVB::FragmentHeader fh; - fh.s_timestamp = 0x12345678; - fh.s_sourceId = 1; - fh.s_size = pFrag->s_header.s_size; - fh.s_barrier = 0; - - - // Fill in event: - - uint32_t nBytes = sizeof(uint32_t) + 2*(sizeof(fh) + pFrag->s_header.s_size); - uint8_t* p = reinterpret_cast(event); - memcpy(p, &nBytes, sizeof(uint32_t)); - p += sizeof(uint32_t); - memcpy(p, &fh, sizeof(fh)); - p += sizeof(fh); - memcpy(p, pFrag, pFrag->s_header.s_size); - p += pFrag->s_header.s_size; - - // Second event change both timestamps and the pattern: - - fh.s_timestamp = 0x87654321; - pFrag->s_body.u_hasBodyHeader.s_bodyHeader.s_timestamp = 0x87654321; - *pData = 0x55555555; - - // Put the event: - - memcpy(p, &fh, sizeof(fh)); - p += sizeof(fh); - memcpy(p, pFrag, pFrag->s_header.s_size); - p += pFrag->s_header.s_size; - - FragmentIndex f(event); - EQ(size_t(2), f.getNumberFragments()); - - auto info = f.getFragment(1); // Second frag. - EQ(uint64_t(0x87654321), info.s_timestamp); - uint32_t* pBody = reinterpret_cast(info.s_itembody); - EQ(*pData, *pBody); - -} \ No newline at end of file From 3a542f0d95e6ec0a44aa890b9c48bc34248f1f93 Mon Sep 17 00:00:00 2001 From: Ron Fox Date: Fri, 30 Aug 2024 11:47:02 -0400 Subject: [PATCH 3/8] Issue # 166 - Use unified format's fragment index stuff. Make core and tests use the centralized fragment stuff in ufmt --- main/Core/CAENParser.cpp | 8 ++++---- main/Core/CEventBuilderEventProcessor.cpp | 6 +++--- main/Core/Makefile.am | 20 ++++++++------------ main/Core/caenevptests.cpp | 6 +++--- main/Core/evbProcessorTests.cpp | 6 +++--- main/Core/parsertest.cpp | 6 +++--- 6 files changed, 24 insertions(+), 28 deletions(-) diff --git a/main/Core/CAENParser.cpp b/main/Core/CAENParser.cpp index 270e9dc1c..fd6cc6e87 100644 --- a/main/Core/CAENParser.cpp +++ b/main/Core/CAENParser.cpp @@ -19,7 +19,7 @@ * @brief: Implement methods of parsing events with CAEN hits. */ #include "CAENParser.h" -#include "FragmentIndex.h" +#include #include #include @@ -50,9 +50,9 @@ CAENParser::~CAENParser() void CAENParser::operator()(void* pEventBody) { - FragmentIndex frags(static_cast(pEventBody)); + ufmt::FragmentIndex frags(static_cast(pEventBody)); for (int i =0; i < frags.getNumberFragments(); i++) { - FragmentInfo info = frags.getFragment(i); + ufmt::FragmentInfo info = frags.getFragment(i); int sid = info.s_sourceId; // That's what we care about. @@ -63,7 +63,7 @@ CAENParser::operator()(void* pEventBody) auto p = m_modules.find(sid); if (p != m_modules.end()) { CAENHit* pHit = makeHit(p->second); - pHit->unpack(info.s_itembody); + pHit->unpack(const_cast(info.s_itembody)); if (p->second.s_module.getHits().size() == 0) { // First hit: diff --git a/main/Core/CEventBuilderEventProcessor.cpp b/main/Core/CEventBuilderEventProcessor.cpp index b03c631fe..12ba4f868 100755 --- a/main/Core/CEventBuilderEventProcessor.cpp +++ b/main/Core/CEventBuilderEventProcessor.cpp @@ -23,7 +23,7 @@ #include #include "CEventBuilderEventProcessor.h" #include "CTreeParameter.h" -#include "FragmentIndex.h" +#include #include #include @@ -128,7 +128,7 @@ CEventBuilderEventProcessor::operator()( ) { *m_eventNumber = ++m_nEvents; - FragmentIndex frags(reinterpret_cast(pEvent)); + ufmt::FragmentIndex frags(reinterpret_cast(pEvent)); // Source cout will be the number of fragments -- note an event is allowed // to have more than one fragment from the same source id....this @@ -153,7 +153,7 @@ CEventBuilderEventProcessor::operator()( if (info.s_processor) { // in case we just made an empty. (*info.s_SourcePresent) = 1; Bool_t ok = (*info.s_processor)( - pFrag->s_itembody, rEvent, rAnalyzer, rDecoder + const_cast(pFrag->s_itembody), rEvent, rAnalyzer, rDecoder ); if (!ok) throw ok; // Failure. } else { diff --git a/main/Core/Makefile.am b/main/Core/Makefile.am index d3d7f665b..d0505c59b 100644 --- a/main/Core/Makefile.am +++ b/main/Core/Makefile.am @@ -242,7 +242,7 @@ TclGrammerApp_SRC = StopRun.cpp StartRun.cpp \ IntegrateCommand.cpp RingFormatCommand.cpp VersionCommand.cpp \ SContentsCommand.cpp CSpectrumStatsCommand.cpp SpecTclDisplayManager.cpp \ XamineEventHandler.cpp SharedMemoryKeyCommand.cpp SharedMemorySizeCommand.cpp \ - CPipelineManager.cpp FragmentIndex.cpp \ + CPipelineManager.cpp \ CEventBuilderEventProcessor.cpp CPipelineCommand.cpp \ CPipelineEventProcessor.cpp CUnpackEvbCommand.cpp \ CAENHit.cpp CAENModuleHits.cpp CAENParser.cpp CAENParameterMap.cpp \ @@ -268,7 +268,7 @@ TclGrammerApp_INCLUDES = AppInit.h ApplyCommand.h AttachCommand.h BindCommand.h IntegrateCommand.h RingFormatCommand.h VersionCommand.h SContentsCommand.h \ CSpectrumStatsCommand.h SpecTclDisplayManager.h \ XamineEventHandler.h SharedMemoryKeyCommand.h SharedMemorySizeCommand.h \ - CPipelineCommand.h CPipelineManager.h fragment.h FragmentIndex.h \ + CPipelineCommand.h CPipelineManager.h \ CEventBuilderEventProcessor.h CPipelineEventProcessor.h \ CUnpackEvbCommand.h CAENHit.h CAENModuleHits.h CAENParser.h \ CAENParameterMap.h CAENEventProcessor.h \ @@ -440,7 +440,7 @@ noinst_PROGRAMS = spectrumPkgTests \ sorterTests treeParamTests fitTests \ xamineTests spectraDisplayTests \ spectclCmdTests evbProcessorTests \ - gateTests fragIndexTests caendpptests \ + gateTests caendpptests \ mirrortests \ helpertests newanalysistests \ paramdecodetests fribfiltertests @@ -475,8 +475,8 @@ newanalysistests_LDADD=$(commonTestLdFlags) caendpptests_SOURCES = TestRunner.cpp PHAHitTest.cpp PSDHitTest.cpp \ modulehittests.cpp parsertest.cpp caenpmaptests.cpp caenevptests.cpp -caendpptests_CXXFLAGS= $(commonTestCXXFLAGS) -caendpptests_LDADD = $(commonTestLdFlags) +caendpptests_CXXFLAGS= $(commonTestCXXFLAGS) @UFMT_CPPFLAGS@ +caendpptests_LDADD = $(commonTestLdFlags) @UFMT_LDFLAGS@ gateTests_CXXFLAGS = $(commonTestCXXFLAGS) @@ -539,16 +539,12 @@ spectclCmdTests_SOURCES = TestRunner.cpp \ SharedMemoryKeyCommandTest.cpp \ SharedMemorySizeCommandTest.cpp -evbProcessorTests_CXXFLAGS = $(commonTestCXXFLAGS) -evbProcessorTests_LDADD = $(commonTestLdFlags) +evbProcessorTests_CXXFLAGS = $(commonTestCXXFLAGS) @UFMT_CPPFLAGS@ +evbProcessorTests_LDADD = $(commonTestLdFlags) @UFMT_LDFLAGS@ evbProcessorTests_SOURCES = TestRunner.cpp evbProcessorTests.cpp \ pipemgrtests.cpp pipecmdtests.cpp pipeevptests.cpp evbunpackCmdTests.cpp -fragIndexTests_CXXFLAGS=$(commonTestCXXFLAGS) -fragIndexTests_LDADD=$(commonTestLdFlags) -fragIndexTests_SOURCES = TestRunner.cpp FragmentIndex.cpp FragmentIndex.h fragidxtests.cpp - mirrortests_CXXFLAGS=$(commonTestCXXFLAGS) mirrortests_LDADD=$(commonTestLdFlags) mirrortests_SOURCES = TestRunner.cpp mdirtests.cpp servertests.cpp \ @@ -572,7 +568,7 @@ fribfiltertests_SOURCES=TestRunner.cpp fribfiltertests.cpp \ TESTS_ENVIRONMENT=LD_LIBRARY_PATH=$(ROOT_LIBRARY_DIR) TESTS =helpertests gateTests spectrumPkgTests displayInterfaceTests \ sorterTests treeParamTests fitTests xamineTests spectraDisplayTests \ - spectclCmdTests evbProcessorTests fragIndexTests caendpptests \ + spectclCmdTests evbProcessorTests caendpptests \ mirrortests newanalysistests paramdecodetests fribfiltertests diff --git a/main/Core/caenevptests.cpp b/main/Core/caenevptests.cpp index 53dd8fe81..9144fb0bd 100644 --- a/main/Core/caenevptests.cpp +++ b/main/Core/caenevptests.cpp @@ -145,8 +145,8 @@ caenevptest::makeFragment(void* pDest, void* pItem) pRingItemHeader pSrc = reinterpret_cast(pItem); pBodyHeader pBh = reinterpret_cast(pSrc+1); - EVB::pFragmentHeader pFrag = reinterpret_cast(pDest); - EVB::pFragmentHeader pBody = pFrag+1; + ufmt::EVB::pFragmentHeader pFrag = reinterpret_cast(pDest); + ufmt::EVB::pFragmentHeader pBody = pFrag+1; // Fill in the fragment header; we get the info from the body header // and ring item header. @@ -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(EVB::FragmentHeader); + return pSrc->s_size + sizeof(ufmt::EVB::FragmentHeader); } /** diff --git a/main/Core/evbProcessorTests.cpp b/main/Core/evbProcessorTests.cpp index d30f06636..9bd1baad3 100755 --- a/main/Core/evbProcessorTests.cpp +++ b/main/Core/evbProcessorTests.cpp @@ -10,7 +10,7 @@ #include "TreeParameter.h" #include "Asserts.h" #include "Event.h" -#include "fragment.h" +#include #include #include #include @@ -260,7 +260,7 @@ makeEmptyFragments(const std::vector >& info) // Figure out how big the event will be... it'll lead with a size // and just be a list of FragmentHeader structs. - size_t nBytes = sizeof(uint32_t) + info.size() * sizeof(EVB::FragmentHeader); + size_t nBytes = sizeof(uint32_t) + info.size() * sizeof(ufmt::EVB::FragmentHeader); void* pResult = malloc(nBytes); ASSERT(pResult); // just fail if we can't make an event. @@ -271,7 +271,7 @@ makeEmptyFragments(const std::vector >& info) // Now the fragments: - EVB::pFragmentHeader pFrag = reinterpret_cast(pSize); + ufmt::EVB::pFragmentHeader pFrag = reinterpret_cast(pSize); for (int i = 0; i < info.size(); i++) { pFrag->s_timestamp = info[i].second; pFrag->s_sourceId = info[i].first; diff --git a/main/Core/parsertest.cpp b/main/Core/parsertest.cpp index 848a61567..473130204 100644 --- a/main/Core/parsertest.cpp +++ b/main/Core/parsertest.cpp @@ -28,7 +28,7 @@ #include "CAENModuleHits.h" #include "DataFormat.h" -#include "fragment.h" +#include #include #include @@ -63,8 +63,8 @@ FakeEvent::putFragment( size_t nBytes, uint64_t timestamp, uint32_t sid, void* pData ) { - EVB::pFragmentHeader p = - reinterpret_cast(m_pCursor); + ufmt::EVB::pFragmentHeader p = + reinterpret_cast(m_pCursor); p->s_timestamp = timestamp; p->s_sourceId = sid; p->s_size = nBytes + sizeof(RingItemHeader) + sizeof(BodyHeader); From bbb8276d2d20189107b34921e1bd69228b47af2c Mon Sep 17 00:00:00 2001 From: Ron Fox Date: Fri, 30 Aug 2024 11:47:28 -0400 Subject: [PATCH 4/8] Issue # 166 - Use unified format's fragment index stuff. Make the ddas parser stuff use the ufmt fragment and fragment index stuff --- main/ddas/DDASBuiltFitUnpacker.cpp | 6 +++--- main/ddas/DDASBuiltFitUnpacker.h | 4 ++-- main/ddas/DDASBuiltUnpacker.cpp | 6 +++--- main/ddas/DDASBuiltUnpacker.h | 4 ++-- main/ddas/Makefile.am | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/main/ddas/DDASBuiltFitUnpacker.cpp b/main/ddas/DDASBuiltFitUnpacker.cpp index d5115865a..b54ab302b 100644 --- a/main/ddas/DDASBuiltFitUnpacker.cpp +++ b/main/ddas/DDASBuiltFitUnpacker.cpp @@ -104,7 +104,7 @@ namespace DAQ { Bool_t CDDASBuiltFitUnpacker::selectivelyParseData(uint16_t* p16) { // index the fragments - FragmentIndex parsedFragments(p16); + ufmt::FragmentIndex parsedFragments(p16); // loop over the fragments for (auto& fragInfo : parsedFragments ) { @@ -121,12 +121,12 @@ namespace DAQ { //////// /// - Bool_t CDDASBuiltFitUnpacker::parseAndStoreFragment(FragmentInfo& info) + Bool_t CDDASBuiltFitUnpacker::parseAndStoreFragment(ufmt::FragmentInfo& info) { DDASFitHit hit; FitHitUnpacker unpacker; - auto pBody = reinterpret_cast(info.s_itemhdr); + auto pBody = reinterpret_cast(info.s_itemhdr); size_t bodySize = *pBody; // # of 16-bit words in body (inclusive) // parse the body of the ring item diff --git a/main/ddas/DDASBuiltFitUnpacker.h b/main/ddas/DDASBuiltFitUnpacker.h index 372defa6d..02e564971 100644 --- a/main/ddas/DDASBuiltFitUnpacker.h +++ b/main/ddas/DDASBuiltFitUnpacker.h @@ -20,7 +20,7 @@ #define DAQ_DDAS_DDASBUILTUNPACKER_H #include -#include "FragmentIndex.h" +#include #include "DDASFitHit.h" #include @@ -152,7 +152,7 @@ namespace DAQ { Bool_t selectivelyParseData(uint16_t* p16); - Bool_t parseAndStoreFragment(FragmentInfo& fragInfo); + Bool_t parseAndStoreFragment(::ufmt::FragmentInfo& fragInfo); }; } // end DDAS namespace diff --git a/main/ddas/DDASBuiltUnpacker.cpp b/main/ddas/DDASBuiltUnpacker.cpp index 5ce459f04..ce62be1f0 100644 --- a/main/ddas/DDASBuiltUnpacker.cpp +++ b/main/ddas/DDASBuiltUnpacker.cpp @@ -104,7 +104,7 @@ namespace DAQ { Bool_t CDDASBuiltUnpacker::selectivelyParseData(uint16_t* p16) { // index the fragments - FragmentIndex parsedFragments(p16); + ::ufmt::FragmentIndex parsedFragments(p16); // loop over the fragments for (auto& fragInfo : parsedFragments ) { @@ -121,12 +121,12 @@ namespace DAQ { //////// /// - Bool_t CDDASBuiltUnpacker::parseAndStoreFragment(FragmentInfo& info) + Bool_t CDDASBuiltUnpacker::parseAndStoreFragment(::ufmt::FragmentInfo& info) { DDASHitUnpacker unpacker; - auto pBody = reinterpret_cast(info.s_itembody); + auto pBody = reinterpret_cast(info.s_itembody); size_t bodySize = *pBody; // # of 16-bit words in body (inclusive) // parse the body of the ring item diff --git a/main/ddas/DDASBuiltUnpacker.h b/main/ddas/DDASBuiltUnpacker.h index 814b0ff45..440127e0c 100644 --- a/main/ddas/DDASBuiltUnpacker.h +++ b/main/ddas/DDASBuiltUnpacker.h @@ -20,7 +20,7 @@ #define DAQ_DDAS_DDASBUILTUNPACKER_H #include -#include "FragmentIndex.h" +#include #include #include @@ -152,7 +152,7 @@ namespace DAQ { Bool_t selectivelyParseData(uint16_t* p16); - Bool_t parseAndStoreFragment(FragmentInfo& fragInfo); + Bool_t parseAndStoreFragment(::ufmt::FragmentInfo& fragInfo); }; } // end DDAS namespace diff --git a/main/ddas/Makefile.am b/main/ddas/Makefile.am index e1be11d0a..f1199c66e 100644 --- a/main/ddas/Makefile.am +++ b/main/ddas/Makefile.am @@ -21,14 +21,14 @@ libDDASUnpacker_la_CXXFLAGS = -I@top_srcdir@/Core \ @LIBTCLPLUS_CFLAGS@ \ @TCL_CPPFLAGS@ \ @ROOT_CFLAGS@ \ - @DDASFMT_CPPFLAGS@ + @DDASFMT_CPPFLAGS@ @UFMT_CPPFLAGS@ libDDASUnpacker_la_LIBADD = @top_builddir@/Core/libTclGrammerApp.la \ @ROOT_LDFLAGS@ \ -lgsl \ @LIBEXCEPTION_LDFLAGS@ \ @TCL_LIBS@ \ - @DDASFMT_LDFLAGS@ + @DDASFMT_LDFLAGS@ @UFMT_LDFLAGS@ ## # Unit tests From e9a825d57b0f0ce8f9be95e5307af16e3a424c36 Mon Sep 17 00:00:00 2001 From: Ron Fox Date: Tue, 3 Sep 2024 09:36:58 -0400 Subject: [PATCH 5/8] Issue #165 - port to unified format 2.x Wean the code base from the internal DataFormat.h file --- main/Core/AnalysisRingItems.h | 2 + main/Core/CAnalysisEventProcessor.cpp | 43 +-- main/Core/CRingBufferDecoder.cpp | 1 + main/Core/DataFormat.h | 369 -------------------------- main/Core/EventMessage.cpp | 4 +- main/Core/Makefile.am | 8 +- main/Core/RingFormatHelperFactory.cpp | 4 +- main/Core/RingItemPump.cpp | 3 +- main/Core/TestFile.cpp | 2 + main/Core/caenevptests.cpp | 14 +- main/Core/helper11tests.cpp | 4 +- main/Core/parsertest.cpp | 12 +- main/db/CDBEvents.cpp | 1 + main/db/CDBEvents.h | 10 +- main/db/DBEvents.cpp | 1 + main/db/Makefile.am | 9 +- main/ddas/FitHitUnpacker.cpp | 1 + main/unifiedfmt-incorp.sh | 4 +- 18 files changed, 69 insertions(+), 423 deletions(-) delete mode 100755 main/Core/DataFormat.h diff --git a/main/Core/AnalysisRingItems.h b/main/Core/AnalysisRingItems.h index a498ff263..47f3e04f2 100644 --- a/main/Core/AnalysisRingItems.h +++ b/main/Core/AnalysisRingItems.h @@ -22,6 +22,8 @@ */ #ifndef ANALYSISRINGITEMS_H #define ANALYSISRINGITEMS_H + + #include namespace frib { namespace analysis { diff --git a/main/Core/CAnalysisEventProcessor.cpp b/main/Core/CAnalysisEventProcessor.cpp index e4e404b57..62d5c0a2c 100755 --- a/main/Core/CAnalysisEventProcessor.cpp +++ b/main/Core/CAnalysisEventProcessor.cpp @@ -34,12 +34,12 @@ #include #include -namespace DAQ11Format { -#include -} + +#include + -#include +#include #include @@ -50,6 +50,7 @@ namespace DAQ11Format { #include #include +using namespace ufmt; /*--------------------------------------------------------------------------- * Dispatch methods: */ @@ -313,7 +314,7 @@ CAnalysisEventProcessor::computeRingPayloadSize() unsigned size = pDecoder->getBodySize(); // Already right for 10.x if (!p10) { // 11.x if (pDecoder->hasBodyHeader()) { - size -= sizeof(DAQ11Format::BodyHeader); + size -= sizeof(v11::BodyHeader); } else { size -= sizeof(uint32_t); } @@ -530,14 +531,14 @@ CAnalysisEventProcessor::getStateChangeAbsTime(CBufferDecoder& rDecoder) if (dynamic_cast(pDecoder->getCurrentFormatHelper())) { // 10.x - NSCLDAQ10::pStateChangeItem pItem = - reinterpret_cast(pDecoder->getItemPointer()); + v10::pStateChangeItem pItem = + reinterpret_cast(pDecoder->getItemPointer()); return pItem->s_Timestamp; } else { - DAQ11Format::pStateChangeItemBody pItem = - reinterpret_cast(pDecoder->getBody()); + v11::pStateChangeItemBody pItem = + reinterpret_cast(pDecoder->getBody()); return pItem->s_Timestamp; } } @@ -575,15 +576,15 @@ CAnalysisEventProcessor::getStateChangeRunTime(CBufferDecoder& rDecoder) if (dynamic_cast(pDecoder->getCurrentFormatHelper())) { // 10 - NSCLDAQ10::pStateChangeItem pItem = - reinterpret_cast(pDecoder->getItemPointer()); + v10::pStateChangeItem pItem = + reinterpret_cast(pDecoder->getItemPointer()); return pItem->s_timeOffset; } else { // 11 - DAQ11Format::pStateChangeItemBody pItem = - reinterpret_cast(pDecoder->getBody()); + v11::pStateChangeItemBody pItem = + reinterpret_cast(pDecoder->getBody()); int divisor = pItem->s_offsetDivisor ? pItem->s_offsetDivisor : 1; return ((double)(pItem->s_timeOffset) )/ divisor; @@ -639,8 +640,8 @@ void CAnalysisEventProcessor::StringBuffer10(CAnalysisBase::StringListType type) { CRingBufferDecoder* pDecoder = dynamic_cast(m_pDecoder); - NSCLDAQ10::pTextItem pItem = - reinterpret_cast(pDecoder->getItemPointer()); + v10::pTextItem pItem = + reinterpret_cast(pDecoder->getItemPointer()); // non string data: @@ -666,8 +667,8 @@ void CAnalysisEventProcessor::StringBuffer11(CAnalysisBase::StringListType type) { CRingBufferDecoder* pDecoder = dynamic_cast(m_pDecoder); - DAQ11Format::pTextItemBody pItem = - reinterpret_cast(pDecoder->getBody()); + v11::pTextItemBody pItem = + reinterpret_cast(pDecoder->getBody()); // Non string data: @@ -694,8 +695,8 @@ void CAnalysisEventProcessor::ScalerBuffer10() { CRingBufferDecoder* pDecoder = dynamic_cast(m_pDecoder); - NSCLDAQ10::pScalerItem pItem = - reinterpret_cast(pDecoder->getItemPointer()); + v10::pScalerItem pItem = + reinterpret_cast(pDecoder->getItemPointer()); auto pHelper = pDecoder->getCurrentFormatHelper(); // Fish out non scaler info. @@ -723,8 +724,8 @@ void CAnalysisEventProcessor::ScalerBuffer11() { CRingBufferDecoder* pDecoder = dynamic_cast(m_pDecoder); - DAQ11Format::pScalerItemBody pItem = - static_cast(pDecoder->getBody()); + v11::pScalerItemBody pItem = + static_cast(pDecoder->getBody()); auto pHelper = pDecoder->getCurrentFormatHelper(); // Non scaler info: diff --git a/main/Core/CRingBufferDecoder.cpp b/main/Core/CRingBufferDecoder.cpp index d1453b9d2..a571d407f 100755 --- a/main/Core/CRingBufferDecoder.cpp +++ b/main/Core/CRingBufferDecoder.cpp @@ -48,6 +48,7 @@ #include using namespace std; +using namespace ufmt; // Constants: diff --git a/main/Core/DataFormat.h b/main/Core/DataFormat.h deleted file mode 100755 index dcef5e55c..000000000 --- a/main/Core/DataFormat.h +++ /dev/null @@ -1,369 +0,0 @@ -#ifndef DATAFORMAT_H -#define DATAFORMAT_H - -/* - This software is Copyright by the Board of Trustees of Michigan - State University (c) Copyright 2005. - - You may use this software under the terms of the GNU public license - (GPL). The terms of this license are described at: - - http://www.gnu.org/licenses/gpl.txt - - Author: - Ron Fox - NSCL - Michigan State University - East Lansing, MI 48824-1321 -*/ - -/*! - \file DataFormat.h - This file contains typedefs for the structures that will be put into - ring buffers for event data. Event data Ring buffers are filled with items. - An item has the structure: - -\verbatim - +----------------------------------+ - | Size of item in bytes (32 bits) | - +----------------------------------+ - | 32 bit type code of item | - +----------------------------------+ - | body (size - 8 bytes of data | - +----------------------------------+ -\endverbatim - - Where the 32 bit type code is really a 16 bit type code stored in the lower 16 bits of the -32 bit word in the native byte ordering of the originating system. This allows it to serve as -a byte order indicator, as data type 0 is not legal, and the top bits of the type code must -be zero. - - Further as of nscldaq-11.0, each body has a minimal form of: - -\verbatim - -typedef struct _DataSourceHeader { - uint32_t s_size; // sizeof(DataSourceHeader) - uint64_t s_timestamp; - uint32_t s_sourceId; - int32_t s_barrier; -} DataSourceHeader, *pDataSourceHeader; - -typedef union _BodyHeader { - uint32_t s_mbz; // Contains zero. - DataSourceHeader s_header; // Has full header. -} BodyHeader; - -struct Body { - BodyHeader s_bodyhdr; - uint8_t s_body[] -}; - - -\endverbatim - -Due to the way in which C/C++ compute structure sizes, however the definition -cannot be expressed this way or else all items will appear to have a body header -in them even if they don't Therefore the actual union must have the actual -body in both branches of the union thus: - -\verbatim - -typdef union Body { - struct { - uint32_t s_mbz; - uint8_t s_body[]; - } u_noHader; - struct { - BodyHeader s_bodyHeader; - uint8_t s_body[]; - } u_hasHeader; -} Body; - -\endverbatim - -*/ - -/* - Define the type codes for the items. - Applications can add user specific types if they use values that are at least - FIRST_USER_TYPE -*/ - - -#include -#include - -/* - 11.0 and later define a format item that starts the run. - so that decoders know what format the ring is in. -*/ - -static const uint16_t FORMAT_MAJOR = 11; /* nscldaq-11. */ -static const uint16_t FORMAT_MINOR = 0; /* nscldaq-x.0 */ - -/* state change item type codes: */ - -static const uint32_t BEGIN_RUN = 1; -static const uint32_t END_RUN = 2; -static const uint32_t PAUSE_RUN = 3; -static const uint32_t RESUME_RUN = 4; - -/* Documentation item type codes: */ - -static const uint32_t PACKET_TYPES = 10; -static const uint32_t MONITORED_VARIABLES = 11; -static const uint32_t RING_FORMAT = 12; /* Has format major/minor in it. */ - -/* Scaler data: */ - -static const uint32_t PERIODIC_SCALERS = 20; - - -/* Note timestamped nonincremental scalers absorbed into incremental scalers. */ - -/* Physics events: */ - -static const uint32_t PHYSICS_EVENT = 30; -static const uint32_t PHYSICS_EVENT_COUNT = 31; - - -/* Event builder related items: */ - -static const uint32_t EVB_FRAGMENT = 40; /* Event builder fragment. */ -static const uint32_t EVB_UNKNOWN_PAYLOAD = 41; /* Evb fragment whose payload isn't a ring item */ -static const uint32_t EVB_GLOM_INFO = 42; /* GLOM Parameters. */ - -/* User defined item codes */ - -static const uint32_t FIRST_USER_ITEM_CODE = 32768; /* 0x8000 */ - -/* Glom can assign the timestamp policy as follows: */ - -static const uint16_t GLOM_TIMESTAMP_FIRST = 0; -static const uint16_t GLOM_TIMESTAMP_LAST = 1; -static const uint16_t GLOM_TIMESTAMP_AVERAGE = 2; - - -/* Longest allowed title: */ - -#ifndef TITLE_MAXSIZE -#define TITLE_MAXSIZE 80 -#endif - - -// Macro to make packed structs: - - -#ifndef PSTRUCT -#define PSTRUCT struct __attribute__((__packed__)) -#endif - -/*! All ring items have common header structures: */ - -typedef PSTRUCT _RingItemHeader { - uint32_t s_size; - uint32_t s_type; -} RingItemHeader, *pRingItemHeader; - -/*! - Bodies either have a body item or a longword zero for the body item header - size field (11.0 and later) -*/ - -typedef PSTRUCT _BodyHeader { - uint32_t s_size; /* 0 or sizeof(DataSourceHeader) */ - uint64_t s_timestamp; - uint32_t s_sourceId; - uint32_t s_barrier; -} BodyHeader, *pBodyHeader; - - - -/*! - This is the most basic item.. a generic item. It consists only of the - header and a generic body -*/ - -typedef PSTRUCT _RingItem { - RingItemHeader s_header; - union { - struct { - uint32_t s_mbz; - uint8_t s_body[1]; - } u_noBodyHeader; - struct { - BodyHeader s_bodyHeader; - uint8_t s_body[1]; - } u_hasBodyHeader; - } s_body; -} RingItem, *pRingItem; - - -/*! - Run state changes are documented by inserting state change items that have the - structure shown below. After 11.0, they may or mey not have abody header - as reflected by the fact that they contain a union as shown below: - -*/ -typedef PSTRUCT _StateChangeItemBody { - uint32_t s_runNumber; - uint32_t s_timeOffset; - uint32_t s_Timestamp; - uint32_t s_offsetDivisor; - char s_title[TITLE_MAXSIZE+1]; -} StateChangeItemBody, *pStateChangeItemBody; - -typedef PSTRUCT _StateChangeItem { - RingItemHeader s_header; - union { - struct { - uint32_t s_mbz; /* Must be zero - no body header*/ - StateChangeItemBody s_body; - } u_noBodyHeader; - struct { - BodyHeader s_bodyHeader; - StateChangeItemBody s_body; - } u_hasBodyHeader; - } s_body; - -} StateChangeItem, *pStateChangeItem; - -/*! - Scaler items contain run time counters. As of 11.0 they may or may not have - a body header too: -*/ - -typedef PSTRUCT _ScalerItemBody { - uint32_t s_intervalStartOffset; - uint32_t s_intervalEndOffset; - uint32_t s_timestamp; - uint32_t s_intervalDivisor; /* 11.0 sub second time intervals */ - uint32_t s_scalerCount; - uint32_t s_isIncremental; /* 11.0 non-incremental scaler flag */ - uint32_t s_scalers[1]; -} ScalerItemBody, *pScalerItemBody; - -typedef PSTRUCT _ScalerItem { - RingItemHeader s_header; - union { - struct { - uint32_t s_mbz; /* Must be zero .. no header */ - ScalerItemBody s_body; - } u_noBodyHeader; - struct { - BodyHeader s_bodyHeader; - ScalerItemBody s_body; - } u_hasBodyHeader; - } s_body; -} ScalerItem, *pScalerItem; - - -/*! - The various documentation Events are just a bunch of null terminated strings that - are back to back in the body of the ring buffer. item. -*/ - -typedef PSTRUCT _TextItemBody { - uint32_t s_timeOffset; - uint32_t s_timestamp; - uint32_t s_stringCount; - uint32_t s_offsetDivisor; - char s_strings[1]; -} TextItemBody, *pTextItemBody; - -typedef PSTRUCT _TextItem { - RingItemHeader s_header; - union { - struct { - uint32_t s_mbz; /* Must be zero (no body header) */ - TextItemBody s_body; - } u_noBodyHeader; - struct { - BodyHeader s_bodyHeader; - TextItemBody s_body; - } u_hasBodyHeader; - } s_body; -} TextItem, *pTextItem; - - -/*! - For now a physics event is just a header and a body of uint16_t's. -*/ - -typedef PSTRUCT _PhysicsEventItem { - RingItemHeader s_header; - union { - struct { - uint32_t s_mbz; - uint16_t s_body[1]; /* Aribrtary length body */ - } u_noBodyHeader; - struct { - BodyHeader s_bodyHeader; - uint16_t s_body[1]; - } u_hasBodyHeader; - } s_body; -} PhysicsEventItem, *pPhysicsEventItem; - -/*! - Clients that sample physics events will often - need to know how many physics events have been produced - so that they can figure out the sampling fraction. -*/ -typedef PSTRUCT __PhysicsEventCountItemBody { - uint32_t s_timeOffset; - uint32_t s_offsetDivisor; - uint32_t s_timestamp; - uint64_t s_eventCount; /* Maybe 4Gevents is too small ;-) */ -} PhysicsEventCountItemBody, *pPhysicsEventCountItemBody; - -typedef PSTRUCT _PhysicsEventCountItem { - RingItemHeader s_header; - union { - struct { - uint32_t s_mbz; /* Must be zero - no body header*/ - PhysicsEventCountItemBody s_body; - } u_noBodyHeader; - struct { - BodyHeader s_bodyHeader; - PhysicsEventCountItemBody s_body; - } u_hasBodyHeader; - } s_body; -} PhysicsEventCountItem, *pPhysicsEventCountItem; - -/** - * Event builder stages can put event fragments into the - * ring buffer for monitoring software: - * (EVB_FRAGMENT): - */ -typedef PSTRUCT _EventBuilderFragment { - RingItemHeader s_header; - BodyHeader s_bodyHeader; - uint8_t s_body[1]; /* Really s_payload bytes of data.. */ -} EventBuilderFragment, *pEventBuilderFragment; - -/** - * The ring item format never has an event header. Just major and minor - * version numbers: - */ - -typedef PSTRUCT _DataFormat { - RingItemHeader s_header; - uint32_t s_mbz; /* No body header */ - uint16_t s_majorVersion; /* FORMAT_MAJOR */ - uint16_t s_minorVersion; /* FORMAT_MINOR */ -} DataFormat, *pDataFormat; - -/** - * Information about glom parameters: - */ -typedef PSTRUCT _GlomParameters { - RingItemHeader s_header; - uint32_t s_mbz; - uint64_t s_coincidenceTicks; - uint16_t s_isBuilding; - uint16_t s_timestampPolicy; /* See GLOM_TIMESTAMP_* above */ - -} GlomParameters, *pGlomParameters; - -#endif diff --git a/main/Core/EventMessage.cpp b/main/Core/EventMessage.cpp index 20a51e760..53ae46e72 100644 --- a/main/Core/EventMessage.cpp +++ b/main/Core/EventMessage.cpp @@ -25,7 +25,9 @@ #include #include #include -#include "DataFormat.h" +#include + +using namespace ufmt; #ifdef WITH_MPI #include #else diff --git a/main/Core/Makefile.am b/main/Core/Makefile.am index d0505c59b..c51f56b57 100644 --- a/main/Core/Makefile.am +++ b/main/Core/Makefile.am @@ -64,7 +64,7 @@ DecoderRing_INCLUDES = CRingBufferDecoder.h \ RingFormatHelper10Creator.h \ RingFormatHelper11Creator.h \ RingFormatHelper12Creator.h \ - DataFormatPre11.h DataFormat.h \ + DataFormatPre11.h \ DataFormat12.h AnalysisRingItems.h \ ParameterDecoding.h @@ -475,7 +475,7 @@ newanalysistests_LDADD=$(commonTestLdFlags) caendpptests_SOURCES = TestRunner.cpp PHAHitTest.cpp PSDHitTest.cpp \ modulehittests.cpp parsertest.cpp caenpmaptests.cpp caenevptests.cpp -caendpptests_CXXFLAGS= $(commonTestCXXFLAGS) @UFMT_CPPFLAGS@ +caendpptests_CXXFLAGS= @UFMT_CPPFLAGS@ $(commonTestCXXFLAGS) caendpptests_LDADD = $(commonTestLdFlags) @UFMT_LDFLAGS@ @@ -550,8 +550,8 @@ mirrortests_LDADD=$(commonTestLdFlags) mirrortests_SOURCES = TestRunner.cpp mdirtests.cpp servertests.cpp \ mservertests.cpp mirrorcmdtests.cpp -helpertests_CXXFLAGS=$(commonTestCXXFLAGS) -helpertests_LDADD=$(commonTestLdFlags) +helpertests_CXXFLAGS=@UFMT_CPPFLAGS@ $(commonTestCXXFLAGS) +helpertests_LDADD=$(commonTestLdFlags) @UFMT_LDFLAGS@ helpertests_SOURCES=TestRunner.cpp helper10tests.cpp helper11tests.cpp \ helper12tests.cpp diff --git a/main/Core/RingFormatHelperFactory.cpp b/main/Core/RingFormatHelperFactory.cpp index 20026d172..9180e4506 100644 --- a/main/Core/RingFormatHelperFactory.cpp +++ b/main/Core/RingFormatHelperFactory.cpp @@ -22,7 +22,9 @@ #include "RingFormatHelperFactory.h" #include "RingFormatHelper.h" #include "RingFormatHelperCreator.h" -#include "DataFormat.h" +#include + +using namespace ufmt; /** * default constructor: diff --git a/main/Core/RingItemPump.cpp b/main/Core/RingItemPump.cpp index 61ec0dd9a..7bb07d41e 100644 --- a/main/Core/RingItemPump.cpp +++ b/main/Core/RingItemPump.cpp @@ -30,13 +30,14 @@ #include #include "CRingBufferDecoder.h" #include "Globals.h" -#include "DataFormat.h" +#include #include "TCLAnalyzer.h" #include "SpecTcl.h" #include #include #include #include +using namespace ufmt; static const size_t MAX_MESSAGE_SIZE = 16*1024; diff --git a/main/Core/TestFile.cpp b/main/Core/TestFile.cpp index 3ca52c701..d4025e1a4 100755 --- a/main/Core/TestFile.cpp +++ b/main/Core/TestFile.cpp @@ -44,6 +44,8 @@ static const char* Copyright = "(C) Copyright Michigan State University 2005, Al #include #include #include + +using namespace ufmt; #ifdef HAVE_STD_NAMESPACE using namespace std; #endif diff --git a/main/Core/caenevptests.cpp b/main/Core/caenevptests.cpp index 9144fb0bd..06594ec95 100644 --- a/main/Core/caenevptests.cpp +++ b/main/Core/caenevptests.cpp @@ -142,8 +142,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION(caenevptest); size_t caenevptest::makeFragment(void* pDest, void* pItem) { - pRingItemHeader pSrc = reinterpret_cast(pItem); - pBodyHeader pBh = reinterpret_cast(pSrc+1); + ufmt::pRingItemHeader pSrc = reinterpret_cast(pItem); + ufmt::pBodyHeader pBh = reinterpret_cast(pSrc+1); ufmt::EVB::pFragmentHeader pFrag = reinterpret_cast(pDest); ufmt::EVB::pFragmentHeader pBody = pFrag+1; @@ -176,8 +176,8 @@ caenevptest::makeRingItem( { // Build pointers to the chunks of the ring item: - pRingItemHeader pItemHeader = reinterpret_cast(p); - pBodyHeader pBHeader = reinterpret_cast(pItemHeader+1); + ufmt::pRingItemHeader pItemHeader = reinterpret_cast(p); + ufmt::pBodyHeader pBHeader = reinterpret_cast(pItemHeader+1); uint32_t* pBody = reinterpret_cast(pBHeader+1); // Fill in the body header: @@ -185,7 +185,7 @@ caenevptest::makeRingItem( pBHeader->s_timestamp = time; pBHeader->s_sourceId = sid; pBHeader->s_barrier = 0; - pBHeader->s_size = sizeof(BodyHeader); + pBHeader->s_size = sizeof(ufmt::BodyHeader); // Fill in the data: @@ -194,9 +194,9 @@ caenevptest::makeRingItem( // Fill in the ring item header: - size_t totalSize = sizeof(uint32_t)+payloadSize + sizeof(BodyHeader) + sizeof(RingItemHeader); + size_t totalSize = sizeof(uint32_t)+payloadSize + sizeof(ufmt::BodyHeader) + sizeof(ufmt::RingItemHeader); pItemHeader->s_size = totalSize; - pItemHeader->s_type = PHYSICS_EVENT; + pItemHeader->s_type = ufmt::PHYSICS_EVENT; return totalSize; } diff --git a/main/Core/helper11tests.cpp b/main/Core/helper11tests.cpp index 3a6a62632..b8f4c6f16 100644 --- a/main/Core/helper11tests.cpp +++ b/main/Core/helper11tests.cpp @@ -22,13 +22,13 @@ #include #include "Asserts.h" #include "RingFormatHelper11.h" -#include "DataFormat.h" +#include #include "BufferTranslator.h" #include #include #include - +using namespace ufmt; class ring11test : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ring11test); CPPUNIT_TEST(hasbodyhdr_1); diff --git a/main/Core/parsertest.cpp b/main/Core/parsertest.cpp index 473130204..d6a48e29d 100644 --- a/main/Core/parsertest.cpp +++ b/main/Core/parsertest.cpp @@ -26,7 +26,7 @@ #undef private #include "CAENHit.h" #include "CAENModuleHits.h" -#include "DataFormat.h" +#include #include #include @@ -67,13 +67,13 @@ FakeEvent::putFragment( reinterpret_cast(m_pCursor); p->s_timestamp = timestamp; p->s_sourceId = sid; - p->s_size = nBytes + sizeof(RingItemHeader) + sizeof(BodyHeader); + p->s_size = nBytes + sizeof(ufmt::RingItemHeader) + sizeof(ufmt::BodyHeader); p->s_barrier = 0; - pRingItemHeader pRHeader = reinterpret_cast(p+1); + ufmt::pRingItemHeader pRHeader = reinterpret_cast(p+1); pRHeader->s_size = p->s_size; - pRHeader->s_type = PHYSICS_EVENT; - pBodyHeader pBHeader = reinterpret_cast(pRHeader+1); - pBHeader->s_size = sizeof(BodyHeader); + pRHeader->s_type = ufmt::PHYSICS_EVENT; + ufmt::pBodyHeader pBHeader = reinterpret_cast(pRHeader+1); + pBHeader->s_size = sizeof(ufmt::BodyHeader); pBHeader->s_timestamp = timestamp; pBHeader->s_sourceId = sid; pBHeader->s_barrier = 0; diff --git a/main/db/CDBEvents.cpp b/main/db/CDBEvents.cpp index 8647b1ddb..75b12362b 100755 --- a/main/db/CDBEvents.cpp +++ b/main/db/CDBEvents.cpp @@ -31,6 +31,7 @@ #include #include #include +using namespace ufmt; /////////////////////////////////////////////////////////////////// // CDBEventPlayer implementation. // diff --git a/main/db/CDBEvents.h b/main/db/CDBEvents.h index 51907b54c..be63c9638 100755 --- a/main/db/CDBEvents.h +++ b/main/db/CDBEvents.h @@ -108,9 +108,9 @@ class CDBEventWriter { CDBEventWriter(const char* databaseFile, unsigned batchSize = 500); virtual ~CDBEventWriter(); - void beginRun(const RingItem* pStateTransition); - void endRun(const RingItem* pStateTransition); - void scaler(const RingItem* pScaler); + void beginRun(const ufmt::RingItem* pStateTransition); + void endRun(const ufmt::RingItem* pStateTransition); + void scaler(const ufmt::RingItem* pScaler); void event(CEvent* pEvent); // For autosaving spectra at end of run. @@ -128,8 +128,8 @@ class CDBEventWriter { std::string getDbPath() { return m_dbName; } private: - void requireItem(const RingItem* pItem, unsigned itemType); - const void* getBody(const RingItem* pItem); + void requireItem(const ufmt::RingItem* pItem, unsigned itemType); + const void* getBody(const ufmt::RingItem* pItem); void saveSpectra(); }; diff --git a/main/db/DBEvents.cpp b/main/db/DBEvents.cpp index 6b9eb4af4..aafca1fdb 100755 --- a/main/db/DBEvents.cpp +++ b/main/db/DBEvents.cpp @@ -25,6 +25,7 @@ #include #include #include +using namespace ufmt; ///////////////////////////////////////////////////////////////////////// // CDBSink implementation: diff --git a/main/db/Makefile.am b/main/db/Makefile.am index 11b0a2e4a..555b55766 100644 --- a/main/db/Makefile.am +++ b/main/db/Makefile.am @@ -12,10 +12,10 @@ libSqlite3pp_la_LDFLAGS=@SQLITE3_LDFLAGS@ libSpecTclDb_la_CXXFLAGS=-I@top_srcdir@/Core @SQLITE3_CFLAGS@ \ -I@top_srcdir@/Utility @ROOT_CFLAGS@ @TCL_CPPFLAGS@ \ @LIBTCLPLUS_CFLAGS@ -I@top_srcdir@/factories \ - -DTCLLIBS=@prefix@/TclLibs -g + -DTCLLIBS=@prefix@/TclLibs -g @UFMT_CPPFLAGS@ libSpecTclDb_la_LDFLAGS=libSqlite3pp.la \ @builddir@/../Core/libTclGrammerApp.la \ - @SQLITE3_LDFLAGS@ @ROOT_LDFLAGS@ @LIBTCLPLUS_LDFLAGS@ + @SQLITE3_LDFLAGS@ @ROOT_LDFLAGS@ @LIBTCLPLUS_LDFLAGS@ @UFMT_LDFLAGS@ libSpecTclDb_la_SOURCES= SpecTclDatabase.cpp SaveSet.cpp DBParameter.cpp \ DBSpectrum.cpp DBGate.cpp \ @@ -32,10 +32,11 @@ include_HEADERS=CDBEvents.h DBEvents.h \ libSpecTclDbTcl_la_DEPENDENCIES = libSpecTclDb.la libSqlite3pp.la libSpecTclDbTcl_la_CXXFLAGS=@SQLITE3_CFLAGS@ -g @TCL_CPPFLAGS@ \ @LIBTCLPLUS_CFLAGS@ @ROOT_CFLAGS@ -I@top_srcdir@/Core \ - -I@top_srcdir@/Utility -I@top_srcdir@/factories + -I@top_srcdir@/Utility -I@top_srcdir@/factories @UFMT_CPPFLAGS@ libSpecTclDbTcl_la_LDFLAGS=libSpecTclDb.la libSqlite3pp.la \ @builddir@/../Core/libTclGrammerApp.la \ - @SQLITE3_LDFLAGS@ @ROOT_LDFLAGS@ @LIBTCLPLUS_LDFLAGS@ @ROOT_LDFLAGS@ + @SQLITE3_LDFLAGS@ @ROOT_LDFLAGS@ @LIBTCLPLUS_LDFLAGS@ @ROOT_LDFLAGS@ \ + @UFMT_LDFLAGS@ libSpecTclDbTcl_la_SOURCES = SpecTclDbTCLPackage.cpp DBTcl.h DBTcl.cpp \ CDBCommands.cpp CDBCommands.h diff --git a/main/ddas/FitHitUnpacker.cpp b/main/ddas/FitHitUnpacker.cpp index 7c4940338..4b0b59193 100644 --- a/main/ddas/FitHitUnpacker.cpp +++ b/main/ddas/FitHitUnpacker.cpp @@ -27,6 +27,7 @@ #include #include #include +using namespace ufmt; /** * decode diff --git a/main/unifiedfmt-incorp.sh b/main/unifiedfmt-incorp.sh index 41a4f9cc6..68547172b 100755 --- a/main/unifiedfmt-incorp.sh +++ b/main/unifiedfmt-incorp.sh @@ -2,7 +2,7 @@ ## Incorporate the unfied formatting library: -# Most recently used version 2.2 +# Most recently used version 2.2-002 # 2.2 allows us to use the FragmentIndex and fragment.{h,cpp} # in unified format rather than local maintenance headaches # See issue#166 @@ -13,7 +13,7 @@ TARGET="unifiedformat" if [[ ! $TAG ]] then - TAG="2.2" + TAG="2.2-002" fi rm -rf $TARGET From 65d21e72627d37c3a0097e6652b7784ed80d9772 Mon Sep 17 00:00:00 2001 From: Ron Fox Date: Tue, 3 Sep 2024 10:18:09 -0400 Subject: [PATCH 6/8] Issue #165 - port to unified format 2.x Keep weaning off local DataFormat.h and fixing the fallout from it. --- main/Core/helper11tests.cpp | 4 ++-- main/configure.ac | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/main/Core/helper11tests.cpp b/main/Core/helper11tests.cpp index b8f4c6f16..3625048f4 100644 --- a/main/Core/helper11tests.cpp +++ b/main/Core/helper11tests.cpp @@ -22,13 +22,13 @@ #include #include "Asserts.h" #include "RingFormatHelper11.h" -#include +#include #include "BufferTranslator.h" #include #include #include -using namespace ufmt; +using namespace ufmt::v11; class ring11test : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ring11test); CPPUNIT_TEST(hasbodyhdr_1); diff --git a/main/configure.ac b/main/configure.ac index 4b2f3358f..e7f7c4687 100755 --- a/main/configure.ac +++ b/main/configure.ac @@ -831,6 +831,9 @@ AS_VAR_IF([have_cmake], [yes], [], AC_MSG_ERROR([cmake must be in the path to bu # Check that the unified format library has been incorporated into # the source tree and configure/build it into $prefix/unifiedformat +# +# Note using -DCMAKE_BUILD_TYPE=Debug turns off optimization and +# allows gdb into the library. AC_CHECK_FILE([${srcdir}/unifiedformat/CMakeLists.txt], [AC_MSG_NOTICE([Using previously incorporated unified format library at ${srcdir}/unifiedformat]) @@ -840,7 +843,7 @@ AC_CHECK_FILE([${srcdir}/unifiedformat/CMakeLists.txt], rm -rf unifiedformat/build AS_MKDIR_P(unifiedformat/build) AC_MSG_NOTICE([Building unified format]) -(cd unifiedformat/build; cmake .. -DCMAKE_INSTALL_PREFIX=${prefix}/unifiedformat; make clean install) +(cd unifiedformat/build; cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${prefix}/unifiedformat; make clean install) result=$? AS_VAR_IF([result], [0], [], AC_MSG_ERROR([Failed to build and install unified format library with result: ${result}])) UFMT_CPPFLAGS="-I${prefix}/unifiedformat/include" From 7422427084827afcf7627cfad8349b9241246d3b Mon Sep 17 00:00:00 2001 From: Ron Fox Date: Tue, 3 Sep 2024 10:28:06 -0400 Subject: [PATCH 7/8] Issue #165 - port to unified format 2.x Fix error in scalers_2 test...the DataFormat scalers array is 0 sized. --- main/Core/helper11tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/Core/helper11tests.cpp b/main/Core/helper11tests.cpp index 3625048f4..44171d26a 100644 --- a/main/Core/helper11tests.cpp +++ b/main/Core/helper11tests.cpp @@ -609,7 +609,7 @@ void ring11test::scalers_2() #pragma pack(pop) item.s_item.s_header.s_type = PERIODIC_SCALERS; item.s_item.s_header.s_size = - sizeof(RingItemHeader) + sizeof(BodyHeader) + 31*sizeof(uint32_t) + + sizeof(RingItemHeader) + sizeof(BodyHeader) + 32*sizeof(uint32_t) + sizeof(ScalerItemBody); fillBodyHeader(reinterpret_cast(&(item.s_item))); std::vector scalers; From 8200bfb5a13e6ca7f4d1086cbd501dd90cfca702 Mon Sep 17 00:00:00 2001 From: Ron Fox Date: Tue, 3 Sep 2024 11:21:38 -0400 Subject: [PATCH 8/8] Issue #165 - port to unified format 2.x Fix CAENParser allow for fact that fragmentindex body pointer points to the body header. --- main/Core/CAENParser.cpp | 9 +++++++-- main/Core/caenevptests.cpp | 26 +++++++++++++------------- main/Core/parsertest.cpp | 21 ++++++++++++--------- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/main/Core/CAENParser.cpp b/main/Core/CAENParser.cpp index fd6cc6e87..2442ddbb3 100644 --- a/main/Core/CAENParser.cpp +++ b/main/Core/CAENParser.cpp @@ -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(pEventBody)); for (int i =0; i < frags.getNumberFragments(); i++) { ufmt::FragmentInfo info = frags.getFragment(i); - + const uint8_t* pBody = reinterpret_cast(info.s_itembody); + const uint32_t* pBhSize = reinterpret_cast(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 @@ -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(info.s_itembody)); + pHit->unpack(const_cast(reinterpret_cast(pBody))); if (p->second.s_module.getHits().size() == 0) { // First hit: diff --git a/main/Core/caenevptests.cpp b/main/Core/caenevptests.cpp index 06594ec95..0257c9aec 100644 --- a/main/Core/caenevptests.cpp +++ b/main/Core/caenevptests.cpp @@ -33,12 +33,12 @@ #include #include #include -#include +#include #include #include #include - - +using namespace ufmt; +using namespace ufmt::v11; class CAnalyzer; class CBufferDecoder; @@ -142,11 +142,11 @@ CPPUNIT_TEST_SUITE_REGISTRATION(caenevptest); size_t caenevptest::makeFragment(void* pDest, void* pItem) { - ufmt::pRingItemHeader pSrc = reinterpret_cast(pItem); - ufmt::pBodyHeader pBh = reinterpret_cast(pSrc+1); + pRingItemHeader pSrc = reinterpret_cast(pItem); + pBodyHeader pBh = reinterpret_cast(pSrc+1); - ufmt::EVB::pFragmentHeader pFrag = reinterpret_cast(pDest); - ufmt::EVB::pFragmentHeader pBody = pFrag+1; + EVB::pFragmentHeader pFrag = reinterpret_cast(pDest); + EVB::pFragmentHeader pBody = pFrag+1; // Fill in the fragment header; we get the info from the body header // and ring item header. @@ -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); } /** @@ -176,8 +176,8 @@ caenevptest::makeRingItem( { // Build pointers to the chunks of the ring item: - ufmt::pRingItemHeader pItemHeader = reinterpret_cast(p); - ufmt::pBodyHeader pBHeader = reinterpret_cast(pItemHeader+1); + pRingItemHeader pItemHeader = reinterpret_cast(p); + pBodyHeader pBHeader = reinterpret_cast(pItemHeader+1); uint32_t* pBody = reinterpret_cast(pBHeader+1); // Fill in the body header: @@ -185,7 +185,7 @@ caenevptest::makeRingItem( 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: @@ -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; } diff --git a/main/Core/parsertest.cpp b/main/Core/parsertest.cpp index d6a48e29d..6d3182e4d 100644 --- a/main/Core/parsertest.cpp +++ b/main/Core/parsertest.cpp @@ -26,12 +26,15 @@ #undef private #include "CAENHit.h" #include "CAENModuleHits.h" -#include +#include #include #include #include +using namespace ufmt::v11; +using namespace ufmt; + /** * The struct type below is used to compose 'events'. */ @@ -63,17 +66,17 @@ FakeEvent::putFragment( size_t nBytes, uint64_t timestamp, uint32_t sid, void* pData ) { - ufmt::EVB::pFragmentHeader p = - reinterpret_cast(m_pCursor); + EVB::pFragmentHeader p = + reinterpret_cast(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(p+1); + pRingItemHeader pRHeader = reinterpret_cast(p+1); pRHeader->s_size = p->s_size; - pRHeader->s_type = ufmt::PHYSICS_EVENT; - ufmt::pBodyHeader pBHeader = reinterpret_cast(pRHeader+1); - pBHeader->s_size = sizeof(ufmt::BodyHeader); + pRHeader->s_type = PHYSICS_EVENT; + pBodyHeader pBHeader = reinterpret_cast(pRHeader+1); + pBHeader->s_size = sizeof(BodyHeader); pBHeader->s_timestamp = timestamp; pBHeader->s_sourceId = sid; pBHeader->s_barrier = 0; @@ -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.