CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes | Friends

LMFSeqDat Class Reference

#include <LMFSeqDat.h>

Inheritance diagram for LMFSeqDat:
LMFUnique IUniqueDBObject IDBObject

List of all members.

Public Member Functions

std::map< int, LMFSeqDatfetchByRunIOV (RunIOV &iov)
std::map< int, LMFSeqDatfetchByRunIOV (RunIOV &iov, const LMFColor &col)
LMFSeqDat fetchByRunIOV (RunIOV &iov, int seq_num)
std::map< int, LMFSeqDatfetchByRunNumber (int runno)
LMFSeqDat fetchByRunNumber (int runno, int seq_num)
LMFSeqDat fetchByRunNumber (int runno, Tm taken_at)
LMFSeqDat fetchByRunNumber (int runno, std::string taken_at)
LMFSeqDat fetchLast ()
RunIOV fetchLastRun ()
RunIOV getRunIOV () const
int getSequenceNumber () const
Tm getSequenceStart () const
Tm getSequenceStop () const
int getVmax () const
int getVmin () const
bool isValid () const
 LMFSeqDat ()
 LMFSeqDat (oracle::occi::Environment *env, oracle::occi::Connection *conn)
 LMFSeqDat (EcalDBConnection *c)
bool operator!= (const LMFSeqDat &m) const
bool operator== (const LMFSeqDat &m) const
LMFSeqDatsetRunIOV (const RunIOV &iov)
LMFSeqDatsetSequenceNumber (int n)
LMFSeqDatsetSequenceStart (Tm start)
LMFSeqDatsetSequenceStop (Tm end)
LMFSeqDatsetVersions (int vmin, int vmax)
 ~LMFSeqDat ()

Private Member Functions

std::map< int, LMFSeqDatfetchByRunIOV (std::vector< std::string > par, std::string sql, std::string method) throw (std::runtime_error)
std::map< int, LMFSeqDatfetchByRunIOV (int par, std::string sql, std::string method) throw (std::runtime_error)
std::map< int, LMFSeqDatfetchByRunIOV (std::string sql, std::string method) throw (std::runtime_error)
std::string fetchIdSql (Statement *stmt)
void fetchParentIDs () throw (std::runtime_error)
void getParameters (ResultSet *rset)
std::string setByIDSql (Statement *stmt, int id)
void setVmax (int v)
void setVmin (int v)
std::string writeDBSql (Statement *stmt)

Private Attributes

RunIOV m_runIOV

Friends

class EcalCondDBInterface

Detailed Description

Definition at line 14 of file LMFSeqDat.h.


Constructor & Destructor Documentation

LMFSeqDat::LMFSeqDat ( )

Definition at line 10 of file LMFSeqDat.cc.

References LMFUnique::m_intFields, m_runIOV, LMFUnique::m_stringFields, Tm::plusInfinity(), LMFUnique::setClassName(), Tm::str(), and lumiQTWidget::t.

                     : LMFUnique()
{
  setClassName("LMFSeqDat");

  m_runIOV = RunIOV();
  m_intFields["seq_num"] = 0;
  Tm t;
  t = t.plusInfinity();
  m_stringFields["seq_start"] = t.str();
  m_stringFields["seq_stop"]  = t.str();
  m_intFields["vmin"] = 1;
  m_intFields["vmax"] = 0;
}
LMFSeqDat::LMFSeqDat ( oracle::occi::Environment *  env,
oracle::occi::Connection *  conn 
)

Definition at line 37 of file LMFSeqDat.cc.

References LMFUnique::m_intFields, m_runIOV, LMFUnique::m_stringFields, Tm::plusInfinity(), LMFUnique::setClassName(), Tm::str(), and lumiQTWidget::t.

                                                 : LMFUnique(env, conn) {
  setClassName("LMFSeqDat");

  m_runIOV = RunIOV();
  m_intFields["seq_num"] = 0;
  Tm t;
  t = t.plusInfinity();
  m_stringFields["seq_start"] = t.str();
  m_stringFields["seq_stop"]  = t.str();
  m_intFields["vmin"] = 1;
  m_intFields["vmax"] = 0;
}
LMFSeqDat::LMFSeqDat ( EcalDBConnection c)

