CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Protected Attributes | Friends

LMFDat Class Reference

#include <LMFDat.h>

Inheritance diagram for LMFDat:
LMFUnique IUniqueDBObject IDBObject LMFColoredTable LMFCorrCoefDatComponent LMFLaserConfigDat LMFRunDat LMFTestPulseConfigDat LMFClsDat LMFLaserPulseDat LMFPnPrimDat LMFPrimDat

List of all members.

Public Member Functions

void dump () const
void dump (int n) const
virtual void dump (int n, int max) const
void fetch () throw (std::runtime_error)
void fetch (const EcalLogicID &id) throw (std::runtime_error)
void fetch (int logic_id) throw (std::runtime_error)
void fetch (int logic_id, const Tm &tm) throw (std::runtime_error)
void fetch (int logic_id, const Tm *timestamp, int dir) throw (std::runtime_error)
void fetch (const EcalLogicID &id, const Tm &tm) throw (std::runtime_error)
void fetch (const EcalLogicID &id, const Tm &tm, int dir) throw (std::runtime_error)
std::map< int, std::vector
< float > > 
fetchData () throw (std::runtime_error)
virtual std::string foreignKeyName () const
std::vector< float > getData (int id)
bool getData (const EcalLogicID &id, const std::string &key, float &ret)
std::vector< float > getData (const EcalLogicID &id)
bool getData (const EcalLogicID &id, std::vector< float > &ret)
bool getData (int id, std::vector< float > &ret)
std::map< int, std::vector
< float > > 
getData ()
float getData (int id, unsigned int k)
float getData (const EcalLogicID &id, unsigned int k)
bool getData (int id, const std::string &key, float &ret)
float getData (const EcalLogicID &id, const std::string &key)
float getData (int id, const std::string &key)
bool getData (int id, unsigned int k, float &ret)
bool getData (const EcalLogicID &id, unsigned int k, float &ret)
virtual std::string getIovIdFieldName () const
std::list< std::string > getKeyList ()
std::map< std::string,
unsigned int > 
getKeys ()
LMFRunIOV getLMFRunIOV () const
int getLMFRunIOVID ()
std::list< int > getLogicIds ()
void getNext (LMFDat *dat) throw (std::runtime_error)
void getPrevious (LMFDat *dat) throw (std::runtime_error)
std::map< unsigned int,
std::string > 
getReverseMap () const
Tm getSubrunStart () const
virtual std::string getTableName () const
virtual bool isValid ()
 LMFDat ()
 LMFDat (EcalDBConnection *c)
 LMFDat (oracle::occi::Environment *env, oracle::occi::Connection *conn)
std::vector< float > operator[] (int id)
LMFDatsetData (int logic_id, const std::vector< float > &data)
LMFDatsetData (const EcalLogicID &logic_id, const std::string &key, float v)
LMFDatsetData (const EcalLogicID &logic_id, const std::vector< float > &data)
LMFDatsetLMFRunIOV (const LMFRunIOV &iov)
LMFDatsetMaxDataToDump (int n)
void setWhereClause (std::string w)
void setWhereClause (std::string w, std::vector< std::string > p)
int size () const
 ~LMFDat ()

Protected Member Functions

void adjustParameters (int n, std::string &sql, Statement *stmt)
std::string buildInsertSql ()
std::string buildSelectSql (int logic_id=0, int direction=0)
bool check ()
void getKeyTypes () throw (std::runtime_error)
void getNeighbour (LMFDat *dat, int which) throw (std::runtime_error)
int writeDB () throw (std::runtime_error)

Protected Attributes

std::string _where
std::vector< std::string > _wherePars
std::map< int, std::vector
< float > > 
m_data
std::string m_Error
std::map< std::string,
unsigned int > 
m_keys
int m_max
std::string m_tableName
std::vector< std::string > m_type

Friends

class EcalCondDBInterface

Detailed Description

Data Tables for LMF Runs

Definition at line 19 of file LMFDat.h.


Constructor & Destructor Documentation

LMFDat::LMFDat ( )

Definition at line 9 of file LMFDat.cc.

References _where, _wherePars, m_max, and m_tableName.

               : LMFUnique() { 
  m_tableName = ""; 
  m_max = -1; 
  _where = "";
  _wherePars.clear();
}
LMFDat::LMFDat ( EcalDBConnection c)

Definition at line 16 of file LMFDat.cc.

References _where, _wherePars, m_max, and m_tableName.

                                  : LMFUnique(c) {
  m_tableName = "";
  m_max = -1;
  _where = "";
  _wherePars.clear();
}
LMFDat::LMFDat ( oracle::occi::Environment *  env,
oracle::occi::Connection *  conn 
)

Definition at line 23 of file LMFDat.cc.

References _where, _wherePars, m_max, and m_tableName.

                                           : LMFUnique(env, conn) {
  m_tableName = "";
  m_max = -1;
  _where = "";
  _wherePars.clear();
}
LMFDat::~LMFDat ( ) [inline]

Definition at line 27 of file LMFDat.h.

{ }

Member Function Documentation

void LMFDat::adjustParameters ( int  n,
std::string &  sql,
Statement stmt 
) [protected]

