CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TestFunct.cc
Go to the documentation of this file.
4 
5 //typedef TestPayloadClass Payload;
7 
9 
10 std::pair<int,int> TestFunct::GetMetadata(std::string mappingName)
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 }
40 
41 bool TestFunct::Read (std::string mappingName)
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 }
81 
83  int seed,
84  int validity)
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 }
115 
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 }
138 bool TestFunct::Write (std::string mappingName, int payloadID)
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 }
167 
169  int payloadID,
170  int runValidity,
171  bool updateTestMetadata ){
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 }
203 
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 }
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 }
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
int i
Definition: DBlmapReader.cc:9
std::string create(cond::TimeType timetype)
Definition: IOVEditor.cc:260
bool ReadWithIOV(std::string mappingName, int seed, int runValidity)
Definition: TestFunct.cc:82
bool deleteObject(const std::string &objectId)
Definition: DbSession.cc:274
cond::DbSession s
Definition: TestFunct.h:38
bool WriteWithIOV(std::string mappingName, int payloadID, int runValidity, bool updateTestMetadata)
Definition: TestFunct.cc:168
bool ReadAll()
Definition: TestFunct.cc:116
std::string const & token() const
Definition: IOVEditor.cc:542
const std::string getToken(const std::string &tagname) const
Definition: MetaData.cc:52
RegressionTestPayload Payload
Definition: TestFunct.cc:6
const_iterator end() const
Definition: IOVProxy.h:193
bool Write(std::string mappingName, int payloadID)
Definition: TestFunct.cc:138
std::pair< int, int > GetMetadata(std::string mappingName)
Definition: TestFunct.cc:10
bool addMapping(const std::string &name, const std::string &token, cond::TimeType timetype=cond::runnumber)
Definition: MetaData.cc:36
tuple iov
Definition: o2o.py:307
TestFunct()
Definition: TestFunct.cc:8
int start(bool readOnly=false)
start transaction
std::string storeObject(const T *object, const std::string &containerName)
Definition: DbSession.h:132
tuple description
Definition: idDealer.py:66
#define table(NAME)
Definition: DbCore.h:49
bool createDatabase()
Definition: DbSession.cc:221
unsigned int append(cond::Time_t sinceTime, const std::string &payloadToken)
Definition: IOVEditor.cc:416
bool Read(std::string mappingName)
Definition: TestFunct.cc:41
coral::ISchema & nominalSchema()
Definition: DbSession.cc:243
void cleanUp(const std::string &connectionString, std::set< std::string > exclusionList=std::set< std::string >())
Definition: SchemaUtils.cc:22
bool CreateMetaTable()
Definition: TestFunct.cc:204
void deleteEntryByTag(const std::string &tag)
Definition: MetaData.cc:97
tuple query
Definition: o2o.py:269
tuple cout
Definition: gather_cfg.py:121
bool DropTables(std::string connStr)
Definition: TestFunct.cc:231
void listAllTags(std::vector< std::string > &result) const
Definition: MetaData.cc:80
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Definition: DbSession.h:126
int commit()
commit transaction. Will disconnect from database if connection timeout==0 or connectted time close t...
const_iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:264
iov_range_iterator const_iterator
Definition: IOVProxy.h:160
bool DropItem(std::string mappingName)
Definition: TestFunct.cc:252