00001
00007
00009 #include <iostream>
00010 #include <vector>
00011 #include <string>
00012
00013
00014 extern "C" {
00015 #include <unistd.h>
00016 #include <sys/wait.h>
00017 #include <sys/types.h>
00018 #include <signal.h>
00019 };
00020
00021
00022 #include "ipc/core.h"
00023 #include <ipc/partition.h>
00024 #include "cdi/cdiHandle.h"
00025
00026
00027 #include "rc/Conditions.h"
00028 #include "rc/RunParams.h"
00029
00030
00031
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
00045
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
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
00076
00077
00078
00079
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
00097
00098 if (argc < 3 || argc > 7){
00099 printUsage();
00100 }
00101 else{
00102
00103 for (int i=1; i< argc; i+=2){
00104 std::string arg(argv[i]);
00105
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
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
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
00158
00159
00160 if (!validEnvironment(msg)){
00161 std::cerr << "::main : The environmanet check failed:-> " << msg << std::endl;
00162 exit(1);
00163 }
00164
00165
00166 parseArgs(argc,argv,release,obj,partition);
00167
00168
00169
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
00178
00179
00180 cool::DatabaseId dbId = getenv("TDAQ_COOL_PROFILE");
00181
00182
00183
00184
00185
00186
00187
00188
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
00205
00206
00207
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
00225
00226
00230
00231 std::cout << "::main : Checking the data of the last 5 minutes" << std::endl;
00232
00233
00234
00235
00236 cool::ChannelId channelId = 1;
00237
00238
00239
00240
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
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
00260
00261
00262 pool::AttributeListSpecification payloadSpec = folder->payloadSpecification();
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
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";
00282
00283
00284
00285
00286
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
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
00323 return status;
00324 }