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