Definition at line 24 of file LMFSeqDat.cc.

References LMFUnique::m_intFields, m_runIOV, LMFUnique::m_stringFields, Tm::plusInfinity(), LMFUnique::setClassName(), Tm::str(), and lumiQTWidget::t.

                                        : LMFUnique(c) {
  setClassName("LMFSeqDat");

  m_runIOV = RunIOV();
  m_intFields["seq_num"] = 0;
  Tm t;
  t = t.plusInfinity();
  m_stringFields["seq_start"] = t.str();
  m_stringFields["seq_stop"]  = t.str();
  m_intFields["vmin"] = 1;
  m_intFields["vmax"] = 0;
}
LMFSeqDat::~LMFSeqDat ( )

Definition at line 51 of file LMFSeqDat.cc.

{
}

Member Function Documentation

std::map< int, LMFSeqDat > LMFSeqDat::fetchByRunIOV ( RunIOV iov)

Definition at line 268 of file LMFSeqDat.cc.

References RunIOV::getID().

Referenced by fetchByRunIOV(), fetchByRunNumber(), and fetchLast().

                                                           {
  int runIOVID = iov.getID();
  return fetchByRunIOV(runIOVID, 
                       "SELECT SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT "
                       "WHERE RUN_IOV_ID = :1",
                       "fetchByRunIOV");
}
std::map< int, LMFSeqDat > LMFSeqDat::fetchByRunIOV ( RunIOV iov,
const LMFColor col 
)

Definition at line 276 of file LMFSeqDat.cc.

References fetchByRunIOV(), LMFUnique::getID(), and RunIOV::getID().

                                                                       {
  int runIOVID = iov.getID();
  int colorId  = col.getID();
  std::vector<std::string> pars;
  std::stringstream ss;
  ss << "I" << runIOVID;
  pars.push_back(ss.str());
  ss.str(std::string());
  ss << "I" << colorId;
  pars.push_back(ss.str());
  return fetchByRunIOV(pars, 
                       "SELECT S.SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT "
                       "S JOIN CMS_ECAL_LASER_COND.LMF_RUN_IOV R"
                       " ON S.SEQ_ID = R.SEQ_ID WHERE RUN_IOV_ID = :1 AND "
                       " COLOR_ID = :2",
                       "fetchByRunIOVAndColor");
}
LMFSeqDat LMFSeqDat::fetchByRunIOV ( RunIOV iov,
int  seq_num 
) [inline]

Definition at line 66 of file LMFSeqDat.h.

References fetchByRunIOV().

                                                    {
    return fetchByRunIOV(iov)[seq_num];
  }
std::map< int, LMFSeqDat > LMFSeqDat::fetchByRunIOV ( int  par,
std::string  sql,
std::string  method 
) throw (std::runtime_error) [private]

Definition at line 203 of file LMFSeqDat.cc.

References PFRecoTauDiscriminationAgainstElectronMVA_cfi::method.

{
  std::vector<std::string> pars;
  std::stringstream ss;
  ss << "I" << par;
  pars.push_back(ss.str());
  return fetchByRunIOV(pars, sql, method);
}
std::map< int, LMFSeqDat > LMFSeqDat::fetchByRunIOV ( std::string  sql,
std::string  method 
) throw (std::runtime_error) [private]

Definition at line 195 of file LMFSeqDat.cc.

References PFRecoTauDiscriminationAgainstElectronMVA_cfi::method.

{
  std::vector<std::string> pars;
  return fetchByRunIOV(pars, sql, method);
}
std::map< int, LMFSeqDat > LMFSeqDat::fetchByRunIOV ( std::vector< std::string >  par,
std::string  sql,
std::string  method 
) throw (std::runtime_error) [private]

