00001 #include "RecoLuminosity/LumiProducer/interface/RevisionDML.h" 00002 #include "RelationalAccess/ISchema.h" 00003 #include "RelationalAccess/ITable.h" 00004 #include "RelationalAccess/ITableDataEditor.h" 00005 #include "RelationalAccess/IQuery.h" 00006 #include "RelationalAccess/ICursor.h" 00007 #include "CoralBase/AttributeList.h" 00008 #include "CoralBase/Attribute.h" 00009 #include "CoralBase/AttributeSpecification.h" 00010 #include "CoralBase/TimeStamp.h" 00011 #include "RecoLuminosity/LumiProducer/interface/LumiNames.h" 00012 #include "RecoLuminosity/LumiProducer/interface/idDealer.h" 00013 unsigned long long 00014 lumi::RevisionDML::getEntryInBranchByName(coral::ISchema& schema, 00015 const std::string& datatableName, 00016 const std::string& entryname, 00017 const std::string& branchname){ 00018 unsigned long long entry_id=0; 00019 coral::IQuery* qHandle=schema.newQuery(); 00020 qHandle->addToTableList( lumi::LumiNames::entryTableName(datatableName),"e"); 00021 qHandle->addToTableList( lumi::LumiNames::revisionTableName(),"r"); 00022 qHandle->addToOutputList("e.ENTRY_ID","entry_id"); 00023 00024 coral::AttributeList qCondition; 00025 qCondition.extend("entryname",typeid(std::string)); 00026 qCondition.extend("branchname",typeid(std::string)); 00027 qCondition["entryname"].data<std::string>()=entryname; 00028 qCondition["branchname"].data<std::string>()=branchname; 00029 std::string qConditionStr("r.REVISION_ID=e.REVISION_ID and e.NAME=:entryname AND r.BRANCH_NAME=:branchname"); 00030 00031 coral::AttributeList qResult; 00032 qResult.extend("entry_id",typeid(unsigned long long)); 00033 qHandle->defineOutput(qResult); 00034 qHandle->setCondition(qConditionStr,qCondition); 00035 coral::ICursor& cursor=qHandle->execute(); 00036 while(cursor.next()){ 00037 entry_id=cursor.currentRow()["entry_id"].data<unsigned long long>(); 00038 } 00039 delete qHandle; 00040 return entry_id; 00041 } 00042 void 00043 lumi::RevisionDML::bookNewEntry(coral::ISchema& schema, 00044 const std::string& datatableName, 00045 lumi::RevisionDML::Entry& entry){ 00046 lumi::idDealer idg(schema); 00047 const std::string entrytableName=lumi::LumiNames::entryTableName(datatableName); 00048 entry.revision_id=idg.generateNextIDForTable(lumi::LumiNames::revisionTableName()); 00049 entry.data_id=idg.generateNextIDForTable(datatableName); 00050 entry.entry_id=idg.generateNextIDForTable(entrytableName); 00051 } 00052 void 00053 lumi::RevisionDML::bookNewRevision(coral::ISchema& schema, 00054 const std::string& datatableName, 00055 lumi::RevisionDML::Entry& revision){ 00056 lumi::idDealer idg(schema); 00057 revision.revision_id=idg.generateNextIDForTable(lumi::LumiNames::revisionTableName()); 00058 revision.data_id=idg.generateNextIDForTable(datatableName); 00059 } 00060 void 00061 lumi::RevisionDML::addEntry(coral::ISchema& schema, 00062 const std::string& datatableName, 00063 const lumi::RevisionDML::Entry& entry, 00064 unsigned long long branchid, 00065 const std::string& branchname ){ 00066 coral::AttributeList revdata; 00067 revdata.extend("REVISION_ID",typeid(unsigned long long)); 00068 revdata.extend("BRANCH_ID",typeid(unsigned long long)); 00069 revdata.extend("BRANCH_NAME",typeid(std::string)); 00070 revdata.extend("CTIME",typeid(coral::TimeStamp)); 00071 revdata["REVISION_ID"].data<unsigned long long>()=entry.revision_id; 00072 revdata["BRANCH_ID"].data<unsigned long long>()=branchid; 00073 revdata["BRANCH_NAME"].data<std::string>()=branchname; 00074 revdata["CTIME"].data<coral::TimeStamp>()=coral::TimeStamp::now(); 00075 const std::string revTableName=lumi::LumiNames::revisionTableName(); 00076 schema.tableHandle(revTableName).dataEditor().insertRow(revdata); 00077 00078 coral::AttributeList entrydata; 00079 entrydata.extend("REVISION_ID",typeid(unsigned long long)); 00080 entrydata.extend("ENTRY_ID",typeid(unsigned long long)); 00081 entrydata.extend("NAME",typeid(std::string)); 00082 entrydata["REVISION_ID"].data<unsigned long long>()=entry.revision_id; 00083 entrydata["ENTRY_ID"].data<unsigned long long>()=entry.entry_id; 00084 entrydata["NAME"].data<std::string>()=entry.entry_name; 00085 const std::string entryTableName=lumi::LumiNames::entryTableName(datatableName); 00086 schema.tableHandle(entryTableName).dataEditor().insertRow(entrydata); 00087 00088 coral::AttributeList revmapdata; 00089 revmapdata.extend("REVISION_ID",typeid(unsigned long long)); 00090 revmapdata.extend("DATA_ID",typeid(unsigned long long)); 00091 00092 revmapdata["REVISION_ID"].data<unsigned long long>()=entry.revision_id; 00093 revmapdata["DATA_ID"].data<unsigned long long>()=entry.data_id; 00094 00095 const std::string revmapTableName=lumi::LumiNames::revmapTableName(datatableName); 00096 schema.tableHandle(revmapTableName).dataEditor().insertRow(revmapdata); 00097 } 00098 void 00099 lumi::RevisionDML::addRevision(coral::ISchema& schema, 00100 const std::string& datatableName, 00101 const lumi::RevisionDML::Entry& revision, 00102 unsigned long long branchid, 00103 std::string& branchname ){ 00104 coral::AttributeList revdata; 00105 revdata.extend("REVISION_ID",typeid(unsigned long long)); 00106 revdata.extend("BRANCH_ID",typeid(unsigned long long)); 00107 revdata.extend("BRANCH_NAME",typeid(std::string)); 00108 revdata.extend("CTIME",typeid(coral::TimeStamp)); 00109 revdata["REVISION_ID"].data<unsigned long long>()=revision.revision_id; 00110 revdata["BRANCH_ID"].data<unsigned long long>()=branchid; 00111 revdata["BRANCH_NAME"].data<std::string>()=branchname; 00112 revdata["CTIME"].data<coral::TimeStamp>()=coral::TimeStamp::now(); 00113 schema.tableHandle(lumi::LumiNames::revisionTableName()).dataEditor().insertRow(revdata); 00114 coral::AttributeList revmapdata; 00115 revmapdata.extend("REVISION_ID",typeid(unsigned long long)); 00116 revmapdata.extend("DATA_ID",typeid(unsigned long long)); 00117 revmapdata["REVISION_ID"].data<unsigned long long>()=revision.revision_id; 00118 revmapdata["DATA_ID"].data<unsigned long long>()=revision.data_id; 00119 const std::string revmapTableName=lumi::LumiNames::revmapTableName(datatableName); 00120 schema.tableHandle(revmapTableName).dataEditor().insertRow(revmapdata); 00121 } 00122 void 00123 lumi::RevisionDML::insertLumiRunData(coral::ISchema& schema, 00124 const lumi::RevisionDML::LumiEntry& lumientry){ 00125 coral::AttributeList lumirundata; 00126 lumirundata.extend("DATA_ID",typeid(unsigned long long)); 00127 lumirundata.extend("ENTRY_ID",typeid(unsigned long long)); 00128 lumirundata.extend("ENTRY_NAME",typeid(std::string)); 00129 lumirundata.extend("RUNNUM",typeid(unsigned int)); 00130 lumirundata.extend("SOURCE",typeid(std::string)); 00131 lumirundata.extend("NOMINALEGEV",typeid(float)); 00132 lumirundata.extend("NCOLLIDINGBUNCHES",typeid(unsigned int)); 00133 lumirundata["DATA_ID"].data<unsigned long long>()=lumientry.data_id; 00134 lumirundata["ENTRY_ID"].data<unsigned long long>()=lumientry.entry_id; 00135 lumirundata["ENTRY_NAME"].data<std::string>()=lumientry.entry_name; 00136 lumirundata["RUNNUM"].data<unsigned int>()=lumientry.runnumber; 00137 lumirundata["SOURCE"].data<std::string>()=lumientry.source; 00138 lumirundata["NOMINALEGEV"].data<float>()=lumientry.bgev; 00139 lumirundata["NCOLLIDINGBUNCHES"].data<unsigned int>()=lumientry.ncollidingbunches; 00140 const std::string lumidataTableName=lumi::LumiNames::lumidataTableName(); 00141 schema.tableHandle(lumidataTableName).dataEditor().insertRow(lumirundata); 00142 } 00143 void 00144 lumi::RevisionDML::insertTrgRunData(coral::ISchema& schema, 00145 const lumi::RevisionDML::TrgEntry& trgentry){ 00146 coral::AttributeList trgrundata; 00147 trgrundata.extend("DATA_ID",typeid(unsigned long long)); 00148 trgrundata.extend("ENTRY_ID",typeid(unsigned long long)); 00149 trgrundata.extend("ENTRY_NAME",typeid(std::string)); 00150 trgrundata.extend("RUNNUM",typeid(unsigned int)); 00151 trgrundata.extend("SOURCE",typeid(std::string)); 00152 trgrundata.extend("BITZERONAME",typeid(std::string)); 00153 trgrundata.extend("BITNAMECLOB",typeid(std::string)); 00154 trgrundata["DATA_ID"].data<unsigned long long>()=trgentry.data_id; 00155 trgrundata["ENTRY_ID"].data<unsigned long long>()=trgentry.entry_id; 00156 trgrundata["ENTRY_NAME"].data<std::string>()=trgentry.entry_name; 00157 trgrundata["RUNNUM"].data<unsigned int>()=trgentry.runnumber; 00158 trgrundata["SOURCE"].data<std::string>()=trgentry.source; 00159 trgrundata["BITZERONAME"].data<std::string>()=trgentry.bitzeroname; 00160 trgrundata["BITNAMECLOB"].data<std::string>()=trgentry.bitnames; 00161 const std::string trgdataTableName=lumi::LumiNames::trgdataTableName(); 00162 schema.tableHandle(trgdataTableName).dataEditor().insertRow(trgrundata); 00163 } 00164 void 00165 lumi::RevisionDML::insertHltRunData(coral::ISchema& schema, 00166 const lumi::RevisionDML::HltEntry& hltentry){ 00167 coral::AttributeList hltrundata; 00168 hltrundata.extend("DATA_ID",typeid(unsigned long long)); 00169 hltrundata.extend("ENTRY_ID",typeid(unsigned long long)); 00170 hltrundata.extend("ENTRY_NAME",typeid(std::string)); 00171 hltrundata.extend("RUNNUM",typeid(unsigned int)); 00172 hltrundata.extend("SOURCE",typeid(std::string)); 00173 hltrundata.extend("NPATH",typeid(unsigned int)); 00174 hltrundata.extend("PATHNAMECLOB",typeid(std::string)); 00175 hltrundata["DATA_ID"].data<unsigned long long>()=hltentry.data_id; 00176 hltrundata["ENTRY_ID"].data<unsigned long long>()=hltentry.entry_id; 00177 hltrundata["ENTRY_NAME"].data<std::string>()=hltentry.entry_name; 00178 hltrundata["RUNNUM"].data<unsigned int>()=hltentry.runnumber; 00179 hltrundata["SOURCE"].data<std::string>()=hltentry.source; 00180 hltrundata["NPATH"].data<unsigned int>()=hltentry.npath; 00181 hltrundata["PATHNAMECLOB"].data<std::string>()=hltentry.pathnames; 00182 const std::string hltdataTableName=lumi::LumiNames::hltdataTableName(); 00183 schema.tableHandle(hltdataTableName).dataEditor().insertRow(hltrundata); 00184 }