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) override
 
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) override
 
LMFUniquesetInt (std::string key, int value)
 
LMFUniquesetString (std::string key, std::string value)
 
void startProfiling ()
 
void stopProfiling ()
 
 ~LMFUnique () override
 
- 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 getParameters (ResultSet *rset)
 
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 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(), and setClassName().

23  {
24  _profiling = false;
25  m_env = nullptr;
26  m_conn = nullptr;
27  m_ID = 0;
28  setClassName("LMFUnique");
29  nodebug();
30  }
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
void nodebug()
Definition: LMFUnique.h:71
bool _profiling
Definition: LMFUnique.h:103
virtual void setClassName(std::string s)
Definition: LMFUnique.h:93
LMFUnique::LMFUnique ( oracle::occi::Environment *  env,
oracle::occi::Connection *  conn 
)
inline

Definition at line 31 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");
35  nodebug();
37  }
void nodebug()
Definition: LMFUnique.h:71
bool _profiling
Definition: LMFUnique.h:103
virtual void setClassName(std::string s)
Definition: LMFUnique.h:93
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
LMFUnique::LMFUnique ( EcalDBConnection c)
inline

Definition at line 38 of file LMFUnique.h.

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

38  {
39  _profiling = false;
40  m_ID = 0;
41  setClassName("LMFUnique");
42  nodebug();
43  setConnection(c->getEnv(), c->getConn());
44  }
void nodebug()
Definition: LMFUnique.h:71
bool _profiling
Definition: LMFUnique.h:103
virtual void setClassName(std::string s)
Definition: LMFUnique.h:93
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 ( )
override

Definition at line 7 of file LMFUnique.cc.

Referenced by LMFUnique().

7 {}

Member Function Documentation

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

Definition at line 48 of file LMFUnique.cc.

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

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

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

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

Definition at line 173 of file LMFUnique.cc.

Referenced by fetchParentIDs().

173  {
174  /* this method should return a pointer to a newly created object */
175  return nullptr;
176 }
void LMFUnique::debug ( )
inline
void LMFUnique::dump ( void  ) const
virtual

Reimplemented in LMFDat, LMFRunIOV, and LMFIOV.

Definition at line 104 of file LMFUnique.cc.

References FrontierConditions_GlobalTag_cff::dump.

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

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

Reimplemented in LMFDat.

Definition at line 106 of file LMFUnique.cc.

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

106  {
107  /*
108  This method is used to dump the content of an object
109  Indent data if the object is contained inside another object
110  */
111  std::string m_indent = "";
112  std::string m_trail = "";
113  m_trail.resize(70 - 31 - n * 2, '#');
114  m_indent.resize(n * 2, ' ');
115  m_indent += "|";
116  // start of object
117  cout << m_indent << "#################" << setw(15) << m_className << " " << m_trail << endl;
118  cout << m_indent << "Address: " << this << endl;
119  cout << m_indent << "Connection params : " << m_env << ", " << m_conn << endl;
120  // object ID in the DB
121  cout << m_indent << "ID" << setw(18) << ": " << m_ID;
122  if (m_ID == 0) {
123  cout << " *** NULL ID ***";
124  }
125  if (!isValid()) {
126  cout << " INVALID ***";
127  }
128  cout << endl;
129  // iterate over string fields
130  std::map<std::string, std::string>::const_iterator is = m_stringFields.begin();
131  std::map<std::string, std::string>::const_iterator es = m_stringFields.end();
132  while (is != es) {
133  std::string key = is->first;
134  cout << m_indent << key << setw(20 - key.length()) << ": " << is->second << endl;
135  is++;
136  }
137  // iterate over integer fields
138  std::map<std::string, int>::const_iterator ii = m_intFields.begin();
139  std::map<std::string, int>::const_iterator ei = m_intFields.end();
140  while (ii != ei) {
141  std::string key = ii->first;
142  cout << m_indent << key << setw(20 - key.length()) << ": " << ii->second << endl;
143  ii++;
144  }
145  cout << m_indent << "#################" << setw(15) << m_className << " " << m_trail << endl;
146  // iterate over foreign keys
147  std::map<std::string, LMFUnique*>::const_iterator ik = m_foreignKeys.begin();
148  std::map<std::string, LMFUnique*>::const_iterator ek = m_foreignKeys.end();
149  m_indent.clear();
150  m_indent.resize((n + 1) * 2, ' ');
151  while (ik != ek) {
152  cout << m_indent << "Foreign Key: " << ik->first << endl;
153  ik->second->dump(n + 1);
154  ik++;
155  }
156 }
std::string m_className
Definition: LMFUnique.h:95
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
std::map< std::string, LMFUnique * > m_foreignKeys
Definition: LMFUnique.h:102
std::map< l1t::HGCalMulticluster::EnergyInterpretation, double > ei
Definition: classes.h:67
std::map< std::string, std::string > m_stringFields
Definition: LMFUnique.h:98
ii
Definition: cuy.py:590
virtual bool isValid() const
Definition: LMFUnique.h:48
std::map< std::string, int > m_intFields
Definition: LMFUnique.h:100
bool LMFUnique::exists ( )
virtual

