54 std::map<unsigned int, std::string>
m;
55 std::map<std::string, unsigned int>::const_iterator
i =
m_keys.begin();
56 std::map<std::string, unsigned int>::const_iterator
e =
m_keys.end();
58 m[
i->second] =
i->first;
71 cout <<
"Stored data: " <<
s << endl;
73 std::map<int, std::vector<float> >::const_iterator
p =
m_data.begin();
74 std::map<int, std::vector<float> >::const_iterator
end =
m_data.end();
79 std::vector<float>
x =
p->second;
80 cout <<
c <<
" -------------------------------------------" << endl;
81 cout <<
" ID: " <<
id << endl;
82 for (
unsigned int j = 0;
j <
x.size();
j++) {
97 std::stringstream sql;
99 unsigned int nParameters =
m_keys.size() + 2;
100 for (
unsigned int i = 0;
i < nParameters - 1;
i++) {
101 sql <<
":" <<
i + 1 <<
", ";
103 sql <<
":" << nParameters <<
")";
131 std::stringstream sql;
134 if (
_where.length() > 0) {
155 sql <<
"SELECT * FROM (SELECT CMS_ECAL_LASER_COND." <<
getTableName() <<
".* FROM CMS_ECAL_LASER_COND." 158 <<
"WHERE SUBRUN_START " <<
op <<
"= TO_DATE(:" <<
count;
160 sql <<
", 'YYYY-MM-DD HH24:MI:SS') ORDER BY SUBRUN_START " <<
order <<
") WHERE ROWNUM <= 1";
163 sql <<
" AND LOGIC_ID = :" <<
count;
178 if (m_data.size() == 1) {
179 dat->setConnection(this->getEnv(), this->getConn());
180 int logic_id = m_data.begin()->first;
181 Tm lastMeasuredOn = getSubrunStart();
182 lastMeasuredOn +=
which;
183 dat->fetch(logic_id, &lastMeasuredOn,
which);
184 dat->setMaxDataToDump(m_max);
187 throw(std::runtime_error(m_className +
"::getPrevious: Too many LOGIC_IDs in " 197 setInt(foreignKeyName(), 0);
198 fetch(
id.getLogicID(), &tm, direction);
211 std::size_t
n = sql.find(
':');
214 n = sql.find(
':',
n + 1);
216 while (
n != std::string::npos) {
217 char type = sql.at(
n + 1);
221 }
else if (
type ==
'F') {
224 }
else if (
type ==
'I') {
228 n = sql.find(
':',
n + 1);
234 if ((
timestamp ==
nullptr) && (getLMFRunIOVID() == 0)) {
235 throw(std::runtime_error(m_className +
"::fetch: Cannot fetch data with " 236 "timestamp = 0 and LMFRunIOV = 0"));
240 std::cout <<
"[LMFDat] This object is valid..." << std::endl;
243 Statement *stmt = m_conn->createStatement();
244 std::string sql = buildSelectSql(logic_id, direction);
246 std::cout <<
"[LMFDat] Executing query " << std::endl;
247 std::cout <<
" " << sql << std::endl << std::flush;
251 stmt->setPrefetchRowCount(10000);
260 stmt->setInt(
count++, logic_id);
262 adjustParameters(
count, sql, stmt);
264 std::vector<float>
x;
265 int nData = m_keys.size();
267 while (rset->next() != 0) {
268 for (
int i = 0;
i < nData;
i++) {
269 x.push_back(rset->getFloat(
i + 3));
271 int id = rset->getInt(2);
273 setInt(foreignKeyName(), rset->getInt(1));
275 this->setData(
id,
x);
278 stmt->setPrefetchRowCount(0);
279 m_conn->terminateStatement(stmt);
280 }
catch (oracle::occi::SQLException &
e) {
281 throw(std::runtime_error(m_className +
"::fetch: " +
e.getMessage()));
283 m_ID = m_data.size();
291 m_Error +=
" Can't find lmfRunIOV within foreign keys.";
301 std::map<int, std::vector<float> >
s =
m_data;
305 cout <<
m_className <<
":: candidate data items to be written = " <<
s.size() << endl;
313 stmt->setPrefetchRowCount(10000);
315 std::map<int, std::vector<float> >::iterator
i =
s.end();
316 std::map<int, std::vector<float> >::iterator
e =
s.end();
317 while (rset->next() != 0) {
319 cout <<
m_className <<
":: checking " << rset->getInt(1) << endl << std::flush;
321 i =
s.find(rset->getInt(1));
326 stmt->setPrefetchRowCount(0);
327 m_conn->terminateStatement(stmt);
328 }
catch (oracle::occi::SQLException &
e) {
329 throw(std::runtime_error(
m_className +
"::fetchData: " +
e.getMessage()));
348 std::map<int, std::vector<float> > data2write =
fetchData();
349 if (!data2write.empty()) {
354 std::list<dvoid *> bufPointers;
355 int nParameters =
m_keys.size();
356 int nData = data2write.size();
361 int *iovid_vec =
new int[nData];
362 int *logicid_vec =
new int[nData];
363 int *intArray =
new int[nData];
364 float *floatArray =
new float[nData];
365 ub2 *intSize =
new ub2[nData];
366 ub2 *floatSize =
new ub2[nData];
367 size_t intTotalSize =
sizeof(
int) * nData;
368 size_t floatTotalSize =
sizeof(
float) * nData;
374 for (
int i = 0;
i < nData;
i++) {
375 intSize[
i] =
sizeof(
int);
376 floatSize[
i] =
sizeof(
int);
380 int iov_id = runiov->
getID();
381 std::map<int, std::vector<float> >::const_iterator
b = data2write.begin();
382 std::map<int, std::vector<float> >::const_iterator
e = data2write.end();
383 for (
int i = 0;
i < nData;
i++) {
384 iovid_vec[
i] = iov_id;
386 stmt->setDataBuffer(1, (dvoid *)iovid_vec, oracle::occi::OCCIINT,
sizeof(iovid_vec[0]), intSize);
391 logicid_vec[
c++] =
id;
394 stmt->setDataBuffer(2, (dvoid *)logicid_vec, oracle::occi::OCCIINT,
sizeof(logicid_vec[0]), intSize);
397 for (
int i = 0;
i < nParameters;
i++) {
398 b = data2write.begin();
402 std::vector<float>
x =
b->second;
404 intArray[
c] = (
int)rint(
x[
i]);
406 floatArray[
c] =
x[
i];
408 throw(std::runtime_error(
"ERROR: LMFDat::writeDB: unsupported type"));
415 type = oracle::occi::OCCIINT;
416 ub2 *sizeArray = intSize;
417 int size =
sizeof(intArray[0]);
420 memcpy(
buffer, floatArray, floatTotalSize);
421 type = oracle::occi::OCCIFLOAT;
422 sizeArray = floatSize;
423 size =
sizeof(floatArray[0]);
426 memcpy(
buffer, intArray, intTotalSize);
428 bufPointers.push_back(
buffer);
430 for (
int k = 0; ((
k < nData) && (
k <
m_max));
k++) {
439 stmt->executeArrayUpdate(nData);
444 delete[] logicid_vec;
446 std::list<dvoid *>::const_iterator bi = bufPointers.begin();
447 std::list<dvoid *>::const_iterator
be = bufPointers.end();
453 m_conn->terminateStatement(stmt);
455 }
catch (oracle::occi::SQLException &
e) {
460 int iov_id = runiov->
getID();
461 std::cout <<
"==== This object refers to IOV " << iov_id << std::endl;
464 throw(std::runtime_error(
m_className +
"::writeDB: " +
e.getMessage()));
476 for (
unsigned int i = 0;
i <
m_keys.size();
i++) {
483 sql =
"SELECT * FROM TABLE(CMS_ECAL_LASER_COND.LMF_TAB_COLS(:1, :2))";
494 while (rset->next() != 0) {
499 m_conn->terminateStatement(stmt);
500 }
catch (oracle::occi::SQLException &
e) {
501 throw(std::runtime_error(
m_className +
"::getKeyTypes: " +
e.getMessage() +
" [" + sql +
"]"));
511 m_Error =
"class name not set ";
516 m_Error +=
"table name not set ";
523 m_Error +=
"key size does not correspond to table definition";
533 std::vector<float>
ret;
575 std::vector<float>
v;
577 if ((retval) && (
v.size() >
k)) {
std::vector< std::string > _wherePars
LMFUnique & setInt(std::string key, int value)
void getNeighbour(LMFDat *dat, int which) noexcept(false)
oracle::occi::Connection * m_conn
void adjustParameters(int n, std::string &sql, Statement *stmt)
const bool isValid(const Frame &aFrame, const FrameQuality &aQuality, const uint16_t aExpectedPos)
void getPrevious(LMFDat *dat) noexcept(false)
void checkConnection() const noexcept(false)
ret
prodAgent to be discontinued
int writeDB() noexcept(false) override
std::string buildInsertSql()
oracle::occi::ResultSet ResultSet
std::map< std::string, LMFUnique * > m_foreignKeys
std::map< int, std::vector< float > > m_data
std::vector< std::string > m_type
void getNext(LMFDat *dat) noexcept(false)
void free(void *ptr) noexcept
std::map< int, std::vector< float > > fetchData() noexcept(false)
void fetch() noexcept(false)
oracle::occi::Statement Statement
virtual void dump() const
std::map< int, std::vector< float > > getData()
LMFDat & setMaxDataToDump(int n)
virtual std::string foreignKeyName() const
void dump() const override
void * malloc(size_t size) noexcept
int getInt(std::string fieldname) const
void setWhereClause(std::string w)
std::vector< float > operator[](int id)
virtual std::string getIovIdFieldName() const
std::map< std::string, unsigned int > m_keys
virtual int writeForeignKeys() noexcept(false)
std::string buildSelectSql(int logic_id=0, int direction=0)
virtual std::string getTableName() const
std::map< unsigned int, std::string > getReverseMap() const
std::pair< std::string, std::shared_ptr< void > > fetch(const cond::Hash &payloadId, Session &session)
int fetchID() noexcept(false) override
void getKeyTypes() noexcept(false)