CMS 3D CMS Logo

Public Member Functions | Public Attributes

TestFunct Class Reference

#include <TestFunct.h>

List of all members.

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 37 of file TestFunct.h.


Constructor & Destructor Documentation

TestFunct::TestFunct ( )

Definition at line 6 of file TestFunct.cc.

{}

Member Function Documentation

bool TestFunct::CreateMetaTable ( )

Definition at line 193 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.

{
        cond::DbScopedTransaction trans(s);
        try
        {
                trans.start();
                coral::ISchema& schema=s.nominalSchema();
                coral::TableDescription description;
                description.setName("TEST_METADATA");
                description.insertColumn(  "NAME", coral::AttributeSpecification::typeNameForId( typeid(std::string)) );
                description.insertColumn( "SEED", coral::AttributeSpecification::typeNameForId( typeid(int)) );
                description.insertColumn( "RUN", coral::AttributeSpecification::typeNameForId( typeid(int)) );
                std::vector<std::string> cols;
                cols.push_back( "NAME" );
                description.setPrimaryKey(cols);
                description.setNotNullConstraint("SEED");
                description.setNotNullConstraint("RUN");
                coral::ITable& table=schema.createTable(description);
                table.privilegeManager().grantToPublic( coral::ITablePrivilegeManager::Select);
                std::cout<<"Table created"<<std::endl;
                trans.commit();
        }catch( const coral::TableAlreadyExistingException& er ){
                std::cout<<"table alreay existing, not creating a new one"<<std::endl;
                return 1;
        }
        return 0;
}
bool TestFunct::DropItem ( std::string  mappingName)

Definition at line 238 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().

{
        cond::DbScopedTransaction trans(s);
        cond::MetaData  metadata(s);
        try {
                trans.start(false);
                std::string token = metadata.getToken(mappingName);
                s.deleteObject(token);
                metadata.deleteEntryByTag(mappingName);
                trans.commit();
        } 
        catch ( const cond::Exception& exc )
        {
                std::cout << "ERROR: "<<exc.what()<<std::endl;
                return 1;
        }
        
        return 0;
}
bool TestFunct::DropTables ( std::string  connStr)

Definition at line 220 of file TestFunct.cc.

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

{
        std::set<std::string> exclude;
        exclude.insert("VERSION_TABLE");
        exclude.insert("TEST_STATUS");
        exclude.insert("SEQUENCES");
        exclude.insert("TEST_RESULTS");
        try
        {
                ora::SchemaUtils::cleanUp(connStr, exclude); //v4
        }
        catch ( const std::exception& exc )
        {
                std::cout <<" ERROR: "<<exc.what()<<std::endl;
                return 1;
    }
        return 0;
}
std::pair< int, int > TestFunct::GetMetadata ( std::string  mappingName)

Definition at line 8 of file TestFunct.cc.

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

{
        cond::DbScopedTransaction trans(s);
        std::pair<int,int> ret(-1,-1);
        try {
                trans.start(true);
                
                coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
                std::auto_ptr< coral::IQuery > query(mytable.newQuery());
                coral::AttributeList BindVariableList;
                std::string condition="NAME =:NAME";
                BindVariableList.extend("NAME",typeid(std::string));
                BindVariableList["NAME"].data<std::string>()=mappingName;
                query->setCondition( condition, BindVariableList );
                query->addToOutputList( "SEED" );
                query->addToOutputList( "RUN" );
                coral::ICursor& cursor = query->execute();
                while( cursor.next() ) {
                        const coral::AttributeList& row = cursor.currentRow();
                        ret.first = row[ "SEED" ].data<int>();
                        ret.second =row["RUN" ].data<int>();
                }
                trans.commit();
        } catch ( const cond::Exception& exc )
        {
                std::cout << "ERROR: "<<exc.what()<<std::endl;
                return std::pair<int,int>(-1,-1);
        }
        return ret;
}
bool TestFunct::Read ( std::string  mappingName)

Definition at line 39 of file TestFunct.cc.

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

Referenced by ReadAll().

{
        cond::DbScopedTransaction trans(s);
        cond::MetaData  metadata(s);
        int refSeed =0;
        try {
                trans.start(true);
                
                coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
                std::auto_ptr< coral::IQuery > query(mytable.newQuery());
                coral::AttributeList BindVariableList;
                std::string condition="NAME =:NAME";
                BindVariableList.extend("NAME",typeid(std::string));
                BindVariableList["NAME"].data<std::string>()=mappingName;
                query->setCondition( condition, BindVariableList );
                query->addToOutputList( "SEED" );
                coral::ICursor& cursor = query->execute();
                while( cursor.next() ) {
                        const coral::AttributeList& row = cursor.currentRow();
                        refSeed=row[ "SEED" ].data<int>();
                }
                std::string readToken = metadata.getToken(mappingName);
                boost::shared_ptr<TestPayloadClass> readRef0 = s.getTypedObject<TestPayloadClass>( readToken ); //v4    
                std::cout << "Object with id="<<readToken<<" has been read"<<std::endl;
                TestPayloadClass tp = *readRef0;
                TestPayloadClass tp2(refSeed);
                if(tp != tp2)
                        std::cout <<" read failed : seed "<<refSeed<<std::endl;
                trans.commit();
        } catch ( const cond::Exception& exc )
        {
                std::cout << "ERROR: "<<exc.what()<<std::endl;
                return 1;
        }
        return 0;
}
bool TestFunct::ReadAll ( )