Definition at line 255 of file LMFDat.cc.

References _wherePars, prof2calltree::count, run_regression::done, and n.

                                               {
  // adjust positional parameters and change them according to their
  // decalred type
  std::size_t nw = 0;
  std::size_t n = sql.find(":"); 
  for (int done = 1; done < count; done++) {
    // skip already bound variables
    n = sql.find(":", n + 1);
  }
  while (n != std::string::npos) {
    char type = sql.at(n + 1);
    if (type == 'S') {
      stmt->setString(nw + count, _wherePars[nw]);
      nw++;
    } else if (type == 'F') {
      stmt->setFloat(nw + count, atof(_wherePars[nw].c_str()));
      nw++;
    } else if (type == 'I') {
      stmt->setInt(nw + count, atoi(_wherePars[nw].c_str()));
      nw++; 
    } 
    n = sql.find(":", n + 1); 
  }
}
std::string LMFDat::buildInsertSql ( ) [protected]

Definition at line 103 of file LMFDat.cc.

References gather_cfg::cout, getTableName(), i, LMFUnique::m_className, LMFUnique::m_debug, and m_keys.

Referenced by writeDB().

                                 {
  // create the insert statement
  std::stringstream sql;
  sql << "INSERT INTO " + getTableName() + " VALUES (";
  unsigned int nParameters = m_keys.size() + 2; 
  for (unsigned int i = 0; i < nParameters - 1; i++) {
    sql << ":" << i + 1 << ", ";
  }
  sql << ":" << nParameters << ")";
  std::string sqls = sql.str();
  if (m_debug) {
    cout << m_className << "::writeDB: " << sqls << endl;
  }
  return sqls;
}
std::string LMFDat::buildSelectSql ( int  logic_id = 0,
int  direction = 0 
) [protected]

Definition at line 139 of file LMFDat.cc.

References _where, prof2calltree::count, gather_cfg::cout, getIovIdFieldName(), getLMFRunIOVID(), getTableName(), LMFUnique::m_className, and LMFUnique::m_debug.

                                                            {
  // create the insert statement
  // if logic_id = 0 select all channels for a given iov_id
  std::stringstream sql;
  int count = 1;
  if (getLMFRunIOVID() > 0) {
    if (_where.length() > 0) {
      // check if this is an expert query. If so, add a WHERE clause
      _where = " AND " + _where;
    }
    // in this case we are looking for all data collected during the same
    // IOV. There can be many logic_ids per IOV.
    sql << "SELECT * FROM CMS_ECAL_LASER_COND." << getTableName() << " WHERE "
        << getIovIdFieldName() << " = " << getLMFRunIOVID() 
        << _where;
    // the expert query must be specified each time the expert makes the query
    // then empty it
    _where = "";
  } else {
    // in this case we are looking for a specific logic_id whose
    // data have been collected at a given time. There is only
    // one record in this case.
    std::string op = ">";
    std::string order = "ASC";
    if (direction < 0) {
      op = "<";
      order = "DESC";
    }
    sql << "SELECT * FROM (SELECT CMS_ECAL_LASER_COND." 
        << getTableName() << ".* FROM CMS_ECAL_LASER_COND." 
        << getTableName() 
        << " JOIN LMF_RUN_IOV ON " 
        << "LMF_RUN_IOV.LMF_IOV_ID = " 
        << getTableName() << "." << getIovIdFieldName() << " "
        << "WHERE SUBRUN_START " << op << "= TO_DATE(:" << count;
    count++;
    sql << ", 'YYYY-MM-DD HH24:MI:SS') ORDER BY SUBRUN_START " 
        << order << ") WHERE ROWNUM <= 1";
  }
  if (logic_id > 0) {
    sql << " AND LOGIC_ID = :" << count;
  }
  std::string sqls = sql.str();
  if (m_debug) {
    cout << m_className << "::buildSelectSqlDB: " << sqls << endl;
  }
  return sqls;
}
bool LMFDat::check ( void  ) [protected]

Definition at line 576 of file LMFDat.cc.

References getKeyTypes(), getTableName(), LMFUnique::m_className, m_Error, m_keys, m_type, and run_regression::ret.

Referenced by writeDB().

                   {
  // check that everything has been correctly setup
  bool ret = true;
  m_Error = "";
  // first of all we need to check that the class name has been set
  if (m_className == "LMFUnique") {
    m_Error = "class name not set ";
    ret = false;
  }
  //then check that the table name has been set
  if (getTableName() == "") {
    m_Error += "table name not set ";
    ret = false;
  }
  // fill key types if not yet done
  if (m_type.size() != m_keys.size()) {
    getKeyTypes();
    if (m_type.size() != m_keys.size()) {
      m_Error += "key size does not correspond to table definition";
      ret = false;
    }
  }
  return ret;
}
void LMFDat::dump ( int  n) const [virtual]

Reimplemented from LMFUnique.

Definition at line 72 of file LMFDat.cc.

References dump(), and m_max.

                             {
  dump(n, m_max);
}
void LMFDat::dump ( int  n,
int  max 
) const [virtual]

Definition at line 76 of file LMFDat.cc.

