CMS 3D CMS Logo

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< LMFUniquefetchAll () const noexcept(false)
 
int fetchID () noexcept(false)
 
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
 
virtual bool isValid ()
 
 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) noexcept(false)
 
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 () noexcept(false)
 
virtual int writeForeignKeys () noexcept(false)
 
- Protected Member Functions inherited from IDBObject
void checkConnection () const noexcept(false)
 

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:69
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:69
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(), IDBObject::setConnection(), and ~LMFUnique().

37  {
38  _profiling = false;
39  m_ID = 0;
40  setClassName("LMFUnique"); nodebug();
41  setConnection(c->getEnv(), c->getConn());
42  }
void nodebug()
Definition: LMFUnique.h:69
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.

Referenced by LMFUnique().

7  {
8 }

Member Function Documentation

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

Definition at line 50 of file LMFUnique.cc.

References mps_fire::i, and dataset::name.

Referenced by getClassName(), 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 }
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 189 of file LMFUnique.cc.

References NULL.

Referenced by fetchParentIDs().

189  {
190  /* this method should return a pointer to a newly created object */
191  return NULL;
192 }
#define NULL
Definition: scimark2.h:8
void LMFUnique::debug ( )
inline
void LMFUnique::dump ( void  ) const
virtual

Reimplemented in LMFDat, LMFRunIOV, and LMFIOV.

Definition at line 112 of file LMFUnique.cc.

References FrontierConditions_GlobalTag_cff::dump.

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

112  {
113  dump(0);
114 }
virtual void dump() const
Definition: LMFUnique.cc:112
void LMFUnique::dump ( int  n) const
virtual

Reimplemented in LMFDat.

Definition at line 116 of file LMFUnique.cc.

References gather_cfg::cout, cuy::ii, crabWrapper::key, and AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 174 of file LMFUnique.cc.

Referenced by isValid().

174  {
175  fetchID();
176  bool ret = false;
177  if (m_ID > 0) {
178  ret = true;
179  }
180  return ret;
181 }
int fetchID() noexcept(false)
Definition: LMFUnique.cc:213
boost::ptr_list< LMFUnique > LMFUnique::fetchAll ( ) const
virtualnoexcept

Definition at line 64 of file LMFUnique.cc.

References gather_cfg::cout, HcalDbASCIIIO::createObject(), debug(), dump(), MillePedeFileConverter_cfg::e, checklumidiff::l, NULL, connectstrParser::o, setByID(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

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() != 0) {
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  try {
92  l.push_back(o);
93  }
94  catch (boost::bad_pointer &e) {
95  throw(std::runtime_error(m_className + "::fetchAll: " +
96  e.what()));
97  }
98  }
99  }
100  }
101  m_conn->terminateStatement(stmt);
102  }
103  catch (SQLException &e) {
104  throw(std::runtime_error(m_className + "::fetchAll: "+e.getMessage()));
105  }
106  if (m_debug) {
107  cout << m_className << ": list size = " << l.size() << endl;
108  }
109  return l;
110 }
std::string m_className
Definition: LMFUnique.h:98
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
oracle::occi::ResultSet ResultSet
Definition: LMFUnique.h:19
#define NULL
Definition: scimark2.h:8
virtual LMFUnique * createObject() const
Definition: LMFUnique.cc:189
virtual void dump() const
Definition: LMFUnique.cc:112
void setByID(int id) noexcept(false)
Definition: LMFUnique.cc:286
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
virtual std::string fetchAllSql(Statement *stmt) const
Definition: LMFUnique.cc:183
char m_debug
Definition: LMFUnique.h:99
void debug()
Definition: LMFUnique.h:68
std::string LMFUnique::fetchAllSql ( Statement stmt) const
privatevirtual

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

Definition at line 183 of file LMFUnique.cc.

Referenced by fetchIdSql().

183  {
184  /* this method should setup a Statement to select the unique IDs of the
185  objects to return */
186  return "";
187 }
int LMFUnique::fetchID ( )
virtualnoexcept

Implements IUniqueDBObject.

Definition at line 213 of file LMFUnique.cc.

References gather_cfg::cout, MillePedeFileConverter_cfg::e, mps_fire::i, gen::n, and AlCaHLTBitMon_QueryRunRegistry::string.

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

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

Reimplemented in LMFSeqDat, and LMFIOV.

Definition at line 90 of file LMFUnique.h.

References createObject(), noexcept, writeDB(), and writeForeignKeys().

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

Definition at line 54 of file LMFUnique.h.

References m_className.

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

