QEleConfigHandler Class Reference

Inheritance diagram for QEleConfigHandler:

QOnlineMessenger

List of all members.


Detailed Description

non-locking interface to cuore electronics to be used in diana

Author:
Sergio Di Domizio
This class allows to interact in write mode with the Cuore electronics and keeps memory of all the configurations that are applied from when it is created to when it is deleted, or the Reset() method is called.
Electronics configurations for multiple channels can be added with the Add() and Replace() methods, and are applied when the Apply() method is called.
Since, due to the hardware setup, the external bias at a given time must be the same for all channels, this quantity must be explicitly set before each call to Apply() by calling the SetExternalBias() method.
Then, when the Apply() method is called, the external bias is set into each QEleChannelConfig object to the value requested in the call to SetExternalBias().
The Apply() method creates a separated thread where the electronics configuration is actually modified and returns immediately so that the flow of the diana sequence is not interrupted.
The Apply() method causes the application of the requested electronics configuration only if there are no other calls to Apply() that are still ongoing. Otherwise it has no effect.
After an electronics configuration is applied succesfully the QEleChannelConfig objects describing that configuration become available and can be retrieved by calling the GetConfig() method.
The list of logical channels to be handled by this object must be set in the Reset() method.
By mean of the SetWrongPolarityChannels() method this class allows to hide the (hardware) problem for which several Cuoricino channels have a bias polarity that is opposite to the expected one. For all the channels registered with this method the polarity is inverted with respect to the requested value.

Public Member Functions

virtual ~QEleConfigHandler ()
 dtor
bool Add (const QEleChannelConfig &config)
 schedule changes in electronics configuration for a certain logical channel
bool Replace (const QEleChannelConfig &config)
 same as Add(), but if a previously requested configuration exists, it is replaced by the new one.
void RemoveConfig (int lg)
 remove scheduled configuration for channel lg (if any)
void RemoveAllConfigs ()
 remove all scheduled configurations
void SetSleepAfterChangeSec (unsigned int sleepSec)
 set time to sleep after changing electronics configuration
void SetExternalBiasV (float extBiasVolt)
 set external bias voltage in Volts
bool Apply ()
 apply electronics configuration previously requested with calls to Add() or Replace() functions
const QEleChannelConfigGetConfig (unsigned int lg, unsigned int id)
 get configuration associated to the given id and for the given logical channel
bool Reset (int settingsBasket, const std::set< int > &activeChannels)
 reset this object to its initial configuration
void SetWrongPolarityChannels (const std::set< int > &channels)
 set list of channels with wrong bias polarity (due to bad hardware cabling).
const QErrorGetError () const
 get last error
bool ResetError ()
 reset error
bool ConfigOngoing ()
bool IsActiveChannel (int lg) const

Static Public Member Functions

static QEleConfigHandlerGetInstance ()
 get reference to singleton

Private Member Functions

 QEleConfigHandler ()
 ctor
bool SyncThread ()
void CheckThread ()
bool InterruptExecution ()
 interrupt thread execution
bool GetCratesToKill (const std::set< int > &activeChannels)
 read from db the list of daq crates involved in electronics changes
void ClearMaps ()

Private Attributes

std::map< int,
QEleChannelConfig * > 
fInputConfigs
std::map< int,
QEleChannelConfig * > 
fTmpConfigs
std::map< int, std::vector
< QEleChannelConfig * > > 
fPastConfigs
std::set< unsigned int > fCratesToKill
std::set< int > fWrongPolarityChannels
int fSettingsBasket
unsigned int fSleepAfterChangeSec
float fExtBiasV
boost::mutex * fMutex
boost::thread * fThread
QError fError

Static Private Attributes

static QEleConfigHandlergMe = NULL

Member Function Documentation

bool QEleConfigHandler::Add ( const QEleChannelConfig config  ) 

schedule changes in electronics configuration for a certain logical channel

