10 #define EXPAND_QWPARITYSSQLS_STATICS
20 using namespace QwParitySSQLS;
23 template void QwDBInterface::AddThisEntryToList<QwParitySSQLS::md_data>(std::vector<QwParitySSQLS::md_data> &list);
24 template void QwDBInterface::AddThisEntryToList<QwParitySSQLS::lumi_data>(std::vector<QwParitySSQLS::lumi_data> &list);
25 template void QwDBInterface::AddThisEntryToList<QwParitySSQLS::beam>(std::vector<QwParitySSQLS::beam> &list);
37 void operator() (QwParitySSQLS::monitor elem) {
38 QwDebug <<
"StoreMonitorID: monitor_id = " << elem.monitor_id <<
" quantity = " << elem.quantity <<
QwLog::endl;
45 void operator() (QwParitySSQLS::main_detector elem) {
46 QwDebug <<
"StoreMainDetectorID: main_detector_id = " << elem.main_detector_id <<
" quantity = " << elem.quantity <<
QwLog::endl;
53 void operator() (QwParitySSQLS::lumi_detector elem) {
54 QwDebug <<
"StoreLumiDetectorID: lumi_detector_id = " << elem.lumi_detector_id <<
" quantity = " << elem.quantity <<
QwLog::endl;
61 void operator() (QwParitySSQLS::measurement_type elem) {
62 QwDebug <<
"StoreMeasurementID: measurement_type = " << elem.measurement_type_id <<
QwLog::endl;
70 void operator() (QwParitySSQLS::sc_detector elem) {
71 QwDebug <<
"StoreSlowControlDetectorID: sc_detector_id = " << elem.sc_detector_id <<
" name = " << elem.name <<
QwLog::endl;
78 void operator() (QwParitySSQLS::error_code elem) {
79 QwDebug <<
"StoreErrorCodeID: error_code_id = " << elem.error_code_id <<
" quantity = " << elem.quantity <<
QwLog::endl;
128 QwDebug <<
"QwParityDB::~QwParityDB() : Good-bye World from QwParityDB destructor!" <<
QwLog::endl;
139 UInt_t run_id = this->
GetRunID(qwevt);
167 mysqlpp::Query query= this->
Query();
168 query <<
"SELECT * FROM run WHERE run_number = " << runnum;
169 std::vector<run> res;
175 QwError <<
"Unable to find unique run number " << runnum <<
" in database." <<
QwLog::endl;
177 QwError <<
"Please make sure that the database contains one unique entry for this run." <<
QwLog::endl;
184 fRunID = res.at(0).run_id;
188 catch (
const mysqlpp::Exception& er) {
207 mysqlpp::Query query = this->
Query();
209 query <<
"SELECT * FROM run WHERE run_number = " << qwevt.
GetRunNumber();
210 std::vector<run> res;
212 QwDebug <<
"QwParityDB::SetRunID => Number of rows returned: " << res.size() <<
QwLog::endl;
219 QwError <<
"Please make sure that the database contains one unique entry for this run." <<
QwLog::endl;
230 fRunID = res.at(0).run_id;
236 catch (
const mysqlpp::Exception& er)
252 row.run_type =
"good";
259 row.wien_slug = 9999;
260 row.injector_slug = 9999;
264 mysqlpp::Query query=this->
Query();
266 QwDebug<<
"QwParityDB::SetRunID() => Run Insert Query = " << query.str() <<
QwLog::endl;
270 if (query.insert_id()!=0)
273 fRunID = query.insert_id();
278 catch (
const mysqlpp::Exception& er)
323 mysqlpp::Query query = this->
Query();
328 query <<
"SELECT * FROM runlet WHERE run_id = " <<
fRunID <<
" AND full_run = 'false' AND segment_number = " <<
fSegmentNumber;
330 query <<
"SELECT * FROM runlet WHERE run_id = " <<
fRunID <<
" AND full_run = 'true'";
333 std::vector<runlet> res;
335 QwDebug <<
"QwParityDB::SetRunletID => Number of rows returned: " << res.size() <<
QwLog::endl;
342 QwError <<
"Please make sure that the database contains one unique entry for this run." <<
QwLog::endl;
350 QwDebug <<
"QwParityDB::SetRunletID => Runlet ID = " << res.at(0).runlet_id <<
QwLog::endl;
358 catch (
const mysqlpp::Exception& er)
375 row.start_time = mysqlpp::null;
376 row.end_time = mysqlpp::null;
381 row.full_run =
"false";
383 row.segment_number = mysqlpp::null;
384 row.full_run =
"true";
387 mysqlpp::Query query=this->
Query();
389 QwDebug<<
"QwParityDB::SetRunletID() => Run Insert Query = " << query.str() <<
QwLog::endl;
393 if (query.insert_id()!=0)
400 catch (
const mysqlpp::Exception& er)
436 mysqlpp::Query query= this->
Query();
437 query <<
"SELECT analysis_id FROM analysis WHERE beam_mode=" << mysqlpp::quote <<
"nbm";
438 query <<
" AND slope_calculation=" << mysqlpp::quote <<
"off";
439 query <<
" AND slope_correction=" << mysqlpp::quote <<
"off";
440 query <<
" AND runlet_id = " << mysqlpp::quote << this->
GetRunletID(qwevt);
442 mysqlpp::StoreQueryResult res = query.store();
444 if (res.num_rows() != 0) {
446 QwError <<
"The following analysis_id values already exist in the database: ";
447 for (
size_t i=0; i<res.num_rows(); i++) {
457 QwWarning <<
"Analysis will continue. A duplicate entry with new analysis_id will be added to the analysis table." <<
QwLog::endl;
463 catch (
const mysqlpp::Exception& er) {
465 QwError <<
"Unable to determine if there are other database entries for this run. Exiting." <<
QwLog::endl;
473 analysis analysis_row(0);
476 analysis_row.seed_id = 1;
478 std::pair<UInt_t, UInt_t> event_range;
481 analysis_row.time = mysqlpp::DateTime::now();
482 analysis_row.bf_checksum =
"empty";
483 analysis_row.beam_mode =
"nbm";
484 analysis_row.n_mps = 0;
485 analysis_row.n_qrt = 4;
486 analysis_row.first_event = event_range.first;
487 analysis_row.last_event = event_range.second;
488 analysis_row.segment = 0;
489 analysis_row.slope_calculation =
"off";
490 analysis_row.slope_correction =
"off";
499 run_condition.
Get()->Print();
501 TIter next(run_condition.Get());
503 TString str_val, str_var;
507 while ((obj_str = (TObjString *) next())) {
511 str_var = str_val = obj_str->GetString();
512 location = str_val.First(
":");
513 location = location + 2;
514 str_val.Remove(0,location);
517 if (str_var.BeginsWith(
"ROOT Version")) {
518 analysis_row.root_version = str_val;
519 }
else if (str_var.BeginsWith(
"ROOT file creating time")) {
520 analysis_row.root_file_time = str_val;
521 }
else if (str_var.BeginsWith(
"ROOT file created on Hostname")) {
522 analysis_row.root_file_host = str_val;
523 }
else if (str_var.BeginsWith(
"ROOT file created by the user")) {
524 analysis_row.root_file_user = str_val;
525 }
else if (str_var.BeginsWith(
"QwAnalyzer Name")) {
526 analysis_row.analyzer_name = str_val;
527 }
else if (str_var.BeginsWith(
"QwAnalyzer Options")) {
528 analysis_row.analyzer_argv = str_val;
529 }
else if (str_var.BeginsWith(
"QwAnalyzer SVN Revision")) {
530 analysis_row.analyzer_svn_rev = str_val;
531 }
else if (str_var.BeginsWith(
"QwAnalyzer SVN Last Changed Revision")) {
532 analysis_row.analyzer_svn_lc_rev = str_val;
533 }
else if (str_var.BeginsWith(
"QwAnalyzer SVN URL")) {
534 analysis_row.analyzer_svn_url = str_val;
535 }
else if (str_var.BeginsWith(
"DAQ ROC flags when QwAnalyzer runs")) {
536 analysis_row.roc_flags = str_val;
541 mysqlpp::Query query= this->
Query();
542 query.insert(analysis_row);
546 if (query.insert_id()!=0)
554 catch (
const mysqlpp::Exception& er) {
567 mysqlpp::Query query = this->
Query();
568 parameter_files parameter_file_row(0);
571 param_file_list->Print();
572 TIter next(param_file_list);
574 while ((pfl_elem = (TList *) next())) {
575 parameter_file_row.filename = pfl_elem->GetName();
576 query.insert(parameter_file_row);
582 delete param_file_list;
584 catch (
const mysqlpp::Exception& er) {
587 delete param_file_list;
598 QwDebug <<
"QwParityDB::GetAnalysisID() : fRunletID must be set before proceeding. Check to make sure run exists in database." <<
QwLog::endl;
606 QwError <<
"QwParityDB::SetAnalysisID() unable to set valid fAnalysisID for this run. Exiting." <<
QwLog::endl;
626 if (zero_id_is_error && monitor_id==0) {
628 QwError <<
"QwParityDB::GetMonitorID() => Unable to determine valid ID for beam monitor " << name <<
QwLog::endl;
643 mysqlpp::Query query=this->
Query();
650 catch (
const mysqlpp::Exception& er) {
669 if (zero_id_is_error && main_detector_id==0) {
671 QwError <<
"QwParityDB::GetMainDetectorID() => Unable to determine valid ID for beam main_detector " << name <<
QwLog::endl;
674 return main_detector_id;
687 mysqlpp::Query query=this->
Query();
694 catch (
const mysqlpp::Exception& er) {
714 if (sc_detector_id==0) {
715 QwError <<
"QwParityDB::GetSlowControlDetectorID() => Unable to determine valid ID for the epics variable " << name <<
QwLog::endl;
718 return sc_detector_id;
733 if (error_code_id==0) {
734 QwError <<
"QwParityDB::GetErrorCodeID() => Unable to determine valid ID for the error code " << name <<
QwLog::endl;
737 return error_code_id;
749 mysqlpp::Query query=this->
Query();
756 catch (
const mysqlpp::Exception& er) {
772 mysqlpp::Query query=this->
Query();
779 catch (
const mysqlpp::Exception& er) {
798 if (zero_id_is_error && lumi_detector_id==0) {
799 QwError <<
"QwParityDB::GetLumiDetectorID() => Unable to determine valid ID for beam lumi_detector " << name <<
QwLog::endl;
802 return lumi_detector_id;
814 mysqlpp::Query query=this->
Query();
822 catch (
const mysqlpp::Exception& er) {
841 if (measurement_type.empty()) {
842 QwError <<
"QwParityDB::GetMeasurementID() => Unable to determine valid ID for measurement type with " << index <<
QwLog::endl;
845 return measurement_type;
854 mysqlpp::Query query=this->
Query();
862 catch (
const mysqlpp::Exception& er) {
880 options.
AddOptions(
"Parity Analyzer Database options")
881 (
"QwParityDB.disable-analysis-check",
883 "disable check of pre-existing analysis_id");
893 if (options.
GetValue<
bool>(
"QwParityDB.disable-analysis-check"))
#define QwMessage
Predefined log drain for regular messages.
UInt_t GetErrorCodeID(const string &name)
QwParityDB()
Simple constructor.
UInt_t fRunletID
runlet_id of current run
UInt_t GetMonitorID(const string &name, Bool_t zero_id_is_error=kTRUE)
friend class StoreSlowControlDetectorID
Int_t fSegmentNumber
CODA file segment number of current run.
#define default_bool_value(b)
void StoreMainDetectorIDs()
UInt_t SetRunID(QwEventBuffer &qwevt)
Int_t GetSegmentNumber() const
Return CODA file segment number.
UInt_t GetMainDetectorID(const string &name, Bool_t zero_id_is_error=kTRUE)
const string GetMeasurementID(const Int_t index)
Bool_t Connect()
Open a connection to the database using the predefined parameters.
bool fDisableAnalysisCheck
Flag to disable pre-existing analysis_id check.
static std::vector< string > fMeasurementIDs
Bool_t SetRunNumber(const UInt_t runnum)
TList * GetParamFileNameList(TString name) const
Get list of parameter files.
UInt_t SetAnalysisID(QwEventBuffer &qwevt)
A database interface class.
UInt_t fRunID
run_id of current run
UInt_t GetLumiDetectorID(const string &name, Bool_t zero_id_is_error=kTRUE)
static std::map< string, unsigned int > fSlowControlDetectorIDs
Associative array of slow controls data IDs. This declaration will be a problem if QwDatabase is used...
static std::map< string, unsigned int > fLumiDetectorIDs
Associative array of LUMI detector IDs. This declaration will be a problem if QwDatabase is used to c...
UInt_t SetRunletID(QwEventBuffer &qwevt)
char ** GetArgv()
Get the vector of command line arguments.
friend class StoreMainDetectorID
po::options_description_easy_init AddOptions(const std::string &blockname="Specialized options")
Add an option to a named block or create new block.
std::pair< UInt_t, UInt_t > GetEventRange() const
T GetValue(const std::string &key)
Get a templated value.
Virtual base class for the parity subsystems.
#define QwDebug
Predefined log drain for debugging output.
static void DefineAdditionalOptions(QwOptions &options)
Defines QwParityDB-specific class options for QwOptions.
friend class StoreMeasurementID
Bool_t AllowsReadAccess()
UInt_t fAnalysisID
analysis_id of current analysis pass
void StoreLumiDetectorIDs()
void StoreSlowControlDetectorIDs()
mysqlpp::Query Query(const char *qstr=0)
Int_t GetRunNumber() const
Return CODA file run number.
friend class StoreErrorCodeID
friend class StoreLumiDetectorID
int GetArgc()
Get the number of command line arguments.
void FillParameterFiles(QwSubsystemArrayParity &subsys)
void SetupOneRun(QwEventBuffer &qwevt)
A color changing class for the output stream.
time_t GetStartUnixTime()
static std::ostream & endl(std::ostream &)
End of the line.
void StoreMeasurementIDs()
virtual ~QwParityDB()
Destructor.
static std::map< string, unsigned char > fErrorCodeIDs
Associative array of error code IDs. This declaration will be a problem if QwDatabase is used to conn...
UInt_t fRunNumber
Run number of current run.
static std::map< string, unsigned int > fMonitorIDs
Associative array of beam monitor IDs. This declaration will be a problem if QwDatabase is used to co...
#define QwWarning
Predefined log drain for warnings.
Bool_t AreRunletsSplit() const
Return true if file segments are being separated for.
UInt_t GetSlowControlDetectorID(const string &name)
friend class StoreMonitorID
void ProcessAdditionalOptions(QwOptions &options)
Processes the options contained in the QwOptions object.
static std::map< string, unsigned int > fMainDetectorIDs
Associative array of main detector IDs. This declaration will be a problem if QwDatabase is used to c...
#define QwError
Predefined log drain for errors.