CMS 3D CMS Logo

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

ODCond2ConfInfo Class Reference

#include <ODCond2ConfInfo.h>

Inheritance diagram for ODCond2ConfInfo:
IODConfig IDBObject

List of all members.

Public Member Functions

int fetchID () throw (std::runtime_error)
int fetchNextId () throw (std::runtime_error)
Tm getDBDate () const
std::string getDescription () const
int getId () const
std::string getLocation () const
Tm getRecordDate () const
int getRunNumber () const
std::string getTable ()
std::string getType () const
 ODCond2ConfInfo ()
void setDBDate (Tm x)
void setDescription (std::string x)
void setId (int id)
void setLocation (std::string x)
void setParameters (std::map< std::string, std::string > my_keys_map)
void setRecordDate (Tm x)
void setRunNumber (int id)
void setType (std::string x)
 ~ODCond2ConfInfo ()

Private Member Functions

void clear ()
void fetchData (ODCond2ConfInfo *result) throw (std::runtime_error)
void fetchParents () throw (std::runtime_error)
void prepareWrite () throw (std::runtime_error)
void writeDB () throw (std::runtime_error)

Private Attributes

Tm m_db_time
std::string m_desc
int m_ID
std::string m_loc
int m_loc_id
Tm m_rec_time
int m_run
int m_typ_id
std::string m_type

Friends

class EcalCondDBInterface

Detailed Description

Definition at line 12 of file ODCond2ConfInfo.h.


Constructor & Destructor Documentation

ODCond2ConfInfo::ODCond2ConfInfo ( )

Definition at line 12 of file ODCond2ConfInfo.cc.

References NULL.

ODCond2ConfInfo::~ODCond2ConfInfo ( )

Definition at line 39 of file ODCond2ConfInfo.cc.

{
}

Member Function Documentation

void ODCond2ConfInfo::clear ( void  ) [private]

Definition at line 24 of file ODCond2ConfInfo.cc.

                           {
  m_type="";
  m_loc="";
  m_run=0;
  m_desc="";
  m_rec_time = Tm();
  m_db_time = Tm();
  m_typ_id=0;
  m_loc_id=0;


}
void ODCond2ConfInfo::fetchData ( ODCond2ConfInfo result) throw (std::runtime_error) [private]

Definition at line 187 of file ODCond2ConfInfo.cc.

References DateHandler::dateToTm(), and query::result.

{
  this->checkConnection();
  result->clear();

  DateHandler dh(m_env, m_conn);


  if(result->getId()==0 ){
    throw(std::runtime_error("ODCond2ConfInfo::fetchData(): no Id defined for this ODCond2ConfInfo "));
  }

  try {

    m_readStmt->setSQL("SELECT rec_id, REC_TYPE, rec_date, location, "
                       "run_number, short_desc, db_timestamp FROM " + getTable() + " , COND2CONF_TYPE_DEF , location_def "  
                       " where  rec_id = :1  AND COND2CONF_TYPE_DEF.def_id="
                       +getTable()+".REC_TYPE_ID AND location_def.def_id=LOCATION_ID ");
    m_readStmt->setInt(1, result->getId());
    ResultSet* rset = m_readStmt->executeQuery();

    rset->next();

    // 1 is the id and 2 is the config tag and 3 is the version

         
 

    //    result->setId(rset->getInt(1));


    result->setType(rset->getString(2));
    Date startDate = rset->getDate(3);
    result->setLocation(rset->getString(4));
    result->setRunNumber(rset->getInt(5));
    result->setDescription(rset->getString(6));
    Date endDate = rset->getDate(7);

    m_rec_time = dh.dateToTm( startDate );
    m_db_time = dh.dateToTm( endDate );

  } catch (SQLException &e) {
    throw(std::runtime_error("ODCond2ConfInfo::fetchData():  "+e.getMessage()));
  }
}
int ODCond2ConfInfo::fetchID ( ) throw (std::runtime_error)

Definition at line 234 of file ODCond2ConfInfo.cc.

