QApolloDbBase Class Reference
[ApolloDataBase]

Inheritance diagram for QApolloDbBase:

QDb

List of all members.


Detailed Description

singleton interface to cuore data base, intended for daq use

Author:
sergio.didomizio@ge.infn.it A single instance of this class will exist for each process involved in the CUORE DAQ.
This class has only private methods and access to them is provided by mean of friendship. This class should be never used directly. Specific purpose classes should be used instead.

This class is not meant to be used by the Event Builder because Event Builder is actually an instance of diana: it will use the diana data base interface.

The mechanisms for interfacing with the data base are implemented in the QDb base class. This class is intended to implement the policy and is optimized for the needs of the DAQ processes. Different DAQ processes need read (or write) access to different sets of information in the data base: while a process like the DaqServer (that control the whole DAQ system) will need system wide informations in almost all cases, processes like DataReader, DataSender or DataReceiver will need almost only informations related to the DAQ crate they are responsible for.

Different methods in this class are optimized for different purposes. Informations are grouped and cached in such a way that both the number of calls to this class from the DAQ processes and the interaction with the db are minimized.

Private Types

enum  EnvVarName_t {
  DbHost_s, DbPort_s, DbUser_s, DbPwd_s,
  DbName_s
}
enum  DbMode_t {
  UndefMode_s = 0, MasterMode_s = 1L << 1, TuningMode_s = 1L << 2, GuiMode_s = 1L << 3,
  ReadMode_s = 1L << 4
}

Private Member Functions

 QApolloDbBase ()
 Private constructor. Invoked at the first call of the Get() method.
bool Undefined () const
 determine if db status is undefined
bool Reset (unsigned int settingsBasket, unsigned int runNumber)
 reset db. DbMode is set to Master mode
bool Reset (unsigned int settingsBasket)
 reset db. DbMode is set to Tuning mode
bool Reset ()
 reset db. DbMode is set to GUI mode
bool ResetRun ()
 reset db. DbMode is set to Run mode
const std::map< unsigned int,
std::string > & 
CrateMap () const
 get map of active crates and corresponding host name
int GetListOfChannels (std::vector< unsigned int > &chList, unsigned int profileId=0)
 get list of active channels corresponding to given profile
unsigned int GetMapping (std::map< unsigned int, QDaqChannel > &cMap)
 fill map with lg channel and corresponding hardware mapping
unsigned int GetActiveChannels (std::map< unsigned int, QDaqChannel > &cMap, QDaqChannel::SettingsType_t what)
 fill map with lg channel and corresponding QDaqChannels
int GetBoards (unsigned int crateId, std::map< unsigned int, std::string > &boards)
 fill boards map with slot and board name
int GetActiveChannels (unsigned int crateId, unsigned int slot, QDaqChannel::SettingsType_t what, std::vector< QDaqChannel > &v)
 Fill map containing given settins for active lg chnannels belonging to the given DAQ slot and DAQ crate.
void GetListOfTriggers (unsigned int lg, std::vector< std::string > &trgList)
 fill list of trigger names for the given channel
const QVdt & GetTrgParameter (unsigned int trgIndex, const std::string &par_name, unsigned int lg=0)
 Get parameter for given trigger index and given channel.
const std::map< std::string,
QVdt > & 
GetTrgParameters (unsigned int trgIndex, unsigned int lg)
 Get map of parameters for given trigger and logical channel.
bool Dump (unsigned int crateId, bool dump)
 dump settings and mapping for the given lg channel
unsigned int GetCurrentRunNumber () const
 return current run number
unsigned int GetCurrentProfile () const
 return profile associated to current run
QDbDetector::RunType GetCurrentRunType () const
 return current run type Id
unsigned int GetPulserPeriod ()
 get pulser period
void GetRunTypes (std::map< unsigned int, std::string > &runTypes)
 fill map of run type and corresponding description
void GetRuns (std::vector< int > &runs)
 get runs already present in db that refer to current detector
unsigned int GetLastRun ()
 get from db the run number with the most recent start date
void GetSettingsBaskets (int howMany, std::map< std::string, std::vector< QVdt > > &basketsMap)
 Fill map containing settings baskets present in db.
