Bdb packages | Design docs | Source docs | Guidelines | Recent releases

Search | Site Map .

Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/CdbTools/CdbToolsSetCmd.cc

Go to the documentation of this file.
00001 //
00002 //
00003 //
00004 #include "BaBar/BaBar.hh"
00005 #include "CdbTools/CdbToolsSetCmd.hh"
00006 //
00007 //
00008 #include "CdbBase/CdbDatabase.hh"
00009 #include "CdbBase/Cdb.hh"
00010 #include "CdbBase/CdbDatabaseItr.hh"
00011 #include "CdbBase/CdbView.hh"
00012 #include "CdbBase/CdbViewItr.hh"
00013 
00014 
00015 CdbToolsSetCmd::CdbToolsSetCmd(CdbToolsContext* context)
00016   :CdbToolsCmd(context)
00017 {
00018 }
00019 CdbToolsSetCmd::~CdbToolsSetCmd()
00020 {
00021 }
00022 CdbToolsStatus::CdbCmdStatus 
00023 CdbToolsSetCmd::setTechnology(std::string tech)
00024 {
00025   CdbToolsStatus::CdbCmdStatus status = CdbToolsStatus::Success;
00026   context()->setCurrTech( tech );
00027 
00028   return status;
00029 }
00030 CdbToolsStatus::CdbCmdStatus 
00031 CdbToolsSetCmd::setImplementation(std::string impl)
00032 {
00033   CdbToolsStatus::CdbCmdStatus status = CdbToolsStatus::Success;
00034   context()->setCurrImpl( impl );
00035 
00036   return status;
00037 }
00038 CdbToolsStatus::CdbCmdStatus 
00039 CdbToolsSetCmd::setDatabase(std::string dbase)
00040 {
00041   CdbToolsStatus::CdbCmdStatus status = CdbToolsStatus::Invalid;
00042   std::string tech ( context()->currentTech() );
00043   std::string impl ( context()->currentImpl() );  
00044   CdbPtr cdbPtr = Cdb::instance(tech.c_str(), impl.c_str());
00045  
00046   CdbDatabaseItr dItr;
00047   
00048   if(CdbStatus::Success != cdbPtr->databaseIterator( dItr )){
00049     MsgOut <<"Could not get the database iterator."<<endl;
00050     return CdbToolsStatus::Invalid;
00051   }
00052   while( dItr.next( )) {
00053     if(std::string(dItr.value( )) == dbase){
00054       context()->setCurrDB( dbase );
00055 
00056     MsgOut << "Setting current database to: " 
00057            << dItr.value( )  << endl;
00058     return CdbToolsStatus::Success;
00059     }
00060   }
00061   MsgOut << "Could not set current database to: \""
00062          <<dbase <<"\"  Database name might not be valid" << endl;
00063   //if wee haven't returned yet, must be an Invalid database
00064   return status;
00065 }
00066 CdbToolsStatus::CdbCmdStatus 
00067 CdbToolsSetCmd::setView(std::string view)
00068 {
00069   CdbToolsStatus::CdbCmdStatus status = CdbToolsStatus::Invalid;
00070   //Get a pointer to the database
00071 
00072   CdbDatabasePtr dbPtr;
00073   std::string dbname = context()->currentDB();
00074   CdbStatus stat = CdbDatabase::instance(dbPtr, dbname.c_str());
00075 
00076   if(stat != CdbStatus::Success){
00077     MsgOut<<"Faild to find and open the database \"" << dbname
00078           << "\" due to: " << stat << endl;
00079     return CdbToolsStatus::Invalid;
00080   }
00081   CdbViewItr vItr;
00082   if(CdbStatus::Success != dbPtr->viewIterator( vItr )){
00083     MsgOut<<"Could not get a view iterator " << endl;
00084     return CdbToolsStatus::Invalid;
00085   }
00086   
00087   while( vItr.next( ) ) {
00088     if(std::string(vItr.value( ) ) == view){
00089    MsgOut << "Setting current view to : " 
00090           << vItr.value( ) << endl;
00091    context()->setCurrView( view );
00092    return CdbToolsStatus::Success;
00093     }
00094   }
00095 
00096 
00097   MsgOut << "Could not set current view to: \""
00098          <<view <<"\"  View name might not be valid" << endl;
00099   //if wee haven't returned yet, must be an Invalid database
00100   return status;
00101 }
00102   
00103 CdbToolsStatus::CdbCmdStatus
00104 CdbToolsSetCmd::doExecute()
00105 {
00106   CdbToolsStatus::CdbCmdStatus status = CdbToolsStatus::Success;
00107   if(argc() == 1){
00108     MsgOut <<"set what? see 'help set' " << endl;
00109     return CdbToolsStatus::Invalid;
00110   }
00111 
00112   for(int j=1; j<argc(); j++){
00113 
00114     if(argv(j) == "-tech" ||
00115        argv(j) == "-technology"){
00116       if(argv(j+1) == ""){
00117         MsgOut <<"Please provide a name for technoloy"<<endl;
00118         return CdbToolsStatus::Invalid;
00119       }
00120       status =  setTechnology( argv(j+1) );
00121       j++;
00122     }else if(argv(j) == "-impl" ||
00123              argv(j) == "-implementation"){
00124       if(argv(j+1) == ""){
00125         MsgOut <<"Please provide a name for implementation"<<endl;
00126         return CdbToolsStatus::Invalid;
00127       }
00128       status = setImplementation( argv(j+1) );
00129       j++;
00130     }else if(argv(j) == "-db" ||
00131              argv(j) == "-database"){
00132       if(argv(j+1) == ""){
00133         MsgOut <<"Please provide a name for database"<<endl;
00134         return CdbToolsStatus::Invalid;
00135       }
00136       status = setDatabase( argv(j+1) );
00137       j++;
00138       
00139     }else if(argv(j) == "-view" ){
00140       if(argv(j+1) == ""){
00141         MsgOut <<"Please provide a name for view"<<endl;
00142         return CdbToolsStatus::Invalid;
00143       }
00144       status = setView( argv(j+1) );
00145       j++;
00146     }else{
00147       MsgOut<<"Invalid command parameter: \""<<argv(j)<<"\""<<endl;
00148       return CdbToolsStatus::Invalid;
00149     }
00150   }
00151   
00152   
00153   return status;
00154 }
00155 void
00156 CdbToolsSetCmd::help()
00157 {
00158   MsgOut << "Set command.\n"
00159          <<"set -tech[nology]  tech_name       sets current tecnology to tech_name\n"
00160          <<"set -impl[ementation] impl_name    sets current implementation to impl_name\n"
00161          <<"set -db or -database db_name       sets current dabase to db_name\n"
00162          <<"set -view view_name                sets current view to view_name\n"   
00163          << endl;
00164 }
00165 
00166 
00167 
00168 

 


BaBar Public Site | SLAC | News | Links | Who's Who | Contact Us

Page Owner: Jacek Becla
Last Update: October 04, 2002