Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions DbService/data/create.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ GRANT UPDATE ON val.tables_tid_seq TO manager_role;
CREATE TABLE val.calibrations
(cid SERIAL,
tid INTEGER NOT NULL,
chash TEXT NOT NULL DEFAULT '',
create_time TIMESTAMP WITH TIME ZONE NOT NULL,
create_user TEXT NOT NULL,
CONSTRAINT calibrations_pk PRIMARY KEY (cid),
Expand Down
13 changes: 7 additions & 6 deletions DbService/inc/DbTool.hh
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class DbTool {
int printAdhoc();

std::string getResult() { return _result; }
void clearResult() { _result.clear(); }
int printCIDLine(int cid, int indent = 0);
int printIOVLine(int iov, int details = 0, int indent = 0);
int printGIDLine(int gid, int details = 0, int indent = 0);
Expand All @@ -86,6 +87,12 @@ class DbTool {
int commitPatch();
int verifySet();

// when committing several items, sometime the later items depend
// on fnding the earlier items in the cached val structure
// this is a way to refresh the val structure after the earlier commits
// Take caution with local caching of val info..
int refresh();

int testUrl();

private:
Expand Down Expand Up @@ -135,12 +142,6 @@ class DbTool {
// extend because it does not zero eset
int extendEiovMap(int gid, eiovMap& eset, int& minrun, int& maxrun);

// when committing several items, sometime the later items depend
// on fnding the earlier items in the cached val structure
// this is a way to refresh the val structure after the earlier commits
// Take caution with local caching of val info..
int refresh();

int _verbose;
bool _pretty;
std::string _database;
Expand Down
25 changes: 19 additions & 6 deletions DbService/src/DbTool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,13 @@ int mu2e::DbTool::printCalibration() {
args["user"] = "";
args["cid"] = "";
args["ctime"] = "";
args["hash"] = "";
if ((rc = getArgs(args))) return rc;
std::string name = args["name"];
std::string user = args["user"];
std::vector<int> cids = intList(args["cid"]);
timeInterval tint = parseInterval(args["ctime"]);
std::string chash = args["hash"];

// if this is a val table, just exit - there is no summary line
if (name.substr(0, 3) == "Val") {
Expand Down Expand Up @@ -202,7 +204,9 @@ int mu2e::DbTool::printCalibration() {
if (tid < 0 || cc.tid() == tid) {
if (user.empty() || user == cc.create_user()) {
if (tint.start == 0 || inTime(tint, cc.create_time())) {
cids.push_back(cc.cid());
if (chash.empty() || chash == cc.chash() ) {
cids.push_back(cc.cid());
}
}
}
}
Expand Down Expand Up @@ -764,9 +768,9 @@ int mu2e::DbTool::printCIDLine(int cid, int indent) {
auto name = tids.row(cr.tid()).name();

std::stringstream ss;
ss << "CID " << std::setw(5 + 4 * std::max(indent, 0)) << cid << std::setw(20)
<< name << std::setw(12) << cr.create_user() << std::setw(35)
<< cr.create_time() << std::endl;
ss << "CID " << std::setw(5 + 4 * std::max(indent, 0)) << cid << std::setw(22)
<< name << std::setw(12) << cr.create_user()
<< std::setw(35) << cr.create_time() << std::endl;
_result.append(ss.str());

return 0;
Expand Down Expand Up @@ -1037,13 +1041,21 @@ int mu2e::DbTool::commitCalibrationList(DbTableCollection& coll, bool qai,

liveTable.setTid(tid);

if (ptr->hash().empty()) {
std::cout
<< "DbTool::commitCalibrationList found empty hash summary for table named "
<< liveTable.table().name() << std::endl;
return 1;
}

command = "SET ROLE val_role;";
rc = _sql.execute(command, result);
if (rc != 0) return rc;

command =
"INSERT INTO val.calibrations (tid,create_time,create_user) VALUES (" +
std::to_string(tid) + ",CURRENT_TIMESTAMP,SESSION_USER) RETURNING cid;";
"INSERT INTO val.calibrations (tid,chash,create_time,create_user) VALUES (" +
std::to_string(tid) + ",'" + ptr->hash() +
"',CURRENT_TIMESTAMP,SESSION_USER) RETURNING cid;";
rc = _sql.execute(command, result);
if (rc != 0) return rc;

Expand Down Expand Up @@ -2747,6 +2759,7 @@ int mu2e::DbTool::help() {
" [OPTIONS]\n"
" --name NAME : name of the table\n"
" --user USERNAME : only print tables committed by this user \n"
" --hash HASH : only print table with this content hash \n"
" --ctime TIME/TIME : only print contents created in this "
"interval \n"
" --cid INT or INT LIST : only print this cid \n"
Expand Down
11 changes: 7 additions & 4 deletions DbTables/inc/ValCalibrations.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,27 @@ class ValCalibrations : public DbTable {
public:
class Row {
public:
Row(int cid, int tid, std::string create_time, std::string create_user) :
_cid(cid), _tid(tid), _create_time(create_time),
Row(int cid, int tid, std::string chash, std::string create_time, std::string create_user) :
_cid(cid), _tid(tid), _chash(chash), _create_time(create_time),
_create_user(create_user) {}
int tid() const { return _tid; }
int cid() const { return _cid; }
std::string const& chash() const { return _chash; }
std::string const& create_time() const { return _create_time; }
std::string const& create_user() const { return _create_user; }

private:
int _cid;
int _tid;
std::string _chash;
std::string _create_time;
std::string _create_user;
};

constexpr static const char* cxname = "ValCalibrations";

ValCalibrations() :
DbTable(cxname, "val.calibrations", "cid,tid,create_time,create_user") {}
DbTable(cxname, "val.calibrations", "cid,tid,chash,create_time,create_user") {}

const Row& rowAt(const std::size_t index) const { return _rows.at(index); }
const Row& row(const int cid) const { return _rows.at(_index.at(cid)); }
Expand All @@ -44,14 +46,15 @@ class ValCalibrations : public DbTable {

void addRow(const std::vector<std::string>& columns) override {
_rows.emplace_back(std::stoi(columns[0]), std::stoi(columns[1]), columns[2],
columns[3]);
columns[3],columns[4]);
_index[_rows.back().cid()] = _rows.size() - 1;
}

void rowToCsv(std::ostringstream& sstream, std::size_t irow) const override {
Row const& r = _rows.at(irow);
sstream << r.cid() << ",";
sstream << r.tid() << ",";
sstream << r.chash() << ",";
sstream << r.create_time() << ",";
sstream << r.create_user();
}
Expand Down