unsigned int GetSettingsBasketIds (std::vector< int > &baskets)
 fill vector containing settings basket id that are present in data base.
unsigned int GetSettingsBasket (unsigned int id, std::string &comment)
 get comment associated to given settings basket id
unsigned int GetDefaultSettingsBasket ()
 get default settings basket
bool GetStartDateOfRun (unsigned int runNumber, std::string &startDate)
 get start date of a given run number formatted as a string
bool BasketHasPulsers (unsigned int basket)
 check whether a given settings basket has any channel with pulser
void UpdateStart (unsigned int shifterSet)
 insert into data base start time for current run
void UpdateStop (StopStatus_t stopStatus, unsigned int shifterSet, unsigned int nFiles)
 insert into data base stop time for curent run
void InsertStartComments (const std::string &comment)
 insert start user comments into the user_infos table
void InsertStopComments (const std::string &comment)
 insert stop user comments into the user_infos table
void Clear ()
 reset internal variables and db cache
void Init ()
 global parameters initialization
void GuessCurrentRun ()
 guess current run number
void InsertNewRun ()
 insert a new entry ino the db RUNS table
void UndoInsertRun ()
 remove from runs table the entry corresponding to current run
void SanitizeRunsTable ()
 fill incomplete rows in runs table (needed in case of error in measurement stop)
bool LoadHardwareProfile (unsigned int crateId)
 Load hardware mapping for the given Daq crate.
void Load (QDaqChannel::SettingsType_t what)
 Load informations specified by 'what' for the whole system.
void Load (QDaqChannel::SettingsType_t what, unsigned int crateId)
 Load informations specified by 'what' for the given crate.
void LoadHwSettings (QDaqChannel::SettingsType_t setType, unsigned int crateId)
 Load hw settings specified by setType only for crateId.
void LoadTriggerSettings (unsigned int crateId)
 load trigger parameters for channels belonging to given crate
void LoadDefaultTriggerSettings ()
 load default trigger parameters (i.e. for lg_channel=0)
std::string EscapeString (const std::string &inputString, const char &toBeEscaped, const char &escapeChar) const
 escape requested charachter in a string
std::string CleanString (const std::string &inputString) const
 make string suitable for sql escape chars by calling EscapeString() method as many times as needed
bool GetPasswordHash (const std::string &user, std::string &hash)
 get password hash for the requested user name
QApolloUserLevel GetUserLevel (const std::string &user)
 get authentication level for requested user
void GetListOfUsers (std::set< std::string > &users, QApolloUserLevel minLevel, QApolloUserLevel maxLevel)
 get list of existing users with auth level between minLevel and maxLevel

Static Private Member Functions

static QApolloDbBaseGet ()
 get a reference to QApolloDbBase
static std::string GetDbEnv (EnvVarName_t name)

Private Attributes

unsigned int fProfile
 current profile
unsigned int fDaqSet
 current daq set
unsigned int fTrgSet
 current trigger set
unsigned int fFESet
 current frontend set
unsigned int fBesSet
 current bessel set
QDbDetector::RunType fRunType
 current run type
unsigned int fPulserSet
 current pulser set
std::map< unsigned int,
std::string > 
fActiveCrates
 map of active Daq crates and corresponding network address
std::map< unsigned int,
unsigned int > 
fActiveChannels
 map of active channels and corresponding Daq crate
std::vector< unsigned int > fLoadedHwCrates
 Daq crates for which Hardware mapping has been loaded from db.
std::vector< unsigned int > fLoadedTrgCrates
 Daq crates for which Trigger settings have been loaded from db.
std::vector< unsigned int > fLoadedDaqCrates
 Daq crates for which Daq settings have been loaded from db.
std::vector< unsigned int > fLoadedBesCrates
 Daq crates for which Bessel settings have been loaded from db.
std::vector< unsigned int > fLoadedFECrates
 Daq crates for which FrontEnd settings have been loaded from db.
std::vector< unsigned int > fLoadedPulserCrates
 Daq crates for which Pulser settings have been loaded from db.
QApolloDbCache fCache
 cached db informations
unsigned int fMode
 current DbMode
bool fRunningMode
 determine wether an incomplete run entry is present in db
const unsigned int fLowerRunExcluded
const unsigned int fUpperRunExcluded

