CMS 3D CMS Logo

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

ODDCCConfig Class Reference

#include <ODDCCConfig.h>

Inheritance diagram for ODDCCConfig:
IODConfig IDBObject

List of all members.

Public Member Functions

unsigned char * getDCCClob () const
unsigned int getDCCClobSize () const
std::string getDCCConfigurationUrl () const
std::string getDCCWeightsMode () const
int getId () const
int getNTestPatternsToLoad () const
unsigned int getSize () const
int getSMHalf () const
std::string getTable ()
std::string getTestPatternFileUrl () const
 ODDCCConfig ()
void setDCCClob (unsigned char *x)
void setDCCConfigurationUrl (std::string x)
void setDCCWeightsMode (std::string x)
void setId (int id)
void setNTestPatternsToLoad (int id)
void setParameters (std::map< std::string, std::string > my_keys_map)
void setSize (unsigned int id)
void setSMHalf (int id)
void setTestPatternFileUrl (std::string x)
 ~ODDCCConfig ()

Private Member Functions

void clear ()
void fetchData (ODDCCConfig *result) throw (std::runtime_error)
int fetchID () throw (std::runtime_error)
int fetchNextId () throw (std::runtime_error)
void prepareWrite () throw (std::runtime_error)
void writeDB () throw (std::runtime_error)

Private Attributes

unsigned char * m_dcc_clob
std::string m_dcc_url
int m_ID
int m_ntest
unsigned int m_size
int m_sm_half
std::string m_test_url
std::string m_wei

Friends

class EcalCondDBInterface

Detailed Description

Definition at line 15 of file ODDCCConfig.h.


Constructor & Destructor Documentation

ODDCCConfig::ODDCCConfig ( )

Definition at line 15 of file ODDCCConfig.cc.

References hitfit::clear(), and NULL.

ODDCCConfig::~ODDCCConfig ( )

Definition at line 31 of file ODDCCConfig.cc.

{
}

Member Function Documentation

void ODDCCConfig::clear ( void  ) [private]

