CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Protected Member Functions | Protected Attributes | Friends
LMFDat Class Reference

#include <LMFDat.h>

Inheritance diagram for LMFDat:
LMFUnique IUniqueDBObject IDBObject LMFColoredTable LMFCorrCoefDatComponent LMFLaserConfigDat LMFRunDat LMFTestPulseConfigDat LMFClsDat LMFLaserPulseDat LMFPnPrimDat LMFPrimDat

Public Member Functions

void dump () const
 
void dump (int n) const
 
virtual void dump (int n, int max) const
 
void fetch () throw (std::runtime_error)
 
void fetch (int logic_id) throw (std::runtime_error)
 
void fetch (int logic_id, const Tm &tm) throw (std::runtime_error)
 
void fetch (int logic_id, const Tm *timestamp, int dir) throw (std::runtime_error)
 
void fetch (const EcalLogicID &id, const Tm &tm) throw (std::runtime_error)
 
void fetch (const EcalLogicID &id, const Tm &tm, int dir) throw (std::runtime_error)
 
void fetch (const EcalLogicID &id) throw (std::runtime_error)
 
std::map< int, std::vector
< float > > 
fetchData () throw (std::runtime_error)
 
virtual std::string foreignKeyName () const
 
std::vector< float > getData (int id)
 
std::vector< float > getData (const EcalLogicID &id)
 
bool getData (int id, std::vector< float > &ret)
 
bool getData (const EcalLogicID &id, std::vector< float > &ret)
 
std::map< int, std::vector
< float > > 
getData ()
 
float getData (int id, unsigned int k)
 
float getData (const EcalLogicID &id, unsigned int k)
 
float getData (const EcalLogicID &id, const std::string &key)
 
float getData (int id, const std::string &key)
 
bool getData (int id, unsigned int k, float &ret)
 
bool getData (const EcalLogicID &id, unsigned int k, float &ret)
 
bool getData (int id, const std::string &key, float &ret)
 
bool getData (const EcalLogicID &id, const std::string &key, float &ret)
 
virtual std::string getIovIdFieldName () const
 
std::list< std::string > getKeyList ()
 
std::map< std::string,
unsigned int > 
getKeys ()
 
LMFRunIOV getLMFRunIOV () const
 
int getLMFRunIOVID ()
 
std::list< int > getLogicIds ()
 
void getNext (LMFDat *dat) throw (std::runtime_error)
 
void getPrevious (LMFDat *dat) throw (std::runtime_error)
 
std::map< unsigned int,
std::string > 
getReverseMap () const
 
Tm getSubrunStart () const
 
virtual std::string getTableName () const
 
virtual bool isValid ()
 
 LMFDat ()
 
 LMFDat (EcalDBConnection *c)
 
 LMFDat (oracle::occi::Environment *env, oracle::occi::Connection *conn)
 
std::vector< float > operator[] (int id)
 
LMFDatsetData (int logic_id, const std::vector< float > &data)
 
LMFDatsetData (const EcalLogicID &logic_id, const std::vector< float > &data)
 
LMFDatsetData (const EcalLogicID &logic_id, const std::string &key, float v)
 
LMFDatsetLMFRunIOV (const LMFRunIOV &iov)
 
LMFDatsetMaxDataToDump (int n)
 
void setWhereClause (std::string w)
 
void setWhereClause (std::string w, const std::vector< std::string > &p)
 
int size () const
 
 ~LMFDat ()
 
- Public Member Functions inherited from LMFUnique
void attach (std::string name, LMFUnique *u)
 
void debug ()
 
virtual bool exists ()
 
virtual boost::ptr_list
< LMFUnique
fetchAll () const throw (std::runtime_error)
 
int fetchID () throw (std::runtime_error)
 
std::string getClassName ()
 
std::string getClassName () const
 
int getID () const
 
int getInt (std::string fieldname) const
 
std::string getString (std::string fieldname) const
 
virtual bool isValid () const
 
 LMFUnique ()
 
 LMFUnique (oracle::occi::Environment *env, oracle::occi::Connection *conn)
 
 LMFUnique (EcalDBConnection *c)
 
void nodebug ()
 
virtual bool operator< (const LMFUnique &r)
 
virtual bool operator<= (const LMFUnique &r)
 
std::string sequencePostfix (const Tm &t)
 
void setByID (int id) throw (std::runtime_error)
 
LMFUniquesetInt (std::string key, int value)
 
LMFUniquesetString (std::string key, std::string value)
 
void startProfiling ()
 
void stopProfiling ()
 
virtual ~LMFUnique ()
 
- Public Member Functions inherited from IDBObject
oracle::occi::Connection * getConn () const
 
oracle::occi::Environment * getEnv () const
 
void setConnection (oracle::occi::Environment *env, oracle::occi::Connection *conn)
 
virtual ~IDBObject ()
 

Protected Member Functions

void adjustParameters (int n, std::string &sql, Statement *stmt)
 
std::string buildInsertSql ()
 
std::string buildSelectSql (int logic_id=0, int direction=0)
 
bool check ()
 
void getKeyTypes () throw (std::runtime_error)
 
void getNeighbour (LMFDat *dat, int which) throw (std::runtime_error)
 
int writeDB () throw (std::runtime_error)
 
- Protected Member Functions inherited from LMFUnique
virtual void setClassName (std::string s)
 
virtual int writeForeignKeys () throw (std::runtime_error)
 
- Protected Member Functions inherited from IDBObject
void checkConnection () const throw (std::runtime_error)
 

Protected Attributes

std::string _where
 
std::vector< std::string > _wherePars
 
std::map< int, std::vector
< float > > 
m_data
 
std::string m_Error
 
std::map< std::string,
unsigned int > 
m_keys
 
int m_max
 
std::string m_tableName
 
std::vector< std::string > m_type
 
- Protected Attributes inherited from LMFUnique
bool _profiling
 
std::string m_className
 
char m_debug
 
std::map< std::string,
LMFUnique * > 
m_foreignKeys
 
std::map< std::string, int > m_intFields
 
std::map< std::string,
std::string > 
m_stringFields
 
- Protected Attributes inherited from IUniqueDBObject
int m_ID
 
- Protected Attributes inherited from IDBObject
oracle::occi::Connection * m_conn
 
oracle::occi::Environment * m_env
 

Friends

class EcalCondDBInterface
 

Additional Inherited Members

- Public Types inherited from LMFUnique
typedef oracle::occi::ResultSet ResultSet
 
typedef oracle::occi::Statement Statement
 
- Static Public Attributes inherited from IDBObject
static int const ECALDB_NROWS =1024
 

Detailed Description

Data Tables for LMF Runs

Definition at line 19 of file LMFDat.h.

Constructor & Destructor Documentation

LMFDat::LMFDat ( )

Definition at line 9 of file LMFDat.cc.

References _where, _wherePars, m_max, and m_tableName.