Static Private Attributes

static bool gCanWrite = false
 Determine wether this instance of QApolloDbBase can write into db.
static unsigned int gRunNumber = 0
 current run number
static unsigned int gSettingsBasket = 0
 current settings basket

Friends

class QApolloDb
class QApolloDbServer
class QApolloDbGui
class QApolloDbDaq
class QApolloDbSlow


Member Enumeration Documentation

enum QApolloDbBase::DbMode_t [private]

Enumerator:
UndefMode_s  Initial status
MasterMode_s  Master mode: used by DaqServer
TuningMode_s  Tuning mode: within this mode settings can be changed at runtime
GuiMode_s  GUI mode: can only read and insert run comments
ReadMode_s  Read Only mode: used by Daq processes


Member Function Documentation

bool QApolloDbBase::Undefined (  )  const [inline, private]

determine if db status is undefined

Returns:
true if undefined

References fMode, and UndefMode_s.

bool QApolloDbBase::Reset ( unsigned int  settingsBasket,
unsigned int  runNumber 
) [private]

bool QApolloDbBase::Reset ( unsigned int  settingsBasket  )  [private]

reset db. DbMode is set to Tuning mode

Returns:
true on success

References fMode, fRunningMode, fRunType, gSettingsBasket, Init(), QDbDetector::RT_TEST, and TuningMode_s.

bool QApolloDbBase::Reset (  )  [private]

reset db. DbMode is set to GUI mode

Returns:
true on success

References fMode, GuiMode_s, and Init().

bool QApolloDbBase::ResetRun (  )  [private]

reset db. DbMode is set to Run mode

Returns:
true on success

References fRunningMode, and Init().

Referenced by QApolloDbSlow::ResetRun(), and QApolloDbGui::ResetRun().

int QApolloDbBase::GetListOfChannels ( std::vector< unsigned int > &  chList,
unsigned int  profileId = 0 
) [private]

get list of active channels corresponding to given profile

Parameters:
chList vector of active channels
profileId requested profileId. If it is zero, current profile Id is assumed or an error is returned in case DAQ is not running.
Returns:
number of channels in vector or -1 in case of error

References QDb::DoQuery(), fProfile, and gRunNumber.

Referenced by QApolloDb::GetListOfChannels().

unsigned int QApolloDbBase::GetMapping ( std::map< unsigned int, QDaqChannel > &  cMap  )  [private]

fill map with lg channel and corresponding hardware mapping

Parameters:
cMap map to be filled
Returns:
number of active channels

References fCache, QApolloDbCache::GetMapping(), Load(), and QDaqChannel::Mapping_s.

Referenced by QApolloDb::GetMapping().

unsigned int QApolloDbBase::GetActiveChannels ( std::map< unsigned int, QDaqChannel > &  cMap,
QDaqChannel::SettingsType_t  what 
) [private]

fill map with lg channel and corresponding QDaqChannels

Parameters:
what settings to be loaded
cMap map to be filled
Returns:
number of active channels

References fCache, QApolloDbCache::GetActiveChannels(), and Load().

Referenced by QApolloDb::GetActiveChannels().

int QApolloDbBase::GetBoards ( unsigned int  crateId,
std::map< unsigned int, std::string > &  boards 
) [private]

fill boards map with slot and board name

Parameters:
crateId identifier of DAQ crate for which board map is filled
boards map to be filled
Returns:
number of active boards in crateId

References fCache, QApolloDbCache::GetBoards(), and LoadHardwareProfile().

Referenced by QApolloDb::GetBoards().

int QApolloDbBase::GetActiveChannels ( unsigned int  crateId,
unsigned int  slot,
QDaqChannel::SettingsType_t  what,
std::vector< QDaqChannel > &  v 
) [private]

Fill map containing given settins for active lg chnannels belonging to the given DAQ slot and DAQ crate.

Parameters:
crateId identifier of DAQ crate for which channel map is filled
slot identifier of the DAQ slot for which channel map is filled (all slots belonging to crateId are filled if slot = 0)
what type of settings to be loaded. Multiple types can be loaded using the format Type1|Type2
v map to be filled
Returns:
number of channels loaded

References fCache, QApolloDbCache::GetActiveChannels(), and Load().

