#include <Module.h>
Public Member Functions | |
Module (const DAQid &id) | |
Constructor. | |
virtual | ~Module () |
Destructor. | |
virtual int | PrepareForRun ()=0 |
Prepares for a new run. | |
virtual int | Start (int mode=0)=0 |
Start the run. | |
virtual int | Stop (int mode=0)=0 |
Stop the run. | |
virtual int | Pause ()=0 |
Pause the run. | |
virtual int | Continue ()=0 |
Resume the run after pause. | |
virtual int | Reset ()=0 |
Send a reset to the module. | |
virtual int | GetReady ()=0 |
Initialize the Module. | |
virtual int | Trigger ()=0 |
Issues a trigger. | |
virtual void | flush ()=0 |
Flush any remaining data on the Module. | |
virtual bool | hasData ()=0 |
Returns true if the Module has data available. | |
virtual char * | getData (int &size)=0 |
Retrieves the Module's data. | |
virtual char * | allocate (int size) |
Data allocator. | |
virtual void | deallocate (char *ptr) |
Data deallocator Deallocates the memory holding the data of a given event. | |
bool | is_global () |
true if the module is in global mode | |
void | in_global (RunCommand *rc=0) |
Set the Module in global mode. | |
bool | is_local () |
true if the module is in local mode | |
void | in_local () |
Sets the Module in local or standalone mode. | |
void | RegisterDAQ (RunCommand *rc) |
Registers to a RunCommand. | |
void | UnRegisterDAQ (bool reset=false) |
Unregister from the RunCommand that controls this Module. | |
Static Public Member Functions | |
static char * | allocate_real (int size) |
Real Data allocator. | |
static void | deallocate_real (char *ptr) |
Real data deallocator. | |
Private Member Functions | |
void | init () |
Module initialization. | |
void | update (Observable *o, Argument *arg) |
Receives DAQ commands. | |
Private Attributes | |
RunCommand * | cmd |
Pointer to RunCommand. | |
bool | local |
true if module in local or standalone DAQ mode, false otherwise | |
Static Private Attributes | |
static std::allocator< char > | data_allocator |
The module memory allocator. | |
static std::map< void *, int > | allocator_map |
The allocator map. |
This class represents a module.
It is an abstract class that provides the basic DAQ commands:
All those operations are pure virtual methods on Module. That means the user must derive a class from Module and implement those methods.
It is an Observer of RunCommand. To react to DAQ commands one needs to register the Module to a RunCommand. It can also handle a RunState that will display any change in the running conditions. The RunState is set at construction. If none is give it will build a generic one.
It will destroy the RunState, but it wont't do anything to the RunCommand pointer.
A Module derives from ParameterHolder and, therefore, can mantain a list of named Parameters. The use of named parameters assumes the knowledge of the Parameter type.
void Module::init | ( | ) | [private] |
Module initialization.
If the RunState pointer in the constructor is NULL it will create a new one. It will also add the module to the list of the DAQmanager.
References DAQpp::DAQmanager::addModule(), DAQpp::DAQObject::get_id(), DAQpp::DAQObject::GetStatus(), DAQpp::RunState::set_name(), and DAQpp::DAQmanager::theDAQmanager().
Referenced by Module().
void DAQpp::Module::update | ( | Observable * | o, | |
Argument * | arg | |||
) | [private, virtual] |
Receives DAQ commands.
For modules, we do not want it to be public. This will call the corresponding virtual functions for each command.
Implements Observer.
References cmd, Continue(), GetReady(), DAQpp::DAQObject::GetStatus(), DAQpp::RunState::GettingReady, DAQpp::RunState::NotDefined, DAQpp::RunState::NotReady, Pause(), DAQpp::RunState::Paused, PrepareForRun(), DAQpp::RunState::Ready, Reset(), DAQpp::RunState::reset(), DAQpp::RunState::Running, DAQpp::RunState::set_status(), Start(), DAQpp::RunState::start(), DAQpp::RunState::Starting, Stop(), DAQpp::RunState::stop(), and Trigger().
virtual char* DAQpp::Module::getData | ( | int & | size | ) | [pure virtual] |
Retrieves the Module's data.
This method is used by the RunManager controling this module to retrieve the data.
size | returns the size of the data block |
Referenced by DAQpp::RunManager::ModuleAcquire::operator()().
static char* DAQpp::Module::allocate_real | ( | int | size | ) | [inline, static] |
Real Data allocator.
This is a static method to allocate memory for the module.
size | The size in chars of the memory needed. |
References allocator_map, and data_allocator.
Referenced by allocate().
static void DAQpp::Module::deallocate_real | ( | char * | ptr | ) | [inline, static] |
Real data deallocator.
ptr | The memory pointer. The size is obtained from datallocator_map |
References allocator_map, and data_allocator.
Referenced by deallocate().
virtual char* DAQpp::Module::allocate | ( | int | size | ) | [inline, virtual] |
Data allocator.
Allocates the memory needed to store the data of a given event. This function can be overloaded in order to change the memory management inside the module. In that case one may also need to overload deallocate correspondingly.
size | The size in chars of the memory needed. |
References allocate_real().
virtual void DAQpp::Module::deallocate | ( | char * | ptr | ) | [inline, virtual] |
Data deallocator Deallocates the memory holding the data of a given event.
ptr | the pointer to the memory chunck |
References deallocate_real().
Referenced by DAQpp::RunManager::ModuleAcquire::operator()().
void DAQpp::Module::in_local | ( | ) | [inline] |
Sets the Module in local or standalone mode.
It will run with a new RunManager that will only handle this Module.
References cmd, local, and UnRegisterDAQ().
void DAQpp::Module::RegisterDAQ | ( | RunCommand * | rc | ) | [inline] |
Registers to a RunCommand.
This is usually a RunManager that will displach all the commands.
References cmd.
Referenced by DAQpp::RunManager::addModule(), and in_global().
RunCommand* DAQpp::Module::cmd [private] |
Pointer to RunCommand.
It will store the pointer until it is changed with RegisterDAQ. This should allow to set in local and global on the same RunManager.
Referenced by in_global(), in_local(), RegisterDAQ(), UnRegisterDAQ(), and update().
std::allocator< char > Module::data_allocator [static, private] |
The module memory allocator.
In DAQ++, the module is reponsible to allocate memory for the data that it will pass to the RunManager. In order to avoid leaks, DAQ++ is designed so that memory allocation in the module is done through the methods allocate and deallocate. When the RunManager writes the data sent by the Module, it will deallocate the memory.
It may be of interest for some applications to extend the lifetime of the Module data. In that case, the Module instance can overload deallocate so that the RunManager action takes no effect and deallocate the data afterwards with deallocate_real, which is defiend to be static.
Referenced by allocate_real(), and deallocate_real().
std::map< void *, int > Module::allocator_map [static, private] |
The allocator map.
Module mantains a map in which the addresses and sizes of the memory chuncks allocated are stored. That avoids having to remember outside Module the size of the memory chuncks allocated.
Referenced by allocate_real(), and deallocate_real().