CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes
TestFunct Class Reference

#include <TestFunct.h>

Public Member Functions

bool CreateMetaTable ()
 
bool DropItem (std::string mappingName)
 
bool DropTables (std::string connStr)
 
std::pair< int, int > GetMetadata (std::string mappingName)
 
bool Read (std::string mappingName)
 
bool ReadAll ()
 
bool ReadWithIOV (std::string mappingName, int seed, int runValidity)
 
 TestFunct ()
 
bool Write (std::string mappingName, int payloadID)
 
bool WriteWithIOV (std::string mappingName, int payloadID, int runValidity, bool updateTestMetadata)
 

Public Attributes

cond::DbSession s
 

Detailed Description

Definition at line 38 of file TestFunct.h.

Constructor & Destructor Documentation

TestFunct::TestFunct ( )

Definition at line 8 of file TestFunct.cc.

8 {}

Member Function Documentation

bool TestFunct::CreateMetaTable ( )

Definition at line 204 of file TestFunct.cc.

References cond::DbScopedTransaction::commit(), gather_cfg::cout, idDealer::description, cond::DbSession::nominalSchema(), s, python.IdGenerator::schema, cond::DbScopedTransaction::start(), and asciidump::table.

205 {
207  try
208  {
209  trans.start();
210  coral::ISchema& schema=s.nominalSchema();
211  coral::TableDescription description;
212  description.setName("TEST_METADATA");
213  description.insertColumn( "NAME", coral::AttributeSpecification::typeNameForId( typeid(std::string)) );
214  description.insertColumn( "SEED", coral::AttributeSpecification::typeNameForId( typeid(int)) );
215  description.insertColumn( "RUN", coral::AttributeSpecification::typeNameForId( typeid(int)) );
216  std::vector<std::string> cols;
217  cols.push_back( "NAME" );
218  description.setPrimaryKey(cols);
219  description.setNotNullConstraint("SEED");
220  description.setNotNullConstraint("RUN");
221  coral::ITable& table=schema.createTable(description);
222  table.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select);
223  std::cout<<"Table created"<<std::endl;
224  trans.commit();
225  }catch( const coral::TableAlreadyExistingException& er ){
226  std::cout<<"table alreay existing, not creating a new one"<<std::endl;
227  return false;
228  }
229  return true;
230 }
list table
Definition: asciidump.py:386
cond::DbSession s
Definition: TestFunct.h:40
tuple description
Definition: idDealer.py:66
coral::ISchema & nominalSchema()
Definition: DbSession.cc:228
tuple cout
Definition: gather_cfg.py:121
bool TestFunct::DropItem ( std::string  mappingName)

Definition at line 252 of file TestFunct.cc.

References cond::DbScopedTransaction::commit(), gather_cfg::cout, cond::MetaData::deleteEntryByTag(), cond::DbSession::deleteObject(), cond::MetaData::getToken(), s, cond::DbScopedTransaction::start(), and cms::Exception::what().

253 {
255  cond::MetaData metadata(s);
256  try {
257  trans.start(false);
258  std::string token = metadata.getToken(mappingName);
259  s.deleteObject(token);
260  metadata.deleteEntryByTag(mappingName);
261  trans.commit();
262  }
263  catch ( const cond::Exception& exc )
264  {
265  std::cout << "ERROR: "<<exc.what()<<std::endl;
266  return false;
267  }
268 
269  return true;
270 }
virtual char const * what() const
Definition: Exception.cc:141
bool deleteObject(const std::string &objectId)
Definition: DbSession.cc:259
cond::DbSession s
Definition: TestFunct.h:40
tuple cout
Definition: gather_cfg.py:121
bool TestFunct::DropTables ( std::string  connStr)

Definition at line 231 of file TestFunct.cc.

References ora::SchemaUtils::cleanUp(), gather_cfg::cout, and cppFunctionSkipper::exception.

