CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
MODCCSHFDat Class Reference

#include <MODCCSHFDat.h>

Inheritance diagram for MODCCSHFDat:
IDataItem IDBObject

Public Types

typedef oracle::occi::Clob Clob
 

Public Member Functions

unsigned char * getClob () const
 
std::string getFile () const
 
unsigned int getSize () const
 
std::string getTable () override
 
int getTest () const
 
 MODCCSHFDat ()
 
void setClob (unsigned char *x)
 
void setFile (std::string x)
 
void setSize (unsigned int id)
 
void setTest (int id)
 
 ~MODCCSHFDat () override
 
- Public Member Functions inherited from IDataItem
 IDataItem ()
 
- Public Member Functions inherited from IDBObject
oracle::occi::Connection * getConn () const
 
oracle::occi::Environment * getEnv () const
 
void setConnection (oracle::occi::Environment *env, oracle::occi::Connection *conn)
 
virtual ~IDBObject ()
 

Private Member Functions

void fetchData (std::map< EcalLogicID, MODCCSHFDat > *fillMap, MODRunIOV *iov) noexcept(false)
 
void populateClob (Clob &clob, std::string fname, unsigned int clob_size) noexcept(false)
 
void prepareWrite () noexcept(false) override
 
unsigned char * readClob (Clob &clob, int size) noexcept(false)
 
void writeArrayDB (const std::map< EcalLogicID, MODCCSHFDat > *data, MODRunIOV *iov) noexcept(false)
 
void writeDB (const EcalLogicID *ecid, const MODCCSHFDat *item, MODRunIOV *iov) noexcept(false)
 

Private Attributes

unsigned char * m_clob
 
std::string m_file
 
unsigned int m_size
 
int testing
 

Friends

class EcalCondDBInterface
 

Additional Inherited Members

- Static Public Attributes inherited from IDBObject
static const int ECALDB_NROWS = 1024
 
- Protected Member Functions inherited from IDataItem
void checkPrepare () noexcept(false)
 
void createReadStatement () noexcept(false)
 
void setPrefetchRowCount (int ncount) noexcept(false)
 
void terminateReadStatement () noexcept(false)
 
void terminateWriteStatement () noexcept(false)
 
- Protected Member Functions inherited from IDBObject
void checkConnection () const noexcept(false)
 
- Protected Attributes inherited from IDataItem
oracle::occi::Statement * m_readStmt
 
oracle::occi::Statement * m_writeStmt
 
- Protected Attributes inherited from IDBObject
oracle::occi::Connection * m_conn
 
oracle::occi::Environment * m_env
 

Detailed Description

Definition at line 19 of file MODCCSHFDat.h.

Member Typedef Documentation

◆ Clob

typedef oracle::occi::Clob MODCCSHFDat::Clob

Definition at line 21 of file MODCCSHFDat.h.

Constructor & Destructor Documentation

◆ MODCCSHFDat()

MODCCSHFDat::MODCCSHFDat ( )

Definition at line 16 of file MODCCSHFDat.cc.

16  {
17  m_env = nullptr;
18  m_conn = nullptr;
19  m_writeStmt = nullptr;
20  m_readStmt = nullptr;
21 
22  // m_clob = 0;
23  m_size = 0;
24  m_file = "";
25 }

◆ ~MODCCSHFDat()

MODCCSHFDat::~MODCCSHFDat ( )
override

Definition at line 27 of file MODCCSHFDat.cc.

27 {}

Member Function Documentation

◆ fetchData()

void MODCCSHFDat::fetchData ( std::map< EcalLogicID, MODCCSHFDat > *  fillMap,
MODRunIOV iov 
)
privatenoexcept

Definition at line 125 of file MODCCSHFDat.cc.