Definition at line 215 of file LMFSeqDat.cc.

References alignCSCRings::e, getSequenceNumber(), i, prof2calltree::l, PFRecoTauDiscriminationAgainstElectronMVA_cfi::method, alignCSCRings::s, LMFUnique::setByID(), and IDBObject::setConnection().

{
  std::map<int, LMFSeqDat> l;
  this->checkConnection();
  try {
    Statement *stmt = m_conn->createStatement();
    stmt->setSQL(sql);
    for (unsigned int i = 0; i < pars.size(); i++) {
      if (pars[i][0] == 'I') {
        stmt->setInt(i + 1, atoi(pars[i].c_str() + 1));
      } else if (pars[i][0] == 'S') {
        stmt->setString(i + 1, pars[i].c_str() + 1);
      } else {
        throw(std::runtime_error(m_className + "::" + method + ": " + 
                                 "Invalid type"));
      }
    }
    ResultSet *rset = stmt->executeQuery();
    while (rset->next() != 0) {
      int seq_id = rset->getInt(1);
      LMFSeqDat s;
      s.setConnection(m_env, m_conn);
      s.setByID(seq_id);
      l[s.getSequenceNumber()] = s;
    }
    m_conn->terminateStatement(stmt);
  } catch (SQLException &e) {
    throw(std::runtime_error(m_className + "::" + method + ": " + 
                             e.getMessage()));
  }
  return l;
}
std::map< int, LMFSeqDat > LMFSeqDat::fetchByRunNumber ( int  runno)

Definition at line 295 of file LMFSeqDat.cc.

References fetchByRunIOV().

Referenced by fetchByRunNumber().

                                                            {
  return fetchByRunIOV(runno, 
                       "SELECT SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT D "
                       "JOIN CMS_ECAL_COND.RUN_IOV R ON "
                       "D.RUN_IOV_ID = R.IOV_ID WHERE RUN_NUM = :1",
                       "fetchByRunNumber");
}
LMFSeqDat LMFSeqDat::fetchByRunNumber ( int  runno,
int  seq_num 
) [inline]

Definition at line 70 of file LMFSeqDat.h.

References fetchByRunNumber().

                                                     {
    return fetchByRunNumber(runno)[seq_num];
  }
LMFSeqDat LMFSeqDat::fetchByRunNumber ( int  runno,
Tm  taken_at 
)

Definition at line 303 of file LMFSeqDat.cc.

References fetchByRunNumber(), and Tm::str().

                                                            {
  return fetchByRunNumber(runno, taken_at.str());
}
LMFSeqDat LMFSeqDat::fetchByRunNumber ( int  runno,
std::string  taken_at 
)

Definition at line 307 of file LMFSeqDat.cc.

References gather_cfg::cout, fetchByRunIOV(), i, prof2calltree::l, lumiQueryAPI::q, runTheMatrix::ret, lumiregperbunch::runno, and x.

                                                                   {
  std::map<int, LMFSeqDat> l;
  std::vector<std::string> pars;
  std::stringstream ss;
  ss << "I" << runno;
  pars.push_back(ss.str());
  ss.str(std::string());
  ss << "S" << taken_at;
  pars.push_back(ss.str());
  std::string q = "SELECT SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT D "
    "JOIN CMS_ECAL_COND.RUN_IOV R ON "
    "D.RUN_IOV_ID = R.IOV_ID WHERE RUN_NUM = :1 AND "
    "SEQ_START >= TO_DATE(:2, 'YYYY-MM-DD HH24:MI:SS') "
    "AND SEQ_STOP <= TO_DATE(:2, 'YYYY-MM-DD HH24:MI:SS')";
  l = fetchByRunIOV(pars, q, "fetchByRunNumberAt");
  LMFSeqDat ret;
  if (l.size() == 1) {
    std::map<int, LMFSeqDat>::const_iterator x = l.begin();
    ret = x->second;
  } else if (l.size() > 1) {
    std::cout << "WARNING: Your query returned more than one result. " 
              << std::endl;
    std::cout << "         This was not expected. Please check the DB!!!" 
              << std::endl;
    std::cout << "Your query: " << std::endl << q << std::endl;
    std::cout << "Your parameters: " << std::endl;
    for (unsigned int i = 0; i < pars.size(); i++) {
      std::cout << i << ": " << pars[i] << std::endl;
    }
  }
  return ret;
}
std::string LMFSeqDat::fetchIdSql ( Statement stmt) [private, virtual]

