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"
21 unsigned long long entry_id=0;
22 coral::IQuery* qHandle=schema.newQuery();
25 qHandle->addToOutputList(
"e.ENTRY_ID",
"entry_id");
27 coral::AttributeList qCondition;
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");
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();
40 entry_id=cursor.currentRow()[
"entry_id"].data<
unsigned long long>();
67 unsigned long long branchid,
69 coral::AttributeList revdata;
70 revdata.extend(
"REVISION_ID",
typeid(
unsigned long long));
71 revdata.extend(
"BRANCH_ID",
typeid(
unsigned long long));
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;
79 schema.tableHandle(revTableName).dataEditor().insertRow(revdata);
81 coral::AttributeList entrydata;
82 entrydata.extend(
"REVISION_ID",
typeid(
unsigned long long));
83 entrydata.extend(
"ENTRY_ID",
typeid(
unsigned long long));
85 entrydata[
"REVISION_ID"].data<
unsigned long long>()=entry.
revision_id;
86 entrydata[
"ENTRY_ID"].data<
unsigned long long>()=entry.
entry_id;
89 schema.tableHandle(
entryTableName).dataEditor().insertRow(entrydata);
91 coral::AttributeList revmapdata;
92 revmapdata.extend(
"REVISION_ID",
typeid(
unsigned long long));
93 revmapdata.extend(
"DATA_ID",
typeid(
unsigned long long));
95 revmapdata[
"REVISION_ID"].data<
unsigned long long>()=entry.
revision_id;
96 revmapdata[
"DATA_ID"].data<
unsigned long long>()=entry.
data_id;
99 schema.tableHandle(revmapTableName).dataEditor().insertRow(revmapdata);
105 unsigned long long branchid,
107 coral::AttributeList revdata;
108 revdata.extend(
"REVISION_ID",
typeid(
unsigned long long));
109 revdata.extend(
"BRANCH_ID",
typeid(
unsigned long long));
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;
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);
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));
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;
139 lumirundata[
"RUNNUM"].data<
unsigned int>()=lumientry.
runnumber;
141 lumirundata[
"NOMINALEGEV"].data<
float>()=lumientry.
bgev;
142 lumirundata[
"NCOLLIDINGBUNCHES"].data<
unsigned int>()=lumientry.
ncollidingbunches;
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));
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;
160 trgrundata[
"RUNNUM"].data<
unsigned int>()=trgentry.
runnumber;
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));
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;
181 hltrundata[
"RUNNUM"].data<
unsigned int>()=hltentry.
runnumber;
183 hltrundata[
"NPATH"].data<
unsigned int>()=hltentry.
npath;
191 unsigned long long currentdatatagid=0;
192 std::vector<unsigned long long> alltagids;
193 coral::IQuery* qHandle=schema.newQuery();
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>());
206 if(alltagids.size()>0){
207 std::vector<unsigned long long>::iterator currentdatatagidIt=std::max_element(alltagids.begin(),alltagids.end());
208 currentdatatagid=*currentdatatagidIt;
210 return currentdatatagid;
217 coral::IQuery* qHandle=schema.newQuery();
219 const std::string conditionStr(
"TAGNAME=:tagname");
220 coral::AttributeList condition;
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>();
241 unsigned long long lumiid,
242 unsigned long long trgid,
243 unsigned long long hltid,
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));
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;
261 tagrundata[
"COMMENT"].data<
std::string>()=patchcomment;
265 }
catch(
const coral::DuplicateEntryInUniqueKeyException& er){
274 unsigned long long tagid){
276 coral::IQuery* qHandle=schema.newQuery();
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>();
305 if(!cursor.currentRow()[
"TRGDATAID"].isNull()){
306 unsigned long long trgid=cursor.currentRow()[
"TRGDATAID"].data<
unsigned long long>();
311 if(!cursor.currentRow()[
"HLTDATAID"].isNull()){
312 unsigned long long hltid=cursor.currentRow()[
"HLTDATAID"].data<
unsigned long long>();
static const std::string trgdataTableName()
void addEntry(coral::ISchema &schema, const std::string &datatableName, const Entry &entry, unsigned long long branch_id, const std::string &branchname)
unsigned long long hlt_id
DataID dataIDForRun(coral::ISchema &schema, unsigned int runnum, unsigned long long tagid)
static const std::string hltdataTableName()
void insertLumiRunData(coral::ISchema &schema, const LumiEntry &lumientry)
unsigned long long data_id
static const std::string tagRunsTableName()
static const std::string revmapTableName(const std::string &datatablename)
unsigned long long getEntryInBranchByName(coral::ISchema &schema, const std::string &datatableName, const std::string &entryname, const std::string &branchname)
static const std::string entryTableName(const std::string &datatablename)
static const std::string tagsTableName()
unsigned long long HFDataTagIdByName(coral::ISchema &schema, const std::string &datatagname)
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)
unsigned long long revision_id
void insertTrgRunData(coral::ISchema &schema, const TrgEntry &trgentry)
static const std::string lumidataTableName()
unsigned long long entry_id
void bookNewEntry(coral::ISchema &schema, const std::string &datatableName, Entry &entry)
void insertHltRunData(coral::ISchema &schema, const HltEntry &hltentry)
unsigned int ncollidingbunches
unsigned long long generateNextIDForTable(const std::string &tableName, unsigned int interval=1)
void addRevision(coral::ISchema &schema, const std::string &datatableName, const Entry &revision, unsigned long long branch_id, std::string &branchname)
unsigned long long currentHFDataTagId(coral::ISchema &schema)
unsigned long long lumi_id
static const std::string revisionTableName()
unsigned long long trg_id
void bookNewRevision(coral::ISchema &schema, const std::string &datatableName, Entry &revision)