// // File : VReadoutInterface.hh // // Purpose: Header file for VReadoutInterface.cc // // $Id: VReadoutInterface.hh 9725 2010-09-28 07:31:17Z mathes $ // /** @file VReadoutInterface.hh * Declaration of the abstract class VReadoutInterface * and the enum ReadoutState. * @author H.-J. Mathes, Fzk */ #ifndef _VReadoutInterface_hh_ #define _VReadoutInterface_hh_ #include #include #include #include #include /** Enable this pre-processor variable to see the event handshake * between the ShmApp and the ReadoutInterface. */ #define _DEBUG_STATES #ifdef DEBUG_STATES # include #endif // DEBUG_STATES // --- forward declarations ... class VirtualReadout; class TMirrorEvent; class TMirrorRunHeader; class TMirrorRunTrailer; /** Abstract base class describing the event readout specific communication * with the hardware. Classes derived from this class have to reimplement * all the abstract methods for a given implementation of the hardware * interface, for example via sockets, or by direct library calls. * * This implementation assumes: * @li the readout consists of several steps
* - readout of the SLT pixel trigger information
* - decide about further readout based on this data. This makes use of an * reimplementation of the class VSLTInterface
* - if it is decided, the FADC pixel data are read out fully or partially
* - finally, the data in the front-end is cleared (page freed) * @li the readout process will not steer the hardware for DAQ because this * is done by the user interface. * @li no special treatment of calibration data * @li no special treatment of additional current monitor readout */ class VReadoutInterface { friend class SimpleReadoutApplication; public: /** This enum describes the various states in which the hardware readout * could be at any moment. */ typedef enum ReadoutState { kNO_RUN = 0, ///< Not in RUN state. kWAIT_EVENT, ///< Waiting for an event (interrupt) from the hardware or ///< from athread coupled with to the hardware. kEVENT_READY, ///< Event (notify) from the hardware (trigger thread) ///< received. /* kEVENT_SET, ///< Event buffer (where the event is to be read to) ///< has been set. */ kPROCESS_EVENT, ///< Data thread or readout thread are reading FADC data ///< into the previously set event buffer. kEVENT_DONE, ///< Event readout is complete and copying has been done. kACQ_ERROR ///< Some error occurred during DAQ. } EReadoutState; public: /** Constructor for class VReadoutReadoutInterface. * The readout state is initialized to kNO_RUN */ VReadoutInterface() : fLogfile(NULL), fEvent(NULL), fReadoutState(kNO_RUN) { } /** Destructor for class VReadoutReadoutInterface. */ virtual ~VReadoutInterface() { } /** Perform acquisition init on the hardware. */ virtual int AcquisitionInit() = 0; /** Perform acquisition shutdown on the hardware. */ virtual int AcquisitionShutdown() = 0; /** Perform acquisition start on the hardware. */ virtual int AcquisitionStart() = 0; /** Perform acquisition stop on the hardware. */ virtual int AcquisitionStop() = 0; public: // --- from ThreadedReadout.hh (class ThreadedReadout) /** NULLify fEvent and set state to 'kWAIT_EVENT'. */ virtual void ClearEventBuffer() { #ifdef DEBUG_STATES FD_CDEBUG(1) << "WAIT_EVENT !" << std::endl; #endif // DEBUG_STATES fEvent = NULL; fReadoutState = kWAIT_EVENT; } /** Return true if the event readout is done (protocol to buf mgr). */ virtual bool IsEventDone() { return (fReadoutState == kEVENT_DONE) ? true : false; } /** */ virtual bool IsEventReady() { return (fReadoutState == kEVENT_READY) ? true : false; } /** */ virtual bool HasEvent() { return (fReadoutState != kWAIT_EVENT) ? true : false; } /** */ virtual TMirrorEvent* GetEventBuffer() // GetEvent() { return fEvent; } /** */ virtual bool IsEventBufferSet() { return (fEvent != NULL) ? true : false; } /** */ virtual void SetEventBuffer(TMirrorEvent* event) { #ifdef DEBUG_STATES /* std::cout << "EVENT_SET !" << std::endl; */ FD_CDEBUG(1) << "--> SetEventBuffer() !!!" << std::endl; #endif // DEBUG_STATES fEvent = event; /* fReadoutState = kEVENT_SET; */ } /** */ virtual void SetEventDone() { #ifdef DEBUG_STATES std::cout << "EVENT_DONE !" << std::endl; #endif // DEBUG_STATES fReadoutState = kEVENT_DONE; } /** */ virtual void SetEventReady() { #ifdef DEBUG_STATES std::cout << "EVENT_READY !" << std::endl; #endif // DEBUG_STATES fReadoutState = kEVENT_READY; } // virtual EReadoutState GetReadoutState() // { return fReadoutState; } /** Delete event data of event currently hold in FE memory. */ virtual void DeleteEvent() { std::cout << "DeleteEvent() - not implemented !" << std::endl; } /** Fill the hardware related information into the run header. */ virtual void FillRunHeader(TMirrorRunHeader*) = 0; /** Fill the hardware related information into the run trailer. */ virtual void FillRunTrailer(TMirrorRunTrailer*) = 0; /** Get the descriptor for the currently readout frontend page. */ virtual FEPageDesc *GetCurrentPage() = 0; /** Get a pointer to the class which is used to readout the frontend * or a file or ... . */ virtual VirtualReadout *GetReadoutHandle() = 0; /** Read the event header information of the current event * into the beforehand set buffer. */ virtual void ReadEventHeader() { std::cout << "ReadEventHeader() - not implemented !" << std::endl; } /** Read the FADC data of selected pixels of the current event. */ virtual void ReadFADCData(TMirrorPixelList*) { std::cout << "ReadFADCData() - not implemented !" << std::endl; } /** Read the SLT pixel trigger data of current event. */ virtual void ReadMonitorData(TMirrorPixelList*) { std::cout << "ReadMonitorData() - not implemented !" << std::endl; } /** Read the SLT pixel trigger data of current event. */ virtual void ReadPixelData() { std::cout << "ReadPixelData() - not implemented !" << std::endl; } /** Get the handle to the log file. */ virtual FILE* GetLogfile() { return fLogfile; } /** As WaitEvent() might be used to poll for events this method is used * to do the actual event processing of this class. */ virtual int HandleEvent() = 0; /** Set the (optional) handle to a log file. */ virtual void SetLogfile(FILE* file) { fLogfile = file; } /** Wait for the occurrence of an event in this class. */ virtual int WaitEvent(unsigned int millisec) = 0; protected: /** Set the current state of the Readout. */ void SetReadoutState(enum ReadoutState state) { fReadoutState = state; } /** Handle to the log file. */ std::FILE *fLogfile; private: TMirrorEvent *fEvent; EReadoutState fReadoutState; }; #endif // _VReadoutInterface_hh_