Definition at line 106 of file TestFunct.cc.

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

{
        cond::DbScopedTransaction trans(s);
        cond::MetaData  metadata(s);
        std::vector<std::string> tokenList;
        try {
                trans.start(true);
                metadata.listAllTags(tokenList);
                for(unsigned int i=0; i<tokenList.size(); i++)
                {
                        Read(tokenList[i]);
                }
                trans.commit();
        } 
        catch ( const cond::Exception& exc )
        {
                std::cout << "ERROR: "<<exc.what()<<std::endl;
                return 1;
        }
        return 0;
}
bool TestFunct::ReadWithIOV ( std::string  mappingName,
int  seed,
int  runValidity 
)

Definition at line 76 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, s, cond::DbScopedTransaction::start(), and cms::Exception::what().

{
        cond::DbScopedTransaction trans(s);
        cond::MetaData  metadata(s);
        try {
                trans.start(true);
                std::string iovToken = metadata.getToken(mappingName);
                cond::IOVProxy iov(s,iovToken);
                cond::IOVProxy::const_iterator iPayload = iov.find( validity );
                if( iPayload == iov.end() ){
                  std::cout << "ERROR: no payload found in IOV for run="<<validity<<std::endl;
                  return 1;
                }
                boost::shared_ptr<TestPayloadClass> readRef0 = s.getTypedObject<TestPayloadClass>( iPayload->token() ); //v4    
                std::cout << "Object with id="<<iPayload->token()<<" has been read"<<std::endl;
                TestPayloadClass tp = *readRef0;
                TestPayloadClass tp2(seed);
                if(tp != tp2)
                  std::cout <<" read failed : seed="<<seed<<std::endl;
                trans.commit();
        } catch ( const cond::Exception& exc )
        {
                std::cout << "ERROR: "<<exc.what()<<std::endl;
                return 1;
        }
        return 0;
}
bool TestFunct::Write ( std::string  mappingName,
int  payloadID 
)

Definition at line 127 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().

{
                cond::DbScopedTransaction trans(s);
           cond::MetaData  metadata(s);
           std::string tok0("");
        try 
        {
            trans.start();
                coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
                coral::AttributeList rowBuffer;
                coral::ITableDataEditor& dataEditor = mytable.dataEditor();
                dataEditor.rowBuffer( rowBuffer );
                rowBuffer["NAME"].data<std::string>()=mappingName;
                rowBuffer["SEED"].data<int>()=payloadID;
                rowBuffer["RUN"].data<int>()=-1;
                dataEditor.insertRow( rowBuffer );              
                s.createDatabase();
                boost::shared_ptr<TestPayloadClass> myRef0(new TestPayloadClass(payloadID)); //v4
            tok0 = s.storeObject( myRef0.get(),"cont1"); //v4
            metadata.addMapping(mappingName, tok0);
            std::cout << "Stored object with id = "<<tok0<<std::endl;
            trans.commit();
        } catch ( const cond::Exception& exc )
        {
                std::cout << "ERROR: "<<exc.what()<<std::endl;
                return 1;
        }
        return 0;
}
bool TestFunct::WriteWithIOV ( std::string  mappingName,
int  payloadID,
int  runValidity,
bool  updateTestMetadata 
)

Definition at line 157 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().

                                                      {
   cond::DbScopedTransaction trans(s);
   cond::MetaData  metadata(s);
   std::string tok0("");
   try {
     cond::IOVEditor iov(s);
     trans.start();
     if( updateTestMetadata ){
       coral::ITable& mytable=s.nominalSchema().tableHandle("TEST_METADATA");
       coral::AttributeList rowBuffer;
       coral::ITableDataEditor& dataEditor = mytable.dataEditor();
       dataEditor.rowBuffer( rowBuffer );
       rowBuffer["NAME"].data<std::string>()=mappingName;
       rowBuffer["SEED"].data<int>()=payloadID;
       rowBuffer["RUN"].data<int>()= runValidity;
       dataEditor.insertRow( rowBuffer );               
     }
     s.createDatabase();
     boost::shared_ptr<TestPayloadClass> myRef0(new TestPayloadClass(payloadID)); //v4
     std::string payloadTok = s.storeObject( myRef0.get(),"cont1"); 
     iov.create( cond::runnumber );
     iov.append( runValidity, payloadTok );
     metadata.addMapping(mappingName, iov.token());
     trans.commit();
   } catch ( const cond::Exception& exc )
     {
       std::cout << "ERROR: "<<exc.what()<<std::endl;
       return 1;
     }
   return 0;    
   
}

Member Data Documentation