From: <jr...@us...> - 2014-03-25 17:37:19
|
Revision: 3410 http://sourceforge.net/p/nscldaq/code/3410 Author: jrtomps Date: 2014-03-25 17:37:05 +0000 (Tue, 25 Mar 2014) Log Message: ----------- Adds filter framework skeleton Modified Paths: -------------- branches/nscldaq-11.0-filter-development/configure.ac branches/nscldaq-11.0-filter-development/utilities/filter/Makefile.am Added Paths: ----------- branches/nscldaq-11.0-filter-development/utilities/filter/CTemplateFilter.cpp branches/nscldaq-11.0-filter-development/utilities/filter/FilterIncludes.in branches/nscldaq-11.0-filter-development/utilities/filter/Makefile-template.in branches/nscldaq-11.0-filter-development/utilities/filter/SkeletonMain.cpp Modified: branches/nscldaq-11.0-filter-development/configure.ac =================================================================== --- branches/nscldaq-11.0-filter-development/configure.ac 2014-03-25 13:51:40 UTC (rev 3409) +++ branches/nscldaq-11.0-filter-development/configure.ac 2014-03-25 17:37:05 UTC (rev 3410) @@ -320,6 +320,8 @@ utilities/sclclient/Makefile utilities/tkbufdump/Makefile utilities/filter/Makefile + utilities/filter/Makefile-template + utilities/filter/FilterIncludes utilities/compatibility/Makefile utilities/compatibility/eventlog-compat utilities/compatibility/spectcldaq Added: branches/nscldaq-11.0-filter-development/utilities/filter/CTemplateFilter.cpp =================================================================== --- branches/nscldaq-11.0-filter-development/utilities/filter/CTemplateFilter.cpp (rev 0) +++ branches/nscldaq-11.0-filter-development/utilities/filter/CTemplateFilter.cpp 2014-03-25 17:37:05 UTC (rev 3410) @@ -0,0 +1,117 @@ +/* + This software is Copyright by the Board of Trustees of Michigan + State University (c) Copyright 2014. + + 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: + Jeromy Tompkins + NSCL + Michigan State University + East Lansing, MI 48824-1321 +*/ + + + + +#ifndef CTEMPLATEFILTER_CPP +#define CTEMPLATEFILTER_CPP + +#include <CFilter.h> +#include <iostream> +#include <CPhysicsEventItem.h> +#include <stdint.h> + +/**! \class CTemplateFilter + Here is a sample implementation of a filter to append a reversed copy of the + data in physics event to its body. This is for illustration purposes. + + See the documentation for the CFilter base class for the virtually declared + methods available for dealing with non-physics events. The user has access + to all of the different ring item types. In fact, it is not necessary for + the user to return the same type of ring item from method as it received. +*/ +class CTemplateFilter : public CFilter +{ + public: + /**! Virtual copy constructor + DO NOT FORGET THIS! + */ + virtual CTemplateFilter* clone() const { return new CTemplateFilter(*this);} + + + /**! A sample filter for handling physics events + + This filter will be called for every physics event item. It will produce + a ring item double the size of the original item with the first half being + the original data and the second half being the data in reversed order. + This filter is unlikely to have any real use but is defined to be + illustrative of how to manipulate the data of a ring item. + + For some precautionary measures, it also demonstrates how to compute whether + the new data is going to overflow the available space in the filtered item. + Reaching the storage capacity is an unlikely occurence because by default a + ring item has 8192 bytes of storage space. + + @param pItem a pointer to the raw physics event item to process + @return the resulting ring item from this filter. This can be the same item + pointed to by pItem or a newly allocated one. Can be any derived + type of ring item. + */ + virtual CRingItem* handlePhysicsEventItem(CPhysicsEventItem* pItem) + { + // Create a copy of the original item to manipulate. This is unnecessary + // but allows one to safely abort filtering and return the original ring + // item. + CPhysicsEventItem* pFiltItem = new CPhysicsEventItem(*pItem); + + // Get the amt of data currently in the body and the available storage + size_t bodySize = pFiltItem->getBodySize(); + size_t storageSize = pFiltItem->getStorageSize(); + + uint16_t *pBodyBegin=0, *pBodyLast=0, *pCursor=0; + uint16_t *pStorageBegin=0, *pStorageEnd=0; + + // Get a pointer to the first piece of data in the body of the ring item + // and compute the location of the last item in the body + pBodyBegin = reinterpret_cast<uint16_t*>(pFiltItem->getBodyPointer()); + pBodyLast = pBodyBegin + bodySize/sizeof(uint16_t) - 1; + + // Get a pointer to the location where we are expected to put data next + pCursor = reinterpret_cast<uint16_t*>(pFiltItem->getBodyCursor()); + + // Compute the storage space limit is for the current filtered item + pStorageBegin = reinterpret_cast<uint16_t*>(pFiltItem->getItemPointer()); + pStorageEnd = pStorageBegin + storageSize/sizeof(uint16_t); + + // Copy the body data to the end in reverse order. + uint16_t* pIter = pBodyLast; + while ( pIter>=pBodyBegin && pIter<pStorageEnd) { + + // Copy the data + *pCursor = *pIter; + + // Update our pointers + ++pCursor; + --pIter; + } + + if (pIter==pStorageEnd) { + std::cout << "Ran out of space!" << std::endl; + } + + // Tell the item where the next data item is + pFiltItem->setBodyCursor(pCursor); + // Compute the new size of the ring item + pFiltItem->updateSize(); + + return pFiltItem; + } + + +}; + +#endif Added: branches/nscldaq-11.0-filter-development/utilities/filter/FilterIncludes.in =================================================================== --- branches/nscldaq-11.0-filter-development/utilities/filter/FilterIncludes.in (rev 0) +++ branches/nscldaq-11.0-filter-development/utilities/filter/FilterIncludes.in 2014-03-25 17:37:05 UTC (rev 3410) @@ -0,0 +1,40 @@ +KITDIR = @prefix@/filterkit +LIBDIR = @prefix@/lib +INCLUDES = @prefix@/filterkit/include +MAININCLUDES = @prefix@/include +TCL_FLAGS= @TCL_FLAGS@ +TCL_LDFLAGS=@TCL_LDFLAGS@ + + +# Compilation flags: + +CXXFLAGS = -g -fPIC -I. -I$(MAININCLUDES) -I$(INCLUDES) $(TCL_FLAGS) @THREADCXX_FLAGS@ +CCFLAGS=$(CXXFLAGS) + +LDFLAGS = $(LIBDIR)/libdaqshm.so \ + $(LIBDIR)/libdataformat.so \ + $(LIBDIR)/liburl.so \ + $(LIBDIR)/libfilter.so \ + -L/usr/lib -lException \ + $(TCL_LDFLAGS) @THREADLD_FLAGS@ + +# Compilation rules: + +# C++ compilations. note that all the build rules should be identical +# + +.cpp.o: + $(CXX) -g -c $(CXXFLAGS) $(USERCXXFLAGS) $< + +.cxx.o: + $(CXX) -g -c $(CXXFLAGS) $(USERCXXFLAGS) $< + +.cc.o: + $(CXX) -g -c $(CXXFLAGS) $(USERCXXFLAGS) $< + +# +# C compilation(s) if more are aded the build rules should be identical. + +.c.o: + $(CC) -g -c $(CCFLAGS) $(USERCCFLAGS) $< + Added: branches/nscldaq-11.0-filter-development/utilities/filter/Makefile-template.in =================================================================== --- branches/nscldaq-11.0-filter-development/utilities/filter/Makefile-template.in (rev 0) +++ branches/nscldaq-11.0-filter-development/utilities/filter/Makefile-template.in 2014-03-25 17:37:05 UTC (rev 3410) @@ -0,0 +1,35 @@ +INSTDIR=@prefix@ + +include $(INSTDIR)/filterkit/FilterIncludes + + + + +# +# Add your own compilation/link flags here: + +USERCXXFLAGS= +USERCCFLAGS=$(USERCCFLAGS) +USERLDFLAGS= + +# +# Add the names of objects you need here if you modified the name of the driver file, +# this should also reflect thtat. +# +OBJECTS = CTemplateFilter.o SkeletonMain.o + +# +# Modify the line below to provide the name of the library you are trying to build +# it must be of the form libsomethingorother.so +# + +USERFILTER = UserFilter + +$(USERFILTER): $(OBJECTS) + $(CXX) $(OBJECTS) -o $@ $(USERLDFLAGS) $(LDFLAGS) + + + + + + Modified: branches/nscldaq-11.0-filter-development/utilities/filter/Makefile.am =================================================================== --- branches/nscldaq-11.0-filter-development/utilities/filter/Makefile.am 2014-03-25 13:51:40 UTC (rev 3409) +++ branches/nscldaq-11.0-filter-development/utilities/filter/Makefile.am 2014-03-25 17:37:05 UTC (rev 3410) @@ -84,3 +84,14 @@ EXTRA_DIST = filterargs.ggo #EXTRA_DIST = filterargs.ggo filter.xml + +#-------------------- Filter Kit + +install-data-local: + $(mkinstalldirs) @prefix@/filterkit + $(INSTALL_DATA) FilterIncludes \ + @srcdir@/CTemplateFilter.cpp \ + @srcdir@/SkeletonMain.cpp @prefix@/filterkit + $(INSTALL_DATA) Makefile-template @prefix@/filterkit/Makefile + +EXTRA_DIST = CTemplateFilter.cpp Makefile-template.in FilterIncludes.in Added: branches/nscldaq-11.0-filter-development/utilities/filter/SkeletonMain.cpp =================================================================== --- branches/nscldaq-11.0-filter-development/utilities/filter/SkeletonMain.cpp (rev 0) +++ branches/nscldaq-11.0-filter-development/utilities/filter/SkeletonMain.cpp 2014-03-25 17:37:05 UTC (rev 3410) @@ -0,0 +1,49 @@ + +#include <iostream> +#include <CFatalException.h> +#include <CFilterMain.h> + +#include "CTemplateFilter.cpp" + +/// The main function +/**! main function + Creates a CFilterMain object and + executes its operator()() method. + + \return 0 for normal exit, + 1 for known fatal error, + 2 for unknown fatal error +*/ +int main(int argc, char* argv[]) +{ + int status = 0; + + try { + + // Create the main + CFilterMain theApp(argc,argv); + + + // Construct filter(s) here. + CTemplateFilter user_filter; + + // Register the filter(s) here. Note that if more than + // one filter will be registered, the order of registration + // will define the order of execution. If multiple filters are + // registered, the output of the first filter will become the + // input of the second filter and so on. + theApp.registerFilter(&user_filter); + + // Run the main loop + theApp(); + + } catch (CFatalException exc) { + status = 1; + } catch (...) { + std::cout << "Caught unknown fatal error...!" << std::endl; + status = 2; + } + + return status; +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |