cdi_ls_cool.cxx

00001 
00007 
00009 #include <iostream>
00010 #include <vector>
00011 #include <string>
00012 
00013 // Other standard C includes
00014 extern "C" {
00015 #include <unistd.h>
00016 #include <sys/wait.h>
00017 #include <sys/types.h>
00018 #include <signal.h>
00019 };
00020 
00021 // some cclasses needed to store data
00022 #include "ipc/core.h"
00023 #include <ipc/partition.h>
00024 #include "cdi/cdiHandle.h"
00025 
00026 // The objects to be stored
00027 #include "rc/Conditions.h"
00028 #include "rc/RunParams.h"
00029 
00030 // COOL includes
00031 // This application goes directly into COOL
00032 #include <sstream>
00033 #include <string>
00034 #include "AttributeList/AttributeList.h"
00035 #include "CoolApplication/DatabaseSvcFactory.h"
00036 #include "CoolKernel/DatabaseId.h"
00037 #include "CoolKernel/IDatabase.h"
00038 #include "CoolKernel/IDatabaseSvc.h"
00039 #include "CoolKernel/IFolder.h"
00040 #include "CoolKernel/IObject.h"
00041 #include "CoolKernel/IObjectIterator.h"
00042 #include "SealKernel/Exception.h"
00043 #include "SealBase/TimeInfo.h"
00044 //#include "src/timeToString.h"
00045 //#include "src/uppercaseString.h"
00046 
00047 
00051 bool validEnvironment(std::string &msg ){
00052   
00053   msg = "The environment variable ";
00054 
00055   char* st = getenv("SEAL_KEEP_MODULES");
00056   if (st == NULL){
00057     msg = " \'SEAL_KEEP_MODULES\' is not set!";
00058     return false;
00059   }
00060   
00061   st = getenv("SEAL_PLUGINS");
00062   if (st == NULL){
00063     msg = " \'SEAL_PLUGINS\' is not set!";
00064     return false;
00065   }
00066 
00067   //  if (option == 1) {
00068     st = getenv("TDAQ_COOL_PROFILE");
00069     if (st == NULL){
00070       msg = " \'TDAQ_COOL_PROFILE\' is not set!";
00071       return false;
00072     }
00073     /*
00074   }
00075   else{
00076     st = getenv("TDAQ_COND_DB_PROFILE");
00077     if (st == NULL){
00078       msg = " \'TDAQ_COND_DB_PROFILE\' is not set!";
00079       return false;
00080     }
00081   }
00082     */
00083     return true;
00084 }
00085 
00086 void printUsage(){
00087   std::cout << "Usage: cdi_ls_cool -p partition [-r release] [-s ISServer.IsObject]" 
00088         << std::endl << std::endl;
00089   std::cout << "       By default it connects to release \'nightly\' and object \'RunParams.RunParams\'" 
00090         << std::endl;
00091 
00092   exit(EXIT_SUCCESS);
00093 }
00094 
00095 void parseArgs(int &argc,char**&argv,std::string &release,std::string &obj,std::string &partition){
00096   // let's parse the arguments
00097   // at least 3 arguments must be given...and we should not have more than 7
00098   if (argc < 3 || argc > 7){
00099     printUsage();
00100   }
00101   else{
00102     // just the odd indexes have the parameters choosen
00103     for (int i=1; i< argc; i+=2){
00104       std::string arg(argv[i]);
00105       // The user can ask for help
00106       if (arg == "-h" || arg == "--help"){
00107     printUsage();
00108       }
00109       
00110       if (arg != "-p" && arg != "-r" && arg != "-s" && arg != "--partition" && arg != "--release" && arg != "--object"){
00111     std::cerr << "Bad option \'" << arg << "\'" << std::endl;
00112     printUsage();
00113       }
00114       else{
00115     if (arg == "-p" || arg == "--partition"){
00116       // defining the partition
00117       std::cout << "::parseArgs : Using partition [" << argv[i+1] << "]" << std::endl;
00118       partition = argv[i+1];
00119     }
00120     else{
00121       if (arg == "-r" || arg == "--release"){
00122         std::cout << "::parseArgs : Using release [" << argv[i+1] << "]" << std::endl;
00123         release = argv[i+1];
00124       }
00125       else{
00126         if (arg == "-s" || arg == "--object"){
00127           std::cout << "::parseArgs : Checking object [" <<  argv[i+1] << "]" << std::endl;
00128           obj = argv[i+1];
00129         }
00130         else {
00131           std::cerr << "::parseArgs : There was a problemparsing the arguments" << std::endl;
00132         }
00133       }
00134     }
00135       }
00136     }
00137     
00138     // if, after parsing, the partition is still undefined, we need to get out
00139     if (!(partition.length())){
00140       std::cerr << "::main:ERROR : partition not defined." << std::endl;
00141       exit(EXIT_FAILURE);
00142     }
00143     
00144   }
00145   
00146 }
00147 
00148 int main(int argc, char ** argv){
00149   
00150   int status = EXIT_SUCCESS;
00151   
00152   std::string msg;
00153   std::string folder;
00154   std::string release = "nightly", obj = "RunParams.RunParams", partition = "";
00155 
00156 
00157   // the ffirst thing to do is to check the number of arguments and the environment
00158 
00159   // let's check the environment
00160   if (!validEnvironment(msg)){
00161     std::cerr << "::main : The environmanet check failed:-> " << msg << std::endl;
00162     exit(1);
00163   }
00164  
00165   // let's parse the arguments given
00166   parseArgs(argc,argv,release,obj,partition);
00167   
00168   // From now n let's start the real work.
00169   // we are going to use the TDAQ_COOL_PROFILE env to knwo where to connect
00170   
00171   try {
00172     
00173     std::cout << "::main : Get a handle to the COOL database service" << std::endl;
00174     cool::IDatabaseSvc& dbSvc = cool::DatabaseSvcFactory::databaseService();
00175     
00176     //------------------------
00177     // DEFINE THE DATABASE ID
00178     //------------------------
00179 
00180     cool::DatabaseId dbId = getenv("TDAQ_COOL_PROFILE");
00181     
00182     //---------------------------
00183     // OPEN AN EXISTING DATABASE
00184     //---------------------------
00185 
00186     // Open an existing COOL conditions database
00187     // Since this is a reading tool, for sure that 
00188     // the database will exist
00189     std::cout << "::main : " << "Open an existing conditions database: " << dbId << std::endl;
00190     cool::IDatabasePtr db = dbSvc.openDatabase( dbId );
00191     std::cout << "::main : " << "Conditions database opened: " << std::endl;
00192 
00203     //----------------------------
00204     // GENERATING THE FOLDER NAME
00205     //----------------------------
00206 
00207     // let's build the folder name
00208     std::string folderName = "/TDAQ/" + partition + "/" + obj + "-" + release;
00209     std::cout << "::main : Checking folder [" << folderName << "]" << std::endl;
00210     
00211     cool::IFolderPtr folder = db->getFolder( folderName );
00212     
00223     //------------------
00224     // OBJECT RETRIEVAL
00225     //------------------
00226 
00230     // Bulk-retrieve the objects stored in channel 1 of folder in the last 5 min [now() - 5,now()]
00231     std::cout << "::main : Checking the data of the last 5 minutes" << std::endl;
00232 
00233     // Why a tag? In online mode we don't use tags
00234     //    std::string tag = "";
00235     
00236     cool::ChannelId channelId = 1;
00237     // the time is stored as the number of nanoseconds 
00238     // since the 1/1/1970
00239     // the function time returns the number of seconds
00240     // then I need to multiply that value by 10^9
00241     cool::ValidityKey until =(cool::ValidityKey)( time(NULL));
00242     until *= 1000000000;  
00243     cool::ValidityKey since = until;
00244     since -= 300000000000;
00245 
00246     std::cout << "::main : Browsing data for intervals [" << since 
00247           << "|" << until << "]" << std::endl;
00248     
00249     // Let's go for the object browsing
00250     cool::IObjectIteratorPtr objIt = folder->browseObjects( since, until, channelId, "" );
00251 
00252     std::cout << "::main : " << "Retrieved object iterator for folder "
00253           << folder->fullPath() << std::endl;
00254     
00255     if ( objIt->isEmpty() ) {
00256       std::cout << "::main : " << "Iterator contains no objects" << std::endl;
00257     } else {
00258 
00259       // let's print the data as a table
00260       // we don't know the object structure right now...so let's get the AttributeListSpecification
00261       // which has all the information needed
00262       pool::AttributeListSpecification payloadSpec = folder->payloadSpecification();
00263       
00264       /*
00265       //let's print the names and types of the data in the object
00266       std::cout << "[\'channelId\'\t][\'SINCE\'\t][\'UNTIL\'\t]";
00267       for (size_t i = 0; i< payloadSpec.size(); i++){
00268       std::string name = payloadSpec[i].name();
00269       std::cout << "[\'" << name << "\'\t]";
00270       }
00271       std::cout << std::endl;
00272       */
00273       
00274       // Let's now print the data
00275       // Let's go for the beggining of the iterator
00276       objIt->goToStart();
00277       while( objIt->hasNext() ) {
00278         cool::IObjectPtr object = objIt->next();
00279         std::cout << "[\'channelID\'] = [" << object->channelId() << "]\n"
00280           << "[  \'SINCE\'  ] = [" << object->since() << "]\n"
00281           << "[  \'UNTIL\'  ] = ["<< object->until() << "]\n"; //<< std::endl;
00282       
00283     //  std::cout << "::main : " << "Object: payload values : " << std::endl;
00284     
00285     // Since we don't know the structure of the object stored let's
00286     // use the payloadSpec to see it
00287     for (size_t i = 0; i< payloadSpec.size(); i++){
00288       std::string name = payloadSpec[i].name();
00289       std::cout << "[\'" << name << "\'] = [" << object->payloadValue(name)  << "]" << std::endl;
00290       //      std::cout << "[" << object->payloadValue(name)  << "\t]";
00291     }
00292     std::cout << std::endl;
00293     
00294         if( ! object->isStored() ) {
00295           std::cout << " ::main : " << "Object: isStored=false" << std::endl;
00296         } else {
00297           std::cout << " ::main : " << "Object: isStored=true, insertionTime=" 
00298             << object->insertionTime()  << std::endl;
00299         }
00300       } 
00301     }
00302     
00303 
00304   }
00305 
00306   catch(seal::Exception& se) 
00307     {
00308       std::cerr << "::main : ERROR! Seal Exception: '" << se << "'" << std::endl;
00309       status =  EXIT_FAILURE;
00310     }
00311   catch(std::exception& e)
00312     {
00313       std::cerr << "::main : ERROR! Standard C++ exception: '" << e.what() << "'" << std::endl;
00314       status = EXIT_FAILURE;
00315     }
00316   catch(...) 
00317     {
00318       std::cerr << "::main : ERROR! Unknown exception caught" << std::endl;
00319       status = EXIT_FAILURE;
00320     }
00321   
00322   // if everything went ok up to now. It is safe to exit with status
00323   return status;
00324 }

Generated on Mon Feb 6 14:01:17 2006 for SCT DAQ/DCS Software - C++ by  doxygen 1.4.6