Definition at line 158 of file LMFUnique.cc.

References runTheMatrix::ret.

Referenced by isValid().

158  {
159  fetchID();
160  bool ret = false;
161  if (m_ID > 0) {
162  ret = true;
163  }
164  return ret;
165 }
ret
prodAgent to be discontinued
int fetchID() noexcept(false) override
Definition: LMFUnique.cc:197
boost::ptr_list< LMFUnique > LMFUnique::fetchAll ( ) const
virtualnoexcept

Definition at line 61 of file LMFUnique.cc.

References gather_cfg::cout, createObject(), debug(), dump(), MillePedeFileConverter_cfg::e, cmsLHEtoEOSManager::l, EcalTangentSkim_cfg::o, setByID(), and AlCaHLTBitMon_QueryRunRegistry::string.

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

61  {
62  /*
63  Returns a list of pointers to DB objects
64  */
65  boost::ptr_list<LMFUnique> l;
66  this->checkConnection();
67 
68  try {
69  Statement* stmt = m_conn->createStatement();
70  std::string sql = fetchAllSql(stmt);
71  if (!sql.empty()) {
72  if (m_debug) {
73  cout << m_className + ": Query " + sql << endl;
74  }
75  ResultSet* rset = stmt->executeQuery();
76  while (rset->next() != 0) {
78  if (m_debug) {
79  o->debug();
80  }
81  if (o != nullptr) {
82  o->setByID(rset->getInt(1));
83  if (m_debug) {
84  o->dump();
85  }
86  try {
87  l.push_back(o);
88  } catch (boost::bad_pointer& e) {
89  throw(std::runtime_error(m_className + "::fetchAll: " + e.what()));
90  }
91  }
92  }
93  }
94  m_conn->terminateStatement(stmt);
95  } catch (SQLException& e) {
96  throw(std::runtime_error(m_className + "::fetchAll: " + e.getMessage()));
97  }
98  if (m_debug) {
99  cout << m_className << ": list size = " << l.size() << endl;
100  }
101  return l;
102 }
std::string m_className
Definition: LMFUnique.h:95
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
oracle::occi::ResultSet ResultSet
Definition: LMFUnique.h:19
virtual LMFUnique * createObject() const
Definition: LMFUnique.cc:173
virtual void dump() const
Definition: LMFUnique.cc:104
void setByID(int id) noexcept(false) override
Definition: LMFUnique.cc:267
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
virtual std::string fetchAllSql(Statement *stmt) const
Definition: LMFUnique.cc:167
char m_debug
Definition: LMFUnique.h:96
void debug()
Definition: LMFUnique.h:70
std::string LMFUnique::fetchAllSql ( Statement stmt) const
privatevirtual

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

Definition at line 167 of file LMFUnique.cc.

Referenced by fetchIdSql().

167  {
168  /* this method should setup a Statement to select the unique IDs of the
169  objects to return */
170  return "";
171 }
int LMFUnique::fetchID ( )
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 197 of file LMFUnique.cc.

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

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

197  {
198  /*
199  This method fetch the ID of the object from the database according
200  to the given specifications.
201 
202  It is assumed that there is only one object in the database with the
203  given specifications. In case more than one object can be retrieved
204  this method throws an exception.
205 
206  Since not all the specifications can define completely the object
207  itself, at the end, we setup the object based on its ID.
208  */
209  // Return tag from memory if available
210  if (m_ID) {
211  return m_ID;
212  }
213 
214  this->checkConnection();
215 
216  // fetch this ID
217  try {
218  Statement* stmt = m_conn->createStatement();
219  // prepare the sql query
220  std::string sql = fetchIdSql(stmt);
221  if (!sql.empty()) {
222  if (m_debug) {
223  cout << m_className + ": Query " + sql << endl;
224  }
225 
226  ResultSet* rset = stmt->executeQuery();
227  if (rset->next() != 0) {
228  m_ID = rset->getInt(1);
229  } else {
230  m_ID = 0;
231  }
232  if (m_debug) {
233  cout << m_className + ": ID set to " << m_ID << endl;
234  }
235  int n = rset->getNumArrayRows();
236  if (m_debug) {
237  cout << m_className + ": Returned " << n << " rows" << endl;
238  }
239  if (n > 1) {
240  throw(std::runtime_error(m_className + "::fetchID: too many rows returned " + "executing query " + sql));
241  m_ID = 0;
242  }
243  }
244  m_conn->terminateStatement(stmt);
245  } catch (SQLException& e) {
246  throw(std::runtime_error(m_className + "::fetchID: " + e.getMessage()));
247  }
248  // given the ID of this object setup it completely
249  if (m_ID > 0) {
250  setByID(m_ID);
251  }
252  // if foreignKeys are there, set these objects too
253  map<string, LMFUnique*>::iterator i = m_foreignKeys.begin();
254  map<string, LMFUnique*>::iterator e = m_foreignKeys.end();
255  while (i != e) {
256  if (i->second->getID() == 0) {
257  i->second->fetchID();
258  }
259  i++;
260  }
261  if (m_debug) {
262  cout << m_className << ": fetchID:: returning " << m_ID << endl;
263  }
264  return m_ID;
265 }
std::string m_className
Definition: LMFUnique.h:95
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
oracle::occi::ResultSet ResultSet
Definition: LMFUnique.h:19
std::map< std::string, LMFUnique * > m_foreignKeys
Definition: LMFUnique.h:102
void setByID(int id) noexcept(false) override
Definition: LMFUnique.cc:267
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
virtual std::string fetchIdSql(Statement *stmt)
Definition: LMFUnique.h:82
char m_debug
Definition: LMFUnique.h:96
virtual std::string LMFUnique::fetchIdSql ( Statement stmt)
inlineprivatevirtual
virtual void LMFUnique::fetchParentIDs ( )
inlineprivatevirtual