232 {
233  std::set<std::string> exclude;
234  exclude.insert("VERSION_TABLE");
235  exclude.insert("TEST_STATUS");
236  exclude.insert("SEQUENCES");
237  exclude.insert("TEST_RESULTS");
238  exclude.insert("RUN_HEADER");
239  exclude.insert("RUN_RESULT");
240  exclude.insert("RUN_STEP_RESULT");
241  try
242  {
243  ora::SchemaUtils::cleanUp(connStr, exclude); //v4
244  }
245  catch ( const std::exception& exc )
246  {
247  std::cout <<" ERROR: "<<exc.what()<<std::endl;
248  return false;
249  }
250  return true;
251 }
void cleanUp(const std::string &connectionString, std::set< std::string > exclusionList=std::set< std::string >())
Definition: SchemaUtils.cc:22
tuple cout
Definition: gather_cfg.py:121
std::pair< int, int > TestFunct::GetMetadata ( std::string  mappingName)

Definition at line 10 of file TestFunct.cc.

References cond::DbScopedTransaction::commit(), gather_cfg::cout, cond::DbSession::nominalSchema(), o2o::query, run_regression::ret, s, cond::DbScopedTransaction::start(), and cms::Exception::what().

11 {
13  std::pair<int,int> ret(-1,-1);
14  try {
15  trans.start(true);
16 
17  coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
18  std::auto_ptr< coral::IQuery > query(mytable.newQuery());
19  coral::AttributeList BindVariableList;
20  std::string condition="NAME =:NAME";
21  BindVariableList.extend("NAME",typeid(std::string));
22  BindVariableList["NAME"].data<std::string>()=mappingName;
23  query->setCondition( condition, BindVariableList );
24  query->addToOutputList( "SEED" );
25  query->addToOutputList( "RUN" );
26  coral::ICursor& cursor = query->execute();
27  while( cursor.next() ) {
28  const coral::AttributeList& row = cursor.currentRow();
29  ret.first = row[ "SEED" ].data<int>();
30  ret.second =row["RUN" ].data<int>();
31  }
32  trans.commit();
33  } catch ( const cond::Exception& exc )
34  {
35  std::cout << "ERROR: "<<exc.what()<<std::endl;
36  return std::pair<int,int>(-1,-1);
37  }
38  return ret;
39 }
virtual char const * what() const
Definition: Exception.cc:141
cond::DbSession s
Definition: TestFunct.h:40
coral::ISchema & nominalSchema()
Definition: DbSession.cc:228
tuple query
Definition: o2o.py:269
tuple cout
Definition: gather_cfg.py:121
bool TestFunct::Read ( std::string  mappingName)

Definition at line 41 of file TestFunct.cc.

References cond::DbScopedTransaction::commit(), gather_cfg::cout, cond::MetaData::getToken(), cond::DbSession::getTypedObject(), cond::DbSession::nominalSchema(), o2o::query, run_regression::ret, s, cond::DbScopedTransaction::start(), and cms::Exception::what().

Referenced by ReadAll().

42 {
44  cond::MetaData metadata(s);
45  int refSeed =0;
46  bool ret = false;
47  try {
48  trans.start(true);
49 
50  coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
51  std::auto_ptr< coral::IQuery > query(mytable.newQuery());
52  coral::AttributeList BindVariableList;
53  std::string condition="NAME =:NAME";
54  BindVariableList.extend("NAME",typeid(std::string));
55  BindVariableList["NAME"].data<std::string>()=mappingName;
56  query->setCondition( condition, BindVariableList );
57  query->addToOutputList( "SEED" );
58  coral::ICursor& cursor = query->execute();
59  while( cursor.next() ) {
60  const coral::AttributeList& row = cursor.currentRow();
61  refSeed=row[ "SEED" ].data<int>();
62  }
63  std::string readToken = metadata.getToken(mappingName);
64  boost::shared_ptr<Payload> readRef0 = s.getTypedObject<Payload>( readToken ); //v4
65  std::cout << "Object with id="<<readToken<<" has been read"<<std::endl;
66  Payload tp = *readRef0;
67  Payload tp2(refSeed);
68  if(tp == tp2){
69  ret = true;
70  } else {
71  std::cout <<" read failed : seed "<<refSeed<<std::endl;
72  }
73  trans.commit();
74  } catch ( const cond::Exception& exc )
75  {
76  std::cout << "ERROR: "<<exc.what()<<std::endl;
77  return false;
78  }
79  return ret;
80 }
virtual char const * what() const
Definition: Exception.cc:141
cond::DbSession s
Definition: TestFunct.h:40
coral::ISchema & nominalSchema()
Definition: DbSession.cc:228
tuple query
Definition: o2o.py:269
tuple cout
Definition: gather_cfg.py:121
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:125
bool TestFunct::ReadAll ( )