void QApolloDbBase::GetListOfTriggers ( unsigned int  lg,
std::vector< std::string > &  trgList 
) [private]

fill list of trigger names for the given channel

If no entry corresponding to the given lg channel is found in the db then the default trigger names (i.e. lg=0) are returned.

Parameters:
lg lg channel for which trigger names are returned. Default trigger names can be obtained asking for lg=0.
trgList vector containing trigger names. trigger name "NULL" means that no trigger is associated with that trigger tag for that lg

References fActiveChannels, fCache, QApolloDbCache::fChannels, fLoadedTrgCrates, QDaqChannel::fTrgName1, QDaqChannel::fTrgName2, QDaqChannel::fTrgName3, QDaqChannel::fTrgName4, and LoadTriggerSettings().

Referenced by QApolloDb::GetListOfTriggers().

const QVdt & QApolloDbBase::GetTrgParameter ( unsigned int  trgIndex,
const std::string &  par_name,
unsigned int  lg = 0 
) [private]

Get parameter for given trigger index and given channel.

Parameters:
par_name name of parameter to be returned
trgIndex trigger tag for which parameter is returned. Can be 1,2,3 or 4.
lg logical channel for which parameter is returned
Returns:
const reference to a QVdt containing requested trigger parameter

References fActiveChannels, fCache, QApolloDbCache::fChannels, fLoadedTrgCrates, QDaqChannel::fTrgName1, QDaqChannel::fTrgName2, QDaqChannel::fTrgName3, QDaqChannel::fTrgName4, QDaqChannel::fTrgSettings1, QDaqChannel::fTrgSettings2, QDaqChannel::fTrgSettings3, QDaqChannel::fTrgSettings4, and LoadTriggerSettings().

Referenced by QApolloDb::GetTrgParameter().

const std::map< std::string, QVdt > & QApolloDbBase::GetTrgParameters ( unsigned int  trgIndex,
unsigned int  lg 
) [private]

Get map of parameters for given trigger and logical channel.

Parameters:
trgIndex trigger tag for which parameter is returned.
lg logical channel for which parameter is returned
Returns:
const reference to a map containing requested trigger parameters

References fActiveChannels, fCache, QApolloDbCache::fChannels, fLoadedTrgCrates, QDaqChannel::fTrgSettings1, QDaqChannel::fTrgSettings2, QDaqChannel::fTrgSettings3, QDaqChannel::fTrgSettings4, and LoadTriggerSettings().

Referenced by QApolloDb::GetTrgParameters().

bool QApolloDbBase::Dump ( unsigned int  crateId,
bool  dump 
) [private]

dump settings and mapping for the given lg channel

Returns:
true if channel is not present in cache, true otherwise

References QApolloDbCache::Dump(), fCache, and fLoadedHwCrates.

Referenced by QApolloDb::Dump().

unsigned int QApolloDbBase::GetPulserPeriod (  )  [private]

get pulser period

Returns:
pulser period in ms or zero in case of error

References QDb::DoQueryInt(), and fPulserSet.

Referenced by QApolloDb::GetPulserPeriod().

void QApolloDbBase::GetRuns ( std::vector< int > &  runs  )  [private]

get runs already present in db that refer to current detector

Parameters:
runs filled with existing runs for this detector. Runs are sorted.

References QDb::DoQuery().

Referenced by QApolloDb::GetRuns().

unsigned int QApolloDbBase::GetLastRun (  )  [private]

get from db the run number with the most recent start date

Returns:
run number with the most recent start date, or zero if there are no runs at all in the database

References QDb::DoQuery(), and QError::SetDescription().

Referenced by QApolloDb::GetLastRun().

void QApolloDbBase::GetSettingsBaskets ( int  howMany,
std::map< std::string, std::vector< QVdt > > &  basketsMap 
) [private]

Fill map containing settings baskets present in db.

Parameters:
howMany number of entries to be loaded. All entries are loaded if howMany is zero
basketsMap Map to be filled. Map Keys are db column names; map values are QVdt vectors

References QDb::DoQuery().

Referenced by QApolloDb::GetSettingsBaskets().

unsigned int QApolloDbBase::GetSettingsBasketIds ( std::vector< int > &  baskets  )  [private]