Definition at line 194 of file ODDCCConfig.cc.

                       {

   m_dcc_url="";
   m_test_url="";
   m_ntest=0;
   m_sm_half=0;
   m_wei="";

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

Definition at line 207 of file ODDCCConfig.cc.

References alignCSCRings::e, and query::result.

{
  this->checkConnection();
  //  result->clear();
  if(result->getId()==0 && (result->getConfigTag()=="") ){
    //    throw(std::runtime_error("ODDCCConfig::fetchData(): no Id defined for this ODDCCConfig "));
    result->fetchID();
  }

  try {

    m_readStmt->setSQL("SELECT * "
                       "FROM ECAL_DCC_CONFIGURATION  "
                       " where  dcc_configuration_id = :1 or dcc_tag=:2 " );
    m_readStmt->setInt(1, result->getId());
    m_readStmt->setString(2, result->getConfigTag());
    ResultSet* rset = m_readStmt->executeQuery();

    rset->next();

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

    result->setId(rset->getInt(1));
    result->setConfigTag(rset->getString(2));
    result->setDCCConfigurationUrl(rset->getString(3));
    result->setTestPatternFileUrl(rset->getString(4));
    result->setNTestPatternsToLoad(rset->getInt(5));
    result->setSMHalf(rset->getInt(6));

    Clob clob = rset->getClob (7);
    m_size = clob.length();
    Stream *instream = clob.getStream (1,0);
    unsigned char *buffer = new unsigned char[m_size];
    memset (buffer, 0, m_size);
    instream->readBuffer ((char*)buffer, m_size);
    /*
    cout << "Opening the clob in Read only mode" << endl;
    clob.open (OCCI_LOB_READONLY);
    int clobLength=clob.length ();
    cout << "Length of the clob is: " << clobLength << endl;
    m_size=clobLength;
    unsigned char* buffer = readClob (clob, m_size);
    clob.close ();
    cout<< "the clob buffer is:"<<endl;  
    for (int i = 0; i < clobLength; ++i)
      cout << (char) buffer[i];
    cout << endl;


    */
    result->setDCCClob(buffer );
    result->setDCCWeightsMode(rset->getString(8));


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

Definition at line 269 of file ODDCCConfig.cc.

References alignCSCRings::e.

{
  if (m_ID!=0) {
    return m_ID;
  }
  
  this->checkConnection();
  
  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL("SELECT DCC_configuration_id FROM ecal_dcc_configuration "
                 "WHERE  dcc_tag=:dcc_tag "
                 );
    
    stmt->setString(1, getConfigTag() );
    
    
    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("ODDCCConfig::fetchID:  "+e.getMessage()));
  }
  
  
  return m_ID;
}
int ODDCCConfig::fetchNextId ( ) throw (std::runtime_error) [private]

Definition at line 35 of file ODDCCConfig.cc.

References alignCSCRings::e, and query::result.

                                                      {

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

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

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

}
unsigned char* ODDCCConfig::getDCCClob ( ) const [inline]

Definition at line 42 of file ODDCCConfig.h.

References m_dcc_clob.

Referenced by popcon::EcalSRPHandler::getNewObjects().

{ return m_dcc_clob; }
unsigned int ODDCCConfig::getDCCClobSize ( ) const [inline]

Definition at line 43 of file ODDCCConfig.h.

References m_size.

Referenced by popcon::EcalSRPHandler::getNewObjects().

{ return m_size; }
std::string ODDCCConfig::getDCCConfigurationUrl ( ) const [inline]

Definition at line 30 of file ODDCCConfig.h.

References m_dcc_url.

{ return m_dcc_url; }
std::string ODDCCConfig::getDCCWeightsMode ( ) const [inline]

Definition at line 45 of file ODDCCConfig.h.

References m_wei.

Referenced by popcon::EcalSRPHandler::getNewObjects().

{ return m_wei; }
int ODDCCConfig::getId ( ) const [inline]

Definition at line 25 of file ODDCCConfig.h.

References m_ID.

{ return m_ID; }
int ODDCCConfig::getNTestPatternsToLoad ( ) const [inline]

Definition at line 36 of file ODDCCConfig.h.

References m_ntest.

{ return m_ntest; }
unsigned int ODDCCConfig::getSize ( ) const [inline]

Definition at line 27 of file ODDCCConfig.h.

References m_size.

{ return m_size; }
int ODDCCConfig::getSMHalf ( ) const [inline]

Definition at line 39 of file ODDCCConfig.h.

References m_sm_half.

{ return m_sm_half; }
std::string ODDCCConfig::getTable ( ) [inline, virtual]

Implements IODConfig.

Definition at line 22 of file ODDCCConfig.h.

{ return "ECAL_DCC_CONFIGURATION"; }
std::string ODDCCConfig::getTestPatternFileUrl ( ) const [inline]

Definition at line 33 of file ODDCCConfig.h.

References m_test_url.

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

Implements IODConfig.

Definition at line 59 of file ODDCCConfig.cc.

References gather_cfg::cout, and alignCSCRings::e.

{
  this->checkConnection();

  int next_id=fetchNextId();

  try {
    m_writeStmt = m_conn->createStatement();
    m_writeStmt->setSQL("INSERT INTO ECAL_DCC_CONFIGURATION (dcc_configuration_id, dcc_tag, "
                        " DCC_CONFIGURATION_URL, TESTPATTERN_FILE_URL, "
                        " N_TESTPATTERNS_TO_LOAD , SM_HALF, weightsmode, " 
                        " dcc_configuration) "
                        "VALUES (:1, :2, :3, :4, :5, :6 , :7 ,:8 )");
    m_writeStmt->setInt(1, next_id);
    m_writeStmt->setString(2, getConfigTag());
    m_writeStmt->setString(3, getDCCConfigurationUrl());
    m_writeStmt->setString(4, getTestPatternFileUrl());
    m_writeStmt->setInt(5, getNTestPatternsToLoad());
    m_writeStmt->setInt(6, getSMHalf());
    m_writeStmt->setString(7, getDCCWeightsMode());

    // and now the clob
    oracle::occi::Clob clob(m_conn);
    clob.setEmpty();
    m_writeStmt->setClob(8,clob);
    m_writeStmt->executeUpdate ();
    m_ID=next_id; 

    m_conn->terminateStatement(m_writeStmt);
    std::cout<<"DCC Clob inserted into CONFIGURATION with id="<<next_id<<std::endl;

    // now we read and update it 
    m_writeStmt = m_conn->createStatement(); 
    m_writeStmt->setSQL ("SELECT dcc_configuration FROM ECAL_DCC_CONFIGURATION WHERE"
                         " dcc_configuration_id=:1 FOR UPDATE");

    std::cout<<"updating the clob 0"<<std::endl;
   
    
    
  } catch (SQLException &e) {
    throw(std::runtime_error("ODDCCConfig::prepareWrite():  "+e.getMessage()));
  }

  std::cout<<"updating the clob 1 "<<std::endl;
  
  
}
void ODDCCConfig::setDCCClob ( unsigned char *  x) [inline]

Definition at line 41 of file ODDCCConfig.h.

References m_dcc_clob, and x.

{ m_dcc_clob = x; }
void ODDCCConfig::setDCCConfigurationUrl ( std::string  x) [inline]

Definition at line 29 of file ODDCCConfig.h.

References m_dcc_url, and x.

{ m_dcc_url = x; }
void ODDCCConfig::setDCCWeightsMode ( std::string  x) [inline]

Definition at line 44 of file ODDCCConfig.h.

References m_wei, and x.

{ m_wei = x; }
void ODDCCConfig::setId ( int  id) [inline]

Definition at line 24 of file ODDCCConfig.h.

References m_ID.

Referenced by popcon::EcalSRPHandler::getNewObjects().

{ m_ID = id; }
void ODDCCConfig::setNTestPatternsToLoad ( int  id) [inline]

Definition at line 35 of file ODDCCConfig.h.

References m_ntest.

{ m_ntest = id; }
void ODDCCConfig::setParameters ( std::map< std::string, std::string >  my_keys_map)
void ODDCCConfig::setSize ( unsigned int  id) [inline]

Definition at line 26 of file ODDCCConfig.h.

References m_size.

{ m_size = id; }
void ODDCCConfig::setSMHalf ( int  id) [inline]

Definition at line 38 of file ODDCCConfig.h.

References m_sm_half.

{ m_sm_half = id; }
void ODDCCConfig::setTestPatternFileUrl ( std::string  x) [inline]

Definition at line 32 of file ODDCCConfig.h.

References m_test_url, and x.

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

Definition at line 153 of file ODDCCConfig.cc.

References gather_cfg::cout, and alignCSCRings::e.

{


  std::cout<<"updating the clob "<<std::endl;


  try {

 
    m_writeStmt->setInt(1, m_ID);
    ResultSet* rset = m_writeStmt->executeQuery();

    rset->next ();
    oracle::occi::Clob clob = rset->getClob (1);

    cout << "Opening the clob in read write mode" << endl;

    std::cout << "Populating the clob" << endl;
    
    populateClob (clob, getDCCConfigurationUrl(), m_size);
    int clobLength=clob.length ();
    cout << "Length of the clob is: " << clobLength << endl;
  
    m_writeStmt->executeUpdate();

    m_writeStmt->closeResultSet (rset);

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

Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from IDBObject.

Definition at line 17 of file ODDCCConfig.h.


Member Data Documentation

unsigned char* ODDCCConfig::m_dcc_clob [private]

Definition at line 61 of file ODDCCConfig.h.

Referenced by getDCCClob(), and setDCCClob().

std::string ODDCCConfig::m_dcc_url [private]

Definition at line 62 of file ODDCCConfig.h.

Referenced by getDCCConfigurationUrl(), and setDCCConfigurationUrl().

int ODDCCConfig::m_ID [private]

Definition at line 60 of file ODDCCConfig.h.

Referenced by getId(), and setId().

int ODDCCConfig::m_ntest [private]

Definition at line 64 of file ODDCCConfig.h.

Referenced by getNTestPatternsToLoad(), and setNTestPatternsToLoad().

unsigned int ODDCCConfig::m_size [private]

Definition at line 66 of file ODDCCConfig.h.

Referenced by getDCCClobSize(), getSize(), and setSize().

int ODDCCConfig::m_sm_half [private]

Definition at line 65 of file ODDCCConfig.h.

Referenced by getSMHalf(), and setSMHalf().

std::string ODDCCConfig::m_test_url [private]

Definition at line 63 of file ODDCCConfig.h.

Referenced by getTestPatternFileUrl(), and setTestPatternFileUrl().

std::string ODDCCConfig::m_wei [private]

Definition at line 67 of file ODDCCConfig.h.

Referenced by getDCCWeightsMode(), and setDCCWeightsMode().