Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:04

0001 #include <stdexcept>
0002 #include "OnlineDB/Oracle/interface/Oracle.h"
0003 
0004 #include "OnlineDB/EcalCondDB/interface/LMFColor.h"
0005 
0006 using namespace std;
0007 using namespace oracle::occi;
0008 
0009 LMFColor::LMFColor() {
0010   m_ID = 0;
0011   m_className = "LMFColor";
0012   m_stringFields["sname"] = "none";
0013   m_stringFields["lname"] = "none";
0014   m_intFields["color"] = -1;
0015 }
0016 
0017 LMFColor::LMFColor(oracle::occi::Environment *env, oracle::occi::Connection *conn) : LMFUnique(env, conn) {
0018   m_ID = 0;
0019   m_className = "LMFColor";
0020   m_stringFields["sname"] = "none";
0021   m_stringFields["lname"] = "none";
0022   m_intFields["color"] = -1;
0023 }
0024 
0025 LMFColor::LMFColor(EcalDBConnection *c) : LMFUnique(c) {
0026   m_ID = 0;
0027   m_className = "LMFColor";
0028   m_stringFields["sname"] = "none";
0029   m_stringFields["lname"] = "none";
0030   m_intFields["color"] = -1;
0031 }
0032 
0033 LMFColor::LMFColor(EcalDBConnection *c, std::string color) : LMFUnique(c) {
0034   m_ID = 0;
0035   m_className = "LMFColor";
0036   m_stringFields["sname"] = "none";
0037   m_stringFields["lname"] = "none";
0038   m_intFields["color"] = -1;
0039   setName(color);
0040 }
0041 
0042 LMFColor::~LMFColor() {}
0043 
0044 std::string LMFColor::fetchAllSql(Statement *stmt) const {
0045   std::string sql =
0046       "SELECT COLOR_ID FROM "
0047       "CMS_ECAL_LASER_COND.LMF_COLOR_DEF";
0048   stmt->setSQL(sql);
0049   return sql;
0050 }
0051 
0052 LMFUnique *LMFColor::createObject() const {
0053   LMFColor *n = new LMFColor;
0054   n->setConnection(m_env, m_conn);
0055   return n;
0056 }
0057 
0058 std::string LMFColor::fetchIdSql(Statement *stmt) {
0059   // the query depends on the object status
0060   std::string sql;
0061   if ((getInt("color") >= 0) && (getString("sname") != "none")) {
0062     sql =
0063         "SELECT COLOR_ID FROM CMS_ECAL_LASER_COND.LMF_COLOR_DEF "
0064         "WHERE SNAME   = :1 AND COLOR_INDEX = :2";
0065     stmt->setSQL(sql);
0066     stmt->setString(1, getShortName());
0067     stmt->setInt(2, getColorIndex());
0068   } else if (getInt("color") >= 0) {
0069     sql =
0070         "SELECT COLOR_ID FROM CMS_ECAL_LASER_COND.LMF_COLOR_DEF "
0071         "WHERE COLOR_INDEX = :1";
0072     stmt->setSQL(sql);
0073     stmt->setInt(1, getColorIndex());
0074   } else if (!getString("sname").empty()) {
0075     sql =
0076         "SELECT COLOR_ID FROM CMS_ECAL_LASER_COND.LMF_COLOR_DEF "
0077         "WHERE SNAME   = :1";
0078     stmt->setSQL(sql);
0079     stmt->setString(1, getShortName());
0080   }
0081   return sql;
0082 }
0083 
0084 std::string LMFColor::setByIDSql(Statement *stmt, int id) {
0085   std::string sql =
0086       "SELECT COLOR_INDEX, SNAME, LNAME "
0087       "FROM CMS_ECAL_LASER_COND.LMF_COLOR_DEF WHERE COLOR_ID = :1";
0088   stmt->setSQL(sql);
0089   stmt->setInt(1, id);
0090   return sql;
0091 }
0092 
0093 void LMFColor::getParameters(ResultSet *rset) {
0094   setInt("color", rset->getInt(1));
0095   setString("sname", rset->getString(2));
0096   setString("lname", rset->getString(3));
0097 }
0098 
0099 template <typename T, typename U>
0100 inline T &unique_static_cast(U &i) {
0101   return *(static_cast<T *>(i.get()));
0102 }
0103 
0104 bool LMFColor::isValid() {
0105   auto listOfValidColors = fetchAll();
0106   auto i = listOfValidColors.begin();
0107   auto e = listOfValidColors.end();
0108   bool ret = false;
0109   while (i != e) {
0110     const LMFColor &c = unique_static_cast<const LMFColor>(*i);
0111     if (c.getShortName() == getShortName()) {
0112       ret = true;
0113       i = e;
0114     }
0115     i++;
0116   }
0117   return ret;
0118 }