9  : LMFUnique() {
10  m_tableName = "";
11  m_max = -1;
12  _where = "";
13  _wherePars.clear();
14 }
std::vector< std::string > _wherePars
Definition: LMFDat.h:160
LMFUnique()
Definition: LMFUnique.h:23
int m_max
Definition: LMFDat.h:149
std::string _where
Definition: LMFDat.h:159
std::string m_tableName
Definition: LMFDat.h:156
LMFDat::LMFDat ( EcalDBConnection c)

Definition at line 16 of file LMFDat.cc.

References _where, _wherePars, m_max, and m_tableName.

16  : LMFUnique(c) {
17  m_tableName = "";
18  m_max = -1;
19  _where = "";
20  _wherePars.clear();
21 }
std::vector< std::string > _wherePars
Definition: LMFDat.h:160
LMFUnique()
Definition: LMFUnique.h:23
int m_max
Definition: LMFDat.h:149
std::string _where
Definition: LMFDat.h:159
std::string m_tableName
Definition: LMFDat.h:156
LMFDat::LMFDat ( oracle::occi::Environment *  env,
oracle::occi::Connection *  conn 
)

Definition at line 23 of file LMFDat.cc.

References _where, _wherePars, m_max, and m_tableName.

24  : LMFUnique(env, conn) {
25  m_tableName = "";
26  m_max = -1;
27  _where = "";
28  _wherePars.clear();
29 }
std::vector< std::string > _wherePars
Definition: LMFDat.h:160
LMFUnique()
Definition: LMFUnique.h:23
int m_max
Definition: LMFDat.h:149
std::string _where
Definition: LMFDat.h:159
tuple conn
Definition: results_mgr.py:53
std::string m_tableName
Definition: LMFDat.h:156
LMFDat::~LMFDat ( )
inline

Definition at line 27 of file LMFDat.h.

27 { }

Member Function Documentation

void LMFDat::adjustParameters ( int  n,
std::string &  sql,
Statement stmt 
)
protected

Definition at line 255 of file LMFDat.cc.

References _wherePars, prof2calltree::count, run_regression::done, and gen::n.

256  {
257  // adjust positional parameters and change them according to their
258  // decalred type
259  std::size_t nw = 0;
260  std::size_t n = sql.find(":");
261  for (int done = 1; done < count; done++) {
262  // skip already bound variables
263  n = sql.find(":", n + 1);
264  }
265  while (n != std::string::npos) {
266  char type = sql.at(n + 1);
267  if (type == 'S') {
268  stmt->setString(nw + count, _wherePars[nw]);
269  nw++;
270  } else if (type == 'F') {
271  stmt->setFloat(nw + count, atof(_wherePars[nw].c_str()));
272  nw++;
273  } else if (type == 'I') {
274  stmt->setInt(nw + count, atoi(_wherePars[nw].c_str()));
275  nw++;
276  }
277  n = sql.find(":", n + 1);
278  }
279 }
type
Definition: HCALResponse.h:21
std::vector< std::string > _wherePars
Definition: LMFDat.h:160
std::string LMFDat::buildInsertSql ( )
protected

Definition at line 103 of file LMFDat.cc.

References gather_cfg::cout, getTableName(), i, LMFUnique::m_className, LMFUnique::m_debug, m_keys, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by writeDB().

103  {
104  // create the insert statement
105  std::stringstream sql;
106  sql << "INSERT INTO " + getTableName() + " VALUES (";
107  unsigned int nParameters = m_keys.size() + 2;
108  for (unsigned int i = 0; i < nParameters - 1; i++) {
109  sql << ":" << i + 1 << ", ";
110  }
111  sql << ":" << nParameters << ")";
112  std::string sqls = sql.str();
113  if (m_debug) {
114  cout << m_className << "::writeDB: " << sqls << endl;
115  }
116  return sqls;
117 }
std::string m_className
Definition: LMFUnique.h:99
int i
Definition: DBlmapReader.cc:9
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
tuple cout
Definition: gather_cfg.py:121
virtual std::string getTableName() const
Definition: LMFDat.h:49
char m_debug
Definition: LMFUnique.h:100
std::string LMFDat::buildSelectSql ( int  logic_id = 0,
int  direction = 0 
)
protected

Definition at line 139 of file LMFDat.cc.

References _where, prof2calltree::count, gather_cfg::cout, getIovIdFieldName(), getLMFRunIOVID(), getTableName(), LMFUnique::m_className, LMFUnique::m_debug, and AlCaHLTBitMon_QueryRunRegistry::string.

139  {
140  // create the insert statement
141  // if logic_id = 0 select all channels for a given iov_id
142  std::stringstream sql;
143  int count = 1;
144  if (getLMFRunIOVID() > 0) {
145  if (_where.length() > 0) {
146  // check if this is an expert query. If so, add a WHERE clause
147  _where = " AND " + _where;
148  }
149  // in this case we are looking for all data collected during the same
150  // IOV. There can be many logic_ids per IOV.
151  sql << "SELECT * FROM CMS_ECAL_LASER_COND." << getTableName() << " WHERE "
152  << getIovIdFieldName() << " = " << getLMFRunIOVID()
153  << _where;
154  // the expert query must be specified each time the expert makes the query
155  // then empty it
156  _where = "";
157  } else {
158  // in this case we are looking for a specific logic_id whose
159  // data have been collected at a given time. There is only
160  // one record in this case.
161  std::string op = ">";
162  std::string order = "ASC";
163  if (direction < 0) {
164  op = "<";
165  order = "DESC";
166  }
167  sql << "SELECT * FROM (SELECT CMS_ECAL_LASER_COND."
168  << getTableName() << ".* FROM CMS_ECAL_LASER_COND."
169  << getTableName()
170  << " JOIN LMF_RUN_IOV ON "
171  << "LMF_RUN_IOV.LMF_IOV_ID = "
172  << getTableName() << "." << getIovIdFieldName() << " "
173  << "WHERE SUBRUN_START " << op << "= TO_DATE(:" << count;
174  count++;
175  sql << ", 'YYYY-MM-DD HH24:MI:SS') ORDER BY SUBRUN_START "
176  << order << ") WHERE ROWNUM <= 1";
177  }
178  if (logic_id > 0) {
179  sql << " AND LOGIC_ID = :" << count;
180  }
181  std::string sqls = sql.str();
182  if (m_debug) {
183  cout << m_className << "::buildSelectSqlDB: " << sqls << endl;
184  }
185  return sqls;
186 }
std::string m_className
Definition: LMFUnique.h:99
int getLMFRunIOVID()
Definition: LMFDat.cc:35
virtual std::string getIovIdFieldName() const
Definition: LMFDat.cc:119
std::string _where
Definition: LMFDat.h:159
tuple cout
Definition: gather_cfg.py:121
virtual std::string getTableName() const
Definition: LMFDat.h:49
char m_debug
Definition: LMFUnique.h:100
bool LMFDat::check ( void  )
protected

Definition at line 576 of file LMFDat.cc.

References getKeyTypes(), getTableName(), LMFUnique::m_className, m_Error, m_keys, m_type, and run_regression::ret.

Referenced by writeDB().

