int cond::CreateKeyUtilities::execute(){ std::string inFile(""); if( hasOptionValue("create") ) { inFile = getOptionValue<std::string>("create"); size_t keySize = 0; if( hasOptionValue("generate") ) keySize = Auth::COND_AUTHENTICATION_KEY_SIZE; if(!inFile.empty()){ DecodingKey key; key.init( DecodingKey::FILE_NAME, Auth::COND_KEY, false ); key.createFromInputFile( inFile, keySize ); if( hasDebug() ) key.list( std::cout ); key.flush(); return 0; } return 1; } if( hasOptionValue("read") ) { inFile = getOptionValue<std::string>("read"); if(!inFile.empty()){ DecodingKey key; key.init( inFile, Auth::COND_KEY ); key.list( std::cout ); return 0; } return 1; } if( hasOptionValue("dump_template") ) { std::cout <<DecodingKey::templateFile() <<std::endl; return 0; } return 1; }
int cond::RunInfoUtils::execute(){ std::string connect = getOptionValue<std::string>("connect"); std::string fromConnect = getOptionValue<std::string>("fromConnect"); // this is mandatory std::string tag = getOptionValue<std::string>("tag"); std::cout <<"# Source tag is "<<tag<<std::endl; size_t max_entries = 1000; if(hasOptionValue("max_entries")) max_entries = getOptionValue<size_t>("max_entries"); persistency::ConnectionPool connPool; if( hasOptionValue("authPath") ){ connPool.setAuthenticationPath( getOptionValue<std::string>( "authPath") ); } if(hasDebug()) connPool.setMessageVerbosity( coral::Debug ); connPool.configure(); persistency::Session session = connPool.createSession( connect, true ); std::cout <<"# Connecting to target database on "<<connect<<std::endl; persistency::Session sourceSession = connPool.createSession( fromConnect ); std::cout <<"# Connecting to source database on "<<fromConnect<<std::endl; RunInfoUpdate updater( session ); persistency::TransactionScope tsc( session.transaction() ); tsc.start(false); sourceSession.transaction().start(); updater.import( max_entries, tag, sourceSession ); sourceSession.transaction().commit(); tsc.commit(); return 0; }
int cond::ListIOVUtilities::execute(){ initializePluginManager(); bool listAll = hasOptionValue("all"); cond::DbSession session = openDbSession( "connect", true ); if( listAll ){ cond::MetaData metadata_svc(session); std::vector<std::string> alltags; cond::DbScopedTransaction transaction(session); transaction.start(true); metadata_svc.listAllTags(alltags); transaction.commit(); std::copy (alltags.begin(), alltags.end(), std::ostream_iterator<std::string>(std::cout,"\n") ); }else{ std::string tag = getOptionValue<std::string>("tag"); cond::MetaData metadata_svc(session); std::string token; cond::DbScopedTransaction transaction(session); transaction.start(true); token=metadata_svc.getToken(tag); transaction.commit(); { bool verbose = hasOptionValue("verbose"); bool details = hasOptionValue("summary"); TFile * xml=0; if (details) { xml = TFile::Open(std::string(tag+".xml").c_str(),"recreate"); } cond::IOVProxy iov( session, token, !details, details); unsigned int counter=0; std::string payloadContainer=iov.payloadContainerName(); std::cout<<"Tag "<<tag; if (verbose) std::cout << "\nStamp: " << iov.iov().comment() << "; time " << cond::time::to_boost(iov.iov().timestamp()) << "; revision " << iov.iov().revision(); std::cout <<"\nTimeType " << cond::timeTypeSpecs[iov.timetype()].name <<"\nPayloadContainerName "<<payloadContainer<<"\n" <<"since \t till \t payloadToken"<<std::endl; for (cond::IOVProxy::const_iterator ioviterator=iov.begin(); ioviterator!=iov.end(); ioviterator++) { std::cout<<ioviterator->since() << " \t "<<ioviterator->till() <<" \t "<<ioviterator->wrapperToken(); if (details) { ora::Object obj = session.getObject(ioviterator->wrapperToken()); std::ostringstream ss; ss << tag << '_' << ioviterator->since(); xml->WriteObjectAny(obj.address(),obj.typeName().c_str(), ss.str().c_str()); obj.destruct(); } std::cout<<std::endl; ++counter; } if (xml) xml->Close(); std::cout<<"Total # of payload objects: "<<counter<<std::endl; } } return 0; }
int cond::SchemaManager::execute(){ bool drop= hasOptionValue("drop"); bool dropAll= hasOptionValue("dropAll"); bool create= hasOptionValue("create"); std::string payloadName(""); if( hasOptionValue("payload") ) payloadName = getOptionValue<std::string>("payload"); std::string typeName(""); if( hasOptionValue("type") ) typeName = getOptionValue<std::string>("type"); cond::DbSession session = openDbSession("connect", Auth::COND_ADMIN_ROLE); cond::IOVSchemaUtility util( session, std::cout ); cond::DbScopedTransaction trans( session ); if( dropAll ){ trans.start(false); util.dropAll(); trans.commit(); return 0; } if( drop || create ){ trans.start(false); if( drop ){ if(payloadName.empty()){ throw cond::Exception("Payload name not provided."); } util.dropPayloadContainer( payloadName ); } if( create ){ util.createIOVContainer(); if(!payloadName.empty()) util.createPayloadContainer( payloadName, typeName ); } trans.commit(); return 0; } throw cond::Exception("Option create or drop not provided."); }
int cond::SchemaIOVUtilities::execute(){ bool dropSchema= hasOptionValue("drop"); bool createSchema= hasOptionValue("create"); cond::DbSession session = openDbSession("connect", Auth::COND_ADMIN_ROLE ); cond::IOVSchemaUtility util( session, std::cout ); cond::DbScopedTransaction trans( session ); if( dropSchema || createSchema ){ trans.start(false); if( dropSchema ){ util.dropIOVContainer(); } if( createSchema ){ util.createIOVContainer(); } trans.commit(); return 0; } throw cond::Exception("Option create or drop not provided."); }
int cond::KeyManager::execute(){ if( hasOptionValue("dump_template") ) { if( hasOptionValue("textFile") ) { std::string textFile = getOptionValue<std::string>("textFile"); std::ofstream outFile ( textFile.c_str() ); if (outFile.is_open()){ outFile <<DecodingKey::templateFile()<<std::endl; outFile.close(); } else { std::cout <<"ERROR: file \""<<textFile<<"\" cannot be open."<<std::endl; outFile.close(); return 1; } } else { std::cout <<DecodingKey::templateFile()<<std::endl; } return 0; } if( hasOptionValue("create") ) { std::string textFile = getOptionValue<std::string>("textFile"); size_t keySize = Auth::COND_AUTHENTICATION_KEY_SIZE; DecodingKey key; key.init( DecodingKey::FILE_NAME, Auth::COND_KEY, false ); key.createFromInputFile( textFile, keySize ); if( hasDebug() ) key.list( std::cout ); key.flush(); return 0; } if( !hasOptionValue("dump") && !hasOptionValue("read")) { return 0; } std::string path = getOptionValue<std::string>("keyPath"); boost::filesystem::path keyPath( path ); boost::filesystem::path keyFile( DecodingKey::FILE_PATH ); keyPath /= keyFile; std::string keyFileName = keyPath.string(); if(!boost::filesystem::exists( keyFileName )){ std::cout <<"ERROR: specified key file \""<<keyFileName<<"\" does not exist."<<std::endl; return 1; } if( hasOptionValue("dump") ) { std::string textFile = getOptionValue<std::string>("textFile"); std::ofstream outFile ( textFile.c_str() ); if (outFile.is_open()){ DecodingKey key; key.init( keyFileName, Auth::COND_KEY ); key.list( outFile ); outFile.close(); return 0; } else { std::cout <<"ERROR: file \""<<textFile<<"\" cannot be open."<<std::endl; outFile.close(); return 1; } } if( hasOptionValue("read") ) { DecodingKey key; key.init( keyFileName, Auth::COND_KEY ); key.list( std::cout ); return 0; } return 1; }
bool Options::parseCommandLine(int argc, const char* const* argv) { bool success = true; program_name_ = argv[0]; desc_.add_options()( "help", "show help message" )( "version,v", "show version information" )( "input-filename,i", po::value<std::string>(&input_filename_)->required(), "input file name (.mp3, .wav, .flac, .dat)" )( "output-filename,o", po::value<std::string>(&output_filename_)->required(), "output file name (.wav, .dat, .png, .json)" )( "zoom,z", po::value<int>(&samples_per_pixel_)->default_value(256), "zoom level (samples per pixel)" )( "pixels-per-second", po::value<int>(&pixels_per_second_)->default_value(100), "zoom level (pixels per second)" )( "bits,b", po::value<int>(&bits_)->default_value(16), "bits (8 or 16)" )( "start,s", po::value<double>(&start_time_)->default_value(0.0), "start time (seconds)" )( "end,e", po::value<double>(&end_time_)->default_value(0.0), "end time (seconds)" )( "width,w", po::value<int>(&image_width_)->default_value(800), "image width (pixels)" )( "height,h", po::value<int>(&image_height_)->default_value(250), "image height (pixels)" )( "colors,c", po::value<std::string>(&color_scheme_)->default_value("audacity"), "color scheme (audition or audacity)" )( "border-color", po::value<RGBA>(&border_color_), "border color (rrggbb[aa])" )( "background-color", po::value<RGBA>(&background_color_), "background color (rrggbb[aa])" )( "waveform-color", po::value<RGBA>(&waveform_color_), "wave color (rrggbb[aa])" )( "axis-label-color", po::value<RGBA>(&axis_label_color_), "axis label color (rrggbb[aa])" )( "no-axis-labels", "render waveform image without axis labels" )( "with-axis-labels", "render waveform image with axis labels (default)" ); po::variables_map variables_map; try { po::command_line_parser parser(argc, argv); parser.options(desc_); po::store(parser.run(), variables_map); help_ = variables_map.count("help") != 0; version_ = variables_map.count("version") != 0; if (help_ || version_) { return true; } render_axis_labels_ = variables_map.count("no-axis-labels") == 0; const auto& end_option = variables_map["end"]; has_end_time_ = !end_option.defaulted(); const auto& samples_per_pixel_option = variables_map["zoom"]; has_samples_per_pixel_ = !samples_per_pixel_option.defaulted(); const auto& pixels_per_second_option = variables_map["pixels-per-second"]; has_pixels_per_second_ = !pixels_per_second_option.defaulted(); const auto& bits_option = variables_map["bits"]; has_bits_ = !bits_option.defaulted(); po::notify(variables_map); has_border_color_ = hasOptionValue(variables_map, "border-color"); has_background_color_ = hasOptionValue(variables_map, "background-color"); has_waveform_color_ = hasOptionValue(variables_map, "waveform-color"); has_axis_label_color_ = hasOptionValue(variables_map, "axis-label-color"); if (bits_ != 8 && bits_ != 16) { error_stream << "Invalid bits: must be either 8 or 16\n"; success = false; } } catch (std::runtime_error& e) { reportError(e); success = false; } catch (const po::error& e) { reportError(e); success = false; } return success; }
int cond::ValidateUtilities::execute(){ initializeForDbConnection(); std::string tag(""); if( hasOptionValue("tag") ) tag = getOptionValue<std::string>("tag"); std::string dir(""); if( hasOptionValue("dir") ) dir = getOptionValue<std::string>("dir"); bool debug = hasDebug(); std::string refConnect = getOptionValue<std::string>("reference"); std::string candidate = getOptionValue<std::string>("candidate" ); std::tuple<std::string,std::string,std::string> connPars = persistency::parseConnectionString( refConnect ); if( std::get<0>( connPars ) == "frontier" ) throwException("Cannot validate data from FronTier cache.","ValidateUtilities::execute"); std::string refDbName = std::get<1>( connPars )+"_"+std::get<2>( connPars ); if(debug){ std::cout << "tag " << tag << std::endl; } std::vector<std::string> tagToProcess; if( !tag.empty() ){ tagToProcess.push_back( tag ); } else { cond::DbSession refdb = openDbSession( "reference", cond::Auth::COND_READER_ROLE, true ); refdb.transaction().start( true ); cond::MetaData metadata(refdb); metadata.listAllTags( tagToProcess ); refdb.transaction().commit(); } persistency::ConnectionPool connPool; std::cout <<"# Opening session on reference database..."<<std::endl; persistency::Session session0 = connPool.createSession( refConnect ); std::cout <<"# Opening session on candidates database..."<<std::endl; persistency::Session session1 = connPool.createSession( candidate ); session1.transaction().start(); if( !session1.existsDatabase() ) throwException( "Candidate DB \""+candidate+" does not exist.", "MigrateUtilities::execute" ); std::cout <<"# "<<tagToProcess.size()<<" tag(s) to process."<<std::endl; std::cout <<std::endl; size_t nt = 0; size_t tid = 0; for( auto t : tagToProcess ){ tid++; std::cout <<"--> Processing tag["<<tid<<"]: "<<t<<std::endl; std::string refFileName(""); std::string candFileName(""); try{ std::cout <<" Writing reference db"<<std::endl; refFileName = writeTag( t, "ref", session0, dir ); std::string destTag(""); cond::MigrationStatus status; if( !session1.checkMigrationLog( refConnect, t, destTag, status ) ) { std::cout << " ERROR: Tag "<< t <<" has not been migrated in database " << candidate <<std::endl; boost::filesystem::remove( boost::filesystem::path(refFileName) ); } else { std::cout <<" Writing candidate db"<<std::endl; candFileName = writeTag( destTag, "cand", session1, dir ); bool cmp = compareFiles( refFileName, candFileName ); if(!cmp){ std::cout <<" ERROR: Comparison found differences."<<std::endl; flushFile( refDbName, t, refFileName ); flushFile( refDbName, t, candFileName ); } else { std::cout <<" Comparison OK."<<std::endl; } nt++; } } catch ( const std::exception& e ){ std::cout <<" ERROR:"<<e.what()<<std::endl; std::cout <<" Tag "<<t<<" will be skipped."<<std::endl; } cleanUp( refFileName ); cleanUp( candFileName ); } std::cout <<std::endl<<"# "<<nt<<" tag(s) checked for validation."<<std::endl; return 0; }
int cond::MigrateGTUtilities::execute(){ std::string gtag = getOptionValue<std::string>("globaltag"); std::string release = getOptionValue<std::string>("release"); bool debug = hasDebug(); std::string destConnect = getOptionValue<std::string>("destConnect" ); std::string sourceConnect = getOptionValue<std::string>("sourceConnect"); bool verbose = hasOptionValue("verbose"); bool dryRun = hasOptionValue("dryRun"); bool onlineMode = hasOptionValue("online"); std::vector<std::tuple<std::string,std::string,std::string,std::string,std::string> > gtlist; if(! getGTList( gtag, gtlist ) ) throw std::runtime_error( std::string("Source GT ")+gtag+" has not been found." ); ConnectionPool connPool; if( hasDebug() ) connPool.setMessageVerbosity( coral::Debug ); Session session = connPool.createSession( destConnect, !dryRun ); session.transaction().start( dryRun ); if( session.existsGlobalTag( gtag ) ){ std::cout <<"GT "<<gtag<<" already exists in the destination database."<<std::endl; return 1; } GTEditor newGT; if( !dryRun ){ newGT = session.createGlobalTag( gtag ); newGT.setDescription( "GT "+gtag+" migrated from account "+sourceConnect ); newGT.setRelease( release ); newGT.setSnapshotTime( boost::posix_time::time_from_string(std::string(cond::time::MAX_TIMESTAMP) ) ); } std::cout <<"Processing "<<gtlist.size()<<" tags."<<std::endl; size_t nerr = 0; for(auto gtitem : gtlist ){ std::string tag = std::get<0>( gtitem ); std::string payloadTypeName = std::get<1>( gtitem ); std::string recordName = std::get<2>( gtitem ); std::string recordLabel = std::get<3>( gtitem ); std::string connectionString = std::get<4>( gtitem ); std::cout <<"--> Processing tag "<<tag<<" (objectType: "<<payloadTypeName<<") on account "<<connectionString<<std::endl; std::string sourceConn = convert( connectionString, onlineMode ); // "oracle://cms_orcon_adg/"+account; std::string destTag(""); cond::MigrationStatus status; bool exists = session.checkMigrationLog( sourceConn, tag, destTag, status ); if(!exists || status==cond::ERROR){ std::cout <<" ERROR: Tag "<<tag<<" from "<<sourceConn<<" has not been migrated to the destination database."<<std::endl; if( !dryRun ){ return 1; } else { nerr++; } } else { std::cout <<" Inserting tag "<<destTag<<std::endl; } if( !dryRun ) newGT.insert( recordName, recordLabel, destTag ); } if( !dryRun )newGT.flush(); session.transaction().commit(); std::cout << std::endl; if( !dryRun ) { std::cout <<"Global Tag \""<<gtag<<"\" imported."<<std::endl; } else { std::cout <<"Importing Global Tag \""<<gtag<<"\" will run with "<<nerr<<" error(s)"<<std::endl; } return 0; }
int cond::MigrateUtilities::execute(){ std::string newTag(""); std::string tag(""); if( hasOptionValue("tag")) { tag = getOptionValue<std::string>("tag"); if( hasOptionValue("newTag")) newTag = getOptionValue<std::string>("newTag"); } bool debug = hasDebug(); std::string destConnect = getOptionValue<std::string>("destConnect" ); std::string sourceConnect = getOptionValue<std::string>("sourceConnect"); std::tuple<std::string,std::string,std::string> connPars = parseConnectionString( sourceConnect ); if( std::get<0>( connPars ) == "frontier" ) throwException("Cannot migrate data from FronTier cache.","MigrateUtilities::execute"); std::cout <<"# Connecting to source database on "<<sourceConnect<<std::endl; cond::DbSession sourcedb = openDbSession( "sourceConnect", cond::Auth::COND_READER_ROLE, true ); if(debug){ std::cout << "tag " << tag << std::endl; } sourcedb.transaction().start( true ); cond::MetaData metadata(sourcedb); std::vector<std::string> tagToProcess; if( !tag.empty() ){ tagToProcess.push_back( tag ); } else { metadata.listAllTags( tagToProcess ); } persistency::ConnectionPool connPool; std::cout <<"# Opening session on destination database..."<<std::endl; persistency::Session session = connPool.createSession( destConnect, true ); session.transaction().start( false ); if( !session.existsDatabase() ) session.createDatabase(); session.transaction().commit(); std::cout <<"# "<<tagToProcess.size()<<" tag(s) to process."<<std::endl; std::cout <<std::endl; size_t nt = 0; size_t tid = 0; for( auto t : tagToProcess ){ tid++; std::cout <<"--> Processing tag["<<tid<<"]: "<<t<<std::endl; session.transaction().start( false ); std::string destTag(""); if( session.checkMigrationLog( sourceConnect, t, destTag ) ){ std::cout <<" Tag already migrated." << std::endl; session.transaction().rollback(); continue; } destTag = t; if( !newTag.empty() ){ destTag = newTag; } else { if( session.existsIov( destTag ) ){ destTag = destTag+"["+std::get<1>( connPars )+"/"+std::get<2>( connPars )+"]"; std::cout <<" Tag "<<t<<" already existing, renamed to "<<destTag<<std::endl; } } if( session.existsIov( destTag ) ){ session.transaction().rollback(); throwException("Tag \""+destTag+"\" already exists.","MigrateUtilities::execute"); } std::cout <<" Resolving source tag oid..."<<std::endl; std::string iovTok = metadata.getToken(t); if(iovTok.empty()){ session.transaction().rollback(); throw std::runtime_error(std::string("tag ")+t+std::string(" not found") ); } std::map<std::string,Hash> tokenToHash; size_t niovs = 0; std::set<Hash> pids; persistency::IOVEditor editor; std::cout <<" Loading source tag..."<<std::endl; try{ cond::IOVProxy sourceIov(sourcedb, iovTok); int tt = (int) sourceIov.timetype(); if( sourceIov.size() == 0 ) { std::cout <<" No iov found. Skipping tag."<<std::endl; session.transaction().rollback(); continue; } std::string payloadType(""); if( sourceIov.payloadClasses().size() > 0 ) { payloadType = *(sourceIov.payloadClasses().begin()); } else { std::string tk = sourceIov.begin()->token(); payloadType = sourcedb.classNameForItem( tk ); } std::cout <<" Importing tag. Size:"<<sourceIov.size()<<" timeType:"<<cond::timeTypeNames(tt)<<" payloadObjectType=\""<<payloadType<<"\""<<std::endl; editor = session.createIov( payloadType, destTag, (cond::TimeType)tt ); editor.setDescription( "Tag "+t+" migrated from "+sourceConnect ); for( auto iov : sourceIov ){ Time_t s = iov.since(); std::string tok = iov.token(); Hash pid(""); auto f = tokenToHash.find( tok ); if( f == tokenToHash.end() ){ if(hasDebug() ) std::cout <<"Debug: fetching object for iov ["<<niovs+1<<"] oid: \""<<t<<"\" from source database"<<std::endl; ora::Object obj = sourcedb.getObject( tok ); if(hasDebug() ) std::cout <<"Debug: importing object into destination database"<<std::endl; pid = import( obj.typeName(), obj.address(), session ); tokenToHash.insert( std::make_pair( tok, pid ) ); obj.destruct(); } else { pid= f->second; } pids.insert( pid ); editor.insert( s, pid ); niovs++; if( niovs && (niovs%1000==0) ) std::cout <<" Total of iov inserted: "<<niovs<<std::endl; } std::cout <<" Total of iov inserted: "<<niovs<<std::endl; std::cout <<" Flushing changes..."<<std::endl; editor.flush(); session.addToMigrationLog( sourceConnect, t, destTag ); session.transaction().commit(); std::cout <<" Tag \""<<t<<"\" imported. Payloads:"<<pids.size()<<" IOVs:"<<niovs<<std::endl; nt++; } catch ( const std::exception& e ){ std::cout <<" ERROR:"<<e.what()<<std::endl; std::cout <<" Tag "<<t<<" will be skipped."<<std::endl; session.transaction().rollback(); continue; } } std::cout <<"# "<<nt<<" tag(s) migrated."<<std::endl; sourcedb.transaction().commit(); return 0; }
int cond::DuplicateIOVUtilities::execute(){ std::string sourceTag = getOptionValue<std::string>("tag"); std::string destTag(sourceTag); if(hasOptionValue("destTag")) destTag = getOptionValue<std::string>("destTag"); cond::Time_t from = getOptionValue<cond::Time_t>("fromTime"); cond::Time_t since = getOptionValue<cond::Time_t>("sinceTime"); bool doLog = hasOptionValue("logDB"); bool debug = hasDebug(); std::string destConnect = getOptionValue<std::string>("connect" ); std::string usertext("no user comments"); if( hasOptionValue("usertext")) usertext = getOptionValue<std::string>("usertext"); cond::DbSession destDb = openDbSession( "connect", Auth::COND_WRITER_ROLE ); std::string iovToken(""); std::string destIovToken(""); cond::TimeType iovType; std::string timetypestr(""); if(debug){ std::cout << "source tag " << sourceTag << std::endl; std::cout << "dest tag " << destTag << std::endl; } cond::IOVProxy sourceIov(destDb); cond::IOVEditor destIov(destDb); // find tag cond::DbScopedTransaction transaction(destDb); transaction.start(false); destDb.storage().lockContainer( IOVNames::container() ); cond::MetaData metadata(destDb); iovToken = metadata.getToken(sourceTag); if(iovToken.empty()) throw std::runtime_error(std::string("tag ")+sourceTag+std::string(" not found") ); sourceIov.load( iovToken ); iovType=sourceIov.timetype(); timetypestr = cond::timeTypeSpecs[iovType].name; if( metadata.hasTag(destTag) ){ destIovToken=metadata.getToken(destTag); destIov.load( destIovToken ); if (iovType!=destIov.proxy().timetype()) { throw std::runtime_error("iov type in source and dest differs"); } } else { destIovToken = destIov.create( iovType ); metadata.addMapping(destTag,destIovToken,iovType); } if(debug){ std::cout<<"source iov token "<< iovToken<<std::endl; std::cout<<"dest iov token "<< destIovToken<<std::endl; std::cout<<"iov type "<< timetypestr<<std::endl; } cond::IOVProxy::const_iterator iElem = sourceIov.find( from ); if( iElem == sourceIov.end() ){ std::cerr <<"[Error] no payload found for time " << from << std::endl; return 1; } std::string payload = iElem->token(); std::string payloadClass = destDb.classNameForItem( payload ); destIov.append(since,payload); destIov.stamp(cond::userInfo(),false); transaction.commit(); ::sleep(1); // setup logDB and write on it... if (doLog){ std::auto_ptr<cond::Logger> logdb; cond::DbSession logSession = openDbSession( "logDB", Auth::COND_WRITER_ROLE ); logdb.reset(new cond::Logger( logSession )); logdb->createLogDBIfNonExist(); cond::UserLogInfo a; a.provenance=destConnect+"/"+destTag; a.usertext="duplicateIOV V1.0;"; std::ostringstream ss; ss << "From="<< from <<"; Since="<< since <<"; " << usertext; a.usertext +=ss.str(); logdb->logOperationNow(a,destConnect,payloadClass,payload,destTag,timetypestr,0,since); } return 0; }
int cond::TestGTPerf::execute(){ std::string gtag = getOptionValue<std::string>("globaltag"); bool debug = hasDebug(); std::string connect = getOptionValue<std::string>("connect"); bool verbose = hasOptionValue("verbose"); int nThrF = getOptionValue<int>("n_fetch"); int nThrD = getOptionValue<int>("n_deser"); std::cout << "\n++> going to use " << nThrF << " threads for loading, " << nThrD << " threads for deserialization. \n" << std::endl; std::string serType = "unknown"; if ( connect.find("CMS_CONDITIONS") != -1 ) { serType = "ROOT-5"; } else if (connect.find("CMS_TEST_CONDITIONS") != -1 ) { serType = "boost"; } Time_t startRun= 150005; if(hasOptionValue("start_run")) startRun = getOptionValue<Time_t>("start_run"); Time_t startTs= 5800013687234232320; if(hasOptionValue("start_ts")) startTs = getOptionValue<Time_t>("start_ts"); Time_t startLumi= 908900979179966; if(hasOptionValue("start_lumi")) startLumi = getOptionValue<Time_t>("start_lumi"); std::string authPath(""); if( hasOptionValue("authPath")) authPath = getOptionValue<std::string>("authPath"); initializePluginManager(); Timer timex(serType); ConnectionPoolWrapper connPool( 1, authPath, hasDebug() ); Session session = connPool.createSession( connect ); session.transaction().start(); std::cout <<"Loading Global Tag "<<gtag<<std::endl; GTProxy gt = session.readGlobalTag( gtag ); session.transaction().commit(); std::cout <<"Loading "<<gt.size()<<" tags..."<<std::endl; std::vector<UntypedPayloadProxy *> proxies; std::map<std::string,size_t> requests; size_t nt = 0; for( auto t: gt ){ nt++; UntypedPayloadProxy * p = new UntypedPayloadProxy; p->init( session ); try{ p->load( t.tagName() ); if (nThrF == 1) { // detailed info only needed in single-threaded mode to get the types/names p->setRecordInfo( t.recordName(), t.recordLabel() ); } proxies.push_back( p ); requests.insert( std::make_pair( t.tagName(), 0 ) ); } catch ( const cond::Exception& e ){ std::cout <<"ERROR: "<<e.what()<<std::endl; } } std::cout << proxies.size() << " tags successfully loaded." << std::endl; timex.interval("loading iovs"); Time_t run = startRun; Time_t lumi = startLumi; Time_t ts = startTs; if (nThrF > 1) session.transaction().commit(); tbb::task_scheduler_init init( nThrF ); std::vector<std::shared_ptr<FetchWorker> > tasks; std::string payloadTypeName; for( auto p: proxies ){ payloadTypeName = p->payloadType(); // ignore problematic ones for now if ( (payloadTypeName == "SiPixelGainCalibrationOffline") // 2 * 133 MB !!! ) { std::cout << "WARNING: Ignoring problematic payload of type " << payloadTypeName << std::endl; continue; } if (nThrF > 1) { auto fw = std::make_shared<FetchWorker>(connPool, connect, p, (std::map<std::string,size_t> *) &requests, run, lumi, ts); tasks.push_back(fw); } else { bool loaded = false; time::TimeType ttype = p->timeType(); auto r = requests.find( p->tag() ); try{ if( ttype==runnumber ){ p->get( run, hasDebug() ); r->second++; } else if( ttype==lumiid ){ p->get( lumi, hasDebug() ); r->second++; } else if( ttype==timestamp){ p->get( ts, hasDebug() ); r->second++; } else { std::cout <<"WARNING: iov request on tag "<<p->tag()<<" (timeType="<<time::timeTypeName(p->timeType())<<") has been skipped."<<std::endl; } timex.fetchInt(p->getBufferSize()); // keep track of time vs. size } catch ( const cond::Exception& e ){ std::cout <<"ERROR:"<<e.what()<<std::endl; } } // end else (single thread) } tbb::parallel_for_each(tasks.begin(),tasks.end(),invoker<std::shared_ptr<FetchWorker> >() ); std::cout << "global counter : " << fooGlobal << std::endl; if (nThrF == 1) session.transaction().commit(); // session.transaction().commit(); timex.interval("loading payloads"); size_t totBufSize = 0; for( auto p: proxies ){ totBufSize += p->getBufferSize(); } std::cout << "++> total buffer size used : " << totBufSize << std::endl; std::vector<std::shared_ptr<void> > payloads; payloads.resize(400); //-todo: check we don't have more payloads than that !! std::shared_ptr<void> payloadPtr; tbb::task_scheduler_init initD( nThrD ); std::vector<std::shared_ptr<DeserialWorker> > tasksD; timex.interval("setup deserialization"); int nEmpty = 0; int nBig = 0; int index = 0; for( auto p: proxies ){ /// if ( p->getBufferSize() == 0 ) { // nothing to do for these ... /// std::cout << "empty buffer found for " << p->payloadType() << std::endl; /// nEmpty++; /// continue; /// } payloadTypeName = p->payloadType(); // ignore problematic ones for now if ( (payloadTypeName == "SiPixelGainCalibrationForHLT") or (payloadTypeName == "SiPixelGainCalibrationOffline") // 2 * 133 MB !!! or (payloadTypeName == "DTKeyedConfig") or (payloadTypeName == "std::vector<unsigned long long>") or (payloadTypeName == " AlignmentSurfaceDeformations") // only in root for now: or (payloadTypeName == "PhysicsTools::Calibration::MVAComputerContainer") or (payloadTypeName == "PhysicsTools::Calibration::MVAComputerContainer") or (payloadTypeName == "PhysicsTools::Calibration::MVAComputerContainer") or (payloadTypeName == "PhysicsTools::Calibration::MVAComputerContainer") ) { std::cout << "INFO: Ignoring payload of type " << payloadTypeName << std::endl; continue; } if (nThrD > 1) { auto dw = std::make_shared<DeserialWorker>(p, payloads[index]); tasksD.push_back(dw); } else { // single tread only try { std::pair<std::string, std::shared_ptr<void> > result = fetchOne( payloadTypeName, p->getBuffer(), p->getStreamerInfo(), payloadPtr); payloads.push_back(result.second); } catch ( const cond::Exception& e ){ std::cout << "\nERROR (cond): " << e.what() << std::endl; std::cout << "for payload type name: " << payloadTypeName << std::endl; } catch ( const std::exception& e ){ std::cout << "\nERROR (boost/std): " << e.what() << std::endl; std::cout << "for payload type name: " << payloadTypeName << std::endl; } timex.deserInt(p->getBufferSize()); // keep track of time vs. size } // single-thread index++; // increment index into payloads } std::cout << std::endl; tbb::parallel_for_each(tasksD.begin(),tasksD.end(),invoker<std::shared_ptr<DeserialWorker> >() ); timex.interval("deserializing payloads"); std::cout << "global counter : " << fooGlobal << std::endl; std::cout << "found " << nEmpty << " empty payloads while deserialising " << std::endl; std::cout <<std::endl; std::cout <<"*** End of job."<<std::endl; std::cout <<"*** GT: "<<gtag<<" Tags:"<<gt.size()<<" Loaded:"<<proxies.size()<<std::endl; std::cout<<std::endl; for( auto p: proxies ){ auto r = requests.find( p->tag() ); if( verbose ){ std::cout <<"*** Tag: "<<p->tag()<<" Requests processed:"<<r->second<<" Queries:"<< p->numberOfQueries() <<std::endl; const std::vector<std::string>& hist = p->history(); for( auto e: p->history() ) std::cout <<" "<<e<<std::endl; } } // only for igprof checking of live mem: // ::exit(0); timex.interval("postprocessing ... "); timex.showIntervals(); if ( nThrF == 1) { std::ofstream ofs("fetchInfo.txt"); timex.showFetchInfo(ofs); std::ofstream ofs2("sizeInfo.txt"); for ( auto p: proxies ) { ofs2 << p->payloadType() << "[" << p->recName() << ":" << p->recLabel() << "]" << " : " << p->getBufferSize() << std::endl; } } if ( nThrD == 1) { std::ofstream ofs1("deserializeInfo.txt"); timex.showDeserInfo(ofs1); } return 0; }