References trackerHits::c, gather_cfg::cout, dump(), end, getReverseMap(), j, m_data, AlCaHLTBitMon_ParallelJobs::p, submit::rm, alignCSCRings::s, and x.

                                      {
  LMFUnique::dump(n);
  int s = m_data.size();
  cout << "Stored data: " << s << endl;
  if (max >= 0) {
    std::map<int, std::vector<float> >::const_iterator p = m_data.begin();
    std::map<int, std::vector<float> >::const_iterator end = m_data.end();
    int c = 0;
    std::map<unsigned int, std::string> rm = getReverseMap();
    while ((p != end) && (c < max)) {
      int id = p->first;
      std::vector<float> x = p->second;
      cout << c << " -------------------------------------------" << endl;
      cout << "   ID: " << id << endl;
      for (unsigned int j = 0; j < x.size(); j++) {
        if (j % 4 == 0) {
          cout << endl << "   ";
        }
        cout << rm[j] << ":" << x[j] << "\t";
      }
      cout << endl;
      p++;
      c++;
    }
  }
}
void LMFDat::dump ( void  ) const [virtual]

Reimplemented from LMFUnique.

Definition at line 68 of file LMFDat.cc.

References m_max.

Referenced by dump(), LMFCorrCoefDat::fetch(), and writeDB().

                        {
  dump(0, m_max);
}
void LMFDat::fetch ( ) throw (std::runtime_error)

Definition at line 237 of file LMFDat.cc.

Referenced by LMFCorrCoefDat::fetch().

{
  fetch(0);
}
void LMFDat::fetch ( int  logic_id) throw (std::runtime_error)

Definition at line 243 of file LMFDat.cc.

References NULL.

{
  fetch(logic_id, NULL, 0);
}
void LMFDat::fetch ( int  logic_id,
const Tm tm 
) throw (std::runtime_error)

Definition at line 249 of file LMFDat.cc.

{
  fetch(logic_id, &tm, 1);
}
void LMFDat::fetch ( int  logic_id,
const Tm timestamp,
int  dir 
) throw (std::runtime_error)

Definition at line 281 of file LMFDat.cc.

References CastorDataFrameFilter_impl::check(), prof2calltree::count, gather_cfg::cout, alignCSCRings::e, i, NULL, convertSQLiteXML::ok, cond::timestamp, and x.

{
  bool ok = check();
  if ((timestamp == NULL) && (getLMFRunIOVID() == 0)) {
    throw(std::runtime_error(m_className + "::fetch: Cannot fetch data with "
                        "timestamp = 0 and LMFRunIOV = 0"));
  }
  if (ok && isValid()) {
    if (m_debug) {
      std::cout << "[LMFDat] This object is valid..." << std::endl;
    }
    try {
      Statement * stmt = m_conn->createStatement();
      std::string sql = buildSelectSql(logic_id, direction);
      if (m_debug) {
        std::cout << "[LMFDat] Executing query " << std::endl;
        std::cout << "         " << sql << std::endl << std::flush;
      }
      if (logic_id == 0) {
        // get data for all crystals with a given timestamp
        stmt->setPrefetchRowCount(10000);
      }
      stmt->setSQL(sql);
      int count = 1;
      if (logic_id > 0) {
        if (timestamp != NULL) {
          stmt->setString(count, timestamp->str());
          count++;
        }
        stmt->setInt(count++, logic_id);
      }
      adjustParameters(count, sql, stmt);
      ResultSet *rset = stmt->executeQuery();
      std::vector<float> x;
      int nData = m_keys.size();
      x.reserve(nData);
      while (rset->next() != 0) {
        for (int i = 0; i < nData; i++) {
          x.push_back(rset->getFloat(i + 3));
        }
        int id = rset->getInt(2);
        if (timestamp != NULL) {
          setInt(foreignKeyName(), rset->getInt(1));
        }
        this->setData(id, x);
        x.clear();
      }
      stmt->setPrefetchRowCount(0);
      m_conn->terminateStatement(stmt);
    }
    catch (oracle::occi::SQLException &e) {
      throw(std::runtime_error(m_className + "::fetch: " + e.getMessage()));
    }
    m_ID = m_data.size();
  }
}
void LMFDat::fetch ( const EcalLogicID id,
const Tm tm 
) throw (std::runtime_error)

Definition at line 224 of file LMFDat.cc.

{
  fetch(id.getLogicID(), &tm, 1);
}
void LMFDat::fetch ( const EcalLogicID id,
const Tm tm,
int  dir 
) throw (std::runtime_error)

Definition at line 230 of file LMFDat.cc.

{
  setInt(foreignKeyName(), 0); /* set the LMF_IOV_ID to undefined */
  fetch(id.getLogicID(), &tm, direction);
}
void LMFDat::fetch ( const EcalLogicID id) throw (std::runtime_error)

Definition at line 218 of file LMFDat.cc.

{
  fetch(id.getLogicID());
}
std::map< int, std::vector< float > > LMFDat::fetchData ( ) throw (std::runtime_error)

Definition at line 352 of file LMFDat.cc.

References gather_cfg::cout, alignCSCRings::e, getIovIdFieldName(), getLMFRunIOVID(), getTableName(), i, LMFUnique::m_className, IDBObject::m_conn, m_data, LMFUnique::m_debug, and alignCSCRings::s.