Definition at line 116 of file TestFunct.cc.

References cond::DbScopedTransaction::commit(), gather_cfg::cout, i, cond::MetaData::listAllTags(), Read(), run_regression::ret, s, cond::DbScopedTransaction::start(), and cms::Exception::what().

117 {
119  cond::MetaData metadata(s);
120  std::vector<std::string> tokenList;
121  bool ret = true;
122  try {
123  trans.start(true);
124  metadata.listAllTags(tokenList);
125  for(unsigned int i=0; i<tokenList.size(); i++)
126  {
127  if(!Read(tokenList[i])) ret = false;
128  }
129  trans.commit();
130  }
131  catch ( const cond::Exception& exc )
132  {
133  std::cout << "ERROR: "<<exc.what()<<std::endl;
134  return false;
135  }
136  return ret;
137 }
virtual char const * what() const
Definition: Exception.cc:141
int i
Definition: DBlmapReader.cc:9
cond::DbSession s
Definition: TestFunct.h:40
bool Read(std::string mappingName)
Definition: TestFunct.cc:41
tuple cout
Definition: gather_cfg.py:121
bool TestFunct::ReadWithIOV ( std::string  mappingName,
int  seed,
int  runValidity 
)

Definition at line 82 of file TestFunct.cc.

References cond::DbScopedTransaction::commit(), gather_cfg::cout, cond::IOVProxy::end(), cond::IOVProxy::find(), cond::MetaData::getToken(), cond::DbSession::getTypedObject(), o2o::iov, run_regression::ret, s, cond::DbScopedTransaction::start(), and cms::Exception::what().

85 {
87  cond::MetaData metadata(s);
88  bool ret = false;
89  try {
90  trans.start(true);
91  std::string iovToken = metadata.getToken(mappingName);
92  cond::IOVProxy iov(s,iovToken);
93  cond::IOVProxy::const_iterator iPayload = iov.find( validity );
94  if( iPayload == iov.end() ){
95  std::cout << "ERROR: no payload found in IOV for run="<<validity<<std::endl;
96  return false;
97  }
98  boost::shared_ptr<Payload> readRef0 = s.getTypedObject<Payload>( iPayload->token() ); //v4
99  std::cout << "Object with id="<<iPayload->token()<<" has been read"<<std::endl;
100  Payload tp = *readRef0;
101  Payload tp2(seed);
102  if(tp == tp2){
103  ret = true;
104  } else {
105  std::cout <<" read failed : seed="<<seed<<std::endl;
106  }
107  trans.commit();
108  } catch ( const cond::Exception& exc )
109  {
110  std::cout << "ERROR: "<<exc.what()<<std::endl;
111  return false;
112  }
113  return ret;
114 }
virtual char const * what() const
Definition: Exception.cc:141
cond::DbSession s
Definition: TestFunct.h:40
tuple iov
Definition: o2o.py:307
tuple cout
Definition: gather_cfg.py:121
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:125
iov_range_iterator const_iterator
Definition: IOVProxy.h:160
bool TestFunct::Write ( std::string  mappingName,
int  payloadID 
)

Definition at line 138 of file TestFunct.cc.