125  {
126  this->checkConnection();
127  fillMap->clear();
128 
129  iov->setConnection(m_env, m_conn);
130  int iovID = iov->fetchID();
131  if (!iovID) {
132  // throw(std::runtime_error("MODCCSHFDat::writeDB: IOV not in DB"));
133  return;
134  }
135 
136  try {
137  m_readStmt->setSQL(
138  "SELECT cv.name, cv.logic_id, cv.id1, cv.id2, cv.id3, cv.maps_to, "
139  " d.ccs_log "
140  "FROM channelview cv JOIN OD_CCS_HF_dat d "
141  "ON cv.logic_id = d.logic_id AND cv.name = cv.maps_to "
142  "WHERE d.iov_id = :iov_id");
143  m_readStmt->setInt(1, iovID);
144  ResultSet* rset = m_readStmt->executeQuery();
145 
146  std::pair<EcalLogicID, MODCCSHFDat> p;
147  MODCCSHFDat dat;
148  while (rset->next()) {
149  p.first = EcalLogicID(rset->getString(1), // name
150  rset->getInt(2), // logic_id
151  rset->getInt(3), // id1
152  rset->getInt(4), // id2
153  rset->getInt(5), // id3
154  rset->getString(6)); // maps_to
155  // to be corrected
156  // dat.setClob( rset->getString(7) );
157 
158  p.second = dat;
159  fillMap->insert(p);
160  }
161  } catch (SQLException& e) {
162  throw(std::runtime_error(std::string("MODCCSHFDat::fetchData(): ") + e.getMessage()));
163  }
164 }

References MillePedeFileConverter_cfg::e, AlCaHLTBitMon_ParallelJobs::p, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ getClob()

unsigned char* MODCCSHFDat::getClob ( ) const
inline

Definition at line 30 of file MODCCSHFDat.h.

30 { return m_clob; }

References m_clob.

◆ getFile()

std::string MODCCSHFDat::getFile ( ) const
inline

Definition at line 39 of file MODCCSHFDat.h.

39 { return m_file; }

References m_file.

◆ getSize()

unsigned int MODCCSHFDat::getSize ( ) const
inline

Definition at line 33 of file MODCCSHFDat.h.

33 { return m_size; }

References m_size.

◆ getTable()

std::string MODCCSHFDat::getTable ( )
inlineoverridevirtual

Implements IDataItem.

Definition at line 27 of file MODCCSHFDat.h.

27 { return "OD_CCS_HF_DAT"; }

◆ getTest()

int MODCCSHFDat::getTest ( ) const
inline

Definition at line 36 of file MODCCSHFDat.h.

36 { return testing; }

References testing.

◆ populateClob()

void MODCCSHFDat::populateClob ( Clob clob,
std::string  fname,
unsigned int  clob_size 
)
privatenoexcept

Definition at line 234 of file MODCCSHFDat.cc.

234  {
235  try {
236  // Uses stream here
237  cout << "Populating the Clob using writeBuffer(Stream) method" << endl;
238  std::cout << "we are here0" << std::endl;
239 
240  std::cout << "we are here0.5 file is:" << fname << std::endl;
241 
242  ifstream inFile;
243  inFile.open(fname.c_str(), ios::in);
244  if (!inFile) {
245  cout << fname << " file not found\n";
246  inFile.close();
247 
248  std::string fname2 = "/u1/fra/null_file.txt";
249  inFile.open(fname2.c_str(), ios::in);
250  }
251  if (clob_size == 0) {
252  inFile.seekg(0, ios::end);
253  clob_size = inFile.tellg();
254  std::cout << " bufsize =" << clob_size << std::endl;
255  // set file pointer to start again
256  inFile.seekg(0, ios::beg);
257  }
258 
259  char* buffer = new char[clob_size + 1];
260 
261  std::cout << "we are here1" << std::endl;
262  unsigned int size;
263  Stream* strm = clob.getStream();
264  std::cout << "we are here2" << std::endl;
265  // while(inFile)
266  // {
267  int buf = 0;
268  memset(buffer, buf, clob_size + 1);
269  inFile.read(buffer, clob_size);
270  std::cout << "we are here2.5" << std::endl;
271 
272  strm->writeBuffer(buffer, strlen(buffer));
273  std::cout << "we are here2.6" << std::endl;
274 
275  //}
276  std::cout << "we are here3" << std::endl;
277  strcpy(buffer, " ");
278  size = strlen(buffer);
279  strm->writeLastBuffer(buffer, size);
280  clob.closeStream(strm);
281  inFile.close();
282  std::cout << "we are here4" << std::endl;
283  delete[] buffer;
284 
285  } catch (SQLException& e) {
286  throw(std::runtime_error(std::string("populateClob(): ") + e.getMessage()));
287  }
288 
289  cout << "Populating the Clob - Success" << endl;
290 }

