Go to the documentation of this file.00001 #include "CondCore/RegressionTest/interface/TestFunct.h"
00002 #include "CondCore/IOVService/interface/IOVEditor.h"
00003 #include "CondCore/IOVService/interface/IOVProxy.h"
00004
00005
00006 TestFunct::TestFunct() {}
00007
00008 std::pair<int,int> TestFunct::GetMetadata(std::string mappingName)
00009 {
00010 cond::DbScopedTransaction trans(s);
00011 std::pair<int,int> ret(-1,-1);
00012 try {
00013 trans.start(true);
00014
00015 coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
00016 std::auto_ptr< coral::IQuery > query(mytable.newQuery());
00017 coral::AttributeList BindVariableList;
00018 std::string condition="NAME =:NAME";
00019 BindVariableList.extend("NAME",typeid(std::string));
00020 BindVariableList["NAME"].data<std::string>()=mappingName;
00021 query->setCondition( condition, BindVariableList );
00022 query->addToOutputList( "SEED" );
00023 query->addToOutputList( "RUN" );
00024 coral::ICursor& cursor = query->execute();
00025 while( cursor.next() ) {
00026 const coral::AttributeList& row = cursor.currentRow();
00027 ret.first = row[ "SEED" ].data<int>();
00028 ret.second =row["RUN" ].data<int>();
00029 }
00030 trans.commit();
00031 } catch ( const cond::Exception& exc )
00032 {
00033 std::cout << "ERROR: "<<exc.what()<<std::endl;
00034 return std::pair<int,int>(-1,-1);
00035 }
00036 return ret;
00037 }
00038
00039 bool TestFunct::Read (std::string mappingName)
00040 {
00041 cond::DbScopedTransaction trans(s);
00042 cond::MetaData metadata(s);
00043 int refSeed =0;
00044 try {
00045 trans.start(true);
00046
00047 coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
00048 std::auto_ptr< coral::IQuery > query(mytable.newQuery());
00049 coral::AttributeList BindVariableList;
00050 std::string condition="NAME =:NAME";
00051 BindVariableList.extend("NAME",typeid(std::string));
00052 BindVariableList["NAME"].data<std::string>()=mappingName;
00053 query->setCondition( condition, BindVariableList );
00054 query->addToOutputList( "SEED" );
00055 coral::ICursor& cursor = query->execute();
00056 while( cursor.next() ) {
00057 const coral::AttributeList& row = cursor.currentRow();
00058 refSeed=row[ "SEED" ].data<int>();
00059 }
00060 std::string readToken = metadata.getToken(mappingName);
00061 boost::shared_ptr<TestPayloadClass> readRef0 = s.getTypedObject<TestPayloadClass>( readToken );
00062 std::cout << "Object with id="<<readToken<<" has been read"<<std::endl;
00063 TestPayloadClass tp = *readRef0;
00064 TestPayloadClass tp2(refSeed);
00065 if(tp != tp2)
00066 std::cout <<" read failed : seed "<<refSeed<<std::endl;
00067 trans.commit();
00068 } catch ( const cond::Exception& exc )
00069 {
00070 std::cout << "ERROR: "<<exc.what()<<std::endl;
00071 return 1;
00072 }
00073 return 0;
00074 }
00075
00076 bool TestFunct::ReadWithIOV(std::string mappingName,
00077 int seed,
00078 int validity)
00079 {
00080 cond::DbScopedTransaction trans(s);
00081 cond::MetaData metadata(s);
00082 try {
00083 trans.start(true);
00084 std::string iovToken = metadata.getToken(mappingName);
00085 cond::IOVProxy iov(s,iovToken);
00086 cond::IOVProxy::const_iterator iPayload = iov.find( validity );
00087 if( iPayload == iov.end() ){
00088 std::cout << "ERROR: no payload found in IOV for run="<<validity<<std::endl;
00089 return 1;
00090 }
00091 boost::shared_ptr<TestPayloadClass> readRef0 = s.getTypedObject<TestPayloadClass>( iPayload->token() );
00092 std::cout << "Object with id="<<iPayload->token()<<" has been read"<<std::endl;
00093 TestPayloadClass tp = *readRef0;
00094 TestPayloadClass tp2(seed);
00095 if(tp != tp2)
00096 std::cout <<" read failed : seed="<<seed<<std::endl;
00097 trans.commit();
00098 } catch ( const cond::Exception& exc )
00099 {
00100 std::cout << "ERROR: "<<exc.what()<<std::endl;
00101 return 1;
00102 }
00103 return 0;
00104 }
00105
00106 bool TestFunct::ReadAll()
00107 {
00108 cond::DbScopedTransaction trans(s);
00109 cond::MetaData metadata(s);
00110 std::vector<std::string> tokenList;
00111 try {
00112 trans.start(true);
00113 metadata.listAllTags(tokenList);
00114 for(unsigned int i=0; i<tokenList.size(); i++)
00115 {
00116 Read(tokenList[i]);
00117 }
00118 trans.commit();
00119 }
00120 catch ( const cond::Exception& exc )
00121 {
00122 std::cout << "ERROR: "<<exc.what()<<std::endl;
00123 return 1;
00124 }
00125 return 0;
00126 }
00127 bool TestFunct::Write (std::string mappingName, int payloadID)
00128 {
00129 cond::DbScopedTransaction trans(s);
00130 cond::MetaData metadata(s);
00131 std::string tok0("");
00132 try
00133 {
00134 trans.start();
00135 coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
00136 coral::AttributeList rowBuffer;
00137 coral::ITableDataEditor& dataEditor = mytable.dataEditor();
00138 dataEditor.rowBuffer( rowBuffer );
00139 rowBuffer["NAME"].data<std::string>()=mappingName;
00140 rowBuffer["SEED"].data<int>()=payloadID;
00141 rowBuffer["RUN"].data<int>()=-1;
00142 dataEditor.insertRow( rowBuffer );
00143 s.createDatabase();
00144 boost::shared_ptr<TestPayloadClass> myRef0(new TestPayloadClass(payloadID));
00145 tok0 = s.storeObject( myRef0.get(),"cont1");
00146 metadata.addMapping(mappingName, tok0);
00147 std::cout << "Stored object with id = "<<tok0<<std::endl;
00148 trans.commit();
00149 } catch ( const cond::Exception& exc )
00150 {
00151 std::cout << "ERROR: "<<exc.what()<<std::endl;
00152 return 1;
00153 }
00154 return 0;
00155 }
00156
00157 bool TestFunct::WriteWithIOV(std::string mappingName,
00158 int payloadID,
00159 int runValidity,
00160 bool updateTestMetadata ){
00161 cond::DbScopedTransaction trans(s);
00162 cond::MetaData metadata(s);
00163 std::string tok0("");
00164 try {
00165 cond::IOVEditor iov(s);
00166 trans.start();
00167 if( updateTestMetadata ){
00168 coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
00169 coral::AttributeList rowBuffer;
00170 coral::ITableDataEditor& dataEditor = mytable.dataEditor();
00171 dataEditor.rowBuffer( rowBuffer );
00172 rowBuffer["NAME"].data<std::string>()=mappingName;
00173 rowBuffer["SEED"].data<int>()=payloadID;
00174 rowBuffer["RUN"].data<int>()= runValidity;
00175 dataEditor.insertRow( rowBuffer );
00176 }
00177 s.createDatabase();
00178 boost::shared_ptr<TestPayloadClass> myRef0(new TestPayloadClass(payloadID));
00179 std::string payloadTok = s.storeObject( myRef0.get(),"cont1");
00180 iov.create( cond::runnumber );
00181 iov.append( runValidity, payloadTok );
00182 metadata.addMapping(mappingName, iov.token());
00183 trans.commit();
00184 } catch ( const cond::Exception& exc )
00185 {
00186 std::cout << "ERROR: "<<exc.what()<<std::endl;
00187 return 1;
00188 }
00189 return 0;
00190
00191 }
00192
00193 bool TestFunct::CreateMetaTable ()
00194 {
00195 cond::DbScopedTransaction trans(s);
00196 try
00197 {
00198 trans.start();
00199 coral::ISchema& schema=s.nominalSchema();
00200 coral::TableDescription description;
00201 description.setName("TEST_METADATA");
00202 description.insertColumn( "NAME", coral::AttributeSpecification::typeNameForId( typeid(std::string)) );
00203 description.insertColumn( "SEED", coral::AttributeSpecification::typeNameForId( typeid(int)) );
00204 description.insertColumn( "RUN", coral::AttributeSpecification::typeNameForId( typeid(int)) );
00205 std::vector<std::string> cols;
00206 cols.push_back( "NAME" );
00207 description.setPrimaryKey(cols);
00208 description.setNotNullConstraint("SEED");
00209 description.setNotNullConstraint("RUN");
00210 coral::ITable& table=schema.createTable(description);
00211 table.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select);
00212 std::cout<<"Table created"<<std::endl;
00213 trans.commit();
00214 }catch( const coral::TableAlreadyExistingException& er ){
00215 std::cout<<"table alreay existing, not creating a new one"<<std::endl;
00216 return 1;
00217 }
00218 return 0;
00219 }
00220 bool TestFunct::DropTables(std::string connStr)
00221 {
00222 std::set<std::string> exclude;
00223 exclude.insert("VERSION_TABLE");
00224 exclude.insert("TEST_STATUS");
00225 exclude.insert("SEQUENCES");
00226 exclude.insert("TEST_RESULTS");
00227 try
00228 {
00229 ora::SchemaUtils::cleanUp(connStr, exclude);
00230 }
00231 catch ( const std::exception& exc )
00232 {
00233 std::cout <<" ERROR: "<<exc.what()<<std::endl;
00234 return 1;
00235 }
00236 return 0;
00237 }
00238 bool TestFunct::DropItem(std::string mappingName)
00239 {
00240 cond::DbScopedTransaction trans(s);
00241 cond::MetaData metadata(s);
00242 try {
00243 trans.start(false);
00244 std::string token = metadata.getToken(mappingName);
00245 s.deleteObject(token);
00246 metadata.deleteEntryByTag(mappingName);
00247 trans.commit();
00248 }
00249 catch ( const cond::Exception& exc )
00250 {
00251 std::cout << "ERROR: "<<exc.what()<<std::endl;
00252 return 1;
00253 }
00254
00255 return 0;
00256 }