CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/RecoLuminosity/LumiProducer/src/idDealer.cc

Go to the documentation of this file.
00001 #include "RecoLuminosity/LumiProducer/interface/idDealer.h"
00002 #include "RelationalAccess/ISchema.h"
00003 #include "RelationalAccess/ITable.h"
00004 #include "RelationalAccess/IQuery.h"
00005 #include "RelationalAccess/ICursor.h"
00006 #include "RelationalAccess/ITableDataEditor.h"
00007 #include "CoralBase/AttributeList.h"
00008 #include "CoralBase/AttributeSpecification.h"
00009 #include "CoralBase/AttributeList.h"
00010 #include "CoralBase/Attribute.h"
00011 #include "RecoLuminosity/LumiProducer/interface/LumiNames.h"
00012 #include <sstream>
00013 //#include <iostream>
00014 lumi::idDealer::idDealer( coral::ISchema& schema):m_schema(schema),m_idtablecolumnName(lumi::LumiNames::idTableColumnName()),m_idtablecolumnType(lumi::LumiNames::idTableColumnType()){
00015 }
00016 unsigned long long lumi::idDealer::getIDforTable( const std::string& tableName ){
00017   std::string idtableName=lumi::LumiNames::idTableName(tableName);
00018   coral::IQuery* q=m_schema.tableHandle(idtableName).newQuery();
00019   q->addToOutputList(m_idtablecolumnName);
00020   q->setForUpdate(); //lock it
00021   coral::ICursor& cursor=q->execute();
00022   unsigned long long result=0;
00023   while ( cursor.next() ){
00024     const coral::AttributeList& row = cursor.currentRow();
00025     result = row[m_idtablecolumnName].data<unsigned long long>();
00026   }
00027   cursor.close();
00028   delete q;
00029   return result;
00030 }
00031 unsigned long long lumi::idDealer::generateNextIDForTable( const std::string& tableName,unsigned int interval ){
00032   std::string idtableName=lumi::LumiNames::idTableName(tableName);
00033   coral::IQuery* q=m_schema.tableHandle(idtableName).newQuery();
00034   q->addToOutputList(m_idtablecolumnName);
00035   unsigned long long r=0;
00036   coral::AttributeList myresult;
00037   myresult.extend(m_idtablecolumnName,typeid(unsigned long long));
00038   q->defineOutput(myresult);
00039   q->setForUpdate(); //lock it
00040   coral::ICursor& cursor=q->execute();
00041   while ( cursor.next() ){
00042     const coral::AttributeList& row = cursor.currentRow();
00043     r = row[m_idtablecolumnName].data<unsigned long long>();
00044   }
00045   coral::ITableDataEditor& dataEditor=m_schema.tableHandle(idtableName).dataEditor();
00046   coral::AttributeList inputData;
00047   //inputData.extend("interval",typeid(unsigned int));
00048   //inputData["interval"].data<unsigned int>()=interval;
00049   //dataEditor.updateRows(m_idtablecolumnName+"="+m_idtablecolumnName+"+1","",inputData);
00050   std::stringstream ss;
00051   ss<<interval;
00052   dataEditor.updateRows(m_idtablecolumnName+"="+m_idtablecolumnName+"+"+ss.str(),"",inputData);
00053   delete q;
00054   return r+interval;
00055 }