Reimplemented from LMFUnique.

Definition at line 75 of file LMFSeqDat.cc.

References gather_cfg::cout, RunIOV::getID(), getSequenceNumber(), getVmax(), getVmin(), LMFUnique::m_className, LMFUnique::m_debug, and m_runIOV.

{
  int runIOVID = m_runIOV.getID();
  if (!runIOVID) { 
    if (m_debug) {
      std::cout << m_className << ": RunIOV not set" << endl;
    }
    return "";
  }

  if (m_debug) {
    std::cout << "Run IOV ID: " << runIOVID << std::endl;
    std::cout << "SEQ #     : " << getSequenceNumber() << std::endl;
    std::cout << "Versions  : " << getVmin() << " - " << getVmax() << endl;
  }
  std::string sql = "SELECT SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT "
    "WHERE "
    "RUN_IOV_ID   = :1 AND "
    "SEQ_NUM      = :2 AND "
    "VMIN         = :3 ";
  if (getVmax() > 0) {
    sql += "AND VMAX = :4";
  } else {
    sql += "ORDER BY VMAX DESC";
  }
  stmt->setSQL(sql);
  stmt->setInt(1, runIOVID);
  stmt->setInt(2, getSequenceNumber());
  stmt->setInt(3, getVmin());
  if (getVmax() > 0) {
    stmt->setInt(4, getVmax());
  }
  return sql;
}
LMFSeqDat LMFSeqDat::fetchLast ( )

Definition at line 251 of file LMFSeqDat.cc.

References fetchByRunIOV(), m, and runTheMatrix::ret.

Referenced by fetchLastRun().

                               {
  LMFSeqDat ret;
  std::map<int, LMFSeqDat> m = 
    fetchByRunIOV("SELECT SEQ_ID FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT "
                  "WHERE SEQ_ID = "
                  "(SELECT MAX(SEQ_ID) FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT)",
                  "fetchLast");
  if (m.size() > 0) {
    ret = m.begin()->second;
  }
  return ret;
}
RunIOV LMFSeqDat::fetchLastRun ( )

Definition at line 264 of file LMFSeqDat.cc.

References fetchLast(), and getRunIOV().

Referenced by EcalCondDBInterface::fetchLMFLastRun().

                               {
  return fetchLast().getRunIOV();
}
void LMFSeqDat::fetchParentIDs ( ) throw (std::runtime_error) [private, virtual]

Reimplemented from LMFUnique.

Definition at line 181 of file LMFSeqDat.cc.

References RunIOV::getID(), IDBObject::m_conn, IDBObject::m_env, m_runIOV, RunIOV::setByID(), and IDBObject::setConnection().

{
  // get the RunIOV
  m_runIOV.setConnection(m_env, m_conn);
  int runIOVID = m_runIOV.getID();
  m_runIOV.setByID(runIOVID);

  if (m_runIOV.getID() == 0) { 
    throw(std::runtime_error("LMFSeqDat:  Given RunIOV does not exist in DB")); 
  }

}
void LMFSeqDat::getParameters ( ResultSet rset) [private, virtual]

Reimplemented from LMFUnique.

Definition at line 118 of file LMFSeqDat.cc.

