CMS 3D CMS Logo

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