Parameters:
config object storing electronics configuration to be applied
Returns:
true on success, false if another configuration for the same logical channel was previously added but is still to be applied, or if requested logical channel was not registered as an active channel when Reset() was called.

References fInputConfigs, fPastConfigs, and QEleChannelConfig::GetLg().

Referenced by MLCBaseController::NextConf().

bool QEleConfigHandler::Replace ( const QEleChannelConfig config  ) 

same as Add(), but if a previously requested configuration exists, it is replaced by the new one.

Returns:
true on success, false if the requested logical channel was not registered as an active channel when Reset() was called.

References fInputConfigs, fPastConfigs, and QEleChannelConfig::GetLg().

void QEleConfigHandler::SetSleepAfterChangeSec ( unsigned int  sleepSec  )  [inline]

set time to sleep after changing electronics configuration

The sleep time is actually doubled compared to the specified value, since two calls to sleep() are present: one after modifying the external bias, and the other one after changing the electronics configuration.

References fSleepAfterChangeSec.

Referenced by MLCBaseController::NextConf().

bool QEleConfigHandler::Apply (  ) 

apply electronics configuration previously requested with calls to Add() or Replace() functions

Returns:
true unless another change to electronics configuration is ongoing or if an error occurred in a previous call to Apply() that was not reset by calling ResetError().
This method creates a map whose content is identical to fInputConfig and passes it to the ApplyElectronicsConfiguration() function wihch, in another thread of execution, actually applies the requested electronics configuration.
Before doing the copy the configs in fInputConfigs are modified so that each of them have the same external bias, as specified by the last call to SetExternalBias().
A further copy of fInputConfigs is done, fTmpConfig, and then fInputConfig is flushed so that it is ready for new calls to Add() or Replace().
The content of fTmpConfig is then copied into fPastConfigs as soon as the call to ApplyElectronicsConfiguration() terminates succesfully.

References CheckThread(), fCratesToKill, fError, fExtBiasV, fInputConfigs, fMutex, fPastConfigs, fSettingsBasket, fSleepAfterChangeSec, fThread, fTmpConfigs, fWrongPolarityChannels, and SyncThread().

Referenced by MLCBaseController::NextConf().

const QEleChannelConfig * QEleConfigHandler::GetConfig ( unsigned int  lg,
unsigned int  id 
)

get configuration associated to the given id and for the given logical channel

Parameters:
lg logical channel
id electronics configuration id
Returns:
const pointer to QEleChannelConfig object or NULL if requested pair of id and logical channel is invalid.

References CheckThread(), fPastConfigs, and QOnlineMessenger::OLWarn().

bool QEleConfigHandler::Reset ( int  settingsBasket,
const std::set< int > &  activeChannels 
)

reset this object to its initial configuration

Parameters:
settingsBasket settings basket to be used for channel mapping
activeChannels list of channels to be handled by this object
All the informations on the past electronics configurations are lost and the counter for the configuration ids is reset.

References ClearMaps(), fPastConfigs, fSettingsBasket, GetCratesToKill(), and InterruptExecution().

Referenced by MLCBaseController::InitHandler().

void QEleConfigHandler::SetWrongPolarityChannels ( const std::set< int > &  channels  )  [inline]

set list of channels with wrong bias polarity (due to bad hardware cabling).

The polarity for the channels belonging to this list will be inverted with respect to what is found in the corresponding QEleChannelConfig object.

References fWrongPolarityChannels.

Referenced by MLCBaseController::InitHandler().

bool QEleConfigHandler::ResetError (  ) 

reset error

Returns:
true on success, false if there is an ongoing electronics configuration (in this case the error is not reset)

References ConfigOngoing(), fError, and QError::Set().

bool QEleConfigHandler::ConfigOngoing (  ) 

Returns:
true if there is an ongoing electronics configuration

References CheckThread(), and fThread.

Referenced by MLCBaseController::Do(), and ResetError().

bool QEleConfigHandler::IsActiveChannel ( int  lg  )  const [inline]

check whether a given logical channel is active

References fPastConfigs.

Referenced by MLCMeasCollector::Do().

