#include <DAQmanager.h>
Public Types | |
enum | DAQstatus { Running = 1, Threaded = 2, Loop = 4, Public = 6 } |
Acquisition flags Set of flags that determine the status and the behaviour of the acquisition. More... | |
enum | msg { startDAQ, stopDAQ, nwModule, nwRunManager, rmModule, rmRunManager, acRunManager, dcRunManager } |
Type of signals. More... | |
typedef std::pair< msg, char * > | newObjArg |
Base for signal arguments. | |
Public Member Functions | |
~DAQmanager () | |
Destructor. | |
void | addModule (Module *m) |
adds a new Module in the list. | |
Module * | deleteModule (Module *m) |
deletes a Module from the list. | |
Module * | find_module (const DAQid &id) |
Finds a Module with a given id. | |
const ModulesMap & | ModuleMap () |
List of existing Module objects. | |
int | countModules () |
Returns the number of Module objects. | |
void | addRunManager (RunManager *m) |
Adds a RunManager in the list. | |
RunManager * | deleteRunManager (RunManager *m) |
Removes a RunManager from the list. | |
int | countRunManager () |
Returns the number of RunManager objects. | |
RunManager * | find_runmanager (const DAQid &id) |
Finds a RunManager with a given id. | |
const RunManagerMap & | RunMmap () |
List of existing DAQpp::RunManager. | |
void | addActiveRunManager (RunManager *rm) |
Adds an active RunManager. | |
void | removeActiveRunManager (RunManager *rm) |
Removes an active RunManager. | |
int | countActiveRunManager () |
Returns the number of active RunManager objects. | |
void | StartRun (int flags) |
Starts a run. | |
void | startRunManager (RunManager *) |
Start a RunManager. | |
void | stopRunManager (RunManager *) |
Stop a RunManager. | |
void | WaitForEndOfRun (int tmout=-1) |
Waits for run completion. | |
bool | isRunning () |
Checks if the DAQ is still running. | |
bool | isLooping () |
Checks if the DAQ is looping. | |
bool | isThreaded () |
Checks if the DAQ is threaded. | |
void | StopRun () |
Stops a run. | |
void | set_trigger (DAQTrigger *func) |
Changes the trigger function. | |
Static Public Member Functions | |
static DAQmanager * | theDAQmanager () |
Returns a pointer to the manager. | |
Protected Member Functions | |
DAQmanager () | |
Hide the constructors. | |
DAQmanager (const DAQmanager &) | |
Copy constructor. Also hidden. | |
void | operator= (const DAQmanager &) |
Assignment operator (hidden). | |
Private Member Functions | |
void | Acquire () |
Starts the acquisition. | |
void | processTheEvent () |
process one event. | |
void | new_obj (msg tp, char *ptr) |
Notifies a change in any of the lists. | |
Private Attributes | |
RunManagerMap | runm |
List of existing RunManager. | |
RunManagerSet | active |
List of active RunManager. | |
ModulesMap | mmap |
List of existing Module. | |
int | state |
Current acquisition status. | |
RunCondition | daq_cond |
This is a Condition that will wait for the RunManager list to be empty. | |
DAQthread | thread |
This is the thread used by DAQmanager when running in Thread mode. | |
DAQTrigger * | trigger |
Data will be read out only when this function returns true. | |
Static Private Attributes | |
static DAQmanager | theManager |
Unique instance. | |
Friends | |
class | DAQinternal |
Classes | |
class | DAQinternal |
class DAQinternal. More... | |
class | DAQthread |
stores the thread id More... | |
class | RunAcquire |
unary function to loop on RunManager objects More... | |
class | RunCondition |
internal condition More... | |
class | RunManagerSet |
class RunManagerSet. More... |
Controls the whole acquisition.
This object is a singleton that controls the whole acquisition. To get the pointer of its only instance one uses theDAQmanager(). It provides the standard operations for a DAQ controler.
It acquires looping on the RunManagers which are activated and those, in turn, delegate the acquisition commands on their Modules.
There are 2 ways of running the acquisition. In the first mode, one has to create first the RunManager objects and then the Module objects. Module objects are then associated to the different RunManager. Once this is done, one needs to activate the RunManager's that should take data, and the run is started with DAQmanager::StartRun(int flag). The flags determine how the acquisition will proceed (see DAQstate).
If 0 is given as argument, the process blocks until all the active RunManagers finish the run. If DAQmanager::Threaded is given, it runs in a different thread. One can always block the main process with DAQmanager::WaitForEndOfRun() until there is no RunManager running (or active)
An example of this configuration could be
// Create the RunManager Rmanager *run_manager = new Rmanager; // The run will stop after 50000 events run_manager->set_MxEvts(50000); // Create the Modules and add them to the RunManager run_manager->addModule( (m1=new MyModule("module1)) ); run_manager->addModule( (m2=new MyModule("module2)) ); // Activate the RunManager run_manager->Activate(); // Run the DAQ in another thread DAQmanager::theDAQmanager()->StartRun(DAQmanager::Threaded); // Wait for end of run DAQmanager::theDAQmanager()->WaitForEndOfRun();
Another example of the previous DAQ mode could be
... Create RunManager and Modules like above ... run_manager->Activate(); // activate RunManager run_manager->set_MxEvts(-1); // Run endlessly DAQmanager::theDAQmanager()->StartRun(DAQmanager::Threaded); // Run only during 1 second timer.start(); while ( timer()<1.); // Stop the run DAQmanager::theDAQmanager()->StopRun();
In some situations one may not know a priory how many RunManager's or Module's will be active, but still wants to start the DAQ. This may be the case of a GUI controling the acquisition that will allow to create RunManager's and Modules dynamically. For these situations DAQmanager implements a DAQ loop that will only be quited if DAQmanager::StopRun() is called.
// // start the DAQ loop DAQpp::DAQmanager::StartRun(DAQmanager::Loop);
In this case, the acquisition will always run in a different thread.
In any of of the cases, the DAQmanager will loop over all the active RunManager objects provided that trigger() returns true. The function can be changed with DAQmanager::set_trigger(). This mechanism provides a way of controling the acquisition with interrupts. Imagine that you have a function that is able to detect the presence of an interrupt (a signal, a VME interrupt, etc.) and that returns true if that is the case. Only when the interrupt is detected will DAQmanager loop over the RunManager objects and, hence, readout the modules.
Once a run is started, the sequence of the acquisition is:
At this stage the acquisition is running. We then make the active RunMangers send a trigger command.
If there is data available:
When the run is over, DAQmanager calls stopRunManager:
DAQmanager derives from Observable and it will notify when a new Module or RunManager is added or removed. The argument of the notification message is
typedef pair<DAQmanager::msg, char *> newObjArg;
DAQmanager::msg
is the list operation and the char pointer is a pointer to the object being inserted or erased from the list.
An example of an Observer update method would be
void MyClass::update(Observable *o, Argument *arg) { Arg< DAQpp::DAQmanager::newObjArg> &msg = *static_cast< Arg< DAQpp::DAQmanager::newObjArg> *>(arg); DAQpp::Module *module; DAQpp::RunManager *run_manager; switch (msg().first) { case DAQpp::DAQmanager::nwModule: module = reinterpret_cast<DAQpp::Module *>(msg().second); break; case DAQpp::DAQmanager::rmModule: module = reinterpret_cast<DAQpp::Module *>(msg().second); break; case DAQpp::DAQmanager::nwRunManager: run_manager = reinterpret_cast<DAQpp::RunManager *>(msg().second); break; case DAQpp::DAQmanager::rmRunManager: run_manager = reinterpret_cast<DAQpp::RunManager *>(msg().second); break; } }
DAQmanager mantains 3 lists of objects:
The third one is somewhat internal, but the first two can be used to find existing object by name. Operations on the lists will trigger a notification to the Observers registeredclass DAQmanager
Acquisition flags Set of flags that determine the status and the behaviour of the acquisition.
Type of signals.
startDAQ | a new DAQ cycle is started |
stopDAQ | the DAQ cycle has finished |
nwModule | a new modules is created |
nwRunManager | a new RunManager is created |
rmModule | a Module has been deleted |
rmRunManager | a RunManager has been destroyed |
acRunManager | a RunManager has been activated |
dcRunManager | a RunManager has been deactivated |
DAQmanager::~DAQmanager | ( | ) |
void DAQmanager::StartRun | ( | int | flags | ) |
Starts a run.
This method starts a new run. It will set the running flag, update the list of active RunManager, reset their RunState, and call PrepareForRun for all of them. Once this is done, it will call Acquire for each of the active RunManager. Depending on the flags provided it can be executed in a new thread and/or run endlessly, regardless of the number of active RunManager, until the runnig flag is erased.
flags | A bitwise-or'd word that determines how the acquisition will proceed. The different bytes can be any of the DAQstatus values. |
References Acquire(), active, isLooping(), isRunning(), isThreaded(), new_obj(), DAQpp::Thread::nice(), Public, Running, DAQpp::Thread::start(), startDAQ, startRunManager(), state, stopDAQ, thread, and Threaded.
void DAQmanager::WaitForEndOfRun | ( | int | tmout = -1 |
) |
Waits for run completion.
tmout | time out in microseconds |
References daq_cond, and DAQpp::Condition::wait().
Referenced by StopRun().
void DAQmanager::set_trigger | ( | DAQTrigger * | func | ) |
RunCondition DAQpp::DAQmanager::daq_cond [private] |
This is a Condition that will wait for the RunManager list to be empty.
It is used by WaitForEndOfRun
Referenced by Acquire(), and WaitForEndOfRun().
DAQTrigger* DAQpp::DAQmanager::trigger [private] |
Data will be read out only when this function returns true.
The function can be changer with set_trigger()
Referenced by processTheEvent(), and set_trigger().