{
  // Return from memory if available
  if (m_ID!=0) {
    return m_ID;
  }

  this->checkConnection();


  fetchParents();

  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL("SELECT rec_id FROM "+ getTable()+
                 "WHERE  rec_type_id=:1 and (run_number=:2 or short_desc=:3 ) order by rec_id DESC " );

    stmt->setInt(1, m_typ_id );
    stmt->setInt(2, getRunNumber() );
    stmt->setString(3, getDescription() );

    ResultSet* rset = stmt->executeQuery();

    if (rset->next()) {
      m_ID = rset->getInt(1);
    } else {
      m_ID = 0;
    }
    m_conn->terminateStatement(stmt);
  } catch (SQLException &e) {
    throw(std::runtime_error("ODCond2ConfInfo::fetchID:  "+e.getMessage()));
  }

  return m_ID;
}
int ODCond2ConfInfo::fetchNextId ( ) throw (std::runtime_error)

Definition at line 45 of file ODCond2ConfInfo.cc.

References query::result.

                                                          {

  int result=0;
  try {
    this->checkConnection();

    m_readStmt = m_conn->createStatement(); 
    m_readStmt->setSQL("select COND2CONF_INFO_SQ.NextVal from DUAL ");
    ResultSet* rset = m_readStmt->executeQuery();
    while (rset->next ()){
      result= rset->getInt(1);
    }
    result++;
    m_conn->terminateStatement(m_readStmt);
    return result; 

  } catch (SQLException &e) {
    throw(std::runtime_error("ODCond2ConfInfo::fetchNextId():  "+e.getMessage()));
  }

}
void ODCond2ConfInfo::fetchParents ( ) throw (std::runtime_error) [private]

Definition at line 67 of file ODCond2ConfInfo.cc.

                                                            {



  if(m_typ_id==0) {
  
    if(getType()!=""){
    try {
      this->checkConnection();
      m_readStmt = m_conn->createStatement(); 
      m_readStmt->setSQL("select def_id from COND2CONF_TYPE_DEF where rec_type="+getType());
      ResultSet* rset = m_readStmt->executeQuery();
      while (rset->next ()){
        m_typ_id= rset->getInt(1);
      }
      m_conn->terminateStatement(m_readStmt);
      
      
    } catch (SQLException &e) {
      throw(std::runtime_error("ODCond2ConfInfo::fetchParents():  "+e.getMessage()));
    }
  }
  }
  if(m_loc_id==0){
  if(getLocation()!=""){
    try {
      this->checkConnection();
      m_readStmt = m_conn->createStatement(); 
      m_readStmt->setSQL("select def_id from location_def where location="+getLocation());
      ResultSet* rset = m_readStmt->executeQuery();
      while (rset->next ()){
        m_loc_id= rset->getInt(1);
      }
      m_conn->terminateStatement(m_readStmt);
    } catch (SQLException &e) {
      throw(std::runtime_error("ODCond2ConfInfo::fetchParents():  "+e.getMessage()));
    }
  }
  }

}
Tm ODCond2ConfInfo::getDBDate ( ) const [inline]

Definition at line 40 of file ODCond2ConfInfo.h.

References m_db_time.

{ return m_db_time; }
std::string ODCond2ConfInfo::getDescription ( ) const [inline]

Definition at line 37 of file ODCond2ConfInfo.h.

References m_desc.

{ return m_desc ; }
int ODCond2ConfInfo::getId ( ) const [inline]

Definition at line 22 of file ODCond2ConfInfo.h.

References m_ID.

{ return m_ID; }
std::string ODCond2ConfInfo::getLocation ( ) const [inline]

Definition at line 31 of file ODCond2ConfInfo.h.

References m_loc.

{ return m_loc; }
Tm ODCond2ConfInfo::getRecordDate ( ) const [inline]

Definition at line 28 of file ODCond2ConfInfo.h.

References m_rec_time.

{ return m_rec_time; }
int ODCond2ConfInfo::getRunNumber ( ) const [inline]

Definition at line 34 of file ODCond2ConfInfo.h.

References m_run.

{ return m_run; }
std::string ODCond2ConfInfo::getTable ( ) [inline, virtual]

Implements IODConfig.

Definition at line 19 of file ODCond2ConfInfo.h.

{ return "COND_2_CONF_INFO"; }
std::string ODCond2ConfInfo::getType ( void  ) const [inline]

Definition at line 25 of file ODCond2ConfInfo.h.

References m_type.

{ return m_type; }
void ODCond2ConfInfo::prepareWrite ( ) throw (std::runtime_error) [private, virtual]

Implements IODConfig.

Definition at line 109 of file ODCond2ConfInfo.cc.

References getId().