bool QEleConfigHandler::SyncThread (  )  [private]

Check the status of a possible electronics configuration thread.
If fThread is NULL this method does nothing and returns false.
Otherwise it executes a timed_join on the thread with a timeout of 50 ms. If the join succeeds, it returns true, otherwise it returns false.
When this method returns true, the content of fError should be checked to discover the exit status of the thread.

References fThread.

Referenced by Apply(), CheckThread(), and InterruptExecution().

void QEleConfigHandler::CheckThread (  )  [private]

Call SyncThread() and, in case of success, update configuration maps

References fError, fPastConfigs, fTmpConfigs, and SyncThread().

Referenced by Apply(), ConfigOngoing(), and GetConfig().

bool QEleConfigHandler::InterruptExecution (  )  [private]

interrupt thread execution

Returns:
true on success, false on failure
This method tries to interrupt the execution of a (possibly) running thread. It waits up to 10 seconds for the thread to complete, otherwise it gives up and returns false.

References fThread, and SyncThread().

Referenced by Reset(), and ~QEleConfigHandler().

bool QEleConfigHandler::GetCratesToKill ( const std::set< int > &  activeChannels  )  [private]

read from db the list of daq crates involved in electronics changes

Parameters:
activeChannels list of channels involved in electronics changes

References fCratesToKill, fError, fSettingsBasket, QDbDetector::GetDaqCrates(), and QError::Set().

Referenced by Reset().

void QEleConfigHandler::ClearMaps (  )  [private]

delete content of the three maps storing electronics configuration

References fInputConfigs, fPastConfigs, and fTmpConfigs.

Referenced by Reset(), and ~QEleConfigHandler().


Member Data Documentation

QEleConfigHandler * QEleConfigHandler::gMe = NULL [static, private]

static pointer to the instance of this object

Referenced by GetInstance().

map storing the input configurations received from calls to Add() and Replace().
key: lg channel, value: pointer to corresponding electronics config

Referenced by Add(), Apply(), ClearMaps(), RemoveAllConfigs(), RemoveConfig(), and Replace().

temporary storage for the configurations that are being applied. See documentation for Apply() for further details.
the map has same structure as fInputConfigs

Referenced by Apply(), CheckThread(), and ClearMaps().

std::map<int, std::vector<QEleChannelConfig*> > QEleConfigHandler::fPastConfigs [private]

key: lg, value: a vector of QEleChannelConfigs*
The i-th element of the vector stores the configuration with id i

Referenced by Add(), Apply(), CheckThread(), ClearMaps(), GetConfig(), IsActiveChannel(), Replace(), and Reset().

std::set<unsigned int> QEleConfigHandler::fCratesToKill [private]

list of daq crates acquiring at least one of the channels that are involved in electronics changes (this list is set in the Reset() method)

Referenced by Apply(), and GetCratesToKill().

set of channels with wrong bias polarity (bad hardware cabling)

Referenced by Apply(), and SetWrongPolarityChannels().

settings basket to be used for channel mapping

Referenced by Apply(), GetCratesToKill(), and Reset().

time in seconds to sleep after changing the external bias and after applying new electronics configuration

Referenced by Apply(), and SetSleepAfterChangeSec().

external bias in V

Referenced by Apply(), and SetExternalBiasV().

boost::mutex* QEleConfigHandler::fMutex [private]

used to avoid concurent calls to Apply()

Referenced by Apply(), and ~QEleConfigHandler().

boost::thread* QEleConfigHandler::fThread [private]

thread where the electronics configuration are applied

Referenced by Apply(), ConfigOngoing(), InterruptExecution(), and SyncThread().

in case of any error, is set to something other than QERR_SUCCESS and is reset as soon as ResetError() is called.

Referenced by Apply(), CheckThread(), GetCratesToKill(), GetError(), and ResetError().


The documentation for this class was generated from the following files:

Generated on Tue Nov 16 10:50:05 2010 for CUORE Software by  doxygen 1.5.6