diff --git a/main/Core/AnalysisRingItems.h b/main/Core/AnalysisRingItems.h index a498ff26..47f3e04f 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/CAENParser.cpp b/main/Core/CAENParser.cpp index 270e9dc1..2442ddbb 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 @@ -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) { - 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); + 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(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/CAnalysisEventProcessor.cpp b/main/Core/CAnalysisEventProcessor.cpp index e4e404b5..62d5c0a2 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/CEventBuilderEventProcessor.cpp b/main/Core/CEventBuilderEventProcessor.cpp index b03c631f..12ba4f86 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/CRingBufferDecoder.cpp b/main/Core/CRingBufferDecoder.cpp index d1453b9d..a571d407 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 dcef5e55..00000000 --- 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 20a51e76..53ae46e7 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/FragmentIndex.cpp b/main/Core/FragmentIndex.cpp deleted file mode 100644 index 7b170a65..00000000 --- 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 eae133ea..00000000 --- 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/Makefile.am b/main/Core/Makefile.am index d3d7f665..c51f56b5 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 @@ -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= @UFMT_CPPFLAGS@ $(commonTestCXXFLAGS) +caendpptests_LDADD = $(commonTestLdFlags) @UFMT_LDFLAGS@ gateTests_CXXFLAGS = $(commonTestCXXFLAGS) @@ -539,23 +539,19 @@ 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 \ 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 @@ -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/RingFormatHelperFactory.cpp b/main/Core/RingFormatHelperFactory.cpp index 20026d17..9180e450 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 61ec0dd9..7bb07d41 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 3ca52c70..d4025e1a 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 53dd8fe8..0257c9ae 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; diff --git a/main/Core/evbProcessorTests.cpp b/main/Core/evbProcessorTests.cpp index d30f0663..9bd1baad 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/fragidxtests.cpp b/main/Core/fragidxtests.cpp deleted file mode 100644 index 22463af9..00000000 --- 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 diff --git a/main/Core/fragment.h b/main/Core/fragment.h deleted file mode 100755 index a4056ce8..00000000 --- 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 diff --git a/main/Core/helper11tests.cpp b/main/Core/helper11tests.cpp index 3a6a6263..44171d26 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::v11; class ring11test : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ring11test); CPPUNIT_TEST(hasbodyhdr_1); @@ -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; diff --git a/main/Core/parsertest.cpp b/main/Core/parsertest.cpp index 848a6156..6d3182e4 100644 --- a/main/Core/parsertest.cpp +++ b/main/Core/parsertest.cpp @@ -26,12 +26,15 @@ #undef private #include "CAENHit.h" #include "CAENModuleHits.h" -#include "DataFormat.h" +#include -#include "fragment.h" +#include #include #include +using namespace ufmt::v11; +using namespace ufmt; + /** * The struct type below is used to compose 'events'. */ @@ -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. diff --git a/main/configure.ac b/main/configure.ac index 4b2f3358..e7f7c468 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" diff --git a/main/db/CDBEvents.cpp b/main/db/CDBEvents.cpp index 8647b1dd..75b12362 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 51907b54..be63c963 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 6b9eb4af..aafca1fd 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 11b0a2e4..555b5576 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/DDASBuiltFitUnpacker.cpp b/main/ddas/DDASBuiltFitUnpacker.cpp index d5115865..b54ab302 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 372defa6..02e56497 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 5ce459f0..ce62be1f 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 814b0ff4..440127e0 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/FitHitUnpacker.cpp b/main/ddas/FitHitUnpacker.cpp index 7c494033..4b0b5919 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/ddas/Makefile.am b/main/ddas/Makefile.am index e1be11d0..f1199c66 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 diff --git a/main/unifiedfmt-incorp.sh b/main/unifiedfmt-incorp.sh index 41a4f9cc..68547172 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