/* * PulserDetector.hh * * Base class for a detector that ha a pulser. Each object of this * class has a bunch of pulsers, and all of them share the same PV * object. * * Created on: Aug 14, 2015 * Author: Hovanes Egiyan */ #ifndef __PULSERDETECTOR_HH__ #define __PULSERDETECTOR_HH__ #include "seqCom.h" #include #include #include #include #include #include #include #include "VPulser.hh" #include "PulserPVs.hh" class PulserDetector { protected: // Detector name std::string pdName; // Map of the pulsers in this detector std::map pdPulserMap; // PVs that belong to the whole detector, can have only one instance per detector instance. PulserPVs* pdPV ; // Flag to show if the PVs are ready to be processed bool pdReadyToProcess; // Map of the flags that is used to sync the SNL code and the C++ code std::map pdFlag; pthread_mutex_t pdMutex; // Mutex for an object pthread_mutexattr_t pdMtxAttr; // Mutex attributes for an object //! Initialize the mutex for the object void initMutex(); //! Destroy the mutex for the object void closeMutex(); // Hide thes constructor so that they are never used PulserDetector(){initMutex();} PulserDetector(const PulserDetector& det ){initMutex();} // One should think about this before using this method // This should not be needed. inline PulserPVs* setPVs( PulserPVs* pv ) {MtxLock objLock(pdMutex);return (pdPV = pv); } public: // Main constructor, the only one that can be used PulserDetector( const std::string detName ); virtual ~PulserDetector() ; virtual inline std::string getName() const { return pdName; } virtual inline std::string setName(const string name ) { return pdName = name; } virtual inline std::map getPulserMap() {MtxLock objLock(pdMutex); return pdPulserMap; } virtual inline std::map getFlags() {MtxLock objLock(pdMutex);return pdFlag;} virtual inline std::map setFlags( const std::map& f ) {MtxLock objLock(pdMutex);return (pdFlag=f);} inline PulserPVs* getPVs() {MtxLock objLock(pdMutex);return pdPV;} inline pthread_mutex_t& getMutex() {return pdMutex; } inline pthread_mutexattr_t& getMutexAttr() {return pdMtxAttr;} // check if pulser with pulserID exists within this detector. virtual bool pulserExists( const std::string pulserID ) ; // Check if the PVs for this detector have been assigned and connected virtual bool inline isReady() {return pdReadyToProcess;} // Add board-related PVs to the PV map for the board virtual int addPVs() = 0; // Assign the SSID and the addresses of the PV arrays declared in the SNL code. virtual void usePVs( SS_ID ssID, PulserPVs::pvStruct& pvStruct ) ; // Connect and set monitor for the PVs needed for this detector virtual void assignPVs() ; // Method to register the flag for synchronization with a new sequencer ID. virtual void registerFlag( const SS_ID ssID, const EV_ID flagID ); // Function that executes in a seprate thread and checks if the PVs have changed // and sets the signal for SNL code to process PVs. static void* ThreadFunc( void* argPtr ); // virtual inline bool inputsChanged(); // Switch state to state of the pulser pulserID virtual void switchState( const std::string pulserID, const short state ) ; // Set the width of the pulser pulserID virtual void setWidth( const std::string pulserID, const unsigned width ) ; // set the frequency for the pulser pulserID virtual void setFrequency( const std::string pulserID, const double freq ) ; // Set the number of pulses for the pulser pulserID virtual void setNPulses( const std::string pulserID, const unsigned n ) ; // Set the delay of the pulser pulserID virtual void setDelay( const std::string pulserID, const unsigned delay ) ; // Return the status of the pulser pulserID virtual short getStatus( const std::string pulserID ) ; // Return the width of the pulser pulserID virtual unsigned getWidth( const std::string pulserID ) ; // Return the frequency of the pulser pulserID virtual double getFrequency( const std::string pulserID ) ; // Return the number of pulses for the pulser pulserID virtual unsigned getNPulses( const std::string pulserID ) ; // Return the delay of the pulser pulserID virtual unsigned getDelay( const std::string pulserID ) ; }; #endif /* __PULSERDETECTOR_HH__ */