00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include <sstream>
00013 #include <algorithm>
00014 #include <cstdlib>
00015 #include <exception>
00016
00017
00018 #include "cdi/cdiCOOLDataHandle.h"
00019 #include "cdi/cdiAux.h"
00020
00021 #include <iostream>
00022 #include <unistd.h>
00023
00024
00025 #include <is/info.h>
00026 #include <is/infoany.h>
00027 #include <rc/Conditions.h>
00028 #include <is/serveriterator.h>
00029 #include <is/infoiterator.h>
00030
00031
00032
00033 #include <boost/regex.hpp>
00034
00035
00036
00037
00038 #include "AttributeList/AttributeList.h"
00039 #include "CoolKernel/IDatabase.h"
00040 #include "CoolKernel/IDatabaseSvc.h"
00041
00042 #include "SealKernel/Exception.h"
00043 #include "SealBase/TimeInfo.h"
00044 #include "CoolKernel/ValidityKey.h"
00045 #include "CoolApplication/DatabaseSvcFactory.h"
00046
00047
00048
00049 #include "POOLCore/POOLContext.h"
00050
00051
00052
00053
00054
00055 void cdiCOOLDataHandle::loadSEALModules(){
00056
00057 pool::POOLContext::loadComponent( "POOL/Services/XMLAuthenticationService" );
00058
00059
00060
00061 pool::POOLContext::loadComponent( "POOL/RelationalPlugins/oracle" );
00062 pool::POOLContext::loadComponent( "POOL/RelationalPlugins/sqlite" );
00063 pool::POOLContext::loadComponent( "POOL/RelationalPlugins/mysql/odbc" );
00064
00065 }
00066
00067
00068
00069 template <class T>
00070 void cdiCOOLDataHandle::convert( ISInfoAny & isa, std::vector<std::string> & to )
00071 {
00072 if ( isa.isAttributeArray() )
00073 {
00074 mout.warning("Trying to store an array...doing nothing...");
00075
00076 std::vector<T> val;
00077 isa >> val;
00078 for ( size_t i = 0; i < val.size() ; i++ )
00079 {
00080 std::ostringstream out;
00081 out << val[i];
00082 to.push_back( out.str() );
00083 }
00084 }
00085 else
00086 {
00087 T val;
00088 isa >> val;
00089 std::ostringstream out;
00090 out << val;
00091 to.push_back( out.str() );
00092 }
00093 }
00094
00099
00100
00101 void cdiCOOLDataHandle::convertTime (ISInfoAny & isAny, seal::IntBits<64>::ULeast &time) {
00102 OWLTime pTime;
00103 isAny >> pTime;
00104 std::string test;
00105 test = pTime.c_str();
00106 mout.verbose("The time given is " + test);
00107
00108
00109
00110 time = pTime.c_time();
00111 time *= 1000000000;
00112 std::ostringstream msg;
00113 msg << "cdiCOOLDataHandle::convertTime> Time resulted: [" << time << "]";
00114 mout.verbose(msg.str());
00115 }
00116
00117
00122 bool cdiCOOLDataHandle::existDB(std::string dbProfile)
00123 {
00124 try {
00125 cool::IDatabasePtr db = m_dbSvc->openDatabase(dbProfile);
00126 cool::IDatabasePtr dbNull;
00127 m_db = dbNull;
00128
00129 return true;
00130 }
00131 catch(seal::Exception &e) {
00132 cool::IDatabasePtr dbNull;
00133 m_db = dbNull;
00134
00135 return false;
00136 }
00137 }
00138
00144 void cdiCOOLDataHandle::getConfig( std::vector<std::string> & names )
00145 {
00146
00147
00148 ISInfoDictionary dictionary(partition);
00149
00150
00151
00152 Conditions conditions;
00153 ISInfo::Status status = dictionary.findValue( configuration_name.c_str(), conditions );
00154
00155 mout.debug( std::string("cdiCOOLDataHandle::getConfig: Getting Informations to subscribe"));
00156
00157 names.clear();
00158
00159 if ( status == ISInfo::Success)
00160 names = conditions.isservers;
00161
00162
00163 if ( std::find( names.begin(), names.end(), std::string( "RunParams.RunParams" )) == names.end() ) {
00164 mout.verbose( std::string("cdiDataHandle::getConfig> Adding [RunParams.RunParams] to names"));
00165 names.push_back( "RunParams.RunParams" );
00166 }
00167
00168
00169
00170 if ( std::find( names.begin(), names.end(), configuration_name ) == names.end() ) {
00171 mout.verbose( std::string("cdiDataHandle::getConfig> Adding [" + configuration_name+ "] to names"));
00172 names.push_back( configuration_name );
00173 }
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 std::vector<std::string>::const_iterator itEnd = names.end();
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 std::string objName;
00197
00198
00199
00200 ISServerIterator ISit(partition);
00201 while( ISit() ){
00202 objName = ISit.name();
00203 mout.verbose(std::string("Checking the server [" + objName + "]"));
00204
00205 ISInfoIterator ii(partition,ISit.name());
00206 while( ii() ){
00207
00208 objName = ii.name();
00209 mout.verbose(std::string("getConfig -> Starting to check object [" + objName + "]"));
00210
00211 for ( std::vector<std::string>::const_iterator it = names.begin(); it != itEnd; ++it){
00212 boost::regex expression((*it).c_str());
00213 boost::cmatch what;
00214
00215
00216 if (boost::regex_match(objName.c_str(),expression)){
00217 mout.verbose(std::string("getConfig -> [" + objName + "] matches the expression [" + (*it) + "]"));
00218
00219 if ( std::find( m_objs.begin(), m_objs.end(), objName ) == m_objs.end() ) {
00220 mout.verbose( std::string("cdiDataHandle::getConfig> Adding [" + objName + "] to list"));
00221 m_objs.push_back( objName );
00222
00223
00224 ISInfoAny isa;
00225 ii.value(isa);
00226 storeObject(objName, isa);
00227 }
00228 else {
00229 mout.verbose( std::string("cdiDataHandle::getConfig> Object [" + objName + "] already added to the list"));
00230 }
00231 }
00232 else {
00233 mout.verbose(std::string("getConfig -> [" + objName + "] does not match the expression [" + (*it) + "]"));
00234 }
00235
00236 }
00237 }
00238 }
00239 mout.debug( std::string("cdiDataHandle::getConfig> Returning without problems"));
00240 }
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00277 std::string cdiCOOLDataHandle::getProfile()
00278 {
00279
00280 std::string preffix = "Environment variable ";
00281 preffix += char(27);
00282 preffix += "[1m";
00283 std::string suffix = "";
00284 suffix += char(27);
00285 suffix += "[0m";
00286
00287
00288
00289 char * tmp2 = getenv( "SEAL_PLUGINS" );
00290
00291 if ( tmp2 == 0 )
00292 {
00293 mout.error(std::string(preffix + "\'SEAL_PLUGINS\'" + suffix + " must be defined to point to the plugins folders!"));
00294 mout.info( "CDI will exit now." );
00295 ISInfo::Status status = ISInfo::NotFound;
00296 std::string msg = cdiCOOLDataHandle::dumpFailure( status );
00297 mout.error(msg);
00298 exit(1);
00299 }
00300
00301 tmp2 = getenv( "SEAL_KEEP_MODULES" );
00302
00303 if ( tmp2 == 0 )
00304 {
00305
00306 mout.error(std::string(preffix + "\'SEAL_KEEP_MODULES\'" + suffix + " must be defined to \"true\""));
00307
00308
00309
00310
00311
00312 if (setenv("SEAL_KEEP_MODULES","true",1) != 0){
00313 mout.error(std::string(preffix + "\'SEAL_KEEP_MODULES\'" + suffix + " was not possible to be set up automatically!"));
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323 }
00324 if (getenv( "SEAL_KEEP_MODULES" ) == 0){
00325 mout.error(std::string(preffix + "\'SEAL_KEEP_MODULES\'" + suffix + " is still not in the environment!"));
00326
00327 exit(1);
00328 }
00329 }
00330 else {
00331 if (tmp2 != "true"){
00332 mout.verbose(std::string("SEAL_KEEP_MODULES="+ std::string(tmp2)));
00333 }
00334 }
00335
00336
00337
00338 char *tmp = getenv( "TDAQ_COOL_PROFILE" );
00339
00340 if ( tmp == 0 ) {
00341 mout.error(std::string(preffix + "\'TDAQ_COOL_PROFILE\'" + suffix + " is not defined with the DB connection string"));
00342 mout.info( "CDI will exit now." );
00343 exit(1);
00344 }
00345
00346 return std::string(tmp);
00347 }
00348
00352 void cdiCOOLDataHandle::get_folder_specs(std::string fname,pool::AttributeListSpecification &payloadSpec) {
00353
00375 try
00376 {
00377 mout.debug(std::string("Getting specification for folder [" + fname + "]"),3);
00378
00379 if ( m_db->existsFolder( fname )) {
00380
00381
00382 m_fld = m_db->getFolder( fname );
00383
00384
00385 payloadSpec = m_fld->payloadSpecification();
00386
00387
00388 #ifdef DEBUG
00389 std::ostringstream AttrSpec;
00390 payloadSpec.print(AttrSpec);
00391 mout.verbose(std::string("<cdiCOOLDataHandle::get_folder_specs> Describing AttributeList:" + AttrSpec.str()));
00392 AttrSpec.~ostringstream();
00393 #endif
00394
00395 mout.debug(std::string("<cdiCOOLDataHandle::get_folder_specs> Folder Attribute List Specification read from the database!"));
00396 return;
00397 }
00398 else {
00399 mout.error(std::string("<cdiCOOLDataHandle::get_folder_specs> Folder does not exist in the database... "));
00400 exit(1);
00401 }
00402 }
00403 catch (seal::Exception &e)
00404 {
00405 std::cerr << "SEAL exception caught [" << e.code() << "] : " << e.message() << std::endl;
00406 exit( 1 );
00407 }
00408 }
00409
00410
00411
00417 void cdiCOOLDataHandle::fillTypes()
00418 {
00419
00420
00421
00422 m_dTypes.insert( std::make_pair( ISType::Boolean,"bool" ) );
00423 m_dTypes.insert( std::make_pair( ISType::S16, "short" ) );
00424 m_dTypes.insert( std::make_pair( ISType::U16, "unsigned short") );
00425 m_dTypes.insert( std::make_pair( ISType::S32, "long" ) );
00426 m_dTypes.insert( std::make_pair( ISType::U32, "unsigned long" ) );
00427 m_dTypes.insert( std::make_pair( ISType::Float, "float" ) );
00428 m_dTypes.insert( std::make_pair( ISType::Double,"double" ) );
00429 m_dTypes.insert( std::make_pair( ISType::S8, "short" ) );
00430 m_dTypes.insert( std::make_pair( ISType::U8, "unsigned short" ) );
00431 m_dTypes.insert( std::make_pair( ISType::String, "string" ) );
00432
00433 m_dTypes.insert( std::make_pair( ISType::Date, "unsigned long long" ) );
00434 m_dTypes.insert( std::make_pair( ISType::Time, "unsigned long long" ) );
00435
00436 }
00437
00438
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00469
00470 cdiCOOLDataHandle::cdiCOOLDataHandle( int verbosity, const IPCPartition & p, const std::string confName)
00471 : mout( verbosity ),
00472 partition( p ),
00473 configuration_name(confName)
00474 {
00475 mout.info(std::string("Initializing CDI Data Handle.."), 3);
00476
00477 cdiCOOLDataHandle::fillTypes();
00478 cdiCOOLDataHandle::loadSEALModules();
00479
00480 try {
00481 init( getProfile() );
00482 }
00483 catch (seal::Exception &e) {
00484 std::cerr << "SEAL exception caught [" << e.code() << "] : " << e.message() << std::endl;
00485 exit( 1 );
00486 }
00487 }
00488
00495 void cdiCOOLDataHandle::init( const std::string & profile )
00496 {
00497 try {
00498 mout.debug(std::string("Initializing COOL....."));
00499
00500 mout.verbose(std::string("COOL PROFILE ->[" + profile + "]"));
00501
00512 m_dbSvc = &(cool::DatabaseSvcFactory::databaseService());
00513
00514
00515
00516
00517
00518
00519 m_dbId = profile;
00520 mout.verbose(std::string("Checking again in profile to verify if the database exists"));
00521
00522 std::string out = "Checking if the COOL DB exists...";
00523
00524 if (cdiCOOLDataHandle::existDB( m_dbId )) {
00525 out += "yes!";
00526 mout.verbose(out);
00527 mout.debug(std::string("Opening the COOL DB"));
00528 m_db = m_dbSvc->openDatabase( m_dbId );
00529 }
00530 else
00531 {
00532 out += "no!";
00533 mout.verbose(out);
00534 mout.debug(std::string("Creating the COOL DB"));
00535
00536
00537
00538
00539
00540 m_db = m_dbSvc->createDatabase( m_dbId );
00541 }
00542 }
00543 catch (seal::Exception &e)
00544 {
00545 std::cerr << "SEAL exception caught [" << e.code() << "] : " << e.message() << std::endl;
00546 exit( 1 );
00547 }
00548 catch (...) {
00549 std::cerr << "Funny exception caught...from where?" << std::endl;
00550 exit ( 1 );
00551 }
00552
00553 }
00554
00559 bool cdiCOOLDataHandle::is_table_exist ( const std::string & name )
00560 {
00561 mout.info(std::string("Entering <cdiCOOLDataHandle::is_table_exist>"), 2);
00562 std::map <std::string, pool::AttributeListSpecification>::iterator it = m_Tables.begin();
00563 for( ; it != m_Tables.end(); ++it )
00564 {
00565 if ( it->first == name )
00566 return true;
00567 }
00568 return false;
00569 }
00570
00574 void cdiCOOLDataHandle::add_table ( pool::AttributeListSpecification &attSpec, const std::string & name )
00575 {
00576 mout.debug(std::string("Entering <cdiCOOLDataHandle::add_table>"));
00577
00578 #ifdef DEBUG
00579 std::ostringstream debug;
00580
00581
00582 mout.verbose("Printing the AttributeListSpec to be added");
00583 attSpec.print(debug);
00584 mout.verbose(debug.str());
00585 debug.~ostringstream();
00586 #endif
00587
00588 m_Tables.insert( std::make_pair( name, attSpec ) );
00589
00590 }
00591
00596 std::string cdiCOOLDataHandle::dumpFailure( ISInfo::Status status )
00597 {
00598 std::string msg;
00599 switch (status) {
00600 case ISInfo::CommFailure:
00601 msg = "Comunication failure [ISInfo::CommFailure]"; break;
00602 case ISInfo::AlreadyExist:
00603 msg = "Information Already Exist [ISInfo::AlreadyExist]"; break;
00604 case ISInfo::NotFound:
00605 msg = "Information Not Found [ISInfo::NotFound]"; break;
00606 case ISInfo::InvalidInfo:
00607 msg = "Invalid Information [ISInfo::InvalidInfo]"; break;
00608 case ISInfo::IncompatibleType:
00609 msg = "Incompatible Information Type [ISInfo::IncompatibleType]"; break;
00610 case ISInfo::InvalidCriteria:
00611 msg = "Invalid Criteria [ISInfo::InvalidCriteria]"; break;
00612 case ISInfo::RepositoryNotFound:
00613 msg = "Information Repository not found [ISInfo::RepositoryNotFound]"; break;
00614 case ISInfo::ProviderNotFound:
00615 msg = "Information Provider not Found [ISInfo::ProviderNotFound]"; break;
00616 case ISInfo::InvalidName:
00617 msg = "Invalid Information Name [ISInfo::InvalidName]"; break;
00618 default:
00619 msg = "Unknown problem with Information"; break;
00620 }
00621
00622 mout.error(msg);
00623 return msg;
00624
00625 }
00626
00632 void cdiCOOLDataHandle::create_folder ( const std::string & name, ISInfoAny & isa )
00633 {
00634 mout.info( std::string( "Entering <cdiCOOLDataHandle::create_folder> " + name ), 2 );
00635
00636
00637
00638 if ( is_table_exist( name ) )
00639 {
00640 mout.debug("Entering <cdiCOOLDataHandle::create_folder> Folder already exist. Ignoring...");
00641 return;
00642 }
00643
00644 mout.debug("Entering <cdiCOOLDataHandle::create_folder> Folder doesn't exist in map.Continuing...");
00645
00646
00647
00648 std::string fname = std::string("/TDAQ/" + partition.name() + "/" + name);
00649
00650
00651 pool::AttributeListSpecification payloadSpec;
00652 pool::AttributeList payload;
00653
00654
00655 mout.debug("<cdiCOOLDataHandle::create_folder> Trying to read Attribute List Specification from the database!");
00656
00657 try
00658 {
00659
00660 if ( m_db->existsFolder( fname )) {
00661
00662
00663 m_fld = m_db->getFolder( fname );
00664
00665
00666
00667 payloadSpec = m_fld->payloadSpecification();
00668
00669 #ifdef DEBUG
00670 std::ostringstream AttrSpec;
00671 payloadSpec.print(AttrSpec);
00672 mout.verbose(std::string("<cdiCOOLDataHandle::create_folder> Describing AttributeList:" + AttrSpec.str()));
00673 AttrSpec.~ostringstream();
00674 #endif
00675
00676
00677
00678
00679 add_table( payloadSpec, name );
00680 mout.debug("<cdiCOOLDataHandle::create_folder> Folder Attribute List Specification read from the database!");
00681 return;
00682 }
00683 else {
00684
00685
00686 mout.debug("<cdiCOOLDataHandle::create_folder> Folder does not exist in the database...continuing to create it!");
00687 }
00688 }
00689 catch (seal::Exception &e)
00690 {
00691 std::cerr << "SEAL exception caught [" << e.code() << "] : " << e.message() << std::endl;
00692 exit(1);
00693 }
00694
00695
00696
00697
00698 mout.debug("<cdiCOOLDataHandle::create_folder> Creating folder [" + fname + "]in the database!");
00699
00700
00701 mout.debug(std::string("<cdiCOOLDataHandle::create_folder> Getting the ISInfoDocument for partition [" + partition.name() + "] !"));
00702 ISInfoDocument isd( partition, isa );
00703
00704
00705 if ( isd.status() == ISInfo::Success )
00706 {
00707 mout.verbose(std::string("<cdiCOOLDataHandle::create_folder> isd.name: [" + isd.name() + "]"));
00708 mout.verbose(std::string("<cdiCOOLDataHandle::create_folder> isd.description: [" + isd.description() + "]"));
00709 }
00710 else
00711 {
00712 mout.verbose(std::string("<cdiCOOLDataHandle::create_folder> IS description for [" + isd.name() + "] is not available" ));
00713 mout.verbose(std::string("Risk of segfault caused by failure to load ISInfoDocument"));
00714 std::string msg = cdiCOOLDataHandle::dumpFailure(isd.status());
00715 }
00716
00717 std::ostringstream msg;
00718 msg << "ISInfoDocument has [" << isa.countAttributes() << "] attributes which will be dumped...";
00719 mout.verbose(msg.str());
00720 msg.seekp(0);
00721
00722
00723
00724 std::string warnMsg = "WARNING:Trying to store an object containing an array. Arrays are not suported. Ignoring column ";
00725
00726
00727 for ( size_t i = 0; i < isa.countAttributes(); i++ )
00728 {
00729 const ISInfoDocument::Attribute * attr = 0;
00730 if ( isd.status() == ISInfo::Success) {
00731 attr = isd.attribute( i );
00732 }
00733 std::ostringstream colName, wMsg;
00734
00735 colName << "column_" << i;
00736 if (isa.isAttributeArray()) {
00737 wMsg << warnMsg << i;
00738 mout.info(wMsg.str());
00739
00740
00741
00742 }
00743
00744 std::ostringstream msg, msg2;
00745
00746 msg << "Attribute name: [" << attr->name() << "] Attribute type: ["
00747 << m_dTypes[isa.getAttributeType()] << "] <-> [" << isa.getAttributeType()
00748 << "]";
00749 if (isa.isAttributeArray()){
00750 msg << " ARRAY=[YES]";
00751 }
00752 else {
00753 msg << " ARRAY=[NO]";
00754 }
00755 mout.verbose(msg.str());
00756
00757
00758
00759
00760
00761
00762 if (isa.isAttributeArray()){
00763 std::string name;
00764 if (attr) {
00765 name = attr->name() + "$ARRAY$" + m_dTypes[isa.getAttributeType()];
00766 }
00767 else {
00768 name = colName.str() + "$ARRAY$" + m_dTypes[isa.getAttributeType()];
00769 }
00770
00771 payloadSpec.push_back(name,"string");
00772 }
00773 else {
00774 payloadSpec.push_back(attr ? attr->name() : colName.str(),m_dTypes[isa.getAttributeType()]);
00775 }
00776
00777
00778
00779 std::vector<std::string> cell;
00780 seal::IntBits<64>::ULeast cellT;
00781
00782 switch ( isa.getAttributeType() )
00783 {
00784 case ISType::Boolean: { convert<bool>( isa, cell ); break; }
00785 case ISType::S16: { convert<short>( isa, cell ); break; }
00786 case ISType::U16: { convert<unsigned short>( isa, cell ); break; }
00787 case ISType::S32: { convert<long>( isa, cell ); break; }
00788 case ISType::U32: { convert<unsigned long>( isa, cell ); break; }
00789 case ISType::Float: { convert<float>( isa, cell ); break; }
00790 case ISType::Double: { convert<double>( isa, cell ); break; }
00791 case ISType::S8: { convert<char>( isa, cell ); break; }
00792 case ISType::U8: { convert<unsigned char>( isa, cell ); break; }
00793 case ISType::String: { convert<std::string>( isa, cell ); break; }
00794 case ISType::Date: { convertTime( isa, cellT ); break; }
00795 case ISType::Time: { convertTime( isa, cellT ); break; }
00796 case ISType::Error:
00797 default: { mout.error("IS Attribute Error "); break; }
00798 }
00799
00800 }
00801
00802
00803 isa.reset();
00804
00805
00806 try
00807 {
00808
00809 mout.debug(std::string("<cdiCOOLDataHandle::create_folder> Proceeding to folder " + name + " creation... "));
00810
00811 m_fld = m_db->createFolder( fname,
00812 payloadSpec,
00813 "",
00814 cool::FolderVersioning::MULTI_VERSION,
00815
00816 true );
00817
00818 m_fName = fname;
00819 mout.verbose("<cdiCOOLDataHandle::create_folder> Folder created!");
00820
00821
00822 add_table( payloadSpec, name );
00823
00824 }
00825
00826 catch (seal::Exception &e)
00827 {
00828 std::cerr << "SEAL exception caught [" << e.code() << "] : " << e.message() << std::endl;
00829 exit( 1 );
00830 }
00831 }
00832
00833
00839 void cdiCOOLDataHandle::process_data ( const std::string & name, ISCallbackInfo * isc )
00840 {
00841 mout.debug("Entering <cdiCOOLDataHandle::process_data>");
00842
00843 ISInfoAny isa;
00844 isc->value( isa );
00845
00846 storeObject(name,isa);
00847
00848 }
00849
00850 void cdiCOOLDataHandle::storeObject(const std::string & name, ISInfoAny &isa) {
00851
00852
00853 std::string rVersion = RELEASE_NAME;
00854 std::string fSuffix;
00855 std::string::size_type beg = rVersion.find("-");
00856
00857 if (beg != std::string::npos)
00858 fSuffix = rVersion.substr(beg);
00859 else
00860 fSuffix = "-" + rVersion;
00861
00862 std::string foldName = name + fSuffix;
00863
00864
00865 cdiCOOLDataHandle::create_folder ( foldName, isa );
00866
00867
00868 mout.verbose(std::string("<cdiCOOLDataHandle::process_data> Folder [" + foldName + "] create and added to the map!" ));
00869 mout.verbose(std::string("<cdiCOOLDataHandle::process_data> Getting AttributeList corresponding to folder [" + foldName + "]" ));
00870
00871 std::ostringstream debug;
00872 debug << "<cdiCOOLDataHandle::process_data> The map constains [" << m_Tables.size() << "] elements";
00873 mout.verbose(debug.str());
00874 debug.seekp(0);
00875
00876
00877 pool::AttributeListSpecification payloadSpec = m_Tables[foldName];
00878
00879 try {
00880
00881 mout.verbose(std::string("<cdiCOOLDataHandle::process_data> Describing the AttrList Specs"));
00882
00883
00884 #ifdef DEBUG
00885 std::ostringstream AttrSpec;
00886 payloadSpec.print(AttrSpec);
00887 mout.verbose(std::string("<cdiCOOLDataHandle::writeData> Describing AttributeList:"));
00888 mout.verbose(AttrSpec.str());
00889 AttrSpec.seekp(0);
00890 #endif
00891
00892 }
00893 catch(seal::Exception &e){
00894 std::cerr << "SEAL exception caught [" << e.code() << "] : " << e.message() << std::endl;
00895 exit( 1 );
00896 }
00897 catch(...) {
00898 std::cerr << "Unknow exception caught describing the AttrLstSpec in map" << std::endl;
00899 exit( 1 );
00900 }
00901
00902 mout.verbose("<cdiCOOLDataHandle::writeData> Filling AttrList");
00903 pool::AttributeList pList(payloadSpec);
00904
00905
00906
00907 for( size_t n = 0; n < isa.countAttributes(); n++ )
00908 {
00909
00910 try{
00911
00912 switch ( isa.getAttributeType() ){
00913 case ISType::Boolean: {
00914 if (isa.isAttributeArray()) {
00915 mout.warning("The attribute is an array...still under testing");
00916 std::ostringstream msg;
00917 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
00918 << "ARRAY[STRING]" << "]" ;
00919 mout.verbose(msg.str());
00920 std::ostringstream aux;
00921 std::vector<std::string> vec;
00922 convert<bool>(isa,vec);
00923 for (size_t pos = 0; pos < vec.size(); pos ++){
00924 aux << vec[pos];
00925 if (pos != (vec.size()-1)){
00926 aux << ":";
00927 }
00928 }
00929 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
00930
00931 }
00932 else {
00933
00934 std::ostringstream msg;
00935 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
00936 << "bool" << "]" ;
00937 mout.verbose(msg.str());
00938 bool aux;
00939 isa >> aux;
00940 pList[payloadSpec[n].name()].setValue<bool>(aux);
00941 }
00942 break;
00943 }
00944 case ISType::S16: {
00945 if (isa.isAttributeArray()) {
00946 mout.warning("The attribute is an array...still under testing");
00947 std::ostringstream msg;
00948 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
00949 << "ARRAY[STRING]" << "]" ;
00950 mout.verbose(msg.str());
00951 std::ostringstream aux;
00952 std::vector<std::string> vec;
00953 convert<int>(isa,vec);
00954 for (size_t pos = 0; pos < vec.size(); pos ++){
00955 aux << vec[pos];
00956 if (pos != (vec.size()-1)){
00957 aux << ":";
00958 }
00959 }
00960 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
00961
00962 }
00963 else {
00964
00965 std::ostringstream msg;
00966 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
00967 << "int" << "]" ;
00968 mout.verbose(msg.str());
00969
00970 short int aux;
00971 isa >> aux;
00972 pList[payloadSpec[n].name()].setValue<short>(aux);
00973 }
00974 break;
00975 }
00976 case ISType::U16: {
00977 if (isa.isAttributeArray()) {
00978 mout.warning("The attribute is an array...still under testing");
00979 std::ostringstream msg;
00980 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
00981 << "ARRAY[STRING]" << "]" ;
00982 mout.verbose(msg.str());
00983 std::ostringstream aux;
00984 std::vector<std::string> vec;
00985 convert<unsigned int>(isa,vec);
00986 for (size_t pos = 0; pos < vec.size(); pos ++){
00987 aux << vec[pos];
00988 if (pos != (vec.size()-1)){
00989 aux << ":";
00990 }
00991 }
00992 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
00993
00994 }
00995 else {
00996
00997
00998 std::ostringstream msg;
00999 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01000 << "unsigned int" << "]" ;
01001 mout.verbose(msg.str());
01002 unsigned short int aux;
01003 isa >> aux;
01004 pList[payloadSpec[n].name()].setValue<unsigned short>(aux);
01005 }
01006 break;
01007 }
01008 case ISType::S32: {
01009 if (isa.isAttributeArray()) {
01010 mout.warning("The attribute is an array...still under testing");
01011 std::ostringstream msg;
01012 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01013 << "ARRAY[STRING]" << "]" ;
01014 mout.verbose(msg.str());
01015 std::ostringstream aux;
01016 std::vector<std::string> vec;
01017 convert<long>(isa,vec);
01018 for (size_t pos = 0; pos < vec.size(); pos ++){
01019 aux << vec[pos];
01020 if (pos != (vec.size()-1)){
01021 aux << ":";
01022 }
01023 }
01024 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
01025
01026 }
01027 else {
01028
01029
01030 std::ostringstream msg;
01031 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01032 << "long" << "]" ;
01033 mout.verbose(msg.str());
01034
01035 long aux;
01036 isa >> aux;
01037 pList[payloadSpec[n].name()].setValue<long>(aux);
01038 }
01039 break;
01040 }
01041 case ISType::U32: {
01042 if (isa.isAttributeArray()) {
01043 mout.warning("The attribute is an array...still under testing");
01044 std::ostringstream msg;
01045 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01046 << "ARRAY[STRING]" << "]" ;
01047 mout.verbose(msg.str());
01048 std::ostringstream aux;
01049 std::vector<std::string> vec;
01050 convert<unsigned long>(isa,vec);
01051 for (size_t pos = 0; pos < vec.size(); pos ++){
01052 aux << vec[pos];
01053 if (pos != (vec.size()-1)){
01054 aux << ":";
01055 }
01056 }
01057 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
01058
01059 }
01060 else {
01061
01062
01063 std::ostringstream msg;
01064 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01065 << "unsigned long" << "]--" ;
01066 mout.verbose(msg.str());
01067
01068 unsigned long aux;
01069 isa >> aux;
01070 pList[payloadSpec[n].name()].setValue<unsigned long>(aux);
01071 }
01072 break;
01073 }
01074 case ISType::Float: {
01075 if (isa.isAttributeArray()) {
01076 mout.warning("The attribute is an array...still under testing");
01077 std::ostringstream msg;
01078 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01079 << "ARRAY[STRING]" << "]" ;
01080 mout.verbose(msg.str());
01081 std::ostringstream aux;
01082 std::vector<std::string> vec;
01083 convert<float>(isa,vec);
01084 for (size_t pos = 0; pos < vec.size(); pos ++){
01085 aux << vec[pos];
01086 if (pos != (vec.size()-1)){
01087 aux << ":";
01088 }
01089 }
01090 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
01091
01092 }
01093 else {
01094
01095
01096 std::ostringstream msg;
01097 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01098 << "float" << "]" ;
01099 mout.verbose(msg.str());
01100 float aux;
01101 isa >> aux;
01102 pList[payloadSpec[n].name()].setValue<float>(aux);
01103
01104 }
01105 break;
01106 }
01107 case ISType::Double: {
01108 if (isa.isAttributeArray()) {
01109 mout.warning("The attribute is an array...still under testing");
01110 std::ostringstream msg;
01111 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01112 << "ARRAY[STRING]" << "]" ;
01113 mout.verbose(msg.str());
01114 std::ostringstream aux;
01115 std::vector<std::string> vec;
01116 convert<double>(isa,vec);
01117 for (size_t pos = 0; pos < vec.size(); pos ++){
01118 aux << vec[pos];
01119 if (pos != (vec.size()-1)){
01120 aux << ":";
01121 }
01122 }
01123 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
01124
01125 }
01126 else {
01127
01128
01129 std::ostringstream msg;
01130 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01131 << "double" << "]" ;
01132 mout.verbose(msg.str());
01133 double aux;
01134 isa >> aux;
01135 pList[payloadSpec[n].name()].setValue<double>(aux);
01136 }
01137 break;
01138 }
01139 case ISType::S8: {
01140 if (isa.isAttributeArray()) {
01141 mout.warning("The attribute is an array...still under testing");
01142 std::ostringstream msg;
01143 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01144 << "ARRAY[STRING]" << "]" ;
01145 mout.verbose(msg.str());
01146 std::ostringstream aux;
01147 std::vector<std::string> vec;
01148 convert<short>(isa,vec);
01149 for (size_t pos = 0; pos < vec.size(); pos ++){
01150 aux << vec[pos];
01151 if (pos != (vec.size()-1)){
01152 aux << ":";
01153 }
01154 }
01155 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
01156
01157 }
01158 else {
01159
01160
01161 std::ostringstream msg;
01162 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01163 << "int" << "]" ;
01164 mout.verbose(msg.str());
01165
01166 short int aux;
01167 isa >> aux;
01168 pList[payloadSpec[n].name()].setValue<short>(aux);
01169 }
01170 break;
01171 }
01172 case ISType::U8: {
01173 if (isa.isAttributeArray()) {
01174 mout.warning("The attribute is an array...still under testing");
01175 std::ostringstream msg;
01176 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01177 << "ARRAY[STRING]" << "]" ;
01178 mout.verbose(msg.str());
01179 std::ostringstream aux;
01180 std::vector<std::string> vec;
01181 convert<unsigned short>(isa,vec);
01182 for (size_t pos = 0; pos < vec.size(); pos ++){
01183 aux << vec[pos];
01184 if (pos != (vec.size()-1)){
01185 aux << ":";
01186 }
01187 }
01188 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
01189
01190 }
01191 else {
01192
01193
01194 std::ostringstream msg;
01195 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01196 << "unsigned int" << "]" ;
01197 mout.verbose(msg.str());
01198 unsigned short int aux;
01199 isa >> aux;
01200 pList[payloadSpec[n].name()].setValue<unsigned short int>(aux);
01201 }
01202 break;
01203 }
01204 case ISType::String: {
01205 if (isa.isAttributeArray()) {
01206 mout.warning("The attribute is an array...still under testing");
01207 std::ostringstream msg;
01208 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01209 << "ARRAY[STRING]" << "]" ;
01210 mout.verbose(msg.str());
01211 std::ostringstream aux;
01212 std::vector<std::string> vec;
01213 convert<std::string>(isa,vec);
01214 for (size_t pos = 0; pos < vec.size(); pos ++){
01215 aux << vec[pos];
01216 if (pos != (vec.size()-1)){
01217 aux << ":";
01218 }
01219 }
01220 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
01221
01222 }
01223 else {
01224
01225
01226 std::ostringstream msg;
01227 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01228 << "string" << "]" ;
01229 mout.verbose(msg.str());
01230 std::string aux;
01231 isa >> aux;
01232 pList[payloadSpec[n].name()].setValue<std::string>(aux);
01233 }
01234 break;
01235 }
01236
01237 case ISType::Date: {
01238 if (isa.isAttributeArray()) {
01239 mout.warning("The attribute is an array...still under testing");
01240 std::ostringstream msg;
01241 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01242 << "ARRAY[STRING]" << "]" ;
01243 mout.verbose(msg.str());
01244
01245 std::ostringstream aux;
01246 seal::IntBits<64>::ULeast time;
01247
01248
01249
01250 std::vector<OWLTime> pTime;
01251 isa >> pTime;
01252
01253 for (size_t p = 0; p < pTime.size(); p++){
01254 time = pTime[p].c_time();
01255 time *= 1000000000;
01256 aux << time;
01257 if (p != (pTime.size()-1)){
01258 aux << ":";
01259 }
01260 }
01261 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
01262
01263 }
01264 else {
01265
01266
01267 std::ostringstream msg;
01268 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01269 << "Date" << "]" ;
01270 mout.verbose(msg.str());
01271
01272 seal::IntBits<64>::ULeast aux;
01273 cdiCOOLDataHandle::convertTime( isa, aux );
01274 pList[payloadSpec[n].name()].setValue<seal::IntBits<64>::ULeast>(aux);
01275 }
01276 break;
01277 }
01278 case ISType::Time: {
01279 if (isa.isAttributeArray()) {
01280 mout.warning("The attribute is an array...still under testing");
01281 std::ostringstream msg;
01282 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01283 << "ARRAY[STRING]" << "]" ;
01284 mout.verbose(msg.str());
01285
01286 std::ostringstream aux;
01287 seal::IntBits<64>::ULeast time;
01288
01289
01290
01291 std::vector<OWLTime> pTime;
01292 isa >> pTime;
01293
01294 for (size_t p = 0; p < pTime.size(); p++){
01295 time = pTime[p].c_time();
01296 time *= 1000000000;
01297 aux << time;
01298 if (p != (pTime.size()-1)){
01299 aux << ":";
01300 }
01301 }
01302 pList[payloadSpec[n].name()].setValue<std::string>(aux.str());
01303
01304 }
01305 else {
01306
01307
01308 std::ostringstream msg;
01309 msg << "Parameter [" << n << "]: [" << payloadSpec[n].type_name() << "]<->["
01310 << "Time" << "]" ;
01311 mout.verbose(msg.str());
01312
01313 seal::IntBits<64>::ULeast aux;
01314 cdiCOOLDataHandle::convertTime( isa, aux );
01315 pList[payloadSpec[n].name()].setValue<seal::IntBits<64>::ULeast>(aux);
01316 }
01317 break;
01318 }
01319 case ISType::Error:
01320 default: {
01321 mout.error("IS Attribute Error " );
01322 break;
01323 }
01324 }
01325 }
01326 catch(seal::Exception &e){
01327 std::cerr << "SEAL exception caught [" << e.code() << "] : " << e.message() << std::endl;
01328 exit( 1 );
01329 }
01330 catch(std::exception &e){
01331 std::cerr << "Standard exception caught[" << e.what() << "]" << std::endl;
01332 exit(1);
01333 }
01334 catch(...) {
01335 std::cerr << "Unknow exception caught. proceeding data from ISInfoAny to AttributeList" << std::endl;
01336 exit (1);
01337 }
01338 }
01339
01340
01341
01342
01343
01344
01345
01346
01347
01348 OWLTime t = isa.time();
01349
01350
01351 #ifdef DEBUG
01352 std::ostringstream msg, msg2;
01353 cool::ValidityKey since = t.c_time();
01354 msg << "[SINCE] = [" << since << "] [TILL] = [" << cool::ValidityKeyMax << "]" << std::endl;
01355 mout.verbose( msg.str());
01356 since = since * 1000000000;
01357 msg2 << "After transformation to nanoseconds : [SINCE] = [" << since << "] [TILL] = [" << cool::ValidityKeyMax << "]" << std::endl;
01358 mout.verbose( msg2.str());
01359 #else
01360 cool::ValidityKey since = t.c_time();
01361
01362 since = since * 1000000000;
01363 #endif
01364 cool::ValidityKey till = cool::ValidityKeyMax;
01365
01366
01367
01368 mout.info("<cdiCOOLDataHandle::process_data> Proceeding to data storage ...", 0);
01369
01370
01371
01372 std::string folder( "/TDAQ/" + partition.name() + "/" + foldName);
01373 m_fld = m_db->getFolder( folder );
01374
01375 try {
01376 mout.debug(std::string("Storing object in [" + folder + "]"));
01377 std::ostringstream msg;
01378 msg << "Object IOV : [" << since << "|" << till << "]";
01379 mout.verbose(msg.str());
01380
01381 #ifdef DEBUG
01382 mout.verbose("Dumping the AttrList that will be stored");
01383 std::ostringstream attstr;
01384 pList.print(attstr);
01385 mout.verbose(attstr.str());
01386 #endif
01387
01388 mout.verbose("Going to store the AttributeList");
01389
01390 m_fld->storeObject( since, till, pList, 1);
01391 mout.verbose("Storing done");
01392 }
01393 catch(seal::Exception &e){
01394 std::cerr << "SEAL exception caught [" << e.code() << "] : " << e.message() << std::endl;
01395 exit( 1 );
01396 }
01397 catch(...) {
01398 std::cerr << "Unknow exception caught procedding data from ISInfoAny to AttributeList" << std::endl;
01399 exit( 1 );
01400 }
01401 mout.info("<cdiCOOLDataHandle::writeData> Object stored successfully",0);
01402 }