Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow for run-type specific run ranges #98

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 9 additions & 38 deletions otsdaq-mu2e/RunInfoPlugins/DBRunInfo_runInfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ DBRunInfo::DBRunInfo(
}

//==============================================================================
DBRunInfo::~DBRunInfo(void) { ; }
DBRunInfo::~DBRunInfo(void) {
PQfinish(runInfoDbConn_);
}

//==============================================================================
void DBRunInfo::openDbConnection()
Expand Down Expand Up @@ -91,36 +93,21 @@ unsigned int DBRunInfo::insertRunCondition(const std::string& runInfoConditions)
"INSERT INTO %s.run_condition( \
condition \
, commit_time) \
VALUES ('%s',CURRENT_TIMESTAMP);",
VALUES ('%s',CURRENT_TIMESTAMP) \
RETURNING condition_id;",
dbSchema_,
condition.c_str());

res = PQexec(runInfoDbConn_, buffer);

if(PQresultStatus(res) != PGRES_COMMAND_OK)
if(PQresultStatus(res) != PGRES_TUPLES_OK)
{
__SS__ << "INSERT INTO 'run_condition' DATABASE TABLE FAILED!!! PQ ERROR: " << PQresultErrorMessage(res)
<< __E__;
PQclear(res);
__SS_THROW__;
}

PQclear(res);

snprintf(buffer,
sizeof(buffer),
"select max(condition_id) from %s.run_condition;",
dbSchema_);

res = PQexec(runInfoDbConn_, buffer);

if(PQresultStatus(res) != PGRES_TUPLES_OK)
{
__SS__ << "SELECT FROM 'run_condition' DATABASE TABLE FAILED!!! PQ ERROR: " << PQresultErrorMessage(res) << __E__;
PQclear(res);
__SS_THROW__;
}

if(PQntuples(res) == 1)
{
conditionID = atoi(PQgetvalue(res, 0, 0));
Expand Down Expand Up @@ -235,7 +222,8 @@ unsigned int DBRunInfo::claimNextRunNumber(unsigned int conditionID, const std::
, context_name \
, context_version \
, commit_time) \
VALUES ('%s','%d','%d','%s','%s','%s','%s','%s',CURRENT_TIMESTAMP);",
VALUES ('%s','%d','%d','%s','%s','%s','%s','%s',CURRENT_TIMESTAMP) \
RETURNING run_number;",
dbSchema_,
runType,
conditionID,
Expand All @@ -248,30 +236,14 @@ unsigned int DBRunInfo::claimNextRunNumber(unsigned int conditionID, const std::

res = PQexec(runInfoDbConn_, buffer);

if(PQresultStatus(res) != PGRES_COMMAND_OK)
if(PQresultStatus(res) != PGRES_TUPLES_OK)
{
__SS__ << "INSERT INTO 'run_configuration' DATABASE TABLE FAILED!!! PQ ERROR: " << PQresultErrorMessage(res)
<< __E__;
PQclear(res);
__SS_THROW__;
}

PQclear(res);

snprintf(buffer,
sizeof(buffer),
"select max(run_number) from %s.run_configuration;",
dbSchema_);

res = PQexec(runInfoDbConn_, buffer);

if(PQresultStatus(res) != PGRES_TUPLES_OK)
{
__SS__ << "SELECT FROM 'run_configuration' DATABASE TABLE FAILED!!! PQ ERROR: " << PQresultErrorMessage(res) << __E__;
PQclear(res);
__SS_THROW__;
}

if(PQntuples(res) == 1)
{
runNumber = atoi(PQgetvalue(res, 0, 0));
Expand Down Expand Up @@ -414,5 +386,4 @@ void DBRunInfo::updateRunInfo(unsigned int runNumber, RunInfoVInterface::RunStop

} //end updateRunInfo()


DEFINE_OTS_PROCESSOR(DBRunInfo)