CMS 3D CMS Logo

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

#include <LMFUnique.h>

Inheritance diagram for LMFUnique:
IUniqueDBObject IDBObject LMFColor LMFDat LMFIOV LMFLmrSubIOV LMFPrimVers LMFRunIOV LMFRunTag LMFSeqDat LMFTrigType

Public Types

typedef oracle::occi::ResultSet ResultSet
 
typedef oracle::occi::Statement Statement
 

Public Member Functions

void attach (std::string name, LMFUnique *u)
 
void debug ()
 
virtual void dump () const
 
virtual void dump (int n) const
 
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 (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

virtual void setClassName (std::string s)
 
virtual int writeDB () throw (std::runtime_error)
 
virtual int writeForeignKeys () throw (std::runtime_error)
 
- Protected Member Functions inherited from IDBObject
void checkConnection () const throw (std::runtime_error)
 

Protected Attributes

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
 

Private Member Functions

virtual LMFUniquecreateObject () const
 
virtual std::string fetchAllSql (Statement *stmt) const
 
virtual std::string fetchIdSql (Statement *stmt)
 
virtual void fetchParentIDs ()
 
virtual void getParameters (ResultSet *rset)
 
virtual std::string setByIDSql (Statement *stmt, int id)
 
virtual std::string writeDBSql (Statement *stmt)
 

Friends

class EcalCondDBInterface
 

Additional Inherited Members

- Static Public Attributes inherited from IDBObject
static int const ECALDB_NROWS =1024
 

Detailed Description

Definition at line 17 of file LMFUnique.h.

Member Typedef Documentation

typedef oracle::occi::ResultSet LMFUnique::ResultSet

Definition at line 19 of file LMFUnique.h.

typedef oracle::occi::Statement LMFUnique::Statement

Definition at line 20 of file LMFUnique.h.

Constructor & Destructor Documentation

LMFUnique::LMFUnique ( )
inline

Definition at line 23 of file LMFUnique.h.

References _profiling, IDBObject::m_conn, IDBObject::m_env, IUniqueDBObject::m_ID, nodebug(), NULL, and setClassName().

23  {
24  _profiling = false;
25  m_env = NULL;
26  m_conn = NULL;
27  m_ID = 0;
28  setClassName("LMFUnique"); nodebug();
29  }
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
void nodebug()
Definition: LMFUnique.h:68
bool _profiling
Definition: LMFUnique.h:106
virtual void setClassName(std::string s)
Definition: LMFUnique.h:96
#define NULL
Definition: scimark2.h:8
LMFUnique::LMFUnique ( oracle::occi::Environment *  env,
oracle::occi::Connection *  conn 
)
inline

Definition at line 30 of file LMFUnique.h.

References _profiling, IUniqueDBObject::m_ID, nodebug(), setClassName(), and IDBObject::setConnection().

31  {
32  _profiling = false;
33  m_ID = 0;
34  setClassName("LMFUnique"); nodebug();
35  setConnection(env, conn);
36  }
void nodebug()
Definition: LMFUnique.h:68
bool _profiling
Definition: LMFUnique.h:106
virtual void setClassName(std::string s)
Definition: LMFUnique.h:96
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
LMFUnique::LMFUnique ( EcalDBConnection c)
inline

Definition at line 37 of file LMFUnique.h.

References _profiling, EcalDBConnection::getConn(), EcalDBConnection::getEnv(), IUniqueDBObject::m_ID, nodebug(), setClassName(), and IDBObject::setConnection().

37  {
38  _profiling = false;
39  m_ID = 0;
40  setClassName("LMFUnique"); nodebug();
41  setConnection(c->getEnv(), c->getConn());
42  }
void nodebug()
Definition: LMFUnique.h:68
bool _profiling
Definition: LMFUnique.h:106
virtual void setClassName(std::string s)
Definition: LMFUnique.h:96
oracle::occi::Environment * getEnv() const
oracle::occi::Connection * getConn() const
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
LMFUnique::~LMFUnique ( )
virtual

Definition at line 7 of file LMFUnique.cc.

7  {
8 }

Member Function Documentation

void LMFUnique::attach ( std::string  name,
LMFUnique u 
)

Definition at line 50 of file LMFUnique.cc.

References i, and mergeVDriftHistosByStation::name.

Referenced by LMFCorrCoefDatComponent::setLMFLmrSubIOV(), LMFDat::setLMFRunIOV(), and LMFRunIOV::setSequence().

50  {
51  std::map<std::string, LMFUnique *>::const_iterator i =
52  m_foreignKeys.find(name);
53  if (i != m_foreignKeys.end()) {
54  if (i->second != u) {
55  m_foreignKeys[name] = u;
56  m_ID = 0;
57  }
58  } else {
59  m_foreignKeys[name] = u;
60  m_ID = 0;
61  }
62 }
int i
Definition: DBlmapReader.cc:9
std::map< std::string, LMFUnique * > m_foreignKeys
Definition: LMFUnique.h:105
LMFUnique * LMFUnique::createObject ( ) const
privatevirtual

Reimplemented in LMFColor, LMFRunTag, LMFPrimVers, LMFIOV, LMFTrigType, LMFCorrVers, and LMFSeqVers.

Definition at line 183 of file LMFUnique.cc.

References NULL.

183  {
184  /* this method should return a pointer to a newly created object */
185  return NULL;
186 }
#define NULL
Definition: scimark2.h:8
void LMFUnique::debug ( )
inline

Definition at line 67 of file LMFUnique.h.

References m_debug.

Referenced by LMFCorrCoefDat::fetch(), fetchAll(), LMFCorrCoefDat::fetchBetween(), and LMFDat::writeDB().

67 { m_debug = 1; }
char m_debug
Definition: LMFUnique.h:99
void LMFUnique::dump ( void  ) const
virtual

Reimplemented in LMFDat, LMFRunIOV, and LMFIOV.

Definition at line 106 of file LMFUnique.cc.

References hcal_timing_source_file_cfg::dump.

Referenced by LMFRunIOV::dump(), LMFDat::dump(), LMFCorrCoefDat::fetch(), fetchAll(), and LMFSeqDat::writeDBSql().

106  {
107  dump(0);
108 }
virtual void dump() const
Definition: LMFUnique.cc:106
void LMFUnique::dump ( int  n) const
virtual

Reimplemented in LMFDat.

Definition at line 110 of file LMFUnique.cc.

References gather_cfg::cout, and combine::key.

110  {
111  /*
112  This method is used to dump the content of an object
113  Indent data if the object is contained inside another object
114  */
115  std::string m_indent = "";
116  std::string m_trail = "";
117  m_trail.resize(70 - 31 - n * 2, '#');
118  m_indent.resize(n*2, ' ');
119  m_indent += "|";
120  // start of object
121  cout << m_indent << "#################" << setw(15) << m_className
122  << " " << m_trail << endl;
123  cout << m_indent << "Address: " << this << endl;
124  cout << m_indent << "Connection params : " << m_env << ", " << m_conn << endl;
125  // object ID in the DB
126  cout << m_indent << "ID" << setw(18) << ": " << m_ID;
127  if (m_ID == 0) {
128  cout << " *** NULL ID ***";
129  }
130  if (!isValid()) {
131  cout << " INVALID ***";
132  }
133  cout << endl;
134  // iterate over string fields
135  std::map<std::string, std::string>::const_iterator is =
136  m_stringFields.begin();
137  std::map<std::string, std::string>::const_iterator es =
138  m_stringFields.end();
139  while (is != es) {
140  std::string key = is->first;
141  cout << m_indent << key << setw(20 - key.length()) << ": " << is->second
142  << endl;
143  is++;
144  }
145  // iterate over integer fields
146  std::map<std::string, int>::const_iterator ii = m_intFields.begin();
147  std::map<std::string, int>::const_iterator ei = m_intFields.end();
148  while (ii != ei) {
149  std::string key = ii->first;
150  cout << m_indent << key << setw(20 - key.length()) << ": " << ii->second
151  << endl;
152  ii++;
153  }
154  cout << m_indent << "#################" << setw(15) << m_className
155  << " " << m_trail << endl;
156  // iterate over foreign keys
157  std::map<std::string, LMFUnique*>::const_iterator ik = m_foreignKeys.begin();
158  std::map<std::string, LMFUnique*>::const_iterator ek = m_foreignKeys.end();
159  m_indent.clear();
160  m_indent.resize((n + 1) * 2, ' ');
161  while (ik != ek) {
162  cout << m_indent << "Foreign Key: " << ik->first << endl;
163  ik->second->dump(n + 1);
164  ik++;
165  }
166 }
std::string m_className
Definition: LMFUnique.h:98
oracle::occi::Environment * m_env
Definition: IDBObject.h:38
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
std::map< std::string, std::string > m_stringFields
Definition: LMFUnique.h:101
std::map< std::string, LMFUnique * > m_foreignKeys
Definition: LMFUnique.h:105
virtual bool isValid() const
Definition: LMFUnique.h:46
list key
Definition: combine.py:13
tuple cout
Definition: gather_cfg.py:41
std::map< std::string, int > m_intFields
Definition: LMFUnique.h:103
bool LMFUnique::exists ( )
virtual

Definition at line 168 of file LMFUnique.cc.

References runTheMatrix::ret.

168  {
169  fetchID();
170  bool ret = false;
171  if (m_ID > 0) {
172  ret = true;
173  }
174  return ret;
175 }
int fetchID()
Definition: LMFUnique.cc:207
boost::ptr_list< LMFUnique > LMFUnique::fetchAll ( ) const
throw (std::runtime_error
)
virtual

Definition at line 64 of file LMFUnique.cc.

References gather_cfg::cout, debug(), dump(), prof2calltree::l, NULL, connectstrParser::o, and setByID().

Referenced by LMFDefFabric::initialize(), and LMFColor::isValid().

66 {
67  /*
68  Returns a list of pointers to DB objects
69  */
70  boost::ptr_list<LMFUnique> l;
71  this->checkConnection();
72 
73  try {
74  Statement* stmt = m_conn->createStatement();
75  std::string sql = fetchAllSql(stmt);
76  if (sql != "") {
77  if (m_debug) {
78  cout << m_className + ": Query " + sql << endl;
79  }
80  ResultSet* rset = stmt->executeQuery();
81  while (rset->next()) {
83  if (m_debug) {
84  o->debug();
85  }
86  if (o != NULL) {
87  o->setByID(rset->getInt(1));
88  if (m_debug) {
89  o->dump();
90  }
91  l.push_back(o);
92  }
93  }
94  }
95  m_conn->terminateStatement(stmt);
96  }
97  catch (SQLException &e) {
98  throw(std::runtime_error(m_className + "::fetchAll: "+e.getMessage()));
99  }
100  if (m_debug) {
101  cout << m_className << ": list size = " << l.size() << endl;
102  }
103  return l;
104 }
std::string m_className
Definition: LMFUnique.h:98
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
#define NULL
Definition: scimark2.h:8
virtual LMFUnique * createObject() const
Definition: LMFUnique.cc:183
virtual void dump() const
Definition: LMFUnique.cc:106
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
void setByID(int id)
Definition: LMFUnique.cc:280
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
virtual std::string fetchAllSql(Statement *stmt) const
Definition: LMFUnique.cc:177
tuple cout
Definition: gather_cfg.py:41
char m_debug
Definition: LMFUnique.h:99
void debug()
Definition: LMFUnique.h:67
void checkConnection() const
Definition: IDBObject.h:41
std::string LMFUnique::fetchAllSql ( Statement stmt) const
privatevirtual

Reimplemented in LMFColor, LMFRunTag, LMFPrimVers, LMFTrigType, LMFCorrVers, and LMFSeqVers.

Definition at line 177 of file LMFUnique.cc.

177  {
178  /* this method should setup a Statement to select the unique IDs of the
179  objects to return */
180  return "";
181 }
int LMFUnique::fetchID ( )
throw (std::runtime_error
)
virtual

Implements IUniqueDBObject.

Definition at line 207 of file LMFUnique.cc.

References gather_cfg::cout, i, and n.

Referenced by LMFDat::getLMFRunIOVID(), LMFColor::setColor(), LMFColor::setName(), and LMFTrigType::setName().

209 {
210  /*
211  This method fetch the ID of the object from the database according
212  to the given specifications.
213 
214  It is assumed that there is only one object in the database with the
215  given specifications. In case more than one object can be retrieved
216  this method throws an exception.
217 
218  Since not all the specifications can define completely the object
219  itself, at the end, we setup the object based on its ID.
220  */
221  // Return tag from memory if available
222  if (m_ID) {
223  return m_ID;
224  }
225 
226  this->checkConnection();
227 
228  // fetch this ID
229  try {
230  Statement* stmt = m_conn->createStatement();
231  // prepare the sql query
232  std::string sql = fetchIdSql(stmt);
233  if (sql != "") {
234  if (m_debug) {
235  cout << m_className + ": Query " + sql << endl;
236  }
237 
238  ResultSet* rset = stmt->executeQuery();
239  if (rset->next()) {
240  m_ID = rset->getInt(1);
241  } else {
242  m_ID = 0;
243  }
244  if (m_debug) {
245  cout << m_className + ": ID set to " << m_ID << endl;
246  }
247  int n = rset->getNumArrayRows();
248  if (m_debug) {
249  cout << m_className + ": Returned " << n << " rows" << endl;
250  }
251  if (n > 1) {
252  throw(std::runtime_error(m_className + "::fetchID: too many rows returned " +
253  "executing query " + sql));
254  m_ID = 0;
255  }
256  }
257  m_conn->terminateStatement(stmt);
258  } catch (SQLException &e) {
259  throw(std::runtime_error(m_className + "::fetchID: "+e.getMessage()));
260  }
261  // given the ID of this object setup it completely
262  if (m_ID > 0) {
263  setByID(m_ID);
264  }
265  // if foreignKeys are there, set these objects too
266  map<string, LMFUnique*>::iterator i = m_foreignKeys.begin();
267  map<string, LMFUnique*>::iterator e = m_foreignKeys.end();
268  while (i != e) {
269  if (i->second->getID() == 0) {
270  i->second->fetchID();
271  }
272  i++;
273  }
274  if (m_debug) {
275  cout << m_className << ": fetchID:: returning " << m_ID << endl;
276  }
277  return m_ID;
278 }
std::string m_className
Definition: LMFUnique.h:98
int i
Definition: DBlmapReader.cc:9
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
void setByID(int id)
Definition: LMFUnique.cc:280
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
std::map< std::string, LMFUnique * > m_foreignKeys
Definition: LMFUnique.h:105
virtual std::string fetchIdSql(Statement *stmt)
Definition: LMFUnique.h:84
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
tuple cout
Definition: gather_cfg.py:41
char m_debug
Definition: LMFUnique.h:99
void checkConnection() const
Definition: IDBObject.h:41
virtual std::string LMFUnique::fetchIdSql ( Statement stmt)
inlineprivatevirtual

Reimplemented in LMFLmrSubIOV, LMFSeqDat, LMFRunIOV, LMFColor, LMFRunTag, LMFPrimVers, LMFIOV, LMFTrigType, LMFCorrVers, and LMFSeqVers.

Definition at line 84 of file LMFUnique.h.

84 { return ""; }
virtual void LMFUnique::fetchParentIDs ( )
inlineprivatevirtual

Reimplemented in LMFSeqDat, and LMFIOV.

Definition at line 90 of file LMFUnique.h.

90 {}
std::string LMFUnique::getClassName ( )
inline

Definition at line 53 of file LMFUnique.h.

References m_className.

53 { return m_className; }
std::string m_className
Definition: LMFUnique.h:98
std::string LMFUnique::getClassName ( ) const
inline

Definition at line 54 of file LMFUnique.h.

References m_className.

54 { return m_className; }
std::string m_className
Definition: LMFUnique.h:98
int LMFUnique::getID ( ) const
inline
int LMFUnique::getInt ( std::string  fieldname) const

Definition at line 197 of file LMFUnique.cc.

References i, and runTheMatrix::ret.

Referenced by LMFColor::fetchIdSql(), LMFColor::getColorIndex(), LMFRunIOV::getLMFColor(), LMFCorrCoefDatComponent::getLMFLmrSubIOV(), LMFCorrCoefDatComponent::getLMFLmrSubIOVID(), LMFDat::getLMFRunIOV(), LMFDat::getLMFRunIOVID(), LMFRunIOV::getLMFRunTag(), LMFRunIOV::getLmr(), LMFRunIOV::getSequence(), LMFSeqDat::getSequenceNumber(), LMFRunIOV::getTriggerType(), LMFRunTag::getVersion(), LMFSeqDat::getVmax(), LMFSeqDat::getVmin(), and LMFRunIOV::writeDBSql().

197  {
198  // this should be better defined
199  int ret = 0;
200  std::map<std::string, int>::const_iterator i = m_intFields.find(s);
201  if (i != m_intFields.end()) {
202  ret = i->second;
203  }
204  return ret;
205 }
int i
Definition: DBlmapReader.cc:9
string s
Definition: asciidump.py:422
std::map< std::string, int > m_intFields
Definition: LMFUnique.h:103
virtual void LMFUnique::getParameters ( ResultSet rset)
inlineprivatevirtual

Reimplemented in LMFLmrSubIOV, LMFSeqDat, LMFRunIOV, LMFColor, LMFRunTag, LMFPrimVers, LMFIOV, LMFTrigType, LMFCorrVers, and LMFSeqVers.

Definition at line 89 of file LMFUnique.h.

89 {}
std::string LMFUnique::getString ( std::string  fieldname) const

Definition at line 188 of file LMFUnique.cc.

References i.

Referenced by LMFColor::fetchIdSql(), LMFRunIOV::getDBInsertionTime(), LMFPrimVers::getDescription(), LMFRunTag::getGeneralTag(), LMFTrigType::getLongName(), LMFColor::getLongName(), LMFSeqDat::getSequenceStart(), LMFSeqDat::getSequenceStop(), LMFTrigType::getShortName(), LMFColor::getShortName(), LMFRunIOV::getSubRunEnd(), LMFRunIOV::getSubRunStart(), and LMFRunIOV::getSubRunType().

188  {
189  std::string rs = "";
190  std::map<std::string, std::string>::const_iterator i = m_stringFields.find(s);
191  if (i != m_stringFields.end()) {
192  rs = i->second;
193  }
194  return rs;
195 }
int i
Definition: DBlmapReader.cc:9
std::map< std::string, std::string > m_stringFields
Definition: LMFUnique.h:101
string s
Definition: asciidump.py:422
virtual bool LMFUnique::isValid ( void  ) const
inlinevirtual

Reimplemented in LMFSeqDat.

Definition at line 46 of file LMFUnique.h.

46 { return true; }
void LMFUnique::nodebug ( )
inline

Definition at line 68 of file LMFUnique.h.

References m_debug.

Referenced by LMFUnique().

68 { m_debug = 0; }
char m_debug
Definition: LMFUnique.h:99
virtual bool LMFUnique::operator< ( const LMFUnique r)
inlinevirtual

Definition at line 73 of file LMFUnique.h.

References IUniqueDBObject::m_ID.

73  {
74  return (m_ID < r.m_ID);
75  }
virtual bool LMFUnique::operator<= ( const LMFUnique r)
inlinevirtual

Definition at line 76 of file LMFUnique.h.

References IUniqueDBObject::m_ID.

76  {
77  return (m_ID <= r.m_ID);
78  }
std::string LMFUnique::sequencePostfix ( Tm  t)

Definition at line 10 of file LMFUnique.cc.

References Tm::str().

Referenced by LMFRunIOV::writeDBSql(), LMFSeqDat::writeDBSql(), and LMFLmrSubIOV::writeDBSql().

10  {
11  std::string ts = t.str();
12  return ts.substr(2, 2);
13 }
std::string str() const
Definition: Tm.cc:82
void LMFUnique::setByID ( int  id)
throw (std::runtime_error
)
virtual

Implements IUniqueDBObject.

Definition at line 280 of file LMFUnique.cc.

References gather_cfg::cout, and cmsPerfRegress::getParameters().

Referenced by LMFCorrCoefDat::fetch(), fetchAll(), LMFSeqDat::fetchByRunIOV(), LMFRunIOV::fetchBySequence(), LMFRunIOV::getLMFColor(), LMFLmrSubIOV::getLMFIOV(), LMFCorrCoefDatComponent::getLMFLmrSubIOV(), LMFDat::getLMFRunIOV(), LMFRunIOV::getLMFRunTag(), LMFRunIOV::getSequence(), LMFCorrCoefDatComponent::getSequence(), and LMFRunIOV::getTriggerType().

282 {
283  /*
284  Given the ID of an object setup it
285  */
286  if (m_debug) {
287  cout << m_className << ": Setting this object as ID = " << id << endl;
288  }
289  this->checkConnection();
290  try {
291  Statement* stmt = m_conn->createStatement();
292  std::string sql = setByIDSql(stmt, id);
293  if (sql == "") {
294  throw(std::runtime_error(m_className + "::setByID: [empty sql])"));
295  }
296  if (m_debug) {
297  cout << m_className + ": " + sql << endl;
298  }
299 
300  ResultSet* rset = stmt->executeQuery();
301  if (rset->next()) {
302  // setup the concrete object
303  getParameters(rset);
304  m_ID = id;
305  if (m_debug) {
306  cout << m_className + ": Setting done. ID set to " << m_ID << endl;
307  }
308  } else {
309  throw(std::runtime_error(m_className + "::setByID: Given id is not in the database"));
310  }
311  m_conn->terminateStatement(stmt);
312  } catch (SQLException &e) {
313  throw(std::runtime_error(m_className + "::setByID: "+e.getMessage()));
314  }
315 }
std::string m_className
Definition: LMFUnique.h:98
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
virtual std::string setByIDSql(Statement *stmt, int id)
Definition: LMFUnique.h:86
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
oracle::occi::ResultSet ResultSet
Definition: HcalDbOmds.cc:21
tuple cout
Definition: gather_cfg.py:41
char m_debug
Definition: LMFUnique.h:99
virtual void getParameters(ResultSet *rset)
Definition: LMFUnique.h:89
void checkConnection() const
Definition: IDBObject.h:41
virtual std::string LMFUnique::setByIDSql ( Statement stmt,
int  id 
)
inlineprivatevirtual

Reimplemented in LMFLmrSubIOV, LMFSeqDat, LMFRunIOV, LMFColor, LMFRunTag, LMFPrimVers, LMFIOV, LMFTrigType, LMFCorrVers, and LMFSeqVers.

Definition at line 86 of file LMFUnique.h.

87  { return ""; }
virtual void LMFUnique::setClassName ( std::string  s)
inlineprotectedvirtual
LMFUnique & LMFUnique::setInt ( std::string  key,
int  value 
)

Definition at line 33 of file LMFUnique.cc.

References i, combine::key, and relativeConstraints::value.

Referenced by LMFDat::getLMFRunIOVID(), LMFRunTag::getParameters(), LMFColor::getParameters(), LMFRunIOV::getParameters(), LMFSeqDat::getParameters(), LMFColor::setColor(), LMFRunIOV::setColor(), LMFRunIOV::setColorIndex(), LMFCorrCoefDatComponent::setLMFLmrSubIOV(), LMFDat::setLMFRunIOV(), LMFRunIOV::setLMFRunTag(), LMFRunIOV::setLmr(), LMFColor::setName(), LMFRunIOV::setSequence(), LMFSeqDat::setSequenceNumber(), LMFRunIOV::setTriggerType(), LMFRunTag::setVersion(), LMFSeqDat::setVmax(), and LMFSeqDat::setVmin().

33  {
34  // check if this key exists
35  std::map<std::string, int>::const_iterator i = m_intFields.find(key);
36  if (i != m_intFields.end()) {
37  // the key exist: check if it changed: reset the ID of the object
38  if (i->second != value) {
40  m_ID = 0;
41  }
42  } else {
43  // create this key and reset the ID of the object
45  m_ID = 0;
46  }
47  return *this;
48 }
int i
Definition: DBlmapReader.cc:9
list key
Definition: combine.py:13
std::map< std::string, int > m_intFields
Definition: LMFUnique.h:103
LMFUnique & LMFUnique::setString ( std::string  key,
std::string  value 
)

Definition at line 15 of file LMFUnique.cc.

References i, combine::key, and relativeConstraints::value.

Referenced by LMFCorrVers::getParameters(), LMFSeqVers::getParameters(), LMFTrigType::getParameters(), LMFPrimVers::getParameters(), LMFRunTag::getParameters(), LMFColor::getParameters(), LMFRunIOV::getParameters(), LMFSeqDat::getParameters(), LMFCorrVers::LMFCorrVers(), LMFPrimVers::LMFPrimVers(), LMFSeqVers::LMFSeqVers(), LMFColor::setColor(), LMFPrimVers::setDescription(), LMFRunTag::setGeneralTag(), LMFColor::setName(), LMFTrigType::setName(), LMFTrigType::setNames(), LMFSeqDat::setSequenceStart(), LMFSeqDat::setSequenceStop(), LMFRunIOV::setSubRunEnd(), LMFRunIOV::setSubRunStart(), and LMFRunIOV::setSubRunType().

15  {
16  // check if this key exists
17  std::map<std::string, std::string>::const_iterator i =
18  m_stringFields.find(key);
19  if (i != m_stringFields.end()) {
20  // the key exist: check if it changed: reset the ID of the object
21  if (i->second != value) {
23  m_ID = 0;
24  }
25  } else {
26  // create this key and reset the ID of the object
28  m_ID = 0;
29  }
30  return *this;
31 }
int i
Definition: DBlmapReader.cc:9
std::map< std::string, std::string > m_stringFields
Definition: LMFUnique.h:101
list key
Definition: combine.py:13
void LMFUnique::startProfiling ( )
inline

Definition at line 79 of file LMFUnique.h.

References _profiling.

79 { _profiling = true; }
bool _profiling
Definition: LMFUnique.h:106
void LMFUnique::stopProfiling ( )
inline

Definition at line 80 of file LMFUnique.h.

References _profiling.

80 { _profiling = false; }
bool _profiling
Definition: LMFUnique.h:106
int LMFUnique::writeDB ( )
throw (std::runtime_error
)
protectedvirtual

Reimplemented in LMFDat, LMFColoredTable, and LMFCorrCoefDatComponent.

Definition at line 333 of file LMFUnique.cc.

References gather_cfg::cout, debug, hcal_timing_source_file_cfg::dump, and end.

335 {
336  clock_t start = 0;
337  clock_t end = 0;
338  if (_profiling) {
339  start = clock();
340  }
341  // write the associated objects first (foreign keys must exist before use)
343  // see if this data is already in the DB
344  if (!(this->fetchID())) {
345  // check the connectioin
346  this->checkConnection();
347 
348  // write new tag to the DB
349  std::string sql = "";
350  try {
351  Statement* stmt = m_conn->createStatement();
352 
353  sql = writeDBSql(stmt);
354  if (sql != "") {
355  if (m_debug) {
356  cout << m_className + ": " + sql << endl;
357  }
358  stmt->executeUpdate();
359  }
360  m_conn->commit();
361  m_conn->terminateStatement(stmt);
362  } catch (SQLException &e) {
363  debug();
364  dump();
365  throw(std::runtime_error(m_className + "::writeDB: " + e.getMessage() +
366  " while executing query " + sql));
367  }
368  // now get the id
369  if (this->fetchID() == 0) {
370  throw(std::runtime_error(m_className + "::writeDB: Failed to write"));
371  }
372  }
373  if (_profiling) {
374  end = clock();
375  if (m_debug) {
376  std::cout << m_className << ":: Spent time in writeDB:" <<
377  ((double) (end - start)) / CLOCKS_PER_SEC << " s" << endl;
378  }
379  }
380  return m_ID;
381 }
std::string m_className
Definition: LMFUnique.h:98
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
bool _profiling
Definition: LMFUnique.h:106
virtual void dump() const
Definition: LMFUnique.cc:106
oracle::occi::SQLException SQLException
Definition: HcalDbOmds.cc:22
virtual int writeForeignKeys()
Definition: LMFUnique.cc:317
virtual std::string writeDBSql(Statement *stmt)
Definition: LMFUnique.h:83
int fetchID()
Definition: LMFUnique.cc:207
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
#define end
Definition: vmac.h:38
tuple cout
Definition: gather_cfg.py:41
char m_debug
Definition: LMFUnique.h:99
void debug()
Definition: LMFUnique.h:67
void checkConnection() const
Definition: IDBObject.h:41
virtual std::string LMFUnique::writeDBSql ( Statement stmt)
inlineprivatevirtual

Reimplemented in LMFLmrSubIOV, LMFSeqDat, LMFRunIOV, and LMFIOV.

Definition at line 83 of file LMFUnique.h.

83 { return ""; }
int LMFUnique::writeForeignKeys ( )
throw (std::runtime_error
)
protectedvirtual

Definition at line 317 of file LMFUnique.cc.

References prof2calltree::count, and i.

Referenced by LMFDat::writeDB().

319 {
320  std::map<std::string, LMFUnique*>::const_iterator i = m_foreignKeys.begin();
321  std::map<std::string, LMFUnique*>::const_iterator e = m_foreignKeys.end();
322  int count = 0;
323  while (i != e) {
324  if (i->second->getID() == 0) {
325  i->second->writeDB();
326  count++;
327  }
328  i++;
329  }
330  return count;
331 }
int i
Definition: DBlmapReader.cc:9
std::map< std::string, LMFUnique * > m_foreignKeys
Definition: LMFUnique.h:105

Friends And Related Function Documentation

friend class EcalCondDBInterface
friend

Definition at line 21 of file LMFUnique.h.

Member Data Documentation

bool LMFUnique::_profiling
protected

Definition at line 106 of file LMFUnique.h.

Referenced by LMFUnique(), startProfiling(), and stopProfiling().

std::string LMFUnique::m_className
protected
char LMFUnique::m_debug
protected
std::map<std::string, LMFUnique*> LMFUnique::m_foreignKeys
protected
std::map<std::string, int> LMFUnique::m_intFields
protected
std::map<std::string, std::string> LMFUnique::m_stringFields
protected