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 QApolloDbBase & | Get () |
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 |
enum QApolloDbBase::DbMode_t [private] |
bool QApolloDbBase::Undefined | ( | ) | const [inline, private] |
bool QApolloDbBase::Reset | ( | unsigned int | settingsBasket, | |
unsigned int | runNumber | |||
) | [private] |
reset db. DbMode is set to Master mode
References fMode, fRunningMode, gCanWrite, gRunNumber, gSettingsBasket, Init(), and MasterMode_s.
Referenced by QApolloDbGui::QApolloDbGui(), QApolloDbServer::QApolloDbServer(), QApolloDbSlow::Reset(), QApolloDbServer::Reset(), and QApolloDb::Reset().
bool QApolloDbBase::Reset | ( | unsigned int | settingsBasket | ) | [private] |
reset db. DbMode is set to Tuning mode
References fMode, fRunningMode, fRunType, gSettingsBasket, Init(), QDbDetector::RT_TEST, and TuningMode_s.
bool QApolloDbBase::Reset | ( | ) | [private] |
bool QApolloDbBase::ResetRun | ( | ) | [private] |
reset db. DbMode is set to Run mode
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
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. |
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
cMap | map to be filled |
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
what | settings to be loaded | |
cMap | map to be filled |
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
crateId | identifier of DAQ crate for which board map is filled | |
boards | map to be filled |
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.
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 |
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.
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.
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 |
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.
trgIndex | trigger tag for which parameter is returned. | |
lg | logical channel for which parameter is returned |
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
References QApolloDbCache::Dump(), fCache, and fLoadedHwCrates.
Referenced by QApolloDb::Dump().
unsigned int QApolloDbBase::GetPulserPeriod | ( | ) | [private] |
get pulser period
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
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
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.
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.
baskets | vector that will be filled with existing setting basket id |
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
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 |
References QDb::DoQueryString(), and GetDefaultSettingsBasket().
Referenced by QApolloDb::GetSettingsBasket().
unsigned int QApolloDbBase::GetDefaultSettingsBasket | ( | ) | [private] |
get default settings basket
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
runNumber | ||
startDate | filled with start date |
References QDb::DoQueryString().
Referenced by QApolloDb::GetStartDateOfRun().
void QApolloDbBase::InsertStartComments | ( | const std::string & | comment | ) | [private] |
insert start user comments into the user_infos table
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
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
inputString | string to be escaped | |
toBeEscaped | charcter to be escaped | |
escapeChar | escape character |
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
inputString | string to be cleaned |
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
References QDb::DoQueryString().
Referenced by QApolloDb::GetPasswordHash().
QApolloUserLevel QApolloDbBase::GetUserLevel | ( | const std::string & | user | ) | [private] |
get authentication level for requested user
References QDb::DoQueryInt(), InvalidLevel, NoPrivLevel, ReadLevel, SoftwareLevel, StartStopLevel, and SuperUserLevel.
Referenced by QApolloDb::GetUserLevel().