References visDQMUpload::buf, edmScanValgrind::buffer, gather_cfg::cout, MillePedeFileConverter_cfg::e, mps_fire::end, alignmentValidation::fname, recoMuon::in, findQualityFiles::size, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ prepareWrite()

void MODCCSHFDat::prepareWrite ( )
overrideprivatevirtualnoexcept

Implements IDataItem.

Definition at line 52 of file MODCCSHFDat.cc.

52  {
53  this->checkConnection();
54 
55  try {
56  m_writeStmt = m_conn->createStatement();
57  m_writeStmt->setSQL(
58  "INSERT INTO OD_CCS_HF_dat (iov_id, logic_id, "
59  "ccs_log) "
60  "VALUES (:iov_id, :logic_id, "
61  ":ccs_log )");
62 
63  } catch (SQLException& e) {
64  throw(std::runtime_error(std::string("MODCCSHFDat::prepareWrite(): ") + e.getMessage()));
65  }
66 }

References MillePedeFileConverter_cfg::e, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ readClob()

unsigned char * MODCCSHFDat::readClob ( Clob clob,
int  size 
)
privatenoexcept

Definition at line 292 of file MODCCSHFDat.cc.

292  {
293  try {
294  Stream* instream = clob.getStream(1, 0);
295  unsigned char* buffer = new unsigned char[size];
296  int buf = 0;
297  memset(buffer, buf, size);
298 
299  instream->readBuffer((char*)buffer, size);
300  cout << "remember to delete the char* at the end of the program ";
301  for (int i = 0; i < size; ++i)
302  cout << (char)buffer[i];
303  cout << endl;
304 
305  clob.closeStream(instream);
306 
307  return buffer;
308 
309  } catch (SQLException& e) {
310  throw(std::runtime_error(std::string("readClob(): ") + e.getMessage()));
311  }
312 }

References visDQMUpload::buf, edmScanValgrind::buffer, gather_cfg::cout, MillePedeFileConverter_cfg::e, mps_fire::i, findQualityFiles::size, and AlCaHLTBitMon_QueryRunRegistry::string.

◆ setClob()

void MODCCSHFDat::setClob ( unsigned char *  x)
inline

Definition at line 29 of file MODCCSHFDat.h.

29 { m_clob = x; }

References m_clob, and x.

◆ setFile()

void MODCCSHFDat::setFile ( std::string  x)

Definition at line 29 of file MODCCSHFDat.cc.

29  {
30  m_file = x;
31  //try {
32  std::cout << "file is " << m_file << endl;
33  // }catch (Exception &e) {
34  //throw(std::runtime_error(std::string("MODCCSHFDat::setFile(): ")+e.getMessage()));
35  //}
36  // here we must open the file and read the CCS Clob
37  std::cout << "Going to read CCS file: " << m_file << endl;
38  ifstream inpFile;
39  inpFile.open(m_file.c_str());
40  // tell me size of file
41  int bufsize = 0;
42  inpFile.seekg(0, ios::end);
43  bufsize = inpFile.tellg();
44  std::cout << " bufsize =" << bufsize << std::endl;
45  // set file pointer to start again
46  inpFile.seekg(0, ios::beg);
47  m_size = bufsize;
48  inpFile.close();
49  std::cout << "Going to read CCS file: " << m_file << endl;
50 }

References gather_cfg::cout, mps_fire::end, and x.

◆ setSize()

void MODCCSHFDat::setSize ( unsigned int  id)
inline

Definition at line 32 of file MODCCSHFDat.h.

32 { m_size = id; }

References triggerObjects_cff::id, and m_size.

◆ setTest()

void MODCCSHFDat::setTest ( int  id)
inline

Definition at line 35 of file MODCCSHFDat.h.

35 { testing = id; }

References triggerObjects_cff::id, and testing.

◆ writeArrayDB()

void MODCCSHFDat::writeArrayDB ( const std::map< EcalLogicID, MODCCSHFDat > *  data,
MODRunIOV iov 
)
privatenoexcept