Referenced by writeDB().

{
  // see if any of the data is already in the database
  std::map<int, std::vector<float> > s = m_data;
  std::string sql = "SELECT LOGIC_ID FROM CMS_ECAL_LASER_COND." + 
    getTableName() + " WHERE "
    + getIovIdFieldName() + " = :1";
  if (m_debug) {
    cout << m_className << ":: candidate data items to be written = " 
         << s.size() << endl;
    cout << m_className << "   Executing " << sql;
    cout << " where " << getIovIdFieldName() << " = " 
         << getLMFRunIOVID() << endl;
  }
  try {
    Statement* stmt = m_conn->createStatement();
    stmt->setSQL(sql);
    stmt->setInt(1, getLMFRunIOVID());
    stmt->setPrefetchRowCount(10000);
    ResultSet* rset = stmt->executeQuery();
    std::map<int, std::vector<float> >::iterator i = s.end();
    std::map<int, std::vector<float> >::iterator e = s.end();
    while (rset->next() != 0) {
      if (m_debug) {
        cout << m_className << ":: checking " << rset->getInt(1) << endl
             << std::flush;
      }
      i = s.find(rset->getInt(1));
      if (i != e) {
        s.erase(i);
      }
    }
    stmt->setPrefetchRowCount(0);
    m_conn->terminateStatement(stmt);
  }
  catch (oracle::occi::SQLException &e) {
    throw(std::runtime_error(m_className + "::fetchData:  "+e.getMessage()));
  }
  if (m_debug) {
    cout << m_className << ":: data items to write = " 
         << s.size() << endl;
  }
  return s;
}
std::string LMFDat::foreignKeyName ( ) const [virtual]

Reimplemented in LMFCorrCoefDatComponent.

Definition at line 31 of file LMFDat.cc.

Referenced by getLMFRunIOV(), getLMFRunIOVID(), isValid(), setLMFRunIOV(), and writeDB().

                                       {
  return "lmfRunIOV";
}
std::vector< float > LMFDat::getData ( const EcalLogicID id)

Definition at line 615 of file LMFDat.cc.

References getData().

                                                      {
  return getData(id.getLogicID());
}
bool LMFDat::getData ( int  id,
std::vector< float > &  ret 
)

Definition at line 621 of file LMFDat.cc.

References errorMatrix2Lands_multiChannel::id, and m_data.

                                                  {
  bool retval = false;
  if (m_data.find(id) != m_data.end()) {
    ret= m_data[id];
    retval = true;
  }
  return retval;
}
bool LMFDat::getData ( const EcalLogicID id,
std::vector< float > &  ret 
)

Definition at line 630 of file LMFDat.cc.

References getData().

                                                                 {
  return getData(id.getLogicID(), ret);
}
std::map< int, std::vector< float > > LMFDat::getData ( void  )

Definition at line 636 of file LMFDat.cc.

References m_data.

Referenced by LMFPrimDat::getAlpha(), LMFPrimDat::getAPDoverAM3(), LMFPrimDat::getAPDoverAMean(), LMFPrimDat::getAPDoverARMS(), LMFPrimDat::getAPDoverBM3(), LMFPrimDat::getAPDoverBMean(), LMFPrimDat::getAPDoverBRMS(), LMFPrimDat::getAPDoverPnM3(), LMFPrimDat::getAPDoverPnMean(), LMFPrimDat::getAPDoverPnRMS(), LMFPrimDat::getBeta(), LMFTestPulseConfigDat::getDACMGPA(), getData(), LMFClsDat::getENorm(), LMFRunDat::getEvents(), LMFLaserPulseDat::getFitMethod(), LMFPnPrimDat::getFlag(), LMFCorrCoefDatComponent::getFlag(), LMFClsDat::getFlag(), LMFPrimDat::getFlag(), LMFClsDat::getFlagNorm(), LMFClsDat::getLMFRefRunIOVID(), LMFLaserConfigDat::getLSRAttenuator(), LMFLaserConfigDat::getLSRCurrent(), LMFLaserConfigDat::getLSRDelay1(), LMFLaserConfigDat::getLSRDelay2(), LMFLaserConfigDat::getLSRPower(), LMFPrimDat::getM3(), LMFPnPrimDat::getM3(), LMFPrimDat::getMean(), LMFClsDat::getMean(), LMFPnPrimDat::getMean(), LMFLaserPulseDat::getMTQAmplification(), LMFLaserPulseDat::getMTQFW20(), LMFLaserPulseDat::getMTQFW80(), LMFLaserPulseDat::getMTQFWHM(), LMFLaserPulseDat::getMTQRise(), LMFLaserPulseDat::getMTQSliding(), LMFLaserPulseDat::getMTQTime(), LMFClsDat::getNevt(), LMFClsDat::getNorm(), LMFCorrCoefDatComponent::getParameterErrors(), LMFCorrCoefDatComponent::getParameters(), LMFPnPrimDat::getPNAoverBM3(), LMFPnPrimDat::getPNAoverBMean(), LMFPnPrimDat::getPNAoverBRMS(), LMFTestPulseConfigDat::getPNGain(), LMFLaserConfigDat::getPNGain(), LMFTestPulseConfigDat::getPNVinj(), LMFRunDat::getQualityFlag(), LMFPnPrimDat::getRMS(), LMFPrimDat::getRMS(), LMFClsDat::getRMS(), LMFCorrCoefDatComponent::getSeqID(), LMFCorrCoefDatComponent::getSequence(), LMFPnPrimDat::getShapeCor(), LMFPrimDat::getShapeCorr(), LMFLaserConfigDat::getVFEGain(), LMFTestPulseConfigDat::getVFEGain(), LMFColoredTable::getVmax(), LMFColoredTable::getVmin(), LMFLaserConfigDat::getWavelength(), and operator[]().

                                               {
  return m_data;
}
float LMFDat::getData ( int  id,
unsigned int  k 
)

