24 oracle::occi::Connection* conn) :
LMFUnique(env, conn) {
39 std::map<std::string, LMFUnique*>::iterator
i =
58 std::map<unsigned int, std::string>
m;
59 std::map<std::string, unsigned int>::const_iterator
i =
m_keys.begin();
60 std::map<std::string, unsigned int>::const_iterator
e =
m_keys.end();
62 m[i->second] = i->first;
79 cout <<
"Stored data: " << s << endl;
81 std::map<int, std::vector<float> >::const_iterator
p =
m_data.begin();
82 std::map<int, std::vector<float> >::const_iterator
end =
m_data.end();
85 while ((p != end) && (c < max)) {
87 std::vector<float>
x = p->second;
88 cout << c <<
" -------------------------------------------" << endl;
89 cout <<
" ID: " <<
id << endl;
90 for (
unsigned int j = 0;
j < x.size();
j++) {
94 cout << rm[
j] <<
":" << x[
j] <<
"\t";
105 std::stringstream sql;
107 unsigned int nParameters =
m_keys.size() + 2;
108 for (
unsigned int i = 0;
i < nParameters - 1;
i++) {
109 sql <<
":" <<
i + 1 <<
", ";
111 sql <<
":" << nParameters <<
")";
142 std::stringstream sql;
145 if (
_where.length() > 0) {
151 sql <<
"SELECT * FROM CMS_ECAL_LASER_COND." <<
getTableName() <<
" WHERE "
167 sql <<
"SELECT * FROM (SELECT CMS_ECAL_LASER_COND."
170 <<
" JOIN LMF_RUN_IOV ON "
171 <<
"LMF_RUN_IOV.LMF_IOV_ID = "
173 <<
"WHERE SUBRUN_START " << op <<
"= TO_DATE(:" <<
count;
175 sql <<
", 'YYYY-MM-DD HH24:MI:SS') ORDER BY SUBRUN_START "
176 << order <<
") WHERE ROWNUM <= 1";
179 sql <<
" AND LOGIC_ID = :" <<
count;
189 throw(std::runtime_error)
191 getNeighbour(dat, -1);
195 throw(std::runtime_error)
197 getNeighbour(dat, +1);
201 throw(std::runtime_error)
204 if (m_data.size() == 1) {
205 dat->setConnection(this->getEnv(), this->getConn());
206 int logic_id = m_data.begin()->first;
207 Tm lastMeasuredOn = getSubrunStart();
208 lastMeasuredOn +=
which;
209 dat->fetch(logic_id, &lastMeasuredOn,
which);
210 dat->setMaxDataToDump(m_max);
213 throw(std::runtime_error(m_className +
"::getPrevious: Too many LOGIC_IDs in "
219 throw(std::runtime_error)
221 fetch(
id.getLogicID());
225 throw(std::runtime_error)
227 fetch(
id.getLogicID(), &tm, 1);
231 throw(std::runtime_error)
233 setInt(foreignKeyName(), 0);
234 fetch(
id.getLogicID(), &tm, direction);
238 throw(std::runtime_error)
244 throw(std::runtime_error)
250 throw(std::runtime_error)
252 fetch(logic_id, &tm, 1);
260 std::size_t
n = sql.find(
":");
263 n = sql.find(
":", n + 1);
265 while (n != std::string::npos) {
266 char type = sql.at(n + 1);
270 }
else if (type ==
'F') {
271 stmt->setFloat(nw + count, atof(
_wherePars[nw].c_str()));
273 }
else if (type ==
'I') {
274 stmt->setInt(nw + count, atoi(
_wherePars[nw].c_str()));
277 n = sql.find(
":", n + 1);
282 throw(std::runtime_error)
286 throw(std::runtime_error(m_className +
"::fetch: Cannot fetch data with "
287 "timestamp = 0 and LMFRunIOV = 0"));
289 if (ok && isValid()) {
291 std::cout <<
"[LMFDat] This object is valid..." << std::endl;
294 Statement * stmt = m_conn->createStatement();
295 std::string sql = buildSelectSql(logic_id, direction);
297 std::cout <<
"[LMFDat] Executing query " << std::endl;
298 std::cout <<
" " << sql << std::endl << std::flush;
302 stmt->setPrefetchRowCount(10000);
308 stmt->setString(count,
timestamp->str());
311 stmt->setInt(count++, logic_id);
313 adjustParameters(count, sql, stmt);
315 std::vector<float>
x;
316 int nData = m_keys.size();
318 while (rset->next() != 0) {
319 for (
int i = 0;
i < nData;
i++) {
320 x.push_back(rset->getFloat(
i + 3));
322 int id = rset->getInt(2);
324 setInt(foreignKeyName(), rset->getInt(1));
326 this->setData(
id, x);
329 stmt->setPrefetchRowCount(0);
330 m_conn->terminateStatement(stmt);
333 throw(std::runtime_error(m_className +
"::fetch: " + e.getMessage()));
335 m_ID = m_data.size();
343 m_Error +=
" Can't find lmfRunIOV within foreign keys.";
353 throw(std::runtime_error)
356 std::map<int, std::vector<float> >
s =
m_data;
357 std::string sql =
"SELECT LOGIC_ID FROM CMS_ECAL_LASER_COND." +
371 stmt->setPrefetchRowCount(10000);
373 std::map<int, std::vector<float> >::iterator
i = s.end();
374 std::map<int, std::vector<float> >::iterator
e = s.end();
375 while (rset->next() != 0) {
380 i = s.find(rset->getInt(1));
385 stmt->setPrefetchRowCount(0);
386 m_conn->terminateStatement(stmt);
389 throw(std::runtime_error(
m_className +
"::fetchData: "+e.getMessage()));
399 throw(std::runtime_error)
411 std::map<int, std::vector<float> > data2write =
fetchData();
412 if (data2write.size() > 0) {
417 std::list<dvoid *> bufPointers;
418 int nParameters =
m_keys.size();
419 int nData = data2write.size();
424 int * iovid_vec =
new int[nData];
425 int * logicid_vec =
new int[nData];
426 int *intArray =
new int[nData];
427 float *floatArray =
new float[nData];
428 ub2 * intSize =
new ub2[nData];
429 ub2 * floatSize =
new ub2[nData];
430 size_t intTotalSize =
sizeof(int)*nData;
431 size_t floatTotalSize =
sizeof(float)*nData;
437 for (
int i = 0;
i < nData;
i++) {
438 intSize[
i] =
sizeof(int);
439 floatSize[
i] =
sizeof(int);
443 int iov_id = runiov->
getID();
444 std::map<int, std::vector<float> >::const_iterator
b = data2write.begin();
445 std::map<int, std::vector<float> >::const_iterator
e = data2write.end();
446 for (
int i = 0;
i < nData;
i++) {
447 iovid_vec[
i] = iov_id;
449 stmt->setDataBuffer(1, (dvoid*)iovid_vec, oracle::occi::OCCIINT,
450 sizeof(iovid_vec[0]), intSize);
455 logicid_vec[c++] = id;
458 stmt->setDataBuffer(2, (dvoid*)logicid_vec, oracle::occi::OCCIINT,
459 sizeof(logicid_vec[0]), intSize);
462 for (
int i = 0;
i < nParameters;
i++) {
463 b = data2write.begin();
467 std::vector<float>
x = b->second;
469 intArray[
c] = (int)rint(x[
i]);
471 floatArray[
c] = x[
i];
473 throw(std::runtime_error(
"ERROR: LMFDat::writeDB: unsupported type"));
480 type = oracle::occi::OCCIINT;
481 ub2 *sizeArray = intSize;
482 int size =
sizeof(intArray[0]);
484 buffer = (dvoid *)malloc(
sizeof(
float)*nData);
485 memcpy(buffer, floatArray, floatTotalSize);
486 type = oracle::occi::OCCIFLOAT;
487 sizeArray = floatSize;
488 size =
sizeof(floatArray[0]);
490 buffer = (dvoid *)malloc(
sizeof(
int)*nData);
491 memcpy(buffer, intArray, intTotalSize);
493 bufPointers.push_back(buffer);
495 for (
int k = 0; ((
k < nData) && (
k <
m_max));
k++) {
500 << ((
float *)(buffer))[
k] << endl;
503 stmt->setDataBuffer(
i + 3, buffer, type, size, sizeArray);
505 stmt->executeArrayUpdate(nData);
507 delete [] floatArray;
510 delete [] logicid_vec;
512 std::list<dvoid *>::const_iterator bi = bufPointers.begin();
513 std::list<dvoid *>::const_iterator be = bufPointers.end();
519 m_conn->terminateStatement(stmt);
526 int iov_id = runiov->
getID();
527 std::cout <<
"==== This object refers to IOV " << iov_id << std::endl;
530 throw(std::runtime_error(
m_className +
"::writeDB: " +
543 throw(std::runtime_error)
546 for (
unsigned int i = 0;
i <
m_keys.size();
i++) {
553 sql =
"SELECT * FROM TABLE(CMS_ECAL_LASER_COND.LMF_TAB_COLS(:1, :2))";
564 while (rset->next() != 0) {
569 m_conn->terminateStatement(stmt);
571 throw(std::runtime_error(
m_className +
"::getKeyTypes: " + e.getMessage() +
582 m_Error =
"class name not set ";
587 m_Error +=
"table name not set ";
594 m_Error +=
"key size does not correspond to table definition";
604 std::vector<float>
ret;
616 return getData(
id.getLogicID());
631 return getData(
id.getLogicID(), ret);
647 return getData(
id.getLogicID(), k);
662 std::vector<float>
v;
664 if ((retval) && (v.size() >
k)) {
674 return getData(
id.getLogicID(), k, ret);
687 return getData(
id.getLogicID(), key, ret);
std::map< int, std::vector< float > > fetchData()
std::vector< std::string > _wherePars
tuple ret
prodAgent to be discontinued
LMFUnique & setInt(std::string key, int value)
oracle::occi::Connection * m_conn
void adjustParameters(int n, std::string &sql, Statement *stmt)
std::map< unsigned int, std::string > getReverseMap() const
std::string buildInsertSql()
oracle::occi::ResultSet ResultSet
std::map< int, std::vector< float > > m_data
virtual void dump() const
std::vector< std::string > m_type
void getPrevious(LMFDat *dat)
oracle::occi::SQLException SQLException
virtual int writeForeignKeys()
int getInt(std::string fieldname) const
T x() const
Cartesian x coordinate.
bool check(const std::string &)
oracle::occi::Statement Statement
void getNext(LMFDat *dat)
std::pair< std::string, boost::shared_ptr< void > > fetch(const cond::Hash &payloadId, Session &session)
std::map< std::string, LMFUnique * > m_foreignKeys
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::map< int, std::vector< float > > getData()
LMFDat & setMaxDataToDump(int n)
void setWhereClause(std::string w)
std::vector< float > operator[](int id)
virtual std::string getIovIdFieldName() const
virtual std::string foreignKeyName() const
std::map< std::string, unsigned int > m_keys
virtual std::string getTableName() const
std::string buildSelectSql(int logic_id=0, int direction=0)
void getNeighbour(LMFDat *dat, int which)
void checkConnection() const