![]() | ![]() | ![]() | Writing a Scaler class | ![]() |
The work of writing a Scaler class is similar to that of writing an Event segment. First you must write a class definition header that defines the interfaces to your class. The header is shown in below:
#ifndef __CMYSCALER_H #define __CMYSCALER_H #include <CScaler.h> #include <vector> class CSIS3820; class CMyScaler : public CScaler { private: CSIS3820* m_pModule; public: CMyScaler(unsigned long base, int crate = 0); virtual ~CMyScaler(); virtual void Initialize(); virtual void Read(vector<unsigned long>& scalers); virtual void Clear(); virtual unsigned int size() {return 32;} }; #endif
The class maintains a pointer to a CSIS3820 object. The CSIS3820 class provides hardware support for the module. The constructor and destructor just create and destroy this object:
#include "CMyScaler.h" #include <CSIS3820.h> #include <iostream> // construct: Create the SIS module: CMyScaler::CMyScaler(unsigned long base, int crate) { try { m_pModule = new CSIS3820(base, crate); } catch(string msg) { cerr << "Error creating CSIS3820: " << msg << endl; } catch(...) { cerr << "Unexpected excpetion caught creating CSIS3820\n"; } } CMyScaler::~CMyScaler() { delete m_pModule; }
To initialize the module, we need to set it in latching mode. In many applications, it is also important to selectively inhibit counting in some channels of the scalers read. The SIS3820 allows the front panel inputs to be used to selectively inhibit groups of 8 channels. We will set up the module to support this as well. Finally, in order to prevent read/clear skew, we will program the module to clear the counters on a latch operation, clear the module and start the scaler counting.
void CMyScaler::Initialize() { m_pModule->setOperatingMode(CSIS3820::LatchingScaler); m_pModule->setInputMode(CSIS3820::InhibitGroups); m_pModule->EnableClearOnLatch(); m_pModule->ClearChannels(); m_pModule->Arm(); m_pModule->Enable(); }
The module is read out by latching it and reading the channels. There's an impedance mismatch between the parameter types required by the CSIS3820 readout functions and the parameters passed to Read. It is therefore necessary to read the data into an internal buffer and then copy it to the end of the output vector:
void CMyScaler::Read(vector<unsigned long>& scalers) { unsigned long data[32]; // 32 channel buffer. m_pModule->LatchAndRead(data); // Read/clear module scalers.insert(scalers.end(), data, data+32); }
The insert memeber function of the vector class is used to append all 32 channels of data to the scalers vector in a single operation.
The Clear member function is called to clear the module after read. In our case we have covered all the clears by clearing the module when it is initialized and setting up the module to clear when latched. The clear member function is therefore empty:
void CMyScaler::Clear() { }
![]() | ![]() | ![]() | Writing a Scaler class | ![]() |