fill vector containing settings basket id that are present in data base.

Parameters:
baskets vector that will be filled with existing setting basket id
Returns:
number of settings baskets found

References QDb::DoQuery(), and QError::SetDescription().

Referenced by QApolloDb::GetSettingsBasketIds().

unsigned int QApolloDbBase::GetSettingsBasket ( unsigned int  id,
std::string &  comment 
) [private]

get comment associated to given settings basket id

Parameters:
id settings basket id for which the comment is requested. If id is zero default settings basket is assumed
comment reference to a string that will be filled with the comment associated to the default settings basket
Returns:
requested settings basket id. In case default id was requested, real id is returned (not zero...)

References QDb::DoQueryString(), and GetDefaultSettingsBasket().

Referenced by QApolloDb::GetSettingsBasket().

unsigned int QApolloDbBase::GetDefaultSettingsBasket (  )  [private]

get default settings basket

Returns:
settings basket used in the last run on THIS_DETECTOR, or zero if THIS_DETECTOR has no previous runs

References QDb::DoQueryInt().

Referenced by QApolloDb::GetDefaultSettingsBasket(), and GetSettingsBasket().

bool QApolloDbBase::GetStartDateOfRun ( unsigned int  runNumber,
std::string &  startDate 
) [private]

get start date of a given run number formatted as a string

Parameters:
runNumber 
startDate filled with start date
Returns:
true unless requested run number does not exist

References QDb::DoQueryString().

Referenced by QApolloDb::GetStartDateOfRun().

void QApolloDbBase::InsertStartComments ( const std::string &  comment  )  [private]

insert start user comments into the user_infos table

Parameters:
comment user comment to be inserted

References CleanString(), QDb::DoQuery(), QDb::DoSQLNoReturn(), gRunNumber, and QError::SetDescription().

Referenced by QApolloDbServer::InsertStartComments().

void QApolloDbBase::InsertStopComments ( const std::string &  comment  )  [private]

insert stop user comments into the user_infos table

Parameters:
comment user comment to be inserted

References CleanString(), QDb::DoQueryInt(), and QDb::DoSQLNoReturn().

Referenced by QApolloDbServer::InsertStopComments().

void QApolloDbBase::GuessCurrentRun (  )  [private]

guess current run number

Guess current run number searching the db for a unique entry in the runs table that has neither start date nor stop date entry.

References QDb::DoQueryInt(), gRunNumber, and gSettingsBasket.

Referenced by Init().

void QApolloDbBase::UndoInsertRun (  )  [private]

remove from runs table the entry corresponding to current run

This method does not perform any check. It simply executes a DELETE statement on current run and only if measurement start_date is null. In particular it returns immediately if current run number is 0 (i.e. it is not set)

References QDb::DoExec(), fRunningMode, and gRunNumber.

Referenced by QApolloDbServer::UndoInsertRun().

std::string QApolloDbBase::EscapeString ( const std::string &  inputString,
const char &  toBeEscaped,
const char &  escapeChar 
) const [private]

escape requested charachter in a string

Parameters:
inputString string to be escaped
toBeEscaped charcter to be escaped
escapeChar escape character
Returns:
escaped string

Referenced by CleanString().

std::string QApolloDbBase::CleanString ( const std::string &  inputString  )  const [private]

make string suitable for sql escape chars by calling EscapeString() method as many times as needed

Parameters:
inputString string to be cleaned
Returns:
clean string

References EscapeString().

Referenced by InsertStartComments(), and InsertStopComments().

bool QApolloDbBase::GetPasswordHash ( const std::string &  user,
std::string &  hash 
) [private]

get password hash for the requested user name

Returns:
true unless the requested user name could not be found

References QDb::DoQueryString().

Referenced by QApolloDb::GetPasswordHash().

QApolloUserLevel QApolloDbBase::GetUserLevel ( const std::string &  user  )  [private]

get authentication level for requested user

Returns:
user level or InvalidLevel if user is not present in the database

References QDb::DoQueryInt(), InvalidLevel, NoPrivLevel, ReadLevel, SoftwareLevel, StartStopLevel, and SuperUserLevel.

Referenced by QApolloDb::GetUserLevel().


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

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