576  {
577  // check that everything has been correctly setup
578  bool ret = true;
579  m_Error = "";
580  // first of all we need to check that the class name has been set
581  if (m_className == "LMFUnique") {
582  m_Error = "class name not set ";
583  ret = false;
584  }
585  //then check that the table name has been set
586  if (getTableName() == "") {
587  m_Error += "table name not set ";
588  ret = false;
589  }
590  // fill key types if not yet done
591  if (m_type.size() != m_keys.size()) {
592  getKeyTypes();
593  if (m_type.size() != m_keys.size()) {
594  m_Error += "key size does not correspond to table definition";
595  ret = false;
596  }
597  }
598  return ret;
599 }
std::string m_className
Definition: LMFUnique.h:99
std::vector< std::string > m_type
Definition: LMFDat.h:150
void getKeyTypes()
Definition: LMFDat.cc:542
std::string m_Error
Definition: LMFDat.h:157
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
virtual std::string getTableName() const
Definition: LMFDat.h:49
void LMFDat::dump ( void  ) const
virtual

Reimplemented from LMFUnique.

Definition at line 68 of file LMFDat.cc.

References m_max.

Referenced by dump(), LMFCorrCoefDat::fetch(), and writeDB().

68  {
69  dump(0, m_max);
70 }
void dump() const
Definition: LMFDat.cc:68
int m_max
Definition: LMFDat.h:149
void LMFDat::dump ( int  n) const
virtual

Reimplemented from LMFUnique.

Definition at line 72 of file LMFDat.cc.

References dump(), and m_max.

72  {
73  dump(n, m_max);
74 }
void dump() const
Definition: LMFDat.cc:68
int m_max
Definition: LMFDat.h:149
void LMFDat::dump ( int  n,
int  max 
) const
virtual

Definition at line 76 of file LMFDat.cc.

References EnergyCorrector::c, gather_cfg::cout, LMFUnique::dump(), end, getReverseMap(), j, m_data, AlCaHLTBitMon_ParallelJobs::p, submit::rm, alignCSCRings::s, and x.

76  {
78  int s = m_data.size();
79  cout << "Stored data: " << s << endl;
80  if (max >= 0) {
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();
83  int c = 0;
84  std::map<unsigned int, std::string> rm = getReverseMap();
85  while ((p != end) && (c < max)) {
86  int id = p->first;
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++) {
91  if (j % 4 == 0) {
92  cout << endl << " ";
93  }
94  cout << rm[j] << ":" << x[j] << "\t";
95  }
96  cout << endl;
97  p++;
98  c++;
99  }
100  }
101 }
std::map< unsigned int, std::string > getReverseMap() const
Definition: LMFDat.cc:57
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
virtual void dump() const
Definition: LMFUnique.cc:112
string rm
Definition: submit.py:76
int j
Definition: DBlmapReader.cc:9
#define end
Definition: vmac.h:37
tuple cout
Definition: gather_cfg.py:121
Definition: DDAxes.h:10
void LMFDat::fetch ( )
throw (std::runtime_error
)

Definition at line 237 of file LMFDat.cc.

Referenced by LMFCorrCoefDat::fetch().

239 {
240  fetch(0);
241 }
void fetch()
Definition: LMFDat.cc:237
void LMFDat::fetch ( int  logic_id)
throw (std::runtime_error
)

Definition at line 243 of file LMFDat.cc.

References cond::persistency::fetch(), and NULL.

245 {
246  fetch(logic_id, NULL, 0);
247 }
#define NULL
Definition: scimark2.h:8
void fetch()
Definition: LMFDat.cc:237
void LMFDat::fetch ( int  logic_id,
const Tm tm 
)
throw (std::runtime_error
)

Definition at line 249 of file LMFDat.cc.

References cond::persistency::fetch().

251 {
252  fetch(logic_id, &tm, 1);
253 }
void fetch()
Definition: LMFDat.cc:237
void LMFDat::fetch ( int  logic_id,
const Tm timestamp,
int  dir 
)
throw (std::runtime_error
)

Definition at line 281 of file LMFDat.cc.

References DDVectorGetter::check(), prof2calltree::count, gather_cfg::cout, alignCSCRings::e, i, NULL, convertSQLiteXML::ok, AlCaHLTBitMon_QueryRunRegistry::string, cond::timestamp, and x.

283 {
284  bool ok = check();
285  if ((timestamp == NULL) && (getLMFRunIOVID() == 0)) {
286  throw(std::runtime_error(m_className + "::fetch: Cannot fetch data with "
287  "timestamp = 0 and LMFRunIOV = 0"));
288  }
289  if (ok && isValid()) {
290  if (m_debug) {
291  std::cout << "[LMFDat] This object is valid..." << std::endl;
292  }
293  try {
294  Statement * stmt = m_conn->createStatement();
295  std::string sql = buildSelectSql(logic_id, direction);
296  if (m_debug) {
297  std::cout << "[LMFDat] Executing query " << std::endl;
298  std::cout << " " << sql << std::endl << std::flush;
299  }
300  if (logic_id == 0) {
301  // get data for all crystals with a given timestamp
302  stmt->setPrefetchRowCount(10000);
303  }
304  stmt->setSQL(sql);
305  int count = 1;
306  if (logic_id > 0) {
307  if (timestamp != NULL) {
308  stmt->setString(count, timestamp->str());
309  count++;
310  }
311  stmt->setInt(count++, logic_id);
312  }
313  adjustParameters(count, sql, stmt);
314  ResultSet *rset = stmt->executeQuery();
315  std::vector<float> x;
316  int nData = m_keys.size();
317  x.reserve(nData);
318  while (rset->next() != 0) {
319  for (int i = 0; i < nData; i++) {
320  x.push_back(rset->getFloat(i + 3));
321  }
322  int id = rset->getInt(2);
323  if (timestamp != NULL) {
324  setInt(foreignKeyName(), rset->getInt(1));
325  }
326  this->setData(id, x);
327  x.clear();
328  }
329  stmt->setPrefetchRowCount(0);
330  m_conn->terminateStatement(stmt);
331  }
332  catch (oracle::occi::SQLException &e) {
333  throw(std::runtime_error(m_className + "::fetch: " + e.getMessage()));
334  }
335  m_ID = m_data.size();
336  }
337 }
std::string m_className
Definition: LMFUnique.h:99
int i
Definition: DBlmapReader.cc:9
LMFUnique & setInt(std::string key, int value)
Definition: LMFUnique.cc:33
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
void adjustParameters(int n, std::string &sql, Statement *stmt)
Definition: LMFDat.cc:255
#define NULL
Definition: scimark2.h:8
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
LMFDat & setData(int logic_id, const std::vector< float > &data)
Definition: LMFDat.h:55
bool check()
Definition: LMFDat.cc:576
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
virtual bool isValid()
Definition: LMFDat.cc:339
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
int getLMFRunIOVID()
Definition: LMFDat.cc:35
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
virtual std::string foreignKeyName() const
Definition: LMFDat.cc:31
std::string str() const
Definition: Tm.cc:89
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
tuple cout
Definition: gather_cfg.py:121
char m_debug
Definition: LMFUnique.h:100
std::string buildSelectSql(int logic_id=0, int direction=0)
Definition: LMFDat.cc:139
Definition: DDAxes.h:10
void LMFDat::fetch ( const EcalLogicID id,
const Tm tm 
)
throw (std::runtime_error
)