References DateHandler::dateToTm(), IDBObject::m_conn, IDBObject::m_env, m_runIOV, RunIOV::setByID(), IDBObject::setConnection(), LMFUnique::setInt(), LMFUnique::setString(), and Tm::str().

                                             {     
  DateHandler dh(m_env, m_conn);
  int runIOVID = rset->getInt(1);
  setInt("seq_num", rset->getInt(2));
  Date startDate = rset->getDate(3);
  Date endDate = rset->getDate(4);
  setInt("vmin", rset->getInt(5));
  setInt("vmax", rset->getInt(6));

  setString("seq_start", dh.dateToTm( startDate ).str());
  setString("seq_stop",  dh.dateToTm( endDate ).str());

  m_runIOV.setConnection(m_env, m_conn);
  m_runIOV.setByID(runIOVID);
}
RunIOV LMFSeqDat::getRunIOV ( ) const

Definition at line 61 of file LMFSeqDat.cc.

References m_runIOV.

Referenced by fetchLastRun(), and operator==().

{ 
  return m_runIOV;
}
int LMFSeqDat::getSequenceNumber ( ) const [inline]

Definition at line 41 of file LMFSeqDat.h.

References LMFUnique::getInt().

Referenced by fetchByRunIOV(), fetchIdSql(), operator==(), and writeDBSql().

{ return getInt("seq_num"); }
Tm LMFSeqDat::getSequenceStart ( ) const [inline]

Definition at line 42 of file LMFSeqDat.h.

References LMFUnique::getString(), Tm::setToString(), and lumiQTWidget::t.

Referenced by isValid(), operator==(), and writeDBSql().

                               { 
    Tm t;
    t.setToString(getString("seq_start"));
    return t;
  }
Tm LMFSeqDat::getSequenceStop ( ) const

Definition at line 55 of file LMFSeqDat.cc.

References LMFUnique::getString(), Tm::setToString(), and lumiQTWidget::t.

Referenced by isValid(), operator==(), and writeDBSql().

                                    {
  Tm t;
  t.setToString(getString("seq_stop"));
  return t;
}
int LMFSeqDat::getVmax ( ) const [inline]

Definition at line 49 of file LMFSeqDat.h.

References LMFUnique::getInt().

Referenced by fetchIdSql(), operator==(), and writeDBSql().

{ return getInt("vmax"); }
int LMFSeqDat::getVmin ( ) const [inline]

Definition at line 48 of file LMFSeqDat.h.

References LMFUnique::getInt().

Referenced by fetchIdSql(), operator==(), and writeDBSql().

{ return getInt("vmin"); }
bool LMFSeqDat::isValid ( void  ) const [virtual]

Reimplemented from LMFUnique.

Definition at line 134 of file LMFSeqDat.cc.

References getSequenceStart(), getSequenceStop(), and runTheMatrix::ret.

Referenced by writeDBSql().

                              {
  bool ret = true;
  if (getSequenceStart().isNull()) {
    ret = false;
  }
  if ((getSequenceStop().str().length() > 0) &&
      (getSequenceStop().microsTime() < getSequenceStart().microsTime())) {
    ret = false;
  }
  if (getSequenceStop() == Tm().plusInfinity()) {
    ret = false;
  }
  return ret;
}
bool LMFSeqDat::operator!= ( const LMFSeqDat m) const [inline]

Definition at line 63 of file LMFSeqDat.h.

References m.

{ return !(*this == m); }
bool LMFSeqDat::operator== ( const LMFSeqDat m) const [inline]
std::string LMFSeqDat::setByIDSql ( Statement stmt,
int  id 
) [private, virtual]

Reimplemented from LMFUnique.

Definition at line 110 of file LMFSeqDat.cc.

                                                       {
  std::string sql = "SELECT RUN_IOV_ID, SEQ_NUM, SEQ_START, SEQ_STOP, " 
    "VMIN, VMAX FROM CMS_ECAL_LASER_COND.LMF_SEQ_DAT WHERE SEQ_ID = :1";
  stmt->setSQL(sql);
  stmt->setInt(1, id);
  return sql;
}
LMFSeqDat & LMFSeqDat::setRunIOV ( const RunIOV iov)

