In this section we will include the full text of the following files:
The Readout Makefile.
The modified skeleton file.
The header for our event segment class.
The implementation of our event segment.
The header for our trigger class.
The implementation of our trigger class.
Example 10-19. Makefile
# # This establishes which version of NSCLDAQ we're using and where it's installed: # Supposedly you only need to change this definition to update to a newer # version of the software: INSTDIR=/usr/opt/daq/11.0-rc18 include $(INSTDIR)/etc/SBSRdoMakeIncludes USERCCFLAGS= USERCXXFLAGS=$(USERCCFLAGS) USERLDFLAGS= OBJECTS=Skeleton.o V775EventSegment.o MyTrigger.o Readout: $(OBJECTS) $(CXXLD) -o Readout $(OBJECTS) $(USERLDFLAGS) $(LDFLAGS) clean: rm -f $(OBJECTS) Readout depend: makedepend $(USERCXXFLAGS) *.cpp *.c help: echo make - Build Readout. echo make clean - Remove products from previous builds. echo make depend - Add header dependencies to Makefile.
Example 10-20. Skeleton.cpp
#include <config.h> #include <Skeleton.h> #include <CExperiment.h> #include <TCLInterpreter.h> #include <CTimedTrigger.h> #include <CAENcard.h> #include "V775EventSegment.h" #include "MyTrigger.h" CTCLApplication* gpTCLApplication = new Skeleton; static const uint32_t V775Base=0x11110000; // Base address of the V775. void Skeleton::SetupReadout(CExperiment* pExperiment) { CReadoutMain::SetupReadout(pExperiment); CAENcard* pModule = new CAENcard(10, 0, false, V775Base); // Establish your trigger here by creating a trigger object // and establishing it. pExperiment->EstablishTrigger(new MyTrigger(*pModule)); // Create and add your event segments here, by creating them and invoking CExperiment's // AddEventSegment pExperiment->AddEventSegment(new CV775EventSegment(*pModule)); } void Skeleton::SetupScalers(CExperiment* pExperiment) { CReadoutMain::SetupScalers(pExperiment); // Establishes the default scaler trigger. // Sample: Set up a timed trigger at 2 second intervals. timespec t; t.tv_sec = 2; t.tv_nsec = 0; CTimedTrigger* pTrigger = new CTimedTrigger(t); pExperiment->setScalerTrigger(pTrigger); // Create and add your scaler modules here. } void Skeleton::addCommands(CTCLInterpreter* pInterp) { CReadoutMain::addCommands(pInterp); // Add standard commands. } void Skeleton::SetupRunVariables(CTCLInterpreter* pInterp) { // Base class will create the standard commands like begin,end,pause,resume // runvar/statevar. CReadoutMain::SetupRunVariables(pInterp); // Add any run variable definitions below. } void Skeleton::SetupStateVariables(CTCLInterpreter* pInterp) { CReadoutMain::SetupStateVariables(pInterp); // Add any state variable definitions below: }
Example 10-21. V775EventSegment.h
#ifndef _V775EVENTSEGMENT_H #define _V775EVENTSEGMENT_H #include <CEventSegment.h> class CAENcard; class CV775EventSegment : public CEventSegment { private: CAENcard& m_module; public: CV775EventSegment(CAENcard& module); public: virtual void initialize(); virtual size_t read(void* pBuffer, size_t maxwords); };
Example 10-22. V775EventSegment.cpp
#include "V775EventSegment.h" #include <CAENcard.h> #include <iostream> #include <stdint.h> static const unsigned TDC_RANGE = 0x1e; // Corresponds to 1.2usec. static const unsigned MAX_WORDS = 34*sizeof(uint32_t)/sizeof(uint16_t); CV775EventSegment::CV775EventSegment(CAENcard& module) : m_module(module) {} void CV775EventSegment::initialize() { try { m_module.commonStart(); m_module.setRange(TDC_RANGE); m_module.clearData(); } catch (std::string msg) { std::cerr << "Unable to initialize TDC (V775)\n"; std::cerr << msg << std::endl; throw; } } size_t CV775EventSegment::read(void* pBuffer, size_t maxWords) { if (MAX_WORDS <= maxWords) { size_t n = m_module.readEvent(pBuffer); m_module.clearData(); return n/sizeof(uint16_t); } else { throw std::string("CV775EventSegment::read - maxWords won't hold my worst case event"); } }