Definition at line 642 of file LMFDat.cc.

References errorMatrix2Lands_multiChannel::id, gen::k, and m_data.

                                            {
  return m_data[id][k];
}
float LMFDat::getData ( const EcalLogicID id,
unsigned int  k 
)

Definition at line 646 of file LMFDat.cc.

References getData().

                                                           {
  return getData(id.getLogicID(), k);
}
float LMFDat::getData ( const EcalLogicID id,
const std::string &  key 
)

Definition at line 650 of file LMFDat.cc.

References getData(), and m_keys.

                                                                 {
  return getData(id.getLogicID(), m_keys[key]);
}
float LMFDat::getData ( int  id,
const std::string &  key 
)

Definition at line 654 of file LMFDat.cc.

References getData(), and m_keys.

                                                  {
  return getData(id, m_keys[key]);
}
bool LMFDat::getData ( int  id,
unsigned int  k,
float &  ret 
)

Definition at line 660 of file LMFDat.cc.

References getData(), gen::k, and v.

                                                       {
  bool retval = false;
  std::vector<float> v;
  retval = getData(id, v);
  if ((retval) && (v.size() > k)) {
    ret= v[k];
    retval = true;
  } else {
    retval = false;
  }
  return retval;
}
std::vector< float > LMFDat::getData ( int  id)

Definition at line 603 of file LMFDat.cc.

References errorMatrix2Lands_multiChannel::id, m_data, and run_regression::ret.

Referenced by LMFCorrCoefDat::getParameters().

                                       {
  std::vector<float> ret;
  if (m_data.find(id) != m_data.end()) {
    ret = m_data[id];
  }
  return ret;
}
bool LMFDat::getData ( const EcalLogicID id,
unsigned int  k,
float &  ret 
)

Definition at line 673 of file LMFDat.cc.

References getData().

                                                                      {
  return getData(id.getLogicID(), k, ret);
}
bool LMFDat::getData ( int  id,
const std::string &  key,
float &  ret 
)

Definition at line 677 of file LMFDat.cc.

References getData(), and m_keys.

                                                             {
  bool retval = false;
  if (m_keys.find(key) != m_keys.end()) {
    retval = getData(id, m_keys[key], ret); 
  }
  return retval;
}
bool LMFDat::getData ( const EcalLogicID id,
const std::string &  key,
float &  ret 
)

Definition at line 685 of file LMFDat.cc.

References getData().

{
  return getData(id.getLogicID(), key, ret);
}
std::string LMFDat::getIovIdFieldName ( ) const [virtual]

Reimplemented in LMFCorrCoefDatComponent.

Definition at line 119 of file LMFDat.cc.

Referenced by buildSelectSql(), fetchData(), and getKeyTypes().

                                          {
  return "LMF_IOV_ID";
}
std::list<std::string> LMFDat::getKeyList ( ) [inline]

Definition at line 113 of file LMFDat.h.

References alignCSCRings::e, i, prof2calltree::l, and m_keys.

                                  {
    std::list<std::string> l;
    std::map<std::string, unsigned int>::const_iterator i = m_keys.begin();
    std::map<std::string, unsigned int>::const_iterator e = m_keys.end();
    while (i != e) {
      l.push_back(i->first);
      i++;
    }
    return l;
  }
std::map<std::string, unsigned int> LMFDat::getKeys ( ) [inline]

Definition at line 110 of file LMFDat.h.

References m_keys.

                                            {
    return m_keys;
  }
void LMFDat::getKeyTypes ( ) throw (std::runtime_error) [protected]

Definition at line 542 of file LMFDat.cc.

References alignCSCRings::e, getIovIdFieldName(), getTableName(), i, LMFUnique::m_className, IDBObject::m_conn, m_keys, m_type, mergeVDriftHistosByStation::name, and lumiQTWidget::t.

Referenced by check().