Definition at line 224 of file LMFDat.cc.

References cond::persistency::fetch().

226 {
227  fetch(id.getLogicID(), &tm, 1);
228 }
void fetch()
Definition: LMFDat.cc:237
void LMFDat::fetch ( const EcalLogicID id,
const Tm tm,
int  dir 
)
throw (std::runtime_error
)

Definition at line 230 of file LMFDat.cc.

References cond::persistency::fetch().

232 {
233  setInt(foreignKeyName(), 0); /* set the LMF_IOV_ID to undefined */
234  fetch(id.getLogicID(), &tm, direction);
235 }
LMFUnique & setInt(std::string key, int value)
Definition: LMFUnique.cc:33
virtual std::string foreignKeyName() const
Definition: LMFDat.cc:31
void fetch()
Definition: LMFDat.cc:237
void LMFDat::fetch ( const EcalLogicID id)
throw (std::runtime_error
)

Definition at line 218 of file LMFDat.cc.

References cond::persistency::fetch().

220 {
221  fetch(id.getLogicID());
222 }
void fetch()
Definition: LMFDat.cc:237
std::map< int, std::vector< float > > LMFDat::fetchData ( )
throw (std::runtime_error
)

Definition at line 352 of file LMFDat.cc.

References gather_cfg::cout, alignCSCRings::e, getIovIdFieldName(), getLMFRunIOVID(), getTableName(), i, LMFUnique::m_className, IDBObject::m_conn, m_data, LMFUnique::m_debug, alignCSCRings::s, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by writeDB().

354 {
355  // see if any of the data is already in the database
356  std::map<int, std::vector<float> > s = m_data;
357  std::string sql = "SELECT LOGIC_ID FROM CMS_ECAL_LASER_COND." +
358  getTableName() + " WHERE "
359  + getIovIdFieldName() + " = :1";
360  if (m_debug) {
361  cout << m_className << ":: candidate data items to be written = "
362  << s.size() << endl;
363  cout << m_className << " Executing " << sql;
364  cout << " where " << getIovIdFieldName() << " = "
365  << getLMFRunIOVID() << endl;
366  }
367  try {
368  Statement* stmt = m_conn->createStatement();
369  stmt->setSQL(sql);
370  stmt->setInt(1, getLMFRunIOVID());
371  stmt->setPrefetchRowCount(10000);
372  ResultSet* rset = stmt->executeQuery();
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) {
376  if (m_debug) {
377  cout << m_className << ":: checking " << rset->getInt(1) << endl
378  << std::flush;
379  }
380  i = s.find(rset->getInt(1));
381  if (i != e) {
382  s.erase(i);
383  }
384  }
385  stmt->setPrefetchRowCount(0);
386  m_conn->terminateStatement(stmt);
387  }
388  catch (oracle::occi::SQLException &e) {
389  throw(std::runtime_error(m_className + "::fetchData: "+e.getMessage()));
390  }
391  if (m_debug) {
392  cout << m_className << ":: data items to write = "
393  << s.size() << endl;
394  }
395  return s;
396 }
std::string m_className
Definition: LMFUnique.h:99
int i
Definition: DBlmapReader.cc:9
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
int getLMFRunIOVID()
Definition: LMFDat.cc:35
virtual std::string getIovIdFieldName() const
Definition: LMFDat.cc:119
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
tuple cout
Definition: gather_cfg.py:121
virtual std::string getTableName() const
Definition: LMFDat.h:49
char m_debug
Definition: LMFUnique.h:100
std::string LMFDat::foreignKeyName ( ) const
virtual

Reimplemented in LMFCorrCoefDatComponent.

Definition at line 31 of file LMFDat.cc.

Referenced by getLMFRunIOV(), getLMFRunIOVID(), isValid(), setLMFRunIOV(), and writeDB().

31  {
32  return "lmfRunIOV";
33 }
std::vector< float > LMFDat::getData ( int  id)

Definition at line 603 of file LMFDat.cc.

References m_data, and run_regression::ret.

603  {
604  std::vector<float> ret;
605  if (m_data.find(id) != m_data.end()) {
606  ret = m_data[id];
607  }
608  return ret;
609 }
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
std::vector< float > LMFDat::getData ( const EcalLogicID id)

Definition at line 615 of file LMFDat.cc.

References getData().

615  {
616  return getData(id.getLogicID());
617 }
std::map< int, std::vector< float > > getData()
Definition: LMFDat.cc:636
bool LMFDat::getData ( int  id,
std::vector< float > &  ret 
)

Definition at line 621 of file LMFDat.cc.

References m_data.

621  {
622  bool retval = false;
623  if (m_data.find(id) != m_data.end()) {
624  ret= m_data[id];
625  retval = true;
626  }
627  return retval;
628 }
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
bool LMFDat::getData ( const EcalLogicID id,
std::vector< float > &  ret 
)

Definition at line 630 of file LMFDat.cc.

References getData().

630  {
631  return getData(id.getLogicID(), ret);
632 }
std::map< int, std::vector< float > > getData()
Definition: LMFDat.cc:636
std::map< int, std::vector< float > > LMFDat::getData ( void  )

Definition at line 636 of file LMFDat.cc.

References m_data.

Referenced by LMFPrimDat::getAlpha(), LMFPrimDat::getAPDoverAM3(), LMFPrimDat::getAPDoverAMean(), LMFPrimDat::getAPDoverARMS(), LMFPrimDat::getAPDoverBM3(), LMFPrimDat::getAPDoverBMean(), LMFPrimDat::getAPDoverBRMS(), LMFPrimDat::getAPDoverPnM3(), LMFPrimDat::getAPDoverPnMean(), LMFPrimDat::getAPDoverPnRMS(), LMFPrimDat::getBeta(), LMFTestPulseConfigDat::getDACMGPA(), getData(), LMFClsDat::getENorm(), LMFRunDat::getEvents(), LMFLaserPulseDat::getFitMethod(), LMFCorrCoefDatComponent::getFlag(), LMFClsDat::getFlag(), LMFPrimDat::getFlag(), LMFPnPrimDat::getFlag(), LMFClsDat::getFlagNorm(), LMFClsDat::getLMFRefRunIOVID(), LMFLaserConfigDat::getLSRAttenuator(), LMFLaserConfigDat::getLSRCurrent(), LMFLaserConfigDat::getLSRDelay1(), LMFLaserConfigDat::getLSRDelay2(), LMFLaserConfigDat::getLSRPower(), LMFPrimDat::getM3(), LMFPnPrimDat::getM3(), LMFClsDat::getMean(), LMFPrimDat::getMean(), LMFPnPrimDat::getMean(), LMFLaserPulseDat::getMTQAmplification(), LMFLaserPulseDat::getMTQFW20(), LMFLaserPulseDat::getMTQFW80(), LMFLaserPulseDat::getMTQFWHM(), LMFLaserPulseDat::getMTQRise(), LMFLaserPulseDat::getMTQSliding(), LMFLaserPulseDat::getMTQTime(), LMFClsDat::getNevt(), LMFClsDat::getNorm(), LMFCorrCoefDatComponent::getParameterErrors(), LMFCorrCoefDatComponent::getParameters(), LMFPnPrimDat::getPNAoverBM3(), LMFPnPrimDat::getPNAoverBMean(), LMFPnPrimDat::getPNAoverBRMS(), LMFTestPulseConfigDat::getPNGain(), LMFLaserConfigDat::getPNGain(), LMFTestPulseConfigDat::getPNVinj(), LMFRunDat::getQualityFlag(), LMFClsDat::getRMS(), LMFPrimDat::getRMS(), LMFPnPrimDat::getRMS(), LMFCorrCoefDatComponent::getSeqID(), LMFCorrCoefDatComponent::getSequence(), LMFPnPrimDat::getShapeCor(), LMFPrimDat::getShapeCorr(), LMFTestPulseConfigDat::getVFEGain(), LMFLaserConfigDat::getVFEGain(), LMFColoredTable::getVmax(), LMFColoredTable::getVmin(), LMFLaserConfigDat::getWavelength(), and operator[]().

