CMS 3D CMS Logo

RevisionDML.cc
Go to the documentation of this file.
2 #include "RelationalAccess/ISchema.h"
3 #include "RelationalAccess/ITable.h"
4 #include "RelationalAccess/ITableDataEditor.h"
5 #include "RelationalAccess/IQuery.h"
6 #include "RelationalAccess/ICursor.h"
7 #include "RelationalAccess/SchemaException.h"
8 #include "CoralBase/AttributeList.h"
9 #include "CoralBase/Attribute.h"
10 #include "CoralBase/AttributeSpecification.h"
11 #include "CoralBase/TimeStamp.h"
15 #include <algorithm>
16 unsigned long long lumi::RevisionDML::getEntryInBranchByName(coral::ISchema& schema,
17  const std::string& datatableName,
18  const std::string& entryname,
19  const std::string& branchname) {
20  unsigned long long entry_id = 0;
21  coral::IQuery* qHandle = schema.newQuery();
22  qHandle->addToTableList(lumi::LumiNames::entryTableName(datatableName), "e");
23  qHandle->addToTableList(lumi::LumiNames::revisionTableName(), "r");
24  qHandle->addToOutputList("e.ENTRY_ID", "entry_id");
25 
26  coral::AttributeList qCondition;
27  qCondition.extend("entryname", typeid(std::string));
28  qCondition.extend("branchname", typeid(std::string));
29  qCondition["entryname"].data<std::string>() = entryname;
30  qCondition["branchname"].data<std::string>() = branchname;
31  std::string qConditionStr("r.REVISION_ID=e.REVISION_ID and e.NAME=:entryname AND r.BRANCH_NAME=:branchname");
32 
33  coral::AttributeList qResult;
34  qResult.extend("entry_id", typeid(unsigned long long));
35  qHandle->defineOutput(qResult);
36  qHandle->setCondition(qConditionStr, qCondition);
37  coral::ICursor& cursor = qHandle->execute();
38  while (cursor.next()) {
39  entry_id = cursor.currentRow()["entry_id"].data<unsigned long long>();
40  }
41  delete qHandle;
42  return entry_id;
43 }
44 void lumi::RevisionDML::bookNewEntry(coral::ISchema& schema,
45  const std::string& datatableName,
47  lumi::idDealer idg(schema);
48  const std::string entrytableName = lumi::LumiNames::entryTableName(datatableName);
50  entry.data_id = idg.generateNextIDForTable(datatableName);
51  entry.entry_id = idg.generateNextIDForTable(entrytableName);
52 }
53 void lumi::RevisionDML::bookNewRevision(coral::ISchema& schema,
54  const std::string& datatableName,
55  lumi::RevisionDML::Entry& revision) {
56  lumi::idDealer idg(schema);
58  revision.data_id = idg.generateNextIDForTable(datatableName);
59 }
60 void lumi::RevisionDML::addEntry(coral::ISchema& schema,
61  const std::string& datatableName,
63  unsigned long long branchid,
64  const std::string& branchname) {
65  coral::AttributeList revdata;
66  revdata.extend("REVISION_ID", typeid(unsigned long long));
67  revdata.extend("BRANCH_ID", typeid(unsigned long long));
68  revdata.extend("BRANCH_NAME", typeid(std::string));
69  revdata.extend("CTIME", typeid(coral::TimeStamp));
70  revdata["REVISION_ID"].data<unsigned long long>() = entry.revision_id;
71  revdata["BRANCH_ID"].data<unsigned long long>() = branchid;
72  revdata["BRANCH_NAME"].data<std::string>() = branchname;
73  revdata["CTIME"].data<coral::TimeStamp>() = coral::TimeStamp::now();
74  const std::string revTableName = lumi::LumiNames::revisionTableName();
75  schema.tableHandle(revTableName).dataEditor().insertRow(revdata);
76 
77  coral::AttributeList entrydata;
78  entrydata.extend("REVISION_ID", typeid(unsigned long long));
79  entrydata.extend("ENTRY_ID", typeid(unsigned long long));
80  entrydata.extend("NAME", typeid(std::string));
81  entrydata["REVISION_ID"].data<unsigned long long>() = entry.revision_id;
82  entrydata["ENTRY_ID"].data<unsigned long long>() = entry.entry_id;
83  entrydata["NAME"].data<std::string>() = entry.entry_name;
84  const std::string entryTableName = lumi::LumiNames::entryTableName(datatableName);
85  schema.tableHandle(entryTableName).dataEditor().insertRow(entrydata);
86 
87  coral::AttributeList revmapdata;
88  revmapdata.extend("REVISION_ID", typeid(unsigned long long));
89  revmapdata.extend("DATA_ID", typeid(unsigned long long));
90 
91  revmapdata["REVISION_ID"].data<unsigned long long>() = entry.revision_id;
92  revmapdata["DATA_ID"].data<unsigned long long>() = entry.data_id;
93 
94  const std::string revmapTableName = lumi::LumiNames::revmapTableName(datatableName);
95  schema.tableHandle(revmapTableName).dataEditor().insertRow(revmapdata);
96 }
97 void lumi::RevisionDML::addRevision(coral::ISchema& schema,
98  const std::string& datatableName,
99  const lumi::RevisionDML::Entry& revision,
100  unsigned long long branchid,
101  std::string& branchname) {
102  coral::AttributeList revdata;
103  revdata.extend("REVISION_ID", typeid(unsigned long long));
104  revdata.extend("BRANCH_ID", typeid(unsigned long long));
105  revdata.extend("BRANCH_NAME", typeid(std::string));
106  revdata.extend("CTIME", typeid(coral::TimeStamp));
107  revdata["REVISION_ID"].data<unsigned long long>() = revision.revision_id;
108  revdata["BRANCH_ID"].data<unsigned long long>() = branchid;
109  revdata["BRANCH_NAME"].data<std::string>() = branchname;
110  revdata["CTIME"].data<coral::TimeStamp>() = coral::TimeStamp::now();
111  schema.tableHandle(lumi::LumiNames::revisionTableName()).dataEditor().insertRow(revdata);
112  coral::AttributeList revmapdata;
113  revmapdata.extend("REVISION_ID", typeid(unsigned long long));
114  revmapdata.extend("DATA_ID", typeid(unsigned long long));
115  revmapdata["REVISION_ID"].data<unsigned long long>() = revision.revision_id;
116  revmapdata["DATA_ID"].data<unsigned long long>() = revision.data_id;
117  const std::string revmapTableName = lumi::LumiNames::revmapTableName(datatableName);
118  schema.tableHandle(revmapTableName).dataEditor().insertRow(revmapdata);
119 }
120 void lumi::RevisionDML::insertLumiRunData(coral::ISchema& schema, const lumi::RevisionDML::LumiEntry& lumientry) {
121  coral::AttributeList lumirundata;
122  lumirundata.extend("DATA_ID", typeid(unsigned long long));
123  lumirundata.extend("ENTRY_ID", typeid(unsigned long long));
124  lumirundata.extend("ENTRY_NAME", typeid(std::string));
125  lumirundata.extend("RUNNUM", typeid(unsigned int));
126  lumirundata.extend("SOURCE", typeid(std::string));
127  lumirundata.extend("NOMINALEGEV", typeid(float));
128  lumirundata.extend("NCOLLIDINGBUNCHES", typeid(unsigned int));
129  lumirundata["DATA_ID"].data<unsigned long long>() = lumientry.data_id;
130  lumirundata["ENTRY_ID"].data<unsigned long long>() = lumientry.entry_id;
131  lumirundata["ENTRY_NAME"].data<std::string>() = lumientry.entry_name;
132  lumirundata["RUNNUM"].data<unsigned int>() = lumientry.runnumber;
133  lumirundata["SOURCE"].data<std::string>() = lumientry.source;
134  lumirundata["NOMINALEGEV"].data<float>() = lumientry.bgev;
135  lumirundata["NCOLLIDINGBUNCHES"].data<unsigned int>() = lumientry.ncollidingbunches;
136  const std::string lumidataTableName = lumi::LumiNames::lumidataTableName();
137  schema.tableHandle(lumidataTableName).dataEditor().insertRow(lumirundata);
138 }
139 void lumi::RevisionDML::insertTrgRunData(coral::ISchema& schema, const lumi::RevisionDML::TrgEntry& trgentry) {
140  coral::AttributeList trgrundata;
141  trgrundata.extend("DATA_ID", typeid(unsigned long long));
142  trgrundata.extend("ENTRY_ID", typeid(unsigned long long));
143  trgrundata.extend("ENTRY_NAME", typeid(std::string));
144  trgrundata.extend("RUNNUM", typeid(unsigned int));
145  trgrundata.extend("SOURCE", typeid(std::string));
146  trgrundata.extend("BITZERONAME", typeid(std::string));
147  trgrundata.extend("BITNAMECLOB", typeid(std::string));
148  trgrundata["DATA_ID"].data<unsigned long long>() = trgentry.data_id;
149  trgrundata["ENTRY_ID"].data<unsigned long long>() = trgentry.entry_id;
150  trgrundata["ENTRY_NAME"].data<std::string>() = trgentry.entry_name;
151  trgrundata["RUNNUM"].data<unsigned int>() = trgentry.runnumber;
152  trgrundata["SOURCE"].data<std::string>() = trgentry.source;
153  trgrundata["BITZERONAME"].data<std::string>() = trgentry.bitzeroname;
154  trgrundata["BITNAMECLOB"].data<std::string>() = trgentry.bitnames;
155  const std::string trgdataTableName = lumi::LumiNames::trgdataTableName();
156  schema.tableHandle(trgdataTableName).dataEditor().insertRow(trgrundata);
157 }
158 void lumi::RevisionDML::insertHltRunData(coral::ISchema& schema, const lumi::RevisionDML::HltEntry& hltentry) {
159  coral::AttributeList hltrundata;
160  hltrundata.extend("DATA_ID", typeid(unsigned long long));
161  hltrundata.extend("ENTRY_ID", typeid(unsigned long long));
162  hltrundata.extend("ENTRY_NAME", typeid(std::string));
163  hltrundata.extend("RUNNUM", typeid(unsigned int));
164  hltrundata.extend("SOURCE", typeid(std::string));
165  hltrundata.extend("NPATH", typeid(unsigned int));
166  hltrundata.extend("PATHNAMECLOB", typeid(std::string));
167  hltrundata["DATA_ID"].data<unsigned long long>() = hltentry.data_id;
168  hltrundata["ENTRY_ID"].data<unsigned long long>() = hltentry.entry_id;
169  hltrundata["ENTRY_NAME"].data<std::string>() = hltentry.entry_name;
170  hltrundata["RUNNUM"].data<unsigned int>() = hltentry.runnumber;
171  hltrundata["SOURCE"].data<std::string>() = hltentry.source;
172  hltrundata["NPATH"].data<unsigned int>() = hltentry.npath;
173  hltrundata["PATHNAMECLOB"].data<std::string>() = hltentry.pathnames;
174  const std::string hltdataTableName = lumi::LumiNames::hltdataTableName();
175  schema.tableHandle(hltdataTableName).dataEditor().insertRow(hltrundata);
176 }
177 
178 unsigned long long lumi::RevisionDML::currentHFDataTagId(coral::ISchema& schema) {
179  unsigned long long currentdatatagid = 0;
180  std::vector<unsigned long long> alltagids;
181  coral::IQuery* qHandle = schema.newQuery();
182  qHandle->addToTableList(lumi::LumiNames::tagsTableName());
183  qHandle->addToOutputList("TAGID");
184  coral::AttributeList qResult;
185  qResult.extend("TAGID", typeid(unsigned long long));
186  qHandle->defineOutput(qResult);
187  coral::ICursor& cursor = qHandle->execute();
188  while (cursor.next()) {
189  if (!cursor.currentRow()["TAGID"].isNull()) {
190  alltagids.push_back(cursor.currentRow()["TAGID"].data<unsigned long long>());
191  }
192  }
193  delete qHandle;
194  if (!alltagids.empty()) {
195  std::vector<unsigned long long>::iterator currentdatatagidIt = std::max_element(alltagids.begin(), alltagids.end());
196  currentdatatagid = *currentdatatagidIt;
197  }
198  return currentdatatagid;
199 }
200 
201 unsigned long long lumi::RevisionDML::HFDataTagIdByName(coral::ISchema& schema, const std::string& datatagname) {
202  unsigned long long datatagid = 0;
203  coral::IQuery* qHandle = schema.newQuery();
204  qHandle->addToTableList(lumi::LumiNames::tagsTableName());
205  const std::string conditionStr("TAGNAME=:tagname");
206  coral::AttributeList condition;
207  condition.extend("tagname", typeid(std::string));
208  condition["tagname"].data<std::string>() = datatagname;
209  qHandle->addToOutputList("TAGID");
210  coral::AttributeList qResult;
211  qResult.extend("TAGID", typeid(unsigned long long));
212  qHandle->setCondition(conditionStr, condition);
213  qHandle->defineOutput(qResult);
214  coral::ICursor& cursor = qHandle->execute();
215  while (cursor.next()) {
216  if (!cursor.currentRow()["TAGID"].isNull()) {
217  datatagid = cursor.currentRow()["TAGID"].data<unsigned long long>();
218  }
219  }
220  delete qHandle;
221  return datatagid;
222 }
223 
224 unsigned long long lumi::RevisionDML::addRunToCurrentHFDataTag(coral::ISchema& schema,
225  unsigned int runnum,
226  unsigned long long lumiid,
227  unsigned long long trgid,
228  unsigned long long hltid,
229  const std::string& patchcomment) {
230  unsigned long long currenttagid = currentHFDataTagId(schema);
231  coral::AttributeList tagrundata;
232  tagrundata.extend("TAGID", typeid(unsigned long long));
233  tagrundata.extend("RUNNUM", typeid(unsigned int));
234  tagrundata.extend("LUMIDATAID", typeid(unsigned long long));
235  tagrundata.extend("TRGDATAID", typeid(unsigned long long));
236  tagrundata.extend("HLTDATAID", typeid(unsigned long long));
237  tagrundata.extend("CREATIONTIME", typeid(coral::TimeStamp));
238  tagrundata.extend("COMMENT", typeid(std::string));
239  tagrundata["TAGID"].data<unsigned long long>() = currenttagid;
240  tagrundata["RUNNUM"].data<unsigned int>() = runnum;
241  tagrundata["LUMIDATAID"].data<unsigned long long>() = lumiid;
242  tagrundata["TRGDATAID"].data<unsigned long long>() = trgid;
243  tagrundata["HLTDATAID"].data<unsigned long long>() = hltid;
244  tagrundata["CREATIONTIME"].data<coral::TimeStamp>() = coral::TimeStamp::now();
245  tagrundata["COMMENT"].data<std::string>() = patchcomment;
246  const std::string tagrunTableName = lumi::LumiNames::tagRunsTableName();
247  try {
248  schema.tableHandle(lumi::LumiNames::tagRunsTableName()).dataEditor().insertRow(tagrundata);
249  } catch (const coral::DuplicateEntryInUniqueKeyException& er) {
250  throw lumi::duplicateRunInDataTagException("", "addRunToCurrentHFDataTag", "RevisionDML");
251  }
252  return currenttagid;
253 }
254 
256  unsigned int runnum,
257  unsigned long long tagid) {
259  coral::IQuery* qHandle = schema.newQuery();
260  qHandle->addToTableList(lumi::LumiNames::tagRunsTableName());
261  qHandle->addToOutputList("LUMIDATAID");
262  qHandle->addToOutputList("TRGDATAID");
263  qHandle->addToOutputList("HLTDATAID");
264  coral::AttributeList qResult;
265  qResult.extend("LUMIDATAID", typeid(unsigned long long));
266  qResult.extend("TRGDATAID", typeid(unsigned long long));
267  qResult.extend("HLTDATAID", typeid(unsigned long long));
268  qHandle->defineOutput(qResult);
269  coral::AttributeList qCondition;
270  qCondition.extend("tagid", typeid(unsigned long long));
271  qCondition.extend("runnum", typeid(unsigned int));
272  qCondition["tagid"].data<unsigned long long>() = tagid;
273  qCondition["runnum"].data<unsigned int>() = runnum;
274  std::string qConditionStr("TAGID<=:tagid AND RUNNUM=:runnum");
275  qHandle->setCondition(qConditionStr, qCondition);
276  coral::ICursor& cursor = qHandle->execute();
277  unsigned long long minlumid = 0;
278  unsigned long long mintrgid = 0;
279  unsigned long long minhltid = 0;
280  while (cursor.next()) {
281  if (!cursor.currentRow()["LUMIDATAID"].isNull()) {
282  unsigned long long lumiid = cursor.currentRow()["LUMIDATAID"].data<unsigned long long>();
283  if (lumiid > minlumid) {
284  result.lumi_id = lumiid;
285  }
286  }
287  if (!cursor.currentRow()["TRGDATAID"].isNull()) {
288  unsigned long long trgid = cursor.currentRow()["TRGDATAID"].data<unsigned long long>();
289  if (trgid > mintrgid) {
290  result.trg_id = trgid;
291  }
292  }
293  if (!cursor.currentRow()["HLTDATAID"].isNull()) {
294  unsigned long long hltid = cursor.currentRow()["HLTDATAID"].data<unsigned long long>();
295  if (hltid > minhltid) {
296  result.hlt_id = hltid;
297  }
298  }
299  }
300  delete qHandle;
301  return result;
302 }
cond::lumiid
Definition: Time.h:19
lumi::LumiNames::revmapTableName
static const std::string revmapTableName(const std::string &datatablename)
Definition: LumiNames.cc:28
idDealer.h
lumi::LumiNames::tagRunsTableName
static const std::string tagRunsTableName()
Definition: LumiNames.cc:17
submitPVValidationJobs.now
now
Definition: submitPVValidationJobs.py:639
mps_splice.entry
entry
Definition: mps_splice.py:68
lumi::RevisionDML::Entry::revision_id
unsigned long long revision_id
Definition: RevisionDML.h:29
lumi::RevisionDML::addRunToCurrentHFDataTag
unsigned long long addRunToCurrentHFDataTag(coral::ISchema &schema, unsigned int runnum, unsigned long long lumiid, unsigned long long trgid, unsigned long long hltid, const std::string &patchcomment)
Definition: RevisionDML.cc:224
lumi::RevisionDML::TrgEntry::source
std::string source
Definition: RevisionDML.h:45
LumiNames.h
lumi::RevisionDML::LumiEntry::ncollidingbunches
unsigned int ncollidingbunches
Definition: RevisionDML.h:40
lumi::RevisionDML::Entry::entry_id
unsigned long long entry_id
Definition: RevisionDML.h:30
lumi::RevisionDML::addRevision
void addRevision(coral::ISchema &schema, const std::string &datatableName, const Entry &revision, unsigned long long branch_id, std::string &branchname)
Definition: RevisionDML.cc:97
RevisionDML.h
lumi::LumiNames::hltdataTableName
static const std::string hltdataTableName()
Definition: LumiNames.cc:15
lumi::RevisionDML::LumiEntry::source
std::string source
Definition: RevisionDML.h:37
lumi::RevisionDML::Entry::entry_name
std::string entry_name
Definition: RevisionDML.h:32
lumi::LumiNames::trgdataTableName
static const std::string trgdataTableName()
Definition: LumiNames.cc:11
lumi::LumiNames::entryTableName
static const std::string entryTableName(const std::string &datatablename)
Definition: LumiNames.cc:29
lumi::idDealer::generateNextIDForTable
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
Definition: idDealer.cc:33
lumi::LumiNames::tagsTableName
static const std::string tagsTableName()
Definition: LumiNames.cc:18
lumi::RevisionDML::TrgEntry::bitzeroname
std::string bitzeroname
Definition: RevisionDML.h:47
lumi::RevisionDML::DataID
Definition: RevisionDML.h:17
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
lumi::RevisionDML::Entry
Definition: RevisionDML.h:26
lumi::RevisionDML::TrgEntry::bitnames
std::string bitnames
Definition: RevisionDML.h:48
lumi::RevisionDML::HltEntry::npath
unsigned int npath
Definition: RevisionDML.h:55
lumi::RevisionDML::TrgEntry
Definition: RevisionDML.h:42
lumi::RevisionDML::HltEntry::source
std::string source
Definition: RevisionDML.h:53
lumi::LumiNames::revisionTableName
static const std::string revisionTableName()
Definition: LumiNames.cc:27
lumi::RevisionDML::HltEntry
Definition: RevisionDML.h:50
lumi::RevisionDML::bookNewRevision
void bookNewRevision(coral::ISchema &schema, const std::string &datatableName, Entry &revision)
Definition: RevisionDML.cc:53
lumi::RevisionDML::currentHFDataTagId
unsigned long long currentHFDataTagId(coral::ISchema &schema)
Definition: RevisionDML.cc:178
lumi::RevisionDML::bookNewEntry
void bookNewEntry(coral::ISchema &schema, const std::string &datatableName, Entry &entry)
Definition: RevisionDML.cc:44
lumi::RevisionDML::HFDataTagIdByName
unsigned long long HFDataTagIdByName(coral::ISchema &schema, const std::string &datatagname)
Definition: RevisionDML.cc:201
lumi::RevisionDML::LumiEntry::bgev
float bgev
Definition: RevisionDML.h:39
lumi::RevisionDML::dataIDForRun
DataID dataIDForRun(coral::ISchema &schema, unsigned int runnum, unsigned long long tagid)
Definition: RevisionDML.cc:255
lumi::RevisionDML::LumiEntry
Definition: RevisionDML.h:34
lumi::RevisionDML::insertTrgRunData
void insertTrgRunData(coral::ISchema &schema, const TrgEntry &trgentry)
Definition: RevisionDML.cc:139
lumi::RevisionDML::addEntry
void addEntry(coral::ISchema &schema, const std::string &datatableName, const Entry &entry, unsigned long long branch_id, const std::string &branchname)
Definition: RevisionDML.cc:60
Exception.h
lumi::RevisionDML::TrgEntry::runnumber
unsigned int runnumber
Definition: RevisionDML.h:46
lumi::RevisionDML::insertHltRunData
void insertHltRunData(coral::ISchema &schema, const HltEntry &hltentry)
Definition: RevisionDML.cc:158
mps_fire.result
result
Definition: mps_fire.py:311
lumi::RevisionDML::insertLumiRunData
void insertLumiRunData(coral::ISchema &schema, const LumiEntry &lumientry)
Definition: RevisionDML.cc:120
lumi::RevisionDML::HltEntry::pathnames
std::string pathnames
Definition: RevisionDML.h:56
lumi::idDealer
Definition: idDealer.h:8
lumi::LumiNames::lumidataTableName
static const std::string lumidataTableName()
Definition: LumiNames.cc:3
lumi::RevisionDML::HltEntry::runnumber
unsigned int runnumber
Definition: RevisionDML.h:54
lumi::RevisionDML::LumiEntry::runnumber
unsigned int runnumber
Definition: RevisionDML.h:38
lumi::duplicateRunInDataTagException
Definition: Exception.h:34
lumi::RevisionDML::Entry::data_id
unsigned long long data_id
Definition: RevisionDML.h:31
lumi::RevisionDML::getEntryInBranchByName
unsigned long long getEntryInBranchByName(coral::ISchema &schema, const std::string &datatableName, const std::string &entryname, const std::string &branchname)
Definition: RevisionDML.cc:16