References cond::MetaData::addMapping(), cond::DbScopedTransaction::commit(), gather_cfg::cout, cond::DbSession::createDatabase(), cond::DbSession::nominalSchema(), s, cond::DbScopedTransaction::start(), cond::DbSession::storeObject(), and cms::Exception::what().

139 {
141  cond::MetaData metadata(s);
142  std::string tok0("");
143  try
144  {
145  trans.start();
146  coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
147  coral::AttributeList rowBuffer;
148  coral::ITableDataEditor& dataEditor = mytable.dataEditor();
149  dataEditor.rowBuffer( rowBuffer );
150  rowBuffer["NAME"].data<std::string>()=mappingName;
151  rowBuffer["SEED"].data<int>()=payloadID;
152  rowBuffer["RUN"].data<int>()=-1;
153  dataEditor.insertRow( rowBuffer );
154  s.createDatabase();
155  boost::shared_ptr<Payload> myRef0(new Payload(payloadID)); //v4
156  tok0 = s.storeObject( myRef0.get(),"cont1"); //v4
157  metadata.addMapping(mappingName, tok0);
158  std::cout << "Stored object with id = "<<tok0<<std::endl;
159  trans.commit();
160  } catch ( const cond::Exception& exc )
161  {
162  std::cout << "ERROR: "<<exc.what()<<std::endl;
163  return false;
164  }
165  return true;
166 }
virtual char const * what() const
Definition: Exception.cc:141
cond::DbSession s
Definition: TestFunct.h:40
RegressionTestPayload Payload
Definition: TestFunct.cc:6
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:131
bool createDatabase()
Definition: DbSession.cc:206
coral::ISchema & nominalSchema()
Definition: DbSession.cc:228
tuple cout
Definition: gather_cfg.py:121
bool TestFunct::WriteWithIOV ( std::string  mappingName,
int  payloadID,
int  runValidity,
bool  updateTestMetadata 
)

Definition at line 168 of file TestFunct.cc.

References cond::MetaData::addMapping(), cond::IOVEditor::append(), cond::DbScopedTransaction::commit(), gather_cfg::cout, cond::IOVEditor::create(), cond::DbSession::createDatabase(), o2o::iov, cond::DbSession::nominalSchema(), cond::runnumber, s, cond::DbScopedTransaction::start(), cond::DbSession::storeObject(), cond::IOVEditor::token(), and cms::Exception::what().

171  {
173  cond::MetaData metadata(s);
174  std::string tok0("");
175  try {
177  trans.start();
178  if( updateTestMetadata ){
179  coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
180  coral::AttributeList rowBuffer;
181  coral::ITableDataEditor& dataEditor = mytable.dataEditor();
182  dataEditor.rowBuffer( rowBuffer );
183  rowBuffer["NAME"].data<std::string>()=mappingName;
184  rowBuffer["SEED"].data<int>()=payloadID;
185  rowBuffer["RUN"].data<int>()= runValidity;
186  dataEditor.insertRow( rowBuffer );
187  }
188  s.createDatabase();
189  boost::shared_ptr<Payload> myRef0(new Payload(payloadID)); //v4
190  std::string payloadTok = s.storeObject( myRef0.get(),"cont1");
191  iov.create( cond::runnumber );
192  iov.append( runValidity, payloadTok );
193  metadata.addMapping(mappingName, iov.token());
194  trans.commit();
195  } catch ( const cond::Exception& exc )
196  {
197  std::cout << "ERROR: "<<exc.what()<<std::endl;
198  return false;
199  }
200  return true;
201 
202 }
virtual char const * what() const
Definition: Exception.cc:141
cond::DbSession s
Definition: TestFunct.h:40
RegressionTestPayload Payload
Definition: TestFunct.cc:6
tuple iov
Definition: o2o.py:307
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:131
bool createDatabase()
Definition: DbSession.cc:206
coral::ISchema & nominalSchema()
Definition: DbSession.cc:228
tuple cout
Definition: gather_cfg.py:121

Member Data Documentation

cond::DbSession TestFunct::s