636  {
637  return m_data;
638 }
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
float LMFDat::getData ( int  id,
unsigned int  k 
)

Definition at line 642 of file LMFDat.cc.

References relval_steps::k, and m_data.

642  {
643  return m_data[id][k];
644 }
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
float LMFDat::getData ( const EcalLogicID id,
unsigned int  k 
)

Definition at line 646 of file LMFDat.cc.

References getData().

646  {
647  return getData(id.getLogicID(), k);
648 }
std::map< int, std::vector< float > > getData()
Definition: LMFDat.cc:636
float LMFDat::getData ( const EcalLogicID id,
const std::string &  key 
)

Definition at line 650 of file LMFDat.cc.

References getData(), and m_keys.

650  {
651  return getData(id.getLogicID(), m_keys[key]);
652 }
std::map< int, std::vector< float > > getData()
Definition: LMFDat.cc:636
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
float LMFDat::getData ( int  id,
const std::string &  key 
)

Definition at line 654 of file LMFDat.cc.

References getData(), and m_keys.

654  {
655  return getData(id, m_keys[key]);
656 }
std::map< int, std::vector< float > > getData()
Definition: LMFDat.cc:636
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
bool LMFDat::getData ( int  id,
unsigned int  k,
float &  ret 
)

Definition at line 660 of file LMFDat.cc.

References getData(), relval_steps::k, and findQualityFiles::v.

660  {
661  bool retval = false;
662  std::vector<float> v;
663  retval = getData(id, v);
664  if ((retval) && (v.size() > k)) {
665  ret= v[k];
666  retval = true;
667  } else {
668  retval = false;
669  }
670  return retval;
671 }
std::map< int, std::vector< float > > getData()
Definition: LMFDat.cc:636
bool LMFDat::getData ( const EcalLogicID id,
unsigned int  k,
float &  ret 
)

Definition at line 673 of file LMFDat.cc.

References getData().

673  {
674  return getData(id.getLogicID(), k, ret);
675 }
std::map< int, std::vector< float > > getData()
Definition: LMFDat.cc:636
bool LMFDat::getData ( int  id,
const std::string &  key,
float &  ret 
)

Definition at line 677 of file LMFDat.cc.

References getData(), and m_keys.

677  {
678  bool retval = false;
679  if (m_keys.find(key) != m_keys.end()) {
680  retval = getData(id, m_keys[key], ret);
681  }
682  return retval;
683 }
std::map< int, std::vector< float > > getData()
Definition: LMFDat.cc:636
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
bool LMFDat::getData ( const EcalLogicID id,
const std::string &  key,
float &  ret 
)

Definition at line 685 of file LMFDat.cc.

References getData().

686 {
687  return getData(id.getLogicID(), key, ret);
688 }
std::map< int, std::vector< float > > getData()
Definition: LMFDat.cc:636
std::string LMFDat::getIovIdFieldName ( ) const
virtual

Reimplemented in LMFCorrCoefDatComponent.

Definition at line 119 of file LMFDat.cc.

Referenced by buildSelectSql(), fetchData(), and getKeyTypes().

119  {
120  return "LMF_IOV_ID";
121 }
std::list<std::string> LMFDat::getKeyList ( )
inline

Definition at line 113 of file LMFDat.h.

References alignCSCRings::e, i, prof2calltree::l, and m_keys.

113  {
114  std::list<std::string> l;
115  std::map<std::string, unsigned int>::const_iterator i = m_keys.begin();
116  std::map<std::string, unsigned int>::const_iterator e = m_keys.end();
117  while (i != e) {
118  l.push_back(i->first);
119  i++;
120  }
121  return l;
122  }
int i
Definition: DBlmapReader.cc:9
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
std::map<std::string, unsigned int> LMFDat::getKeys ( )
inline

Definition at line 110 of file LMFDat.h.

References m_keys.

110  {
111  return m_keys;
112  }
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
void LMFDat::getKeyTypes ( )
throw (std::runtime_error
)
protected

Definition at line 542 of file LMFDat.cc.

References alignCSCRings::e, getIovIdFieldName(), getTableName(), i, LMFUnique::m_className, IDBObject::m_conn, m_keys, m_type, mergeVDriftHistosByStation::name, AlCaHLTBitMon_QueryRunRegistry::string, and edmStreamStallGrapher::t.

Referenced by check().

544 {
545  m_type.reserve(m_keys.size());
546  for (unsigned int i = 0; i < m_keys.size(); i++) {
547  m_type.push_back("");
548  }
549  // get the description of the table
550  std::string sql = "";
551  try {
552  Statement *stmt = m_conn->createStatement();
553  sql = "SELECT * FROM TABLE(CMS_ECAL_LASER_COND.LMF_TAB_COLS(:1, :2))";
554  /*
555  sql = "SELECT COLUMN_NAME, DATA_TYPE FROM "
556  "USER_TAB_COLS WHERE TABLE_NAME = '" + getTableName() + "' "
557  "AND COLUMN_NAME != '" + getIovIdFieldName() + "' AND COLUMN_NAME != "
558  "'LOGIC_ID'";
559  */
560  stmt->setSQL(sql);
561  stmt->setString(1, getTableName());
562  stmt->setString(2, getIovIdFieldName());
563  ResultSet *rset = stmt->executeQuery();
564  while (rset->next() != 0) {
565  std::string name = rset->getString(1);
566  std::string t = rset->getString(2);
567  m_type[m_keys[name]] = t;
568  }
569  m_conn->terminateStatement(stmt);
570  } catch (oracle::occi::SQLException &e) {
571  throw(std::runtime_error(m_className + "::getKeyTypes: " + e.getMessage() +
572  " [" + sql + "]"));
573  }
574 }
std::string m_className
Definition: LMFUnique.h:99
int i
Definition: DBlmapReader.cc:9
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
std::vector< std::string > m_type
Definition: LMFDat.h:150
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
virtual std::string getIovIdFieldName() const
Definition: LMFDat.cc:119
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:26
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
virtual std::string getTableName() const
Definition: LMFDat.h:49
LMFRunIOV LMFDat::getLMFRunIOV ( ) const
inline