{
  m_type.reserve(m_keys.size());
  for (unsigned int i = 0; i < m_keys.size(); i++) {
    m_type.push_back("");
  }
  // get the description of the table
  std::string sql = "";
  try {
    Statement *stmt = m_conn->createStatement();
    sql = "SELECT * FROM TABLE(CMS_ECAL_LASER_COND.LMF_TAB_COLS(:1, :2))";
    /*
    sql = "SELECT COLUMN_NAME, DATA_TYPE FROM " 
      "USER_TAB_COLS WHERE TABLE_NAME = '" + getTableName() + "' " 
      "AND COLUMN_NAME != '" + getIovIdFieldName() +  "' AND COLUMN_NAME != " 
      "'LOGIC_ID'";
    */
    stmt->setSQL(sql);
    stmt->setString(1, getTableName());
    stmt->setString(2, getIovIdFieldName());
    ResultSet *rset = stmt->executeQuery();
    while (rset->next() != 0) {
      std::string name = rset->getString(1);
      std::string t = rset->getString(2);
      m_type[m_keys[name]] = t;
    }
    m_conn->terminateStatement(stmt);
  } catch (oracle::occi::SQLException &e) {
    throw(std::runtime_error(m_className + "::getKeyTypes: " + e.getMessage() +
                        " [" + sql + "]"));
  }
}
LMFRunIOV LMFDat::getLMFRunIOV ( ) const [inline]

Definition at line 36 of file LMFDat.h.

References foreignKeyName(), LMFUnique::getInt(), IDBObject::m_conn, IDBObject::m_env, and LMFUnique::setByID().

Referenced by getSubrunStart().

                                 {
    LMFRunIOV runiov(m_env, m_conn);
    runiov.setByID(getInt(foreignKeyName()));
    return runiov;
  }
int LMFDat::getLMFRunIOVID ( )

Definition at line 35 of file LMFDat.cc.

References LMFUnique::fetchID(), foreignKeyName(), LMFUnique::getInt(), i, errorMatrix2Lands_multiChannel::id, o2o::iov, LMFUnique::m_foreignKeys, NULL, and LMFUnique::setInt().

Referenced by buildSelectSql(), and fetchData().

                           {
  int id = getInt(foreignKeyName());
  if (id == 0) {
    // try to get it from the list of foreign keys
    std::map<std::string, LMFUnique*>::iterator i = 
      m_foreignKeys.find(foreignKeyName());
    if (i != m_foreignKeys.end()) {
      LMFRunIOV *iov = (LMFRunIOV*)(i->second);
      if (iov != NULL) {
        id = iov->fetchID();
        setInt(foreignKeyName(), id);
      }
    }
  }
  return id;
}
std::list<int> LMFDat::getLogicIds ( ) [inline]

Definition at line 99 of file LMFDat.h.

References alignCSCRings::e, i, prof2calltree::l, and m_data.

                             {
    std::list<int> l;
    std::map<int, std::vector<float> >::const_iterator i = m_data.begin();
    std::map<int, std::vector<float> >::const_iterator e = m_data.end();
    while (i != e) {
      l.push_back(i->first);
      i++;
    }
    return l;
  }
void LMFDat::getNeighbour ( LMFDat dat,
int  which 
) throw (std::runtime_error) [protected]

Definition at line 200 of file LMFDat.cc.

References hcal_timing_source_file_cfg::dump.

{
  // there should be just one record in this case
  if (m_data.size() == 1) {
    dat->setConnection(this->getEnv(), this->getConn());
    int logic_id = m_data.begin()->first;
    Tm lastMeasuredOn = getSubrunStart();
    lastMeasuredOn += which;
    dat->fetch(logic_id, &lastMeasuredOn, which);
    dat->setMaxDataToDump(m_max);
  } else {
    dump();
    throw(std::runtime_error(m_className + "::getPrevious: Too many LOGIC_IDs in "
                        "this object"));
  }
}
void LMFDat::getNext ( LMFDat dat) throw (std::runtime_error)

Definition at line 194 of file LMFDat.cc.

{
  getNeighbour(dat, +1);
}
void LMFDat::getPrevious ( LMFDat dat) throw (std::runtime_error)

Definition at line 188 of file LMFDat.cc.

{
  getNeighbour(dat, -1);
}
std::map< unsigned int, std::string > LMFDat::getReverseMap ( ) const

Definition at line 57 of file LMFDat.cc.

References alignCSCRings::e, i, m, and m_keys.

Referenced by dump().

                                                            {
  std::map<unsigned int, std::string> m;
  std::map<std::string, unsigned int>::const_iterator i = m_keys.begin();
  std::map<std::string, unsigned int>::const_iterator e = m_keys.end();
  while (i != e) {
    m[i->second] = i->first;
    i++;
  }
  return m;
}
Tm LMFDat::getSubrunStart ( ) const [inline]

Definition at line 42 of file LMFDat.h.

References getLMFRunIOV(), and LMFRunIOV::getSubRunStart().

                            {
    return getLMFRunIOV().getSubRunStart();
  }
virtual std::string LMFDat::getTableName ( ) const [inline, virtual]
bool LMFDat::isValid ( void  ) [virtual]

Reimplemented from LMFUnique.

Reimplemented in LMFClsDat, LMFLaserPulseDat, LMFPnPrimDat, and LMFPrimDat.

Definition at line 339 of file LMFDat.cc.

References gather_cfg::cout, foreignKeyName(), LMFUnique::m_className, LMFUnique::m_debug, m_Error, LMFUnique::m_foreignKeys, and run_regression::ret.

