Update of /cvsroot/nscldaq/clients/assembler In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv29163 Modified Files: AssemblerCommand.cpp AssemblerCommand.h Makefile.am Added Files: AssemblerWrongStateException.cpp AssemblerWrongStateException.h EventFragment.cpp EventFragment.h FragmentQueue.cpp FragmentQueue.h ScalerFragment.cpp ScalerFragment.h StateTransitionFragment.cpp StateTransitionFragment.h StringListFragment.cpp StringListFragment.h Log Message: Committing so that I can flip over to eclipse. --- NEW FILE: FragmentQueue.cpp --- /* 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 */ #include <config.h> #include "FragmentQueue.h" using namespace std; /*! Insert an item at the back of the fragment queue. */ void FragmentQeueue::insert(EventFragment& fragment) { m_queue.push_back(&fragment); } /* Return the first element of the queue without removing it: */ EventFragment* FragmentQueue::peek() { if (m_queue.empty()) { return static_cast<EventFragment*>(NULL); } return m_queue[0]; } /*! Remove the first element of the queue and return it: */ EventFragment* FragmentQueue::remove() { if (m_queue.empty()) { return static_cast<EventFragment*>(NULL); } EventFragment* result = peek(); m_queue.pop_front(); } /*! Return the number of elements in the queue: */ size_t FragmentQueue::size() const; { return m_queue.size(); } /*! Get the begin iterator. */ FragmentQeueu::iterator FragmentQueue::begin() { return m_queue.begin(); } /*! Get the end iterator: */ FragmentQueue::iterator FragmentQueue::end() { return m_queue.end(); } --- NEW FILE: ScalerFragment.cpp --- /* 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 */ #include <config.h> #include "ScalerFragment.h" #include <buffer.h> using namespace std; ////////////////////////////////////////////////////////////////////////// /*! Construct a scaler fragment using just a raw data buffer. (with the help of the various helper functions. \param rawBuffer - Pointer to a raw NSCLDAQ buffer. */ ScalerFragment::ScalerFragment(uint16_t* rawBuffer) : EventFragment(extractNode(rawBuffer), extractType(rawBufffer), bodyPointer(rawBuffer), extractSize(rawBuffer) - sizeof(bheader)/sizeof(uint16_t)), m_ssig(extractSsig(rawBuffer)), m_lsig(extractLsig(rawBuffer)) { } /////////////////////////////////////////////////////////////////////// /*! Consruct a scaler fragment from some pieces of extracted buffer and the body. \param node - the node that created the fragment. \param type - event type (need this 'cause we could be a snapshot e.g.). \param body - Body of the event. \param bodyWords - The size of the body. \note Since the caller has broken this down already, the only values we can give the signatures are native byte ordering. */ ScalerFragment::ScalerFragment(uint16_t node, uint16_t type uint16_t* body, size_t bodyWords) : EventFragment(node, type, body, bodyWords), m_ssig(0x0102), m_lsig(0x01020304) { } //////////////////////////////////////////////////////////////////// /*! Get the buffer start time. */ uint32_t ScalerFragment::startTime() const { return getLongword(5); } /////////////////////////////////////////////////////////////////// /*! Get buffer stop time: */ uint32_t ScalerFragment::endTime() const { return getLongWord(0); } ///////////////////////////////////////////////////////////////////// /*! Get the scalers as a vector. */ vector<uint32_t> ScalerFragment::scalers() const { vector<uint32_t> result; size_t offset = 10; while(offset < size()) { result.push_back(getLongword(offset)); offset+= 2; } return result; } /////////////////////////////////////////////////////////////////// /*! Get the number of scalers: */ size_t ScalerFragment::size() const { return (ScalerFragment::size() - 10)*sizeof(uint16_t)/sizeof(uint32_t); } /////////////////////////////////////////////////////////////////// /*! Get a specific scaler \param index - selects the scaler to get (scaler number). */ uint32_t ScalerFragment:: operator[](size_t index) const { index = index*sizeof(uint32_t)/sizeof(uint16_t) + 10; // Short index into body. return getLongword(index); } //////////////////////////////////////////////////////////////////// //////////////////////// nonstatic member utilities /////////////// /////////////////////////////////////////////////////////////////// /* convert a longword in the buffer body given a word offset to a longword. The longword is in the buffer native byte ordering. The result will be in the native byte ordering. */ uint32_t ScalerFragment::getLongword(size_t wordOffset) { uint32_t* pLong = static_cast<uint32_t*>(&((*this)[wordOffset])); return tohl(*pLong, m_lsig); } /* Convert a word in the buffer body to a host ordered word given its offset */ uint16_t ScalerFragment::getWord(size_t wordOffet) { uint16_t* pWord = &((*this)[wordOffset]); return tohw(*pWord, m_ssig); } --- NEW FILE: StateTransitionFragment.cpp --- /* 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 */ #include <config.h> #include "StateTransitionFragment.h" #include <buffer.h> #include <string.h> using namespace std; /*! Construct the buffer: */ StateTransitionFragment::StateTransitionFragment(uint16_t* pBuffer) : EventFragment(extractNode(pBuffer), extractType(pBuffer), bodyPointer(pBuffer), extractSize(pBuffer) - sizeof(struct bheader)), m_ssig(ExtractSsig(pBuffer)), m_lsig(ExtractLsig(pBuffer)) { } /*! Return the title string: */ string StateTransitionFragment::title() const { // The buffer body starts with 80 bytes of title that // are gaurenteed to be null terminated. // We can therefore directly construct the title string from it. const char* pTitle = &((*this)[0]); return string(pTitle); } /*! Return the aboslute timestamp from the buffer, unused fields are zeroed. */ struct tm StateTransitionFragment::absoluteTime() const { struct tim timestamp; memset(×tamp, 0, sizeof(timestamp)); timestamp.tm_mon = tohs((*this)[42], m_ssig); timestamp.tm_mday= tohs((*this)[43], m_ssig); timestamp.tm_year= tohs((*this)[44], m_ssig); timestamp.tm_hour= tohs((*this)[45], m_ssig); timestamp.tm_min = tohs((*this)[46], m_ssig); timestamp.tm_sec = tohs((*this)[47], m_ssig); } /*! Return the elapsed time into the run (host byte order). */ uint32_t StateTransitionFragment::elapsedTime() const { return getLongword(&((*this)[0]), 40, m_lsig); } --- NEW FILE: StringListFragment.h --- #ifndef __STRINGLISTFRAGMENT_H #define __STRINGLISTFRAGMENT_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 */ #ifndef __EVENTFRAGMENT_H #include "EventFragment.h" #endif #ifndef __STL_STRING #include <string> #ifndef __STL_STRING #define __STL_STRING #endif #endif #ifndef __STL_VECTOR #include <vector> #ifndef __STL_VECTOR #define __STL_VECTOR #endif #endif /*! Class that encapsulates the various sort of string list event fragments. We'll do an up-front fetch of the strings into an internal vector as that's probably simplest. ... and space is cheap. */ class StringListFragment : public EventFragment { private: std::vector<std::string> m_strings; public: StringListFragment(uint16_t* pBuffer); std::vector<std::string> strings() const; }; #endif --- NEW FILE: EventFragment.cpp --- /* 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 */ #include <config.h.> #include "EventFragment.h" using namespace std; ///////////////////////////////////////////////////////////////////// /*! Construct an event fragment given a body as a pointer to stuff. \param node - originating node. \param type - type of event. \param body - Pointer to the body. \param words - Count of words in the body. */ EventFragment:: EventFragment(uint16_t node, uint16_t type, void* body size_t words) : m_node(node), m_type(type) { uint16_t* pBegin static_cast<uint16_t*>(body); uint16_t* pEnd = pBegin + words; m_body.insert(m_body.begin(), pBegin, pEnd); } //////////////////////////////////////////////////////////////////// /*! Construct an event fragment given a body that is itself a vector \param node - originating node. \param type - type of event. \param body - vector that is the body. */ EventFragment::EventFragment(uint16_t node, uint16_t type, std::vector<uint16_t> body) : m_node(node), m_type(type), m_body(body) { } ////////////////////////////////////////////////////////////////// /*! Return the node from which this event originated: */ uint16_t EventFragment::node() const { return m_node; } ////////////////////////////////////////////////////////////////// /*! Return the type of the event fragment. The event fragment type determines how the body should be interpreted. */ uint16_t EventFragment::type() const { return m_type; } ////////////////////////////////////////////////////////////////// /*! Return a copy of the event body. For efficient access, it is recommended that you use size() and operator[]. */ vector<uint16_t> EventFragment::body() const { return m_body; } ////////////////////////////////////////////////////////////////// /*! Returns the number of elements in the body. Body indices then run from [0,size()). */ size_t EventFragment:: size() const { return m_body.size(); } ////////////////////////////////////////////////////////////////// /*! Returns a reference to an element of the body array. Attempts to reference off the end of the vector are ill defined in this implementation. */ uint16_t& EventFragment::operator[](size_t index) { return m_body[index]; } ///////////////////////////////////////////////////////////////////// /////////////////////// static member utilities ///////////////////// ///////////////////////////////////////////////////////////////////// // Extract the buffer type in host byte order from the raw buffer: uint16_t EventFragment::extractType(uint16_t* rawbuffer) { struct bheader* pHeader = static_cast<struct bheader*>(rawbuffer); return tohs(pHeader->type, pHeader->ssignature); } // Extract the buffers size in howt byte order from the raw buffer. // This function can also deal with the case that // the buffer is a jumbo buffer. // in that case, the low order part of the size is in // nwds, the high order in unused[0]..and // buffmt is 6 or greater. // uint32_t EventFragment::extractSize(uint16_t* rawBuffer) { struct bheader* pHeader = static_cast<struct bheader*>(rawBuffer); uint32_t low = tohs(pHeader->nwds, pHeader->ssignature); uint32_t rev = tohs(pHeader->buffmt, pHeader->ssignature); if (rev < 6) { // 16 bit size... // return low; } uint32_t high = tohs(pHeader->unused[0], pHeader->ssignature); return (high << 16) | low; } // // Extract the node id from the buffer return it in host byte order. // uint16_t EventFragment::extractNode(uint16_t* rawBuffer) { struct bheader* pHeader = static_cast<struct bheader*>(rawBuffer); return tohs(pHeader->cpu, pHeader->ssignature); } // // Extract the short signature from the buffer and return it // in the buffer byte order so it can be used to construct a // conversion. // uint16_t EventFragment::extractSsig(uint16_t* rawBuffer) { struct bheader* pHeader = static_cast<struct bheader*>(rawBuffer); return pHeader->ssignature; } // // Extract the longword signature from the buffer and return it // in the buffer byte order so it can be used to construct a conversion,. // uint32_t EventFragment::extractLsig(uint16_t* rawBuffer) { struct bheader *pHeader = static_cast<struct bheader*>(rawBuffer); return pHeader->lsignature; } // // Return a pointer to the body of the buffer. // uint16_t* EventFragment::bodyPointer(uint16_t* rawBuffer) { char* pBuffer = static_cast<char*>rawBuffer; pBuffer += sizeof(struct bheader); return static_cast<uint16_t*> pBuffer; } // // Given a longword in buffer byte order, and the buffer's // longword signature, return the longword in host byte order. // uint32_t EventFragment::tohl(uint32_t datum, uint32_t lsig) { // If byte ordering matches just return datum: if (lsig == 0x01020304) return datum; // else swap bytes and words: union Long { uint32_t l; uint8_t b[4]; } source, dest; source.l = datum; dest.b[0] = source.b[3]; dest.b[1] = source.b[2]; dest.b[2] = source.b[1]; dest.b[3] = source.b[0]; return deest.l; } // Given a words in buffer byte order, and the buffer's // short signature, return the word in host byte order. // uint16_t EventFragment::tohs(uint16_t datum uint16_t ssig) { if (ssig == 0x0102) return datum; // Same order as host. // swap bytes: union Word { uint16_t s; uint8_t b[2]; } source, dest; source.s = datum; dest.b[0]= source.b[1]; dest.b[1]= source.b[0]; return dest.s; } // // Return the entity count from a raw buffer in local byte ordering. // uint16_t EventFragment::extractEntityCount(uint16_t* rawBuffer) { struct bheader* pHeader = static_cast<struct bheader*>(rawBuffer); return tohs(pHeader->nevt, pHeader.ssignature); } Index: AssemblerCommand.cpp =================================================================== RCS file: /cvsroot/nscldaq/clients/assembler/AssemblerCommand.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** AssemblerCommand.cpp 11 Jun 2007 18:55:25 -0000 1.5 --- AssemblerCommand.cpp 24 Jul 2007 12:37:55 -0000 1.6 *************** *** 210,215 **** m_nodeTable[id].offset = 0; ! m_nodeTable[id].pNodeName = new char[strlen(pHostInformation->h_name) + 1]; ! strcpy(m_nodeTable[id].pNodeName, pHostInformation->h_name); memcpy(&(m_nodeTable[id].ipAddress), pHostInformation->h_addr_list[0], --- 210,214 ---- m_nodeTable[id].offset = 0; ! m_nodeTable[id].pNodeName = copyString(pHostInformation->h_name); memcpy(&(m_nodeTable[id].ipAddress), pHostInformation->h_addr_list[0], *************** *** 628,629 **** --- 627,681 ---- m_definedNodes.clear(); } + + ///////////////////////////////////////////////////////////////////////// + /*! + Fetch the configuration in list mode. This + allows external objects to get access to the final configuration + (e.g. for setting up data sources and event assembly). + \note The storage pointed to by the pNodeName field of each element ofthe + result list is dynamically created and must be deleted by the + caller when the list is destroyed. + */ + list<AssemblerCommand::EventFragmentContributor> + AssemblerCommand::getConfiguration() + { + + std::list<int>::iterator p = m_definedNodes.begin(); + std::list<EventFragmentContributor> result; + while (p != m_definedNodes.end()) { + int index = *p; + EventFragmentContributor nodeInfo; + EventFragmentContributor* infoSource = &(m_nodeTable[index]); + + // easy stuff first. + + nodeInfo.ipAddress = infoSource->ipAddress; + nodeInfo.cpuId = infoSource->cpuId; + nodeInfo.isTrigger = infoSource->isTrigger; + nodeInfo.windowDefined= infoSource->windowDefined; + nodeInfo.windowWidth = infoSource->windowWidth; + nodeInfo.offsetDefined= infoSource->offsetDefined; + nodeInfo.offset = infoSource->offset; + + // Now the node name: + + nodeInfo.pNodeName = copyString(infoSource->pNodeName); + + // Add to the result list. + + p++; + } + return result; + } + + //// Utility to create a dynamic copy of a C string and return a pointer to it. + //// The storage is allocated as a new char[] and therefore must be + //// delete []var. + + char* + AssemblerCommand::copyString(const char* src) + { + char* dest = new char[strlen(src) +1]; + strcpy(dest, src); + return dest; + } Index: AssemblerCommand.h =================================================================== RCS file: /cvsroot/nscldaq/clients/assembler/AssemblerCommand.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** AssemblerCommand.h 11 Jun 2007 18:55:25 -0000 1.4 --- AssemblerCommand.h 24 Jul 2007 12:37:55 -0000 1.5 *************** *** 72,83 **** public: typedef struct { ! char* pNodeName; ! uint32_t ipAddress; // Octets of ip. ! unsigned short cpuId; ! bool isTrigger; ! bool windowDefined; ! unsigned int windowWidth; ! bool offsetDefined; ! int offset; } EventFragmentContributor, *pEventFragmentContributor; --- 72,83 ---- public: typedef struct { ! char* pNodeName; ! uint32_t ipAddress; // Octets of ip. ! unsigned short cpuId; ! bool isTrigger; ! bool windowDefined; ! unsigned int windowWidth; ! bool offsetDefined; ! int offset; } EventFragmentContributor, *pEventFragmentContributor; *************** *** 113,116 **** --- 113,119 ---- int operator!=(const AssemblerCommand& rhs); public: + // Fetch used nodes: + + std::list<EventFragmentContributor> getConfiguration(); //! Command dispatcher: *************** *** 118,121 **** --- 121,126 ---- virtual int operator()(CTCLInterpreter &interp, std::vector<CTCLObject>& objv); + + // Command processors for the ensemble commands: protected: *************** *** 129,141 **** pEventFragmentContributor findNode(unsigned short id); pEventFragmentContributor findNode(const char* name); ! std::string Usage(); ! int Dispatch(std::string keyword, ! CTCLInterpreter& interp, ! std::vector<CTCLObject>& objv); ! void clearTrigger(); ! void describeNode(CTCLObject& description, ! EventFragmentContributor& node); ! void clearTables(); }; --- 134,148 ---- pEventFragmentContributor findNode(unsigned short id); pEventFragmentContributor findNode(const char* name); ! std::string Usage(); ! int Dispatch(std::string keyword, ! CTCLInterpreter& interp, ! std::vector<CTCLObject>& objv); ! void clearTrigger(); ! void describeNode(CTCLObject& description, ! EventFragmentContributor& node); ! void clearTables(); ! ! static char* copyString(const char* src); }; --- NEW FILE: ScalerFragment.h --- #ifndef __SCALERFRAGMENT_H #define __SCALERFRAGMENT_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 */ #ifndef __EVENTFRAGMENT_H #include "EventFragment.h" #endif /*! The scaler event fragment is a fragment that contains scaler data. We can construct this in two ways. - On a raw data buffer. - On the body of a data buffer and node/type information, Doing this requires the help of several static utility functions. */ class ScalerFragment : public EventFragment { uint16_t m_ssig; uint32_t m_lsig; public: ScalerFragment(uint16_t* rawBuffer); ScalerFragment(uint16_t node, uint16_t type, uint16_t* body, size_t bodyWords); // Extract stuff from the body: uint32_t startTime() const; uint32_t endTime() const; std::vector<uint32_t> scalers() const; size_t size() const; uint32_t operator[](size_t index) const; private: uint32_t getLongword(size_t wordOffset); uint16_t getWord(size_t wordOffset); }; #endif Index: Makefile.am =================================================================== RCS file: /cvsroot/nscldaq/clients/assembler/Makefile.am,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Makefile.am 26 Jun 2007 21:03:12 -0000 1.8 --- Makefile.am 24 Jul 2007 12:38:00 -0000 1.9 *************** *** 10,14 **** AssembledStringArrayEvent.cpp \ BadEventTypeException.cpp \ ! AssemblerOutputStage.cpp noinst_HEADERS = AssemblerApplication.h \ --- 10,18 ---- AssembledStringArrayEvent.cpp \ BadEventTypeException.cpp \ ! AssemblerOutputStage.cpp \ ! AssemblerWrongStateException.cpp \ ! EventFragment.cpp \ ! PhysicsFragment.cpp \ ! ScalerFragment.cpp noinst_HEADERS = AssemblerApplication.h \ *************** *** 21,25 **** AssembledStringArrayEvent.h \ BadEventTypeException.h \ ! AssemblerOutputStage.h --- 25,33 ---- AssembledStringArrayEvent.h \ BadEventTypeException.h \ ! AssemblerOutputStage.h \ ! AssemblerWrongStateException.h \ ! EventFragment.h \ ! PhysicsFragment.h \ ! ScalerFragment.h --- NEW FILE: FragmentQueue.h --- #ifndef __FRAGMENTQUEUE_H #define __FRAGMENTQUEUE_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 */ #ifndef __STL_DEQUE #include <deque> #ifndef __STL_DEQUE #define __STL_DEQUE #endif #endif class EventFragment; /*! Fragment queue is a queue of pointers to event fragments. the data sources put fragments in this queue and assembler stage inspects and pulls fragments out of this queue. */ class FragmentQueue { public: typedef std::deque<EventFragment*>::iterator iterator; private: std::deque<EventFragment*> m_queue; public: void insert(EventFragment& fragment); EventFragment* peek(); EventFragment* remove(); size_t size() const; iterator begin(); iterator end(); }; #endif --- NEW FILE: StateTransitionFragment.h --- #ifndef __STATETRANSITIONFRAGMENT_H #define __STATETRANSITIONFRAGMENT_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 */ #ifndef __EVENTFRAGMENT_H #include <EventFragment.h> #endif #ifndef __STL_STRING #include <string> #ifndef __STL_STRING #define __STL_STRING #endif #endif #ifndef __CRT_TIME_H #include <time.h> /* For struct tm. */ #ifndef __CRT_TIME_H #define __CRT_TIME_H #endif #endif #ifndef __CRT_STDINT_H #include <stdint.h> #ifndef __CRT_STDINT_H #define __CRT_STDINT_H #endif #endif /*! This class describes and implements a state transition event fragment. These constitute assembly sentinells and are combined to a single state transition event. */ class StateTransitionFragment : public EventFragment { uint16_t m_ssig; uint32_t m_lsig; public: StateTransitionFragment(uint16_t* pBuffer); std::string title() const; struct tm absoluteTime() const; uint32_t elapsedTime() const; }; #endif --- NEW FILE: AssemblerWrongStateException.cpp --- /* 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 */ #include <config.h> #include <AssemberWrongStateException.h> using namespace std; //////////////////////////////////////////////////////////////////////////// /*! Constructs the exception. Since ReasonText method is const, we take the time here to construct the m_reasonText variable... this also works because we have not really given any method for changing the exception mid-stream as our anticipated usecase is: throw AssemblerWrongStateException ... \param state - The actual state of the system either AssemblerWrongStateException::inactive or AssemblerWrongStateException::active \param attempted - Some text that explains what state was attempted. \param wasDoing - Some text that describes the larger context of the effort. */ AssemblerWrongStateException::AssemblerWrongStateException(AssemblerWrongStateException::State state, string attempted, string wasDoing) : CException(wasDoing.c_str()), m_actualState(state) { m_reasonText = "Assembler input stage was in the wrong state while "; m_reasonText += attempted; m_reasonText += " actual state was: "; m_reasonText += ((state == inactive)) ? "inactive" : "active"; m_reasonText += " while: "; m_reasonText += wasDoing; } ////////////////////////////////////////////////////////////////////////// /*! Return the reason for he exception. This is just m_reasonText. */ const char* AssemblerWRongStateException::ReasonText() const { return m_reasonText.c_str(); } ////////////////////////////////////////////////////////////////////////// /*! Returns the reason code. This is one of: - 0 if the actual state is inactive. - 1 if the actual state is active. */ Int_t AssemblerWrongStateException::ReasonCode() const { return (m_actualState == inactive) ? 0 : 1; } --- NEW FILE: AssemblerWrongStateException.h --- #ifndef __ASSEMBLERWRONGSTATEEXCEPTION_H #define __ASSEMBLERWRONGSTATEEXCEPTION_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 */ #ifndef __EXCEPTION_H #include <Exception.h> #endif #ifndef __STL_STRING #include <string> #ifndef __STL_STRING #define __STL_STRING #endif #endif /*! Reports exceptions that can be thrown when the assembler input stage is in the wrong state while attempting to start/stop asembly. */ class AssemblerWrongStateException : public CException { public: typedef enum _State { inactive, active } State; private: State m_actualState; std::string m_reasonText; public: AssemblerWrongStateException(AssemblerWrongStateException::State state, std::string attempted, std::string wasDoing); virtual const char* ReasonText() const; virtual Int_t ReasonCode() const; }; #endif --- NEW FILE: StringListFragment.cpp --- /* 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 */ #include <config.h> #include "StringListFragment.h" #include <buffer.h> using namespace std; /*! Construct the buffer... */ StringListFragment::StringListFragment(uint16_t* pBuffer) : EventFragment(extractNode(pBuffer), extractType(pBuffer), bodyPointer(pBuffer), extractSize(pBuffer) - sizeof(bheader)/sizeof(uint16_t)), { uint16_t entities = extractEntityCount(pBuffer); pBuffer += sizeof(bheader)/sizeof(uint16_t); int item=0; while(entities) { m_strings.push_back(string(pBuffer)); // Strings are an even number of words hence the +1 below. pBuffer += (m_strings[item].size() + 1)/sizeof(uint16_t); item++; entities--; } } /*! Return a copy of the vector of strings: */ vector<string> StringListFragment::strings() const { returnm_strings; } --- NEW FILE: EventFragment.h --- #ifndef __EVENTFRAGMENT_H #define __EVENTFRAGMENT_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 */ #ifndef __CRT_STDINT_H #include <stdint.h> #ifndef __CRT_STDINT_H #define __CRT_STDINT_H #endif #endif #ifndef __STL_VECTOR #include <vector> // Must also pull in size_t. #ifndef __STL_VECTOR #define __STL_VECTOR #endif #endif /*! Base class for all event fragments. This is not abstract, extensions of this class add functionality rather than polymorphically implementing existing interfaces. */ class EventFragment { private: uint16_t m_node; uint16_t m_type; std::vector<uint16_t> m_body; public: EventFragment(uint16_t node, uint16_t type, void* body size_t words); EventFragment(uint16_t node, uint16_t type, std::vector<uint16_t> body); uint16_t node() const; uint16_t type() const; std::vector<uint16_t> body() const; size_t size() const; uint16_t& operator[](size_t index); protected: // utilities: static uint16_t extractType(uint16_t* rawBuffer); static uint32_t extractSize(uint16_t* rawBuffer); static uint16_t extractNode(uint16_t* rawBuffer); static uint16_t extractSsig(uint16_t* rawBuffer); static uint32_t extractLsig(uint16_t* rawBuffer); static uint16_t extractEntityCount(uint16_t* rawBufer); static uint16_t* bodyPointer(uint16_t* rawBuffer); static uint32_t tohl(uint32_t datum, uint32_t lsig); static uint16_t tohs(uint16_t datum, uint16_t ssig); static uint32_t getLongword(uint16_t* buffer, size_t wordOffset, uint32_t lsig); static uint16_t getWord(uint16_t* buffer, size_t wordOffset, uint16_t ssig); }; #endif |