Definition at line 166 of file MODCCSHFDat.cc.

166  {
167  this->checkConnection();
168  this->checkPrepare();
169 
170  int iovID = iov->fetchID();
171  if (!iovID) {
172  throw(std::runtime_error("MODCCSHFDat::writeArrayDB: IOV not in DB"));
173  }
174 
175  int nrows = data->size();
176  int* ids = new int[nrows];
177  int* iovid_vec = new int[nrows];
178  int* xx = new int[nrows];
179 
180  ub2* ids_len = new ub2[nrows];
181  ub2* iov_len = new ub2[nrows];
182  ub2* x_len = new ub2[nrows];
183 
184  const EcalLogicID* channel;
185  //const MODCCSHFDat* dataitem;
186  int count = 0;
187  typedef map<EcalLogicID, MODCCSHFDat>::const_iterator CI;
188  for (CI p = data->begin(); p != data->end(); ++p) {
189  channel = &(p->first);
190  int logicID = channel->getLogicID();
191  if (!logicID) {
192  throw(std::runtime_error("MODCCSHFDat::writeArrayDB: Bad EcalLogicID"));
193  }
194  ids[count] = logicID;
195  iovid_vec[count] = iovID;
196 
197  // dataitem = &(p->second);
198  // dataIface.writeDB( channel, dataitem, iov);
199  // to be corrected
200 
201  int x = 0;
202  //=dataitem->getWord();
203 
204  xx[count] = x;
205 
206  ids_len[count] = sizeof(ids[count]);
207  iov_len[count] = sizeof(iovid_vec[count]);
208 
209  x_len[count] = sizeof(xx[count]);
210 
211  count++;
212  }
213 
214  try {
215  m_writeStmt->setDataBuffer(1, (dvoid*)iovid_vec, OCCIINT, sizeof(iovid_vec[0]), iov_len);
216  m_writeStmt->setDataBuffer(2, (dvoid*)ids, OCCIINT, sizeof(ids[0]), ids_len);
217  m_writeStmt->setDataBuffer(3, (dvoid*)xx, OCCIINT, sizeof(xx[0]), x_len);
218 
219  m_writeStmt->executeArrayUpdate(nrows);
220 
221  delete[] ids;
222  delete[] iovid_vec;
223  delete[] xx;
224 
225  delete[] ids_len;
226  delete[] iov_len;
227  delete[] x_len;
228 
229  } catch (SQLException& e) {
230  throw(std::runtime_error(std::string("MonPedestalsDat::writeArrayDB(): ") + e.getMessage()));
231  }
232 }

References submitPVResolutionJobs::count, data, MillePedeFileConverter_cfg::e, EcalLogicID::getLogicID(), AlCaHLTBitMon_ParallelJobs::p, AlCaHLTBitMon_QueryRunRegistry::string, x, and geometryCSVtoXML::xx.

◆ writeDB()

void MODCCSHFDat::writeDB ( const EcalLogicID ecid,
const MODCCSHFDat item,
MODRunIOV iov 
)
privatenoexcept

Definition at line 68 of file MODCCSHFDat.cc.

68  {
69  this->checkConnection();
70  this->checkPrepare();
71 
72  int iovID = iov->fetchID();
73  if (!iovID) {
74  throw(std::runtime_error("MODCCSHFDat::writeDB: IOV not in DB"));
75  }
76 
77  int logicID = ecid->getLogicID();
78  if (!logicID) {
79  throw(std::runtime_error("MODCCSHFDat::writeDB: Bad EcalLogicID"));
80  }
81 
82  std::string fname = item->getFile();
83  std::cout << "Going to read CCS file: " << fname << endl;
84 
85  try {
86  m_writeStmt->setInt(1, iovID);
87  m_writeStmt->setInt(2, logicID);
88 
89  // and now the clob
90  oracle::occi::Clob clob(m_conn);
91  clob.setEmpty();
92  m_writeStmt->setClob(3, clob);
93  m_writeStmt->executeUpdate();
94 
95  m_conn->terminateStatement(m_writeStmt);
96  std::cout << "empty CCS Clob inserted into DB" << std::endl;
97 
98  // now we read and update it
99  m_writeStmt = m_conn->createStatement();
100  m_writeStmt->setSQL(
101  "SELECT CCS_LOG FROM OD_CCS_HF_DAT WHERE"
102  " iov_ID=:1 and logic_ID=:2 FOR UPDATE");
103  m_writeStmt->setInt(1, iovID);
104  m_writeStmt->setInt(2, logicID);
105  ResultSet* rset = m_writeStmt->executeQuery();
106  rset->next();
107  oracle::occi::Clob clob2 = rset->getClob(1);
108  cout << "Opening the clob in read write mode" << endl;
109 
110  unsigned int clob_size = item->getSize();
111 
112  populateClob(clob2, fname, clob_size);
113 
114  int clobLength = clob2.length();
115  cout << "Length of the clob is: " << clobLength << endl;
116 
117  m_writeStmt->executeUpdate();
118  m_writeStmt->closeResultSet(rset);
119 
120  } catch (SQLException& e) {
121  throw(std::runtime_error(std::string("MODCCSHFDat::writeDB(): ") + e.getMessage()));
122  }
123 }