Referenced by writeDB().

                     {
  bool ret = true;
  if (m_foreignKeys.find(foreignKeyName()) == m_foreignKeys.end()) {
    ret = false;
    m_Error += " Can't find lmfRunIOV within foreign keys.";
    if (m_debug) {
      cout << m_className << ": Foreign keys map size: " << m_foreignKeys.size() 
           << endl;
    }
  }
  return ret;
}
std::vector< float > LMFDat::operator[] ( int  id)

Definition at line 611 of file LMFDat.cc.

References getData().

                                          {
  return getData(id);
}
LMFDat& LMFDat::setData ( const EcalLogicID logic_id,
const std::vector< float > &  data 
) [inline]

Definition at line 59 of file LMFDat.h.

References data, EcalLogicID::getLogicID(), and m_data.

                                                {
    m_data[logic_id.getLogicID()] = data;
    return *this;
  }
LMFDat& LMFDat::setData ( const EcalLogicID logic_id,
const std::string &  key,
float  v 
) [inline]

Definition at line 64 of file LMFDat.h.

References EcalLogicID::getLogicID(), errorMatrix2Lands_multiChannel::id, combine::key, m_data, m_keys, and v.

                           {
    int id = logic_id.getLogicID();
    m_data[id].resize(m_keys.size());
    m_data[id][m_keys[key]] = v;
    return *this;
  }
LMFDat& LMFDat::setData ( int  logic_id,
const std::vector< float > &  data 
) [inline]
LMFDat& LMFDat::setLMFRunIOV ( const LMFRunIOV iov) [inline]

Definition at line 31 of file LMFDat.h.

References LMFUnique::attach(), foreignKeyName(), LMFUnique::getID(), and LMFUnique::setInt().

                                             {
    setInt(foreignKeyName(), iov.getID());
    attach(foreignKeyName(), (LMFUnique*)&iov);
    return *this;
  }
LMFDat & LMFDat::setMaxDataToDump ( int  n)

Definition at line 52 of file LMFDat.cc.

References m_max, and n.

Referenced by writeDB().

                                      {
  m_max = n;
  return *this;
}
void LMFDat::setWhereClause ( std::string  w)

Definition at line 123 of file LMFDat.cc.

References _where.

                                           {
  // to be used by experts to restrict the results of a query
  _where = where;
}
void LMFDat::setWhereClause ( std::string  w,
std::vector< std::string >  p 
)

Definition at line 128 of file LMFDat.cc.

References _where, _wherePars, and Parameters::parameters.

                                                             {
  // to be used by experts to restrict the results of a query
  // in this case the where clause can contains positional parameter,
  // identified as :/I, :/S, :/F for, respectively, integer, string or
  // float parameters. The parameters are all passed as strings
  // in parameters
  _wherePars  = parameters;
  _where      = where;
}
int LMFDat::size ( void  ) const [inline]

Definition at line 71 of file LMFDat.h.

References m_data.

Referenced by writeDB().

{ return m_data.size(); }
int LMFDat::writeDB ( ) throw (std::runtime_error) [protected, virtual]

Reimplemented from LMFUnique.

Reimplemented in LMFColoredTable, and LMFCorrCoefDatComponent.

Definition at line 398 of file LMFDat.cc.

References b, buildInsertSql(), trackerHits::c, check(), IDBObject::checkConnection(), gather_cfg::cout, LMFUnique::debug(), dump(), alignCSCRings::e, fetchData(), foreignKeyName(), LMFUnique::getID(), i, errorMatrix2Lands_multiChannel::id, isValid(), gen::k, LMFUnique::m_className, IDBObject::m_conn, LMFUnique::m_debug, m_Error, LMFUnique::m_foreignKeys, m_keys, m_max, m_type, convertSQLiteXML::ok, run_regression::ret, setMaxDataToDump(), size(), LMFUnique::writeForeignKeys(), and x.