Definition at line 203 of file LMFUnique.cc.

References mps_fire::i.

Referenced by LMFColor::fetchIdSql(), LMFColor::getColorIndex(), getID(), 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().

203  {
204  // this should be better defined
205  int ret = 0;
206  std::map<std::string, int>::const_iterator i = m_intFields.find(s);
207  if (i != m_intFields.end()) {
208  ret = i->second;
209  }
210  return ret;
211 }
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
virtual bool LMFUnique::isValid ( void  ) const
inlinevirtual

Reimplemented in LMFSeqDat.

Definition at line 46 of file LMFUnique.h.

Referenced by ntupleDataFormat._Object::_checkIsValid(), and core.AutoHandle.AutoHandle::ReallyLoad().

46 { return true; }
virtual bool LMFUnique::isValid ( void  )
inlinevirtual
void LMFUnique::nodebug ( )
inline

Definition at line 69 of file LMFUnique.h.

References fetchAll(), m_debug, and noexcept.

Referenced by LMFUnique().

69 { 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 ( const Tm t)

Definition at line 10 of file LMFUnique.cc.

References Tm::str(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by isValid(), 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:89
void LMFUnique::setByID ( int  id)
virtualnoexcept

Implements IUniqueDBObject.

Definition at line 286 of file LMFUnique.cc.

References gather_cfg::cout, MillePedeFileConverter_cfg::e, cfg-viewer::getParameters(), triggerObjects_cff::id, and AlCaHLTBitMon_QueryRunRegistry::string.

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

288 {
289  /*
290  Given the ID of an object setup it
291  */
292  if (m_debug) {
293  cout << m_className << ": Setting this object as ID = " << id << endl;
294  }
295  this->checkConnection();
296  try {
297  Statement* stmt = m_conn->createStatement();
298  std::string sql = setByIDSql(stmt, id);
299  if (sql == "") {
300  throw(std::runtime_error(m_className + "::setByID: [empty sql])"));
301  }
302  if (m_debug) {
303  cout << m_className + ": " + sql << endl;
304  }
305 
306  ResultSet* rset = stmt->executeQuery();
307  if (rset->next() != 0) {
308  // setup the concrete object
309  getParameters(rset);
310  m_ID = id;
311  if (m_debug) {
312  cout << m_className + ": Setting done. ID set to " << m_ID << endl;
313  }
314  } else {
315  throw(std::runtime_error(m_className + "::setByID: Given id is not in the database"));
316  }
317  m_conn->terminateStatement(stmt);
318  } catch (SQLException &e) {
319  throw(std::runtime_error(m_className + "::setByID: "+e.getMessage()));
320  }
321 }
std::string m_className
Definition: LMFUnique.h:98
oracle::occi::Connection * m_conn
Definition: IDBObject.h:39
oracle::occi::ResultSet ResultSet
Definition: LMFUnique.h:19
virtual std::string setByIDSql(Statement *stmt, int id)
Definition: LMFUnique.h:86
void checkConnection() const noexcept(false)
Definition: IDBObject.h:41
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
char m_debug
Definition: LMFUnique.h:99
virtual void getParameters(ResultSet *rset)
Definition: LMFUnique.h:89
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 mps_fire::i, crabWrapper::key, and relativeConstraints::value.

Referenced by LMFDat::fetch(), getClassName(), 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 }
Definition: value.py:1
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 mps_fire::i, crabWrapper::key, and relativeConstraints::value.

Referenced by getClassName(), 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 }
std::map< std::string, std::string > m_stringFields
Definition: LMFUnique.h:101
Definition: value.py:1
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 ( )
protectedvirtualnoexcept

Reimplemented in LMFDat, LMFColoredTable, and LMFCorrCoefDatComponent.

Definition at line 339 of file LMFUnique.cc.

References gather_cfg::cout, debug, FrontierConditions_GlobalTag_cff::dump, MillePedeFileConverter_cfg::e, end, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by fetchParentIDs().

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

Definition at line 323 of file LMFUnique.cc.

References KineDebug3::count(), MillePedeFileConverter_cfg::e, and mps_fire::i.

Referenced by fetchParentIDs(), and LMFDat::writeDB().

325 {
326  std::map<std::string, LMFUnique*>::const_iterator i = m_foreignKeys.begin();
327  std::map<std::string, LMFUnique*>::const_iterator e = m_foreignKeys.end();
328  int count = 0;
329  while (i != e) {
330  if (i->second->getID() == 0) {
331  i->second->writeDB();
332  count++;
333  }
334  i++;
335  }
336  return count;
337 }
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