Definition at line 36 of file LMFDat.h.

References foreignKeyName(), LMFUnique::getInt(), IDBObject::m_conn, IDBObject::m_env, and LMFUnique::setByID().

Referenced by getSubrunStart().

36  {
37  LMFRunIOV runiov(m_env, m_conn);
38  runiov.setByID(getInt(foreignKeyName()));
39  return runiov;
40  }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
int getInt(std::string fieldname) const
Definition: LMFUnique.cc:203
virtual std::string foreignKeyName() const
Definition: LMFDat.cc:31
int LMFDat::getLMFRunIOVID ( )

Definition at line 35 of file LMFDat.cc.

References LMFUnique::fetchID(), foreignKeyName(), LMFUnique::getInt(), i, o2o::iov, LMFUnique::m_foreignKeys, NULL, and LMFUnique::setInt().

Referenced by buildSelectSql(), and fetchData().

35  {
36  int id = getInt(foreignKeyName());
37  if (id == 0) {
38  // try to get it from the list of foreign keys
39  std::map<std::string, LMFUnique*>::iterator i =
41  if (i != m_foreignKeys.end()) {
42  LMFRunIOV *iov = (LMFRunIOV*)(i->second);
43  if (iov != NULL) {
44  id = iov->fetchID();
45  setInt(foreignKeyName(), id);
46  }
47  }
48  }
49  return id;
50 }
int i
Definition: DBlmapReader.cc:9
LMFUnique & setInt(std::string key, int value)
Definition: LMFUnique.cc:33
#define NULL
Definition: scimark2.h:8
int getInt(std::string fieldname) const
Definition: LMFUnique.cc:203
int fetchID()
Definition: LMFUnique.cc:213
tuple iov
Definition: o2o.py:307
std::map< std::string, LMFUnique * > m_foreignKeys
Definition: LMFUnique.h:106
virtual std::string foreignKeyName() const
Definition: LMFDat.cc:31
std::list<int> LMFDat::getLogicIds ( )
inline

Definition at line 99 of file LMFDat.h.

References alignCSCRings::e, i, prof2calltree::l, and m_data.

99  {
100  std::list<int> l;
101  std::map<int, std::vector<float> >::const_iterator i = m_data.begin();
102  std::map<int, std::vector<float> >::const_iterator e = m_data.end();
103  while (i != e) {
104  l.push_back(i->first);
105  i++;
106  }
107  return l;
108  }
int i
Definition: DBlmapReader.cc:9
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
void LMFDat::getNeighbour ( LMFDat dat,
int  which 
)
throw (std::runtime_error
)
protected

Definition at line 200 of file LMFDat.cc.

References hcal_timing_source_file_cfg::dump, and eostools::which().

202 {
203  // there should be just one record in this case
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);
211  } else {
212  dump();
213  throw(std::runtime_error(m_className + "::getPrevious: Too many LOGIC_IDs in "
214  "this object"));
215  }
216 }
std::string m_className
Definition: LMFUnique.h:99
def which
Definition: eostools.py:333
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
void dump() const
Definition: LMFDat.cc:68
int m_max
Definition: LMFDat.h:149
Tm getSubrunStart() const
Definition: LMFDat.h:42
LMFDat & setMaxDataToDump(int n)
Definition: LMFDat.cc:52
oracle::occi::Connection * getConn() const
Definition: IDBObject.h:32
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
oracle::occi::Environment * getEnv() const
Definition: IDBObject.h:29
Definition: Tm.h:13
void fetch()
Definition: LMFDat.cc:237
void LMFDat::getNext ( LMFDat dat)
throw (std::runtime_error
)

Definition at line 194 of file LMFDat.cc.

196 {
197  getNeighbour(dat, +1);
198 }
void getNeighbour(LMFDat *dat, int which)
Definition: LMFDat.cc:200
void LMFDat::getPrevious ( LMFDat dat)
throw (std::runtime_error
)

Definition at line 188 of file LMFDat.cc.

190 {
191  getNeighbour(dat, -1);
192 }
void getNeighbour(LMFDat *dat, int which)
Definition: LMFDat.cc:200
std::map< unsigned int, std::string > LMFDat::getReverseMap ( ) const

Definition at line 57 of file LMFDat.cc.

References alignCSCRings::e, i, contentValuesFiles::m, and m_keys.

Referenced by dump().

57  {
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();
61  while (i != e) {
62  m[i->second] = i->first;
63  i++;
64  }
65  return m;
66 }
int i
Definition: DBlmapReader.cc:9
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
Tm LMFDat::getSubrunStart ( ) const
inline

Definition at line 42 of file LMFDat.h.

References getLMFRunIOV(), and LMFRunIOV::getSubRunStart().

42  {
43  return getLMFRunIOV().getSubRunStart();
44  }
Tm getSubRunStart() const
Definition: LMFRunIOV.cc:161
LMFRunIOV getLMFRunIOV() const
Definition: LMFDat.h:36
virtual std::string LMFDat::getTableName ( ) const
inlinevirtual

Reimplemented in LMFCorrCoefDatComponent, LMFPnPrimDat, LMFClsDat, LMFPrimDat, LMFLaserPulseDat, and LMFColoredTable.

Definition at line 49 of file LMFDat.h.

References m_tableName.

Referenced by buildInsertSql(), buildSelectSql(), check(), fetchData(), and getKeyTypes().

49  {
50  return m_tableName;
51  }
std::string m_tableName
Definition: LMFDat.h:156
bool LMFDat::isValid ( void  )
virtual

Reimplemented from LMFUnique.

Reimplemented in LMFPrimDat, LMFPnPrimDat, LMFLaserPulseDat, and LMFClsDat.

Definition at line 339 of file LMFDat.cc.

References gather_cfg::cout, foreignKeyName(), LMFUnique::m_className, LMFUnique::m_debug, m_Error, LMFUnique::m_foreignKeys, and run_regression::ret.

Referenced by LMFLaserPulseDat::isValid(), core.AutoHandle.AutoHandle::ReallyLoad(), and writeDB().

339  {
340  bool ret = true;
341  if (m_foreignKeys.find(foreignKeyName()) == m_foreignKeys.end()) {
342  ret = false;
343  m_Error += " Can't find lmfRunIOV within foreign keys.";
344  if (m_debug) {
345  cout << m_className << ": Foreign keys map size: " << m_foreignKeys.size()
346  << endl;
347  }
348  }
349  return ret;
350 }
std::string m_className
Definition: LMFUnique.h:99
std::string m_Error
Definition: LMFDat.h:157
std::map< std::string, LMFUnique * > m_foreignKeys
Definition: LMFUnique.h:106
virtual std::string foreignKeyName() const
Definition: LMFDat.cc:31
tuple cout
Definition: gather_cfg.py:121
char m_debug
Definition: LMFUnique.h:100
std::vector< float > LMFDat::operator[] ( int  id)

Definition at line 611 of file LMFDat.cc.

References getData().