{
  // first of all check if data already present
  if (m_debug) {
    cout << m_className << ": Writing foreign keys" << endl;
  }
  LMFUnique::writeForeignKeys();
  if (m_debug) {
    cout << m_className << ": Foreign keys written" << endl;
  }
  // write data on the database
  int ret = 0;
  std::map<int, std::vector<float> > data2write = fetchData();
  if (data2write.size() > 0) {
    this->checkConnection();
    bool ok = check();
    // write
    if (ok && isValid()) {
      std::list<dvoid *> bufPointers;
      int nParameters = m_keys.size(); 
      int nData = data2write.size();
      if (m_debug) {
        cout << m_className << ": # data items = " << nData << endl;
        cout << m_className << ": # parameters = " << nParameters << endl;
      }
      int * iovid_vec = new int[nData];
      int * logicid_vec = new int[nData];
      int *intArray = new int[nData];
      float *floatArray = new float[nData];
      ub2 * intSize = new ub2[nData];
      ub2 * floatSize = new ub2[nData];
      size_t intTotalSize = sizeof(int)*nData;
      size_t floatTotalSize = sizeof(float)*nData;
      try {
        Statement * stmt = m_conn->createStatement();
        std::string sql = buildInsertSql();
        stmt->setSQL(sql);
        // build the array of the size of each column
        for (int i = 0; i < nData; i++) {
          intSize[i] = sizeof(int);
          floatSize[i] = sizeof(int);
        }
        // build the data array for first column: the same run iov id
        LMFRunIOV *runiov = (LMFRunIOV*)m_foreignKeys[foreignKeyName()];
        int iov_id = runiov->getID();
        std::map<int, std::vector<float> >::const_iterator b = data2write.begin();
        std::map<int, std::vector<float> >::const_iterator e = data2write.end();
        for (int i = 0; i < nData; i++) {
          iovid_vec[i] = iov_id;
        }
        stmt->setDataBuffer(1, (dvoid*)iovid_vec, oracle::occi::OCCIINT,
                            sizeof(iovid_vec[0]), intSize);
        // build the data array for second column: the logic ids
        int c = 0;
        while (b != e) {
          int id = b->first;
          logicid_vec[c++] = id;
          b++;
        }
        stmt->setDataBuffer(2, (dvoid*)logicid_vec, oracle::occi::OCCIINT,
                            sizeof(logicid_vec[0]), intSize);
        // for each column build the data array
        oracle::occi::Type type = oracle::occi::OCCIFLOAT;
        for (int i = 0; i < nParameters; i++) {
          b = data2write.begin();
          // loop on all logic ids
          c = 0;
          while (b != e) {
            std::vector<float> x = b->second;
            if (m_type[i] == "INT") {
              intArray[c] = (int)rint(x[i]);
            } else if ((m_type[i] == "FLOAT") || (m_type[i] == "NUMBER")) {
              floatArray[c] = x[i];
            } else {
              throw(std::runtime_error("ERROR: LMFDat::writeDB: unsupported type"));
            }
            c++;
            b++;
          }
          // copy data into a "permanent" buffer
          dvoid * buffer;
          type = oracle::occi::OCCIINT;
          ub2 *sizeArray = intSize;
          int size = sizeof(intArray[0]);
          if ((m_type[i] == "FLOAT") || (m_type[i] == "NUMBER")) {
            buffer = (dvoid *)malloc(sizeof(float)*nData);
            memcpy(buffer, floatArray, floatTotalSize);
            type = oracle::occi::OCCIFLOAT;
            sizeArray = floatSize;
            size = sizeof(floatArray[0]);
          } else {
            buffer = (dvoid *)malloc(sizeof(int)*nData);
            memcpy(buffer, intArray, intTotalSize);
          }
          bufPointers.push_back(buffer);
          if (m_debug) {
            for (int k = 0; ((k < nData) && (k < m_max)); k++) {
              cout << m_className << ": === Index=== " << k << endl;
              cout << m_className << ": RUN_IOV_ID = " << iovid_vec[k] << endl;
              cout << m_className << ": LOGIC_ID = " << logicid_vec[k] << endl;
              cout << m_className << ": FIELD " << i << ": " 
                   << ((float *)(buffer))[k] << endl;
            }
          }
          stmt->setDataBuffer(i + 3, buffer, type, size, sizeArray);
        }
        stmt->executeArrayUpdate(nData);
        delete [] intArray;
        delete [] floatArray;
        delete [] intSize;
        delete [] floatSize;
        delete [] logicid_vec;
        delete [] iovid_vec;
        std::list<dvoid *>::const_iterator bi = bufPointers.begin();
        std::list<dvoid *>::const_iterator be = bufPointers.end();
        while (bi != be) {
          free(*bi);
          bi++;
        }
        m_conn->commit();
        m_conn->terminateStatement(stmt);
        ret = nData;
      } catch (oracle::occi::SQLException &e) {
        debug();
        setMaxDataToDump(nData);
        // get the Foreign Key
        LMFRunIOV *runiov = (LMFRunIOV*)m_foreignKeys[foreignKeyName()];
        int iov_id = runiov->getID();
        std::cout << "==== This object refers to IOV " << iov_id << std::endl;
        dump();
        m_conn->rollback();
        throw(std::runtime_error(m_className + "::writeDB: " + 
                                 e.getMessage()));
      }
    } else {
      cout << m_className << "::writeDB: Cannot write because " << 
        m_Error << endl;
      dump();
    }
  }
  return ret;
}

Friends And Related Function Documentation

friend class EcalCondDBInterface [friend]

Reimplemented from LMFUnique.

Reimplemented in LMFCorrCoefDatComponent.

Definition at line 21 of file LMFDat.h.


Member Data Documentation

std::string LMFDat::_where [protected]

Definition at line 159 of file LMFDat.h.

Referenced by buildSelectSql(), LMFDat(), and setWhereClause().

std::vector<std::string> LMFDat::_wherePars [protected]

Definition at line 160 of file LMFDat.h.

Referenced by adjustParameters(), LMFDat(), and setWhereClause().

std::map<int, std::vector<float> > LMFDat::m_data [protected]
std::string LMFDat::m_Error [protected]
std::map<std::string, unsigned int> LMFDat::m_keys [protected]
int LMFDat::m_max [protected]

Definition at line 149 of file LMFDat.h.

Referenced by dump(), LMFDat(), setMaxDataToDump(), and writeDB().

std::string LMFDat::m_tableName [protected]
std::vector<std::string> LMFDat::m_type [protected]