Definition at line 66 of file LMFSeqDat.cc.

References o2o::iov, IUniqueDBObject::m_ID, and m_runIOV.

{
  if (iov != m_runIOV) {
    m_ID = 0;
    m_runIOV = iov;
  }
  return *this;
}
LMFSeqDat& LMFSeqDat::setSequenceNumber ( int  n) [inline]

Definition at line 26 of file LMFSeqDat.h.

References LMFUnique::setInt().

{ setInt("seq_num", n); return *this; }
LMFSeqDat& LMFSeqDat::setSequenceStart ( Tm  start) [inline]

Definition at line 27 of file LMFSeqDat.h.

References LMFUnique::setString(), and Tm::str().

                                        { 
    setString("seq_start", start.str()); 
    return *this;
  }
LMFSeqDat& LMFSeqDat::setSequenceStop ( Tm  end) [inline]

Definition at line 31 of file LMFSeqDat.h.

References LMFUnique::setString(), and Tm::str().

Referenced by writeDBSql().

                                     { 
    setString("seq_stop", end.str()); 
    return *this;
  }
LMFSeqDat& LMFSeqDat::setVersions ( int  vmin,
int  vmax 
) [inline]

Definition at line 35 of file LMFSeqDat.h.

References setVmax(), and setVmin().

                                             { 
    setVmin(vmin) ; setVmax(vmax); 
    return *this;
  }
void LMFSeqDat::setVmax ( int  v) [inline, private]

Definition at line 84 of file LMFSeqDat.h.

References LMFUnique::setInt().

Referenced by setVersions().

                      {
    setInt("vmax", v);
  }
void LMFSeqDat::setVmin ( int  v) [inline, private]

Definition at line 81 of file LMFSeqDat.h.

References LMFUnique::setInt().

Referenced by setVersions().

                      {
    setInt("vmin", v);
  }
std::string LMFSeqDat::writeDBSql ( Statement stmt) [private, virtual]

Reimplemented from LMFUnique.

Definition at line 149 of file LMFSeqDat.cc.

References gather_cfg::cout, LMFUnique::dump(), RunIOV::getID(), DateHandler::getPlusInfTm(), getSequenceNumber(), getSequenceStart(), getSequenceStop(), getVmax(), getVmin(), isValid(), IDBObject::m_conn, IDBObject::m_env, m_runIOV, LMFUnique::sequencePostfix(), setSequenceStop(), and DateHandler::tmToDate().

{
  // Validate the data, use infinity-till convention
  DateHandler dh(m_env, m_conn);

  if (!isValid()) {
    dump();
    throw(std::runtime_error("LMFSeqDat::writeDB: not valid"));
  }

  if (getSequenceStop().str().length() == 0) {
    setSequenceStop(dh.getPlusInfTm());
  }
  int runIOVID = m_runIOV.getID();
  if (runIOVID == 0) {
    throw(std::runtime_error("LMFSeqDat::writeDB: RunIOV not set"));
  }
  std::string sp = sequencePostfix(getSequenceStart());
  std::string sql = "INSERT INTO LMF_SEQ_DAT (SEQ_ID, RUN_IOV_ID, SEQ_NUM, "
    "SEQ_START, SEQ_STOP, VMIN, VMAX) "
    "VALUES (SEQ_ID_" + sp + "_SQ.NextVal, :1, :2, :3, :4, :5, :6)";
  cout << sql << endl;
  stmt->setSQL(sql);
  stmt->setInt(1, runIOVID);
  stmt->setInt(2, getSequenceNumber());
  stmt->setDate(3, dh.tmToDate(getSequenceStart()));
  stmt->setDate(4, dh.tmToDate(getSequenceStop()));
  stmt->setInt(5, getVmin());
  stmt->setInt(6, getVmax());
  return sql;
}

Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from LMFUnique.

Definition at line 16 of file LMFSeqDat.h.


Member Data Documentation