611  {
612  return getData(id);
613 }
std::map< int, std::vector< float > > getData()
Definition: LMFDat.cc:636
LMFDat& LMFDat::setData ( int  logic_id,
const std::vector< float > &  data 
)
inline

Definition at line 55 of file LMFDat.h.

References data, and m_data.

Referenced by LMFRunDat::Data(), LMFPrimDat::setAlpha(), LMFPrimDat::setAPDoverAM3(), LMFPrimDat::setAPDoverAMean(), LMFPrimDat::setAPDoverARMS(), LMFPrimDat::setAPDoverBM3(), LMFPrimDat::setAPDoverBMean(), LMFPrimDat::setAPDoverBRMS(), LMFPrimDat::setAPDoverPnM3(), LMFPrimDat::setAPDoverPnMean(), LMFPrimDat::setAPDoverPnRMS(), LMFPrimDat::setBeta(), LMFTestPulseConfigDat::setDACMGPA(), LMFRunDat::setData(), LMFTestPulseConfigDat::setData(), LMFLaserConfigDat::setData(), LMFClsDat::setENorm(), LMFRunDat::setEvents(), LMFLaserPulseDat::setFitMethod(), LMFCorrCoefDatComponent::setFlag(), LMFPrimDat::setFlag(), LMFClsDat::setFlag(), LMFPnPrimDat::setFlag(), LMFClsDat::setFlagNorm(), LMFClsDat::setLMFRefRunIOVID(), LMFLaserConfigDat::setLSRAttenuator(), LMFLaserConfigDat::setLSRCurrent(), LMFLaserConfigDat::setLSRDelay1(), LMFLaserConfigDat::setLSRDelay2(), LMFLaserConfigDat::setLSRPower(), LMFPrimDat::setM3(), LMFPnPrimDat::setM3(), LMFPrimDat::setMean(), LMFPnPrimDat::setMean(), LMFClsDat::setMean(), LMFLaserPulseDat::setMTQAmplification(), LMFLaserPulseDat::setMTQFW20(), LMFLaserPulseDat::setMTQFW80(), LMFLaserPulseDat::setMTQFWHM(), LMFLaserPulseDat::setMTQRise(), LMFLaserPulseDat::setMTQSliding(), LMFLaserPulseDat::setMTQTime(), LMFClsDat::setNevt(), LMFClsDat::setNorm(), LMFCorrCoefDatComponent::setP123(), LMFCorrCoefDatComponent::setP123Errors(), LMFPnPrimDat::setPNAoverBM3(), LMFPnPrimDat::setPNAoverBMean(), LMFPnPrimDat::setPNAoverBRMS(), LMFTestPulseConfigDat::setPNGain(), LMFLaserConfigDat::setPNGain(), LMFTestPulseConfigDat::setPNVinj(), LMFRunDat::setQualityFlag(), LMFPrimDat::setRMS(), LMFPnPrimDat::setRMS(), LMFClsDat::setRMS(), LMFCorrCoefDatComponent::setSequence(), LMFPnPrimDat::setShapeCorr(), LMFPrimDat::setShapeCorr(), LMFColoredTable::setVersions(), LMFTestPulseConfigDat::setVFEGain(), LMFLaserConfigDat::setVFEGain(), LMFColoredTable::setVmax(), LMFColoredTable::setVmin(), and LMFLaserConfigDat::setWavelength().

55  {
56  m_data[logic_id] = data;
57  return *this;
58  }
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
LMFDat& LMFDat::setData ( const EcalLogicID logic_id,
const std::vector< float > &  data 
)
inline

Definition at line 59 of file LMFDat.h.

References data, EcalLogicID::getLogicID(), and m_data.

60  {
61  m_data[logic_id.getLogicID()] = data;
62  return *this;
63  }
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
int getLogicID() const
Definition: EcalLogicID.cc:41
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
LMFDat& LMFDat::setData ( const EcalLogicID logic_id,
const std::string &  key,
float  v 
)
inline

Definition at line 64 of file LMFDat.h.

References EcalLogicID::getLogicID(), relval_steps::key, m_data, m_keys, and findQualityFiles::v.

65  {
66  int id = logic_id.getLogicID();
67  m_data[id].resize(m_keys.size());
68  m_data[id][m_keys[key]] = v;
69  return *this;
70  }
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
int getLogicID() const
Definition: EcalLogicID.cc:41
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
LMFDat& LMFDat::setLMFRunIOV ( const LMFRunIOV iov)
inline

Definition at line 31 of file LMFDat.h.

References LMFUnique::attach(), foreignKeyName(), LMFUnique::getID(), and LMFUnique::setInt().

31  {
32  setInt(foreignKeyName(), iov.getID());
33  attach(foreignKeyName(), (LMFUnique*)&iov);
34  return *this;
35  }
LMFUnique & setInt(std::string key, int value)
Definition: LMFUnique.cc:33
int getID() const
Definition: LMFUnique.h:52
virtual std::string foreignKeyName() const
Definition: LMFDat.cc:31
void attach(std::string name, LMFUnique *u)
Definition: LMFUnique.cc:50
LMFDat & LMFDat::setMaxDataToDump ( int  n)

Definition at line 52 of file LMFDat.cc.

References m_max, and gen::n.

Referenced by writeDB().

52  {
53  m_max = n;
54  return *this;
55 }
int m_max
Definition: LMFDat.h:149
void LMFDat::setWhereClause ( std::string  w)

Definition at line 123 of file LMFDat.cc.

References _where.

123  {
124  // to be used by experts to restrict the results of a query
125  _where = where;
126 }
std::string _where
Definition: LMFDat.h:159
void LMFDat::setWhereClause ( std::string  w,
const std::vector< std::string > &  p 
)

Definition at line 128 of file LMFDat.cc.

References _where, _wherePars, and Parameters::parameters.

129  {
130  // to be used by experts to restrict the results of a query
131  // in this case the where clause can contains positional parameter,
132  // identified as :/I, :/S, :/F for, respectively, integer, string or
133  // float parameters. The parameters are all passed as strings
134  // in parameters
136  _where = where;
137 }
std::vector< std::string > _wherePars
Definition: LMFDat.h:160
dictionary parameters
Definition: Parameters.py:2
std::string _where
Definition: LMFDat.h:159
int LMFDat::size ( void  ) const
inline

Definition at line 71 of file LMFDat.h.

References m_data.

Referenced by writeDB().

71 { return m_data.size(); }
std::map< int, std::vector< float > > m_data
Definition: LMFDat.h:153
int LMFDat::writeDB ( )
throw (std::runtime_error
)
protectedvirtual

Reimplemented from LMFUnique.

Definition at line 398 of file LMFDat.cc.

References b, buildInsertSql(), EnergyCorrector::c, check(), IDBObject::checkConnection(), gather_cfg::cout, LMFUnique::debug(), dump(), alignCSCRings::e, fetchData(), foreignKeyName(), LMFUnique::getID(), i, isValid(), relval_steps::k, LMFUnique::m_className, IDBObject::m_conn, LMFUnique::m_debug, m_Error, LMFUnique::m_foreignKeys, m_keys, m_max, m_type, convertSQLiteXML::ok, run_regression::ret, setMaxDataToDump(), size(), AlCaHLTBitMon_QueryRunRegistry::string, LMFUnique::writeForeignKeys(), and x.