Reimplemented in LMFSeqDat, and LMFIOV.

Definition at line 86 of file LMFUnique.h.

References createObject().

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

Definition at line 56 of file LMFUnique.h.

References m_className.

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

Definition at line 187 of file LMFUnique.cc.

References mps_fire::i, and runTheMatrix::ret.

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().

187  {
188  // this should be better defined
189  int ret = 0;
190  std::map<std::string, int>::const_iterator i = m_intFields.find(s);
191  if (i != m_intFields.end()) {
192  ret = i->second;
193  }
194  return ret;
195 }
ret
prodAgent to be discontinued
std::map< std::string, int > m_intFields
Definition: LMFUnique.h:100
virtual void LMFUnique::getParameters ( ResultSet rset)
inlineprotectedvirtual

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

Definition at line 90 of file LMFUnique.h.

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

90 {}
std::string LMFUnique::getString ( std::string  fieldname) const
virtual bool LMFUnique::isValid ( void  ) const
inlinevirtual

Reimplemented in LMFSeqDat.

Definition at line 48 of file LMFUnique.h.

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

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

Definition at line 71 of file LMFUnique.h.

References fetchAll(), m_debug, and noexcept.

Referenced by LMFUnique().

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

Definition at line 75 of file LMFUnique.h.

References IUniqueDBObject::m_ID.

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

Definition at line 76 of file LMFUnique.h.

References IUniqueDBObject::m_ID.

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

Definition at line 9 of file LMFUnique.cc.

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

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

9  {
10  std::string ts = t.str();
11  return ts.substr(2, 2);
12 }
std::string str() const
Definition: Tm.cc:66
void LMFUnique::setByID ( int  id)
overridevirtualnoexcept

Implements IUniqueDBObject.

Definition at line 267 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().

267  {
268  /*
269  Given the ID of an object setup it
270  */
271  if (m_debug) {
272  cout << m_className << ": Setting this object as ID = " << id << endl;
273  }
274  this->checkConnection();
275  try {
276  Statement* stmt = m_conn->createStatement();
277  std::string sql = setByIDSql(stmt, id);
278  if (sql.empty()) {
279  throw(std::runtime_error(m_className + "::setByID: [empty sql])"));
280  }
281  if (m_debug) {
282  cout << m_className + ": " + sql << endl;
283  }
284 
285  ResultSet* rset = stmt->executeQuery();
286  if (rset->next() != 0) {
287  // setup the concrete object
288  getParameters(rset);
289  m_ID = id;
290  if (m_debug) {
291  cout << m_className + ": Setting done. ID set to " << m_ID << endl;
292  }
293  } else {
294  throw(std::runtime_error(m_className + "::setByID: Given id is not in the database"));
295  }
296  m_conn->terminateStatement(stmt);
297  } catch (SQLException& e) {
298  throw(std::runtime_error(m_className + "::setByID: " + e.getMessage()));
299  }
300 }
std::string m_className
Definition: LMFUnique.h:95
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
oracle::occi::ResultSet ResultSet
Definition: LMFUnique.h:19
virtual std::string setByIDSql(Statement *stmt, int id)
Definition: LMFUnique.h:84
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
char m_debug
Definition: LMFUnique.h:96
virtual void getParameters(ResultSet *rset)
Definition: LMFUnique.h:90
virtual std::string LMFUnique::setByIDSql ( Statement stmt,
int  id 
)
inlineprivatevirtual

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