References gather_cfg::cout, MillePedeFileConverter_cfg::e, alignmentValidation::fname, B2GTnPMonitor_cfi::item, and AlCaHLTBitMon_QueryRunRegistry::string.

Friends And Related Function Documentation

◆ EcalCondDBInterface

friend class EcalCondDBInterface
friend

Definition at line 22 of file MODCCSHFDat.h.

Member Data Documentation

◆ m_clob

unsigned char* MODCCSHFDat::m_clob
private

Definition at line 51 of file MODCCSHFDat.h.

Referenced by getClob(), and setClob().

◆ m_file

std::string MODCCSHFDat::m_file
private

Definition at line 53 of file MODCCSHFDat.h.

Referenced by getFile().

◆ m_size

unsigned int MODCCSHFDat::m_size
private

Definition at line 52 of file MODCCSHFDat.h.

Referenced by getSize(), and setSize().

◆ testing

int MODCCSHFDat::testing
private

Definition at line 54 of file MODCCSHFDat.h.

Referenced by getTest(), and setTest().

MODCCSHFDat::m_clob
unsigned char * m_clob
Definition: MODCCSHFDat.h:51
mps_fire.i
i
Definition: mps_fire.py:428
MODCCSHFDat
Definition: MODCCSHFDat.h:19
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
gather_cfg.cout
cout
Definition: gather_cfg.py:144
IDataItem::checkPrepare
void checkPrepare() noexcept(false)
Definition: IDataItem.h:26
DDAxes::x
EcalLogicID::getLogicID
int getLogicID() const
Definition: EcalLogicID.cc:28
IDataItem::m_readStmt
oracle::occi::Statement * m_readStmt
Definition: IDataItem.h:24
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
MODRunIOV::fetchID
int fetchID() noexcept(false) override
Definition: MODRunIOV.cc:61
IDataItem::m_writeStmt
oracle::occi::Statement * m_writeStmt
Definition: IDataItem.h:23
IDBObject::m_conn
oracle::occi::Connection * m_conn
Definition: IDBObject.h:34
mps_fire.end
end
Definition: mps_fire.py:242
EcalLogicID
Definition: EcalLogicID.h:7
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
MODCCSHFDat::m_file
std::string m_file
Definition: MODCCSHFDat.h:53
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
IDBObject::checkConnection
void checkConnection() const noexcept(false)
Definition: IDBObject.h:36
recoMuon::in
Definition: RecoMuonEnumerators.h:6
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
visDQMUpload.buf
buf
Definition: visDQMUpload.py:154
MODCCSHFDat::m_size
unsigned int m_size
Definition: MODCCSHFDat.h:52
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
IDBObject::setConnection
void setConnection(oracle::occi::Environment *env, oracle::occi::Connection *conn)
Definition: IDBObject.h:23
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
MODCCSHFDat::testing
int testing
Definition: MODCCSHFDat.h:54
MODCCSHFDat::populateClob
void populateClob(Clob &clob, std::string fname, unsigned int clob_size) noexcept(false)
Definition: MODCCSHFDat.cc:234
IDBObject::m_env
oracle::occi::Environment * m_env
Definition: IDBObject.h:33
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37