Referenced by LMFCorrCoefDatComponent::writeDB(), and LMFColoredTable::writeDB().

400 {
401  // first of all check if data already present
402  if (m_debug) {
403  cout << m_className << ": Writing foreign keys" << endl;
404  }
406  if (m_debug) {
407  cout << m_className << ": Foreign keys written" << endl;
408  }
409  // write data on the database
410  int ret = 0;
411  std::map<int, std::vector<float> > data2write = fetchData();
412  if (data2write.size() > 0) {
413  this->checkConnection();
414  bool ok = check();
415  // write
416  if (ok && isValid()) {
417  std::list<dvoid *> bufPointers;
418  int nParameters = m_keys.size();
419  int nData = data2write.size();
420  if (m_debug) {
421  cout << m_className << ": # data items = " << nData << endl;
422  cout << m_className << ": # parameters = " << nParameters << endl;
423  }
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;
432  try {
433  Statement * stmt = m_conn->createStatement();
434  std::string sql = buildInsertSql();
435  stmt->setSQL(sql);
436  // build the array of the size of each column
437  for (int i = 0; i < nData; i++) {
438  intSize[i] = sizeof(int);
439  floatSize[i] = sizeof(int);
440  }
441  // build the data array for first column: the same run iov id
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;
448  }
449  stmt->setDataBuffer(1, (dvoid*)iovid_vec, oracle::occi::OCCIINT,
450  sizeof(iovid_vec[0]), intSize);
451  // build the data array for second column: the logic ids
452  int c = 0;
453  while (b != e) {
454  int id = b->first;
455  logicid_vec[c++] = id;
456  b++;
457  }
458  stmt->setDataBuffer(2, (dvoid*)logicid_vec, oracle::occi::OCCIINT,
459  sizeof(logicid_vec[0]), intSize);
460  // for each column build the data array
461  oracle::occi::Type type = oracle::occi::OCCIFLOAT;
462  for (int i = 0; i < nParameters; i++) {
463  b = data2write.begin();
464  // loop on all logic ids
465  c = 0;
466  while (b != e) {
467  std::vector<float> x = b->second;
468  if (m_type[i] == "INT") {
469  intArray[c] = (int)rint(x[i]);
470  } else if ((m_type[i] == "FLOAT") || (m_type[i] == "NUMBER")) {
471  floatArray[c] = x[i];
472  } else {
473  throw(std::runtime_error("ERROR: LMFDat::writeDB: unsupported type"));
474  }
475  c++;
476  b++;
477  }
478  // copy data into a "permanent" buffer
479  dvoid * buffer;
480  type = oracle::occi::OCCIINT;
481  ub2 *sizeArray = intSize;
482  int size = sizeof(intArray[0]);
483  if ((m_type[i] == "FLOAT") || (m_type[i] == "NUMBER")) {
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]);
489  } else {
490  buffer = (dvoid *)malloc(sizeof(int)*nData);
491  memcpy(buffer, intArray, intTotalSize);
492  }
493  bufPointers.push_back(buffer);
494  if (m_debug) {
495  for (int k = 0; ((k < nData) && (k < m_max)); k++) {
496  cout << m_className << ": === Index=== " << k << endl;
497  cout << m_className << ": RUN_IOV_ID = " << iovid_vec[k] << endl;
498  cout << m_className << ": LOGIC_ID = " << logicid_vec[k] << endl;
499  cout << m_className << ": FIELD " << i << ": "
500  << ((float *)(buffer))[k] << endl;
501  }
502  }
503  stmt->setDataBuffer(i + 3, buffer, type, size, sizeArray);
504  }
505  stmt->executeArrayUpdate(nData);
506  delete [] intArray;
507  delete [] floatArray;
508  delete [] intSize;
509  delete [] floatSize;
510  delete [] logicid_vec;
511  delete [] iovid_vec;
512  std::list<dvoid *>::const_iterator bi = bufPointers.begin();
513  std::list<dvoid *>::const_iterator be = bufPointers.end();
514  while (bi != be) {
515  free(*bi);
516  bi++;
517  }
518  m_conn->commit();
519  m_conn->terminateStatement(stmt);
520  ret = nData;
521  } catch (oracle::occi::SQLException &e) {
522  debug();
523  setMaxDataToDump(nData);
524  // get the Foreign Key
526  int iov_id = runiov->getID();
527  std::cout << "==== This object refers to IOV " << iov_id << std::endl;
528  dump();
529  m_conn->rollback();
530  throw(std::runtime_error(m_className + "::writeDB: " +
531  e.getMessage()));
532  }
533  } else {
534  cout << m_className << "::writeDB: Cannot write because " <<
535  m_Error << endl;
536  dump();
537  }
538  }
539  return ret;
540 }
std::map< int, std::vector< float > > fetchData()
Definition: LMFDat.cc:352
std::string m_className
Definition: LMFUnique.h:99
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
int getID() const
Definition: LMFUnique.h:52
std::string buildInsertSql()
Definition: LMFDat.cc:103
std::vector< std::string > m_type
Definition: LMFDat.h:150
int size() const
Definition: LMFDat.h:71
bool check()
Definition: LMFDat.cc:576
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:27
virtual int writeForeignKeys()
Definition: LMFUnique.cc:323
void dump() const
Definition: LMFDat.cc:68
virtual bool isValid()
Definition: LMFDat.cc:339
int m_max
Definition: LMFDat.h:149
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
std::string m_Error
Definition: LMFDat.h:157
std::map< std::string, LMFUnique * > m_foreignKeys
Definition: LMFUnique.h:106
LMFDat & setMaxDataToDump(int n)
Definition: LMFDat.cc:52
double b
Definition: hdecay.h:120
virtual std::string foreignKeyName() const
Definition: LMFDat.cc:31
std::map< std::string, unsigned int > m_keys
Definition: LMFDat.h:155
tuple cout
Definition: gather_cfg.py:121
char m_debug
Definition: LMFUnique.h:100
Definition: DDAxes.h:10
void debug()
Definition: LMFUnique.h:68
void checkConnection() const
Definition: IDBObject.h:41

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 21 of file LMFDat.h.

Member Data Documentation

std::string LMFDat::_where
protected

Definition at line 159 of file LMFDat.h.

Referenced by buildSelectSql(), LMFDat(), and setWhereClause().

std::vector<std::string> LMFDat::_wherePars
protected

Definition at line 160 of file LMFDat.h.

Referenced by adjustParameters(), LMFDat(), and setWhereClause().

std::map<int, std::vector<float> > LMFDat::m_data
protected
std::string LMFDat::m_Error
protected
std::map<std::string, unsigned int> LMFDat::m_keys
protected
int LMFDat::m_max
protected

Definition at line 149 of file LMFDat.h.

Referenced by dump(), LMFDat(), setMaxDataToDump(), and writeDB().

std::string LMFDat::m_tableName
protected
std::vector<std::string> LMFDat::m_type
protected