Definition at line 84 of file LMFUnique.h.

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

Definition at line 31 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().

31  {
32  // check if this key exists
33  std::map<std::string, int>::const_iterator i = m_intFields.find(key);
34  if (i != m_intFields.end()) {
35  // the key exist: check if it changed: reset the ID of the object
36  if (i->second != value) {
38  m_ID = 0;
39  }
40  } else {
41  // create this key and reset the ID of the object
43  m_ID = 0;
44  }
45  return *this;
46 }
Definition: value.py:1
std::map< std::string, int > m_intFields
Definition: LMFUnique.h:100
LMFUnique & LMFUnique::setString ( std::string  key,
std::string  value 
)

Definition at line 14 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().

14  {
15  // check if this key exists
16  std::map<std::string, std::string>::const_iterator i = m_stringFields.find(key);
17  if (i != m_stringFields.end()) {
18  // the key exist: check if it changed: reset the ID of the object
19  if (i->second != value) {
21  m_ID = 0;
22  }
23  } else {
24  // create this key and reset the ID of the object
26  m_ID = 0;
27  }
28  return *this;
29 }
std::map< std::string, std::string > m_stringFields
Definition: LMFUnique.h:98
Definition: value.py:1
void LMFUnique::startProfiling ( )
inline

Definition at line 77 of file LMFUnique.h.

References _profiling.

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

Definition at line 78 of file LMFUnique.h.

References _profiling.

78 { _profiling = false; }
bool _profiling
Definition: LMFUnique.h:103
int LMFUnique::writeDB ( )
protectedvirtualnoexcept

Reimplemented in LMFDat, LMFColoredTable, and LMFCorrCoefDatComponent.

Definition at line 316 of file LMFUnique.cc.

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

Referenced by getParameters().

316  {
317  clock_t start = 0;
318  clock_t end = 0;
319  if (_profiling) {
320  start = clock();
321  }
322  // write the associated objects first (foreign keys must exist before use)
324  // see if this data is already in the DB
325  if (!(this->fetchID())) {
326  // check the connectioin
327  this->checkConnection();
328 
329  // write new tag to the DB
330  std::string sql = "";
331  try {
332  Statement* stmt = m_conn->createStatement();
333 
334  sql = writeDBSql(stmt);
335  if (!sql.empty()) {
336  if (m_debug) {
337  cout << m_className + ": " + sql << endl;
338  }
339  stmt->executeUpdate();
340  }
341  m_conn->commit();
342  m_conn->terminateStatement(stmt);
343  } catch (SQLException& e) {
344  debug();
345  dump();
346  throw(std::runtime_error(m_className + "::writeDB: " + e.getMessage() + " while executing query " + sql));
347  }
348  // now get the id
349  if (this->fetchID() == 0) {
350  throw(std::runtime_error(m_className + "::writeDB: Failed to write"));
351  }
352  }
353  if (_profiling) {
354  end = clock();
355  if (m_debug) {
356  std::cout << m_className << ":: Spent time in writeDB:" << ((double)(end - start)) / CLOCKS_PER_SEC << " s"
357  << endl;
358  }
359  }
360  return m_ID;
361 }
std::string m_className
Definition: LMFUnique.h:95
Definition: start.py:1
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
bool _profiling
Definition: LMFUnique.h:103
virtual void dump() const
Definition: LMFUnique.cc:104
virtual std::string writeDBSql(Statement *stmt)
Definition: LMFUnique.h:81
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
oracle::occi::Statement Statement
Definition: LMFUnique.h:20
#define end
Definition: vmac.h:39
virtual int writeForeignKeys() noexcept(false)
Definition: LMFUnique.cc:302
char m_debug
Definition: LMFUnique.h:96
void debug()
Definition: LMFUnique.h:70
int fetchID() noexcept(false) override
Definition: LMFUnique.cc:197
virtual std::string LMFUnique::writeDBSql ( Statement stmt)
inlineprivatevirtual

Reimplemented in LMFLmrSubIOV, LMFSeqDat, LMFRunIOV, and LMFIOV.

Definition at line 81 of file LMFUnique.h.

81 { return ""; }
int LMFUnique::writeForeignKeys ( )
protectedvirtualnoexcept

Definition at line 302 of file LMFUnique.cc.

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

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

302  {
303  std::map<std::string, LMFUnique*>::const_iterator i = m_foreignKeys.begin();
304  std::map<std::string, LMFUnique*>::const_iterator e = m_foreignKeys.end();
305  int count = 0;
306  while (i != e) {
307  if (i->second->getID() == 0) {
308  i->second->writeDB();
309  count++;
310  }
311  i++;
312  }
313  return count;
314 }
std::map< std::string, LMFUnique * > m_foreignKeys
Definition: LMFUnique.h:102

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 103 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