{
  this->checkConnection();

  int next_id=0;
  if(getId()==0){
    next_id=fetchNextId();
  }

  fetchParents();
  try {
    m_writeStmt = m_conn->createStatement();
    m_writeStmt->setSQL("INSERT INTO "+getTable()+" ( rec_id, rec_type_id, rec_date, "
                "location_id, run_number, short_desc ) " 
                        " VALUES ( :1, :2, :3 , :4, :5, :6 ) " );

    m_writeStmt->setInt(1, next_id);
    m_writeStmt->setInt(3, m_typ_id);
    m_writeStmt->setInt(4, m_loc_id);
    
    m_ID=next_id;

  } catch (SQLException &e) {
    throw(std::runtime_error("ODCond2ConfInfo::prepareWrite():  "+e.getMessage()));
  }

}
void ODCond2ConfInfo::setDBDate ( Tm  x) [inline]

Definition at line 39 of file ODCond2ConfInfo.h.

References m_db_time, and x.

{ m_db_time = x; }
void ODCond2ConfInfo::setDescription ( std::string  x) [inline]

Definition at line 36 of file ODCond2ConfInfo.h.

References m_desc, and x.

{ m_desc = x; }
void ODCond2ConfInfo::setId ( int  id) [inline]

Definition at line 21 of file ODCond2ConfInfo.h.

References m_ID.

{ m_ID = id; }
void LocationDef::setLocation ( std::string  x) [inline]

Definition at line 30 of file ODCond2ConfInfo.h.

References m_loc, and x.

{ m_loc = x; }
void ODCond2ConfInfo::setParameters ( std::map< std::string, std::string >  my_keys_map)
void ODCond2ConfInfo::setRecordDate ( Tm  x) [inline]

Definition at line 27 of file ODCond2ConfInfo.h.

References m_rec_time, and x.

{ m_rec_time = x; }
void ODCond2ConfInfo::setRunNumber ( int  id) [inline]

Definition at line 33 of file ODCond2ConfInfo.h.

References m_run.

{ m_run = id; }
void ODCond2ConfInfo::setType ( std::string  x) [inline]

Definition at line 24 of file ODCond2ConfInfo.h.

References m_type, and x.

{ m_type = x; }
void ODCond2ConfInfo::writeDB ( ) throw (std::runtime_error) [private]

Definition at line 154 of file ODCond2ConfInfo.cc.

References DateHandler::tmToDate().

{
  this->checkConnection();
  this->checkPrepare();


  DateHandler dh(m_env, m_conn);
  if (m_rec_time.isNull()) {
    int very_old_time=0;
    m_rec_time = Tm(very_old_time);
  }

  try {

    m_writeStmt->setDate(3, dh.tmToDate(this->m_rec_time));
    m_writeStmt->setInt(5, this->getRunNumber());
    m_writeStmt->setString(6, this->getDescription());

    m_writeStmt->executeUpdate();


  } catch (SQLException &e) {
    throw(std::runtime_error("ODCond2ConfInfo::writeDB():  "+e.getMessage()));
  }
  // Now get the ID
  if (!this->fetchID()) {
    throw(std::runtime_error("ODCond2ConfInfo::writeDB:  Failed to write"));
  }

}

Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 14 of file ODCond2ConfInfo.h.


Member Data Documentation

Definition at line 68 of file ODCond2ConfInfo.h.

Referenced by getDBDate(), and setDBDate().

std::string ODCond2ConfInfo::m_desc [private]

Definition at line 67 of file ODCond2ConfInfo.h.

Referenced by getDescription(), and setDescription().

int ODCond2ConfInfo::m_ID [private]

Definition at line 62 of file ODCond2ConfInfo.h.

Referenced by getId(), and setId().

std::string ODCond2ConfInfo::m_loc [private]

Definition at line 65 of file ODCond2ConfInfo.h.

Referenced by getLocation(), and setLocation().

Definition at line 69 of file ODCond2ConfInfo.h.

Definition at line 64 of file ODCond2ConfInfo.h.

Referenced by getRecordDate(), and setRecordDate().

int ODCond2ConfInfo::m_run [private]

Definition at line 66 of file ODCond2ConfInfo.h.

Referenced by getRunNumber(), and setRunNumber().

Definition at line 70 of file ODCond2ConfInfo.h.

std::string ODCond2ConfInfo::m_type [private]

Definition at line 63 of file ODCond2ConfInfo.h.

Referenced by getType(), and setType().