file_cpi_impl::file_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, boost::shared_ptr <saga::adaptor> adaptor) : file_cpi (p, info, adaptor, cpi::Noflags) { adaptor_data_t adata (this); file_instance_data_t idata (this); //SAGA_ADAPTOR_THROW ("Not Implemented (yet), but soon will be!", saga::NotImplemented); saga::url location(idata->location_); std::string host(location.get_host()); std::string scheme(location.get_scheme()); // make sure that we only allow globusonline:// URLs if (scheme != "globusonline") { SAGA_OSSTREAM strm; strm << "Could not initialize file object for [" << idata->location_ << "]. " << "Only globusonline:// schemes are supported."; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::adaptors::AdaptorDeclined); } }
/////////////////////////////////////////////////////////////////////////////// // // init() is called whenever the cpi's instance data have changed. In that // case, it re-initializes the proxy directory instance which points into the // locally mounted sshfs name spaces, or into the local file system in // general. // // init() will generally throw if the idata->location points elsewhere. // init() is however assumed to be atomic, so it either succeeds, or it fails // but then leaves the object state unchanged. That way, the individual // methods don't need to attempt to recover from a failed init. The only side // effect can be an additionally mounted sshfs, which is getting cleaned up by // the adaptor d'tor (that cleanup is optional though). // // The single argument, the url 'save', is used to restore state on failure // void dir_cpi_impl::init (void) { adaptor_instance_data_t adata (this); directory_instance_data_t idata (this); if ( idata->location_.get_scheme () != "ssh" && idata->location_.get_scheme () != "any" ) { SAGA_LOG_DEBUG ("sshfs can not handle url:"); SAGA_LOG_DEBUG (idata->location_.get_string ().c_str ()); std::stringstream ss; ss << "Cannot handle URL scheme " << idata->location_.get_scheme () << " - can only handle schemas 'ssh' or 'any'." << std::endl; SAGA_ADAPTOR_THROW_NO_CONTEXT (ss.str ().c_str (), saga::adaptors::AdaptorDeclined); } // create a new api object from the changed instance data. try { d_ = saga::filesystem::directory (adata->strip_session (s_), adata->try_translate (s_, idata->location_), idata->mode_); } catch ( const saga:: exception & e ) { std::stringstream ss; ss << "Cannot handle URL: \n\t" << e.what () << "\n"; SSH_ADAPTOR_RETHROW (e, ss.str ().c_str (), saga::BadParameter); } }
// SAGA API functions void job_cpi_impl::sync_get_state (saga::job::state & ret) { adaptor_data_type adata (this); ret = drmaa_->get_state(jobid_); }
void dir_cpi_impl::sync_permissions_check (bool & ret, std::string id, int perm) { adaptor_instance_data_t adata (this); SSH_ADAPTOR_TRY ret = d_.permissions_check (id, perm); SSH_ADAPTOR_CATCH; }
static const bfd_target * os9k_callback (bfd *abfd) { struct internal_exec *execp = exec_hdr (abfd); unsigned long bss_start; /* Architecture and machine type. */ bfd_set_arch_mach (abfd, bfd_arch_i386, 0); /* The positions of the string table and symbol table. */ obj_str_filepos (abfd) = 0; obj_sym_filepos (abfd) = 0; /* The alignments of the sections. */ obj_textsec (abfd)->alignment_power = execp->a_talign; obj_datasec (abfd)->alignment_power = execp->a_dalign; obj_bsssec (abfd)->alignment_power = execp->a_balign; /* The starting addresses of the sections. */ obj_textsec (abfd)->vma = execp->a_tload; obj_datasec (abfd)->vma = execp->a_dload; /* And reload the sizes, since the aout module zaps them. */ obj_textsec (abfd)->size = execp->a_text; bss_start = execp->a_dload + execp->a_data; /* BSS = end of data section. */ obj_bsssec (abfd)->vma = align_power (bss_start, execp->a_balign); /* The file positions of the sections. */ obj_textsec (abfd)->filepos = execp->a_entry; obj_datasec (abfd)->filepos = execp->a_dload; /* The file positions of the relocation info *** obj_textsec (abfd)->rel_filepos = N_TROFF(*execp); obj_datasec (abfd)->rel_filepos = N_DROFF(*execp); */ adata (abfd).page_size = 1; /* Not applicable. */ adata (abfd).segment_size = 1;/* Not applicable. */ adata (abfd).exec_bytes_size = MHCOM_BYTES_SIZE; return abfd->xvec; }
void file_cpi_impl::sync_get_size (saga::off_t & size_out) { file_instance_data_t idata (this); adaptor_instance_data_t adata (this); /// suite_instance_data_t sdata (this); SSH_ADAPTOR_TRY size_out = f_.get_size (); SSH_ADAPTOR_CATCH; }
void dir_cpi_impl::sync_permissions_deny (saga::impl::void_t & ret, saga::url tgt, std::string id, int perm, int flags) { adaptor_instance_data_t adata (this); SSH_ADAPTOR_TRY d_.permissions_deny (adata->try_translate (s_, tgt), id, perm, flags); SSH_ADAPTOR_CATCH; }
// constructor job_cpi_impl::job_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, TR1::shared_ptr <saga::adaptor> adaptor) : base_cpi (p, info, adaptor, cpi::Noflags) , session_ (p->get_session ()) , state_ (saga::job::New) { instance_data idata (this); adaptor_data_type adata (this); saga::url contact_url = idata->rm_; SAGA_LOG_INFO("url: " + contact_url.get_url ()); // check if URL is usable if ( ! contact_url.get_scheme ().empty () && contact_url.get_scheme () != "drmaa" && contact_url.get_scheme () != "any" ) { SAGA_OSSTREAM strm; strm << "Could not initialize job service for [" << contact_url << "]. " << "Only these schemas are supported: any://, drmaa://, or none."; SAGA_ADAPTOR_THROW (SAGA_OSSTREAM_GETSTRING (strm), saga::adaptors::AdaptorDeclined); } // TODO: load drmaa && drmaa_init SAGA_LOG_INFO("getting DRMAA singleton"); drmaa_ = &(saga::adaptors::utils::get_singleton<psnc_drmaa::drmaa>()); if ( idata->init_from_jobid_ ) { jobid_ = idata->jobid_; state_ = drmaa_->get_state(jobid_); } else { // init from job description jd_ = idata->jd_; state_ = saga::job::New; if ( ! jd_.attribute_exists (sja::description_executable) ) { SAGA_ADAPTOR_THROW ("job description misses executable", saga::BadParameter); } } // FIXME: register metrics etc. }
void dir_cpi_impl::sync_is_file (bool & is_file, saga::url name) { adaptor_instance_data_t adata (this); directory_instance_data_t idata (this); saga::url u = adata->make_absolute (idata->location_, name); SSH_ADAPTOR_TRY is_file = d_.is_file (adata->try_translate (s_, u)); SSH_ADAPTOR_CATCH; }
static bfd_boolean aout_adobe_mkobject (bfd *abfd) { struct bout_data_struct *rawptr; bfd_size_type amt = sizeof (struct bout_data_struct); rawptr = bfd_zalloc (abfd, amt); if (rawptr == NULL) return FALSE; abfd->tdata.bout_data = rawptr; exec_hdr (abfd) = &rawptr->e; adata (abfd).reloc_entry_size = sizeof (struct reloc_std_external); adata (abfd).symbol_entry_size = sizeof (struct external_nlist); adata (abfd).page_size = 1; /* Not applicable. */ adata (abfd).segment_size = 1; /* Not applicable. */ adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; return TRUE; }
dir_cpi_impl::dir_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, boost::shared_ptr<saga::adaptor> adaptor) : directory_cpi (p, info, adaptor, cpi::Noflags) { adaptor_data_t adata (this); directory_instance_data_t idata (this); SAGA_ADAPTOR_THROW ("Not Implemented", saga::NotImplemented); }
void dir_cpi_impl::sync_get_size (saga::off_t & size_out, saga::url name, int flag) { adaptor_instance_data_t adata (this); directory_instance_data_t idata (this); saga::url u = adata->make_absolute (idata->location_, name); SSH_ADAPTOR_TRY size_out = d_.get_size (adata->try_translate (s_, u), flag); SSH_ADAPTOR_CATCH; }
void ext_model::init_fms() { if (!fsettings() || !get_meteo_proxy()) return ; fms::pilot_state_t fmsst = get_state(); ada::data_t const& fsetttings = *fsettings(); fms::aircraft_data_t adata(fsetttings, payload_ * fsetttings.max_payload_mass); pilot_impl_ = fms::create_aircraft_pilot(get_meteo_proxy(), fmsst, adata); fms::pilot_control_ptr(pilot_impl_)->set_instrument(!get_plan().empty() ? get_plan().front() : fms::instrument_ptr()); }
file_cpi_impl::file_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, boost::shared_ptr <saga::adaptor> adaptor) : file_cpi (p, info, adaptor, cpi::Noflags) { adaptor_instance_data_t adata (this); file_instance_data_t idata (this); s_ = p->get_session (); init (); }
void dir_cpi_impl::sync_open_dir (saga::filesystem::directory & ret, saga::url name, int openmode) { adaptor_instance_data_t adata (this); directory_instance_data_t idata (this); saga::url u = adata->make_absolute (idata->location_, name); // we do *not* use the stripped session here, as the target is in all // likelyhood an ssh file SSH_ADAPTOR_TRY ret = saga::filesystem::directory (s_, u, openmode); SSH_ADAPTOR_CATCH }
dir_cpi_impl::dir_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, boost::shared_ptr<saga::adaptor> adaptor) : directory_cpi (p, info, adaptor, cpi::Noflags), dserv_( serv_.get_sector_dir_service()) { std::string error ; adaptor_data_t adata (this); directory_instance_data_t idata (this); /* Parse the location and open the directory */ location = idata->location_ ; set_dir_name() ; s_ = p->get_session() ; mode = idata->mode_ ; /* if( !adata->get_auth_flag() ) { bool auth = adata->authenticate( s_, location, mode, serv_, glob_ini, adap_ini ) ; if( !auth ) { SAGA_ADAPTOR_THROW ("Could not authenticate with the Sector/Sphere Master Server.", saga::NoSuccess ) ; } adata->set_auth_flag() ; } */ bool open = open_dir( error ) ; if( !open ) { SAGA_ADAPTOR_THROW ( error , saga::NoSuccess ) ; } }
static bfd_boolean sparclynx_set_sizes(bfd *abfd) { switch (bfd_get_arch(abfd)) { default: return FALSE; case bfd_arch_sparc: adata (abfd).page_size = 0x2000; adata (abfd).segment_size = 0x2000; adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; return TRUE; case bfd_arch_m68k: adata (abfd).page_size = 0x2000; adata (abfd).segment_size = 0x20000; adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; return TRUE; } }
static bfd_boolean tic30_aout_set_sizes (bfd *abfd) { adata (abfd).page_size = TARGET_PAGE_SIZE; #ifdef SEGMENT_SIZE adata (abfd).segment_size = SEGMENT_SIZE; #else adata (abfd).segment_size = TARGET_PAGE_SIZE; #endif #ifdef ZMAGIC_DISK_BLOCK_SIZE adata (abfd).zmagic_disk_block_size = ZMAGIC_DISK_BLOCK_SIZE; #else adata (abfd).zmagic_disk_block_size = TARGET_PAGE_SIZE; #endif adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; return TRUE; }
static bfd_boolean MY (write_object_contents) (bfd * abfd) { struct external_exec exec_bytes; struct internal_exec *execp = exec_hdr (abfd); bfd_size_type text_size; /* dummy vars */ file_ptr text_end; memset (&exec_bytes, 0, sizeof (exec_bytes)); obj_reloc_entry_size (abfd) = RELOC_STD_SIZE; if (adata (abfd).magic == undecided_magic) NAME (aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end); execp->a_syms = 0; execp->a_entry = bfd_get_start_address (abfd); execp->a_trsize = ((obj_textsec (abfd)->reloc_count) * obj_reloc_entry_size (abfd)); execp->a_drsize = ((obj_datasec (abfd)->reloc_count) * obj_reloc_entry_size (abfd)); N_SET_MACHTYPE (*execp, 0xc); N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags); NAME (aout,swap_exec_header_out) (abfd, execp, &exec_bytes); /* update fields not covered by default swap_exec_header_out */ /* this is really the sym table size but we store it in drelocs */ H_PUT_32 (abfd, (bfd_get_symcount (abfd) * 12), exec_bytes.e_drelocs); if (bfd_seek (abfd, (file_ptr) 0, FALSE) != 0 || (bfd_bwrite (&exec_bytes, (bfd_size_type) EXEC_BYTES_SIZE, abfd) != EXEC_BYTES_SIZE)) return FALSE; /* Write out the symbols, and then the relocs. We must write out the symbols first so that we know the symbol indices. */ if (bfd_get_symcount (abfd) != 0) { /* Skip the relocs to where we want to put the symbols. */ if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*execp) + execp->a_drsize), SEEK_SET) != 0) return FALSE; } if (!MY (write_syms) (abfd)) return FALSE; if (bfd_get_symcount (abfd) != 0) { if (bfd_seek (abfd, (file_ptr) N_TRELOFF (*execp), SEEK_CUR) != 0) return FALSE; if (!NAME (aout,squirt_out_relocs) (abfd, obj_textsec (abfd))) return FALSE; if (bfd_seek (abfd, (file_ptr) N_DRELOFF (*execp), SEEK_CUR) != 0) return FALSE; if (!NAME (aout,squirt_out_relocs) (abfd, obj_datasec (abfd))) return FALSE; } return TRUE; }
dir_cpi_impl::dir_cpi_impl (proxy * p, cpi_info const & info, saga::ini::ini const & glob_ini, saga::ini::ini const & adap_ini, boost::shared_ptr<saga::adaptor> adaptor) : directory_cpi (p, info, adaptor, cpi::Noflags) { adaptor_data_t adata (this); directory_instance_data_t idata (this); saga::url dir_url(idata->location_); std::string host(dir_url.get_host()); if (host.empty()) { SAGA_OSSTREAM strm; strm << "dir_cpi_impl::init: cannot handle file: " << dir_url.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } std::string scheme(dir_url.get_scheme()); if (!scheme.empty() && scheme != "kfs" && scheme != "any") { SAGA_OSSTREAM strm; strm << "dir_cpi_impl::init: cannot handle file: " << dir_url.get_url(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } fs_ = getKfsClientFactory()->GetClient(dir_url.get_host(), dir_url.get_port()); if(!fs_) { SAGA_OSSTREAM strm; strm << "Could not connect to host : " << dir_url.get_host(); strm << "on port " << dir_url.get_port(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::NoSuccess); } // check if file exists AND is a dir (not a file) bool exists = false; bool is_dir = false; if(fs_->Exists(dir_url.get_path().c_str())) { exists = true; //Check to see if it is a directory instance_data idata(this); if(fs_->IsDirectory(dir_url.get_path().c_str())) is_dir = true; } saga::filesystem::flags OpenMode = (saga::filesystem::flags)idata->mode_; if(exists) { if(!is_dir) { SAGA_ADAPTOR_THROW ("URL does not point to a directory: " + idata->location_.get_url(), saga::BadParameter); } else { if((OpenMode & saga::filesystem::Create) && (OpenMode & saga::filesystem::Exclusive)) { SAGA_ADAPTOR_THROW ("Directory " + idata->location_.get_url() + " already exists.", saga::AlreadyExists); } } } else { // !exists if(!(OpenMode & saga::filesystem::Create)) { SAGA_ADAPTOR_THROW ("Directory does not exist and saga::filesystem::Create flag not given: " + idata->location_.get_url(), saga::DoesNotExist); } else { if(fs_->Mkdir(dir_url.get_path().c_str()) != 0) { SAGA_OSSTREAM strm; strm << "Could not create directory " << idata->location_.get_path(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::DoesNotExist); } } } exists = false; is_dir = false; //Make sure directory exists if(fs_->Exists(dir_url.get_path().c_str())) exists = true; if ((idata->mode_ & saga::filesystem::Create || idata->mode_ & saga::filesystem::CreateParents) && idata->mode_ & saga::filesystem::Exclusive) { //Check to see if it is a directory if(fs_->IsDirectory(dir_url.get_path().c_str())) is_dir = true; if(is_dir) { SAGA_ADAPTOR_THROW(dir_url.get_path().c_str() + ": already exists", saga::AlreadyExists); } } if(!exists) { //create directory if needed if (idata->mode_ & saga::filesystem::Create) { if(fs_->Mkdir(dir_url.get_path().c_str()) != 0) { SAGA_OSSTREAM strm; strm << "Could not create directory " << idata->location_.get_path(); SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::DoesNotExist); } } } // we don't need to create the directory twice idata->mode_ &= ~(saga::filesystem::Create | saga::filesystem::CreateParents); if (idata->mode_ & saga::filesystem::Read || idata->mode_ & saga::filesystem::Write || idata->mode_ & saga::filesystem::ReadWrite) { //check to see if it exists and is a direcotory exists = false; is_dir = false; if(fs_->Exists(dir_url.get_path().c_str())) { exists = true; //Check to see if it is a directory if(fs_->IsDirectory(dir_url.get_path().c_str())) is_dir = true; } if (!exists || !is_dir) { SAGA_OSSTREAM strm; strm << idata->location_.get_path() << ": doesn't refer to a directory object"; SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); } } if (idata->mode_ & ~( saga::filesystem::Create | saga::filesystem::CreateParents | saga::filesystem::Exclusive | saga::filesystem::Overwrite | saga::filesystem::Read | saga::filesystem::Write | saga::filesystem::ReadWrite )) { SAGA_ADAPTOR_THROW("Unknown openmode value: " + boost::lexical_cast<std::string>(idata->mode_), saga::BadParameter); } //SAGA_ADAPTOR_THROW ("Not Implemented", saga::NotImplemented); }
int main(int argc, char *argv[]) { { libmaus2::lz::LineSplittingGzipOutputStream LSG("gzsplit",4,17); for ( uint64_t i = 0; i < 17; ++i ) LSG << "line_" << i << "\n"; } { libmaus2::lz::LineSplittingGzipOutputStream LSG("nogzsplit",4,17); } testGzip(); testlz4(); #if 0 maskBamDuplicateFlag(std::cin,std::cout); return 0; #endif #if 0 { libmaus2::lz::BgzfInflateDeflateParallel BIDP(std::cin,std::cout,Z_DEFAULT_COMPRESSION,32,128); libmaus2::autoarray::AutoArray<char> B(64*1024,false); int r; uint64_t t = 0; uint64_t last = std::numeric_limits<uint64_t>::max(); uint64_t lcnt = 0; uint64_t const mod = 64*1024*1024; libmaus2::timing::RealTimeClock rtc; rtc.start(); libmaus2::timing::RealTimeClock lrtc; lrtc.start(); while ( (r = BIDP.read(B.begin(),B.size())) ) { BIDP.write(B.begin(),r); lcnt += r; t += r; if ( t/mod != last/mod ) { if ( isatty(STDERR_FILENO) ) std::cerr << "\r" << std::string(60,' ') << "\r"; std::cerr << rtc.formatTime(rtc.getElapsedSeconds()) << " " << t/(1024*1024) << "MB, " << (lcnt/lrtc.getElapsedSeconds())/(1024.0*1024.0) << "MB/s"; if ( isatty(STDERR_FILENO) ) std::cerr << std::flush; else std::cerr << std::endl; lrtc.start(); last = t; lcnt = 0; } } if ( isatty(STDERR_FILENO) ) std::cerr << "\r" << std::string(60,' ') << "\r"; std::cerr << rtc.formatTime(rtc.getElapsedSeconds()) << " " << t/(1024*1024) << "MB, " << (t/rtc.getElapsedSeconds())/(1024.0*1024.0) << "MB/s"; std::cerr << std::endl; return 0; } #endif #if 0 { ::libmaus2::lz::BgzfDeflateParallel BDP(std::cout,32,128,Z_DEFAULT_COMPRESSION); while ( std::cin ) { libmaus2::autoarray::AutoArray<char> B(16384); std::cin.read(B.begin(),B.size()); int64_t const r = std::cin.gcount(); BDP.write(B.begin(),r); } BDP.flush(); std::cout.flush(); } return 0; #endif #if 0 { try { libmaus2::lz::BgzfInflateParallel BIP(std::cin /* ,4,16 */); uint64_t c = 0; uint64_t b = 0; uint64_t d = 0; libmaus2::timing::RealTimeClock rtc; rtc.start(); libmaus2::autoarray::AutoArray<uint8_t> adata(64*1024,false); while ( (d=BIP.read(reinterpret_cast<char *>(adata.begin()),adata.size())) != 0 ) { b += d; if ( ++c % (16*1024) == 0 ) { std::cerr << c << "\t" << b/(1024.0*1024.0*1024.0) << "\t" << static_cast<double>(b)/(1024.0*1024.0*rtc.getElapsedSeconds()) << " MB/s" << std::endl; } } std::cerr << c << "\t" << b/(1024.0*1024.0*1024.0) << "\t" << static_cast<double>(b)/(1024.0*1024.0*rtc.getElapsedSeconds()) << " MB/s" << std::endl; std::cerr << "decoded " << b << " bytes in " << rtc.getElapsedSeconds() << " seconds." << std::endl; } catch(std::exception const & ex) { std::cerr << ex.what() << std::endl; return EXIT_FAILURE; } } return 0; #endif std::cerr << "Testing random data on bgzf..."; testBgzfRandom(); std::cerr << "done." << std::endl; std::cerr << "Testing mono..."; testBgzfMono(); std::cerr << "done." << std::endl; ::libmaus2::lz::BgzfDeflate<std::ostream> bdefl(std::cout); char const * str = "Hello, world.\n"; bdefl.write(reinterpret_cast<char const *>(str),strlen(str)); bdefl.flush(); bdefl.write(reinterpret_cast<char const *>(str),strlen(str)); bdefl.flush(); bdefl.addEOFBlock(); return 0; ::libmaus2::lz::BgzfInflateStream SW(std::cin); ::libmaus2::autoarray::AutoArray<char> BB(200,false); while ( SW.read(BB.begin(),BB.size()) ) { } if ( argc < 2 ) return EXIT_FAILURE; return 0; #if 0 ::libmaus2::lz::GzipHeader GZH(argv[1]); return 0; #endif std::ostringstream ostr; ::libmaus2::autoarray::AutoArray<uint8_t> message = ::libmaus2::util::GetFileSize::readFile(argv[1]); std::cerr << "Deflating message of length " << message.size() << "..."; ::libmaus2::lz::Deflate DEFL(ostr); DEFL.write ( reinterpret_cast<char const *>(message.begin()), message.size() ); DEFL.flush(); std::cerr << "done." << std::endl; std::cerr << "Checking output..."; std::istringstream istr(ostr.str()); ::libmaus2::lz::Inflate INFL(istr); int c; uint64_t i = 0; while ( (c=INFL.get()) >= 0 ) { assert ( c == message[i] ); i++; } std::cerr << "done." << std::endl; // std::cerr << "Message size " << message.size() << std::endl; std::string testfilename = "test"; ::libmaus2::lz::BlockDeflate BD(testfilename); BD.write ( message.begin(), message.size() ); BD.flush(); uint64_t const decpos = message.size() / 3; ::libmaus2::lz::BlockInflate BI(testfilename,decpos); ::libmaus2::autoarray::AutoArray<uint8_t> dmessage (message.size(),false); uint64_t const red = BI.read(dmessage.begin()+decpos,dmessage.size()); assert ( red == dmessage.size()-decpos ); std::cerr << "("; for ( uint64_t i = decpos; i < message.size(); ++i ) assert ( message[i] == dmessage[i] ); std::cerr << ")\n"; std::string shortmes1("123456789"); std::string shortmes2("AA"); std::string shortmes3("BB"); std::string shortmes4("CC"); std::string textfile1("test1"); std::string textfile2("test2"); std::string textfile3("test3"); std::string textfile4("test4"); ::libmaus2::lz::BlockDeflate BD1(textfile1); BD1.write ( reinterpret_cast<uint8_t const *>(shortmes1.c_str()), shortmes1.size() ); BD1.flush(); ::libmaus2::lz::BlockDeflate BD2(textfile2); BD2.write ( reinterpret_cast<uint8_t const *>(shortmes2.c_str()), shortmes2.size() ); BD2.flush(); ::libmaus2::lz::BlockDeflate BD3(textfile3); BD3.write ( reinterpret_cast<uint8_t const *>(shortmes3.c_str()), shortmes3.size() ); BD3.flush(); ::libmaus2::lz::BlockDeflate BD4(textfile4); BD4.write ( reinterpret_cast<uint8_t const *>(shortmes4.c_str()), shortmes4.size() ); BD4.flush(); std::vector < std::string > filenames; filenames.push_back(textfile1); filenames.push_back(textfile2); filenames.push_back(textfile3); filenames.push_back(textfile4); for ( uint64_t j = 0; j <= 15; ++j ) { ::libmaus2::lz::ConcatBlockInflate CBI(filenames,j); for ( uint64_t i = 0; i < j; ++i ) std::cerr << ' '; for ( uint64_t i = 0; i < CBI.n-j; ++i ) std::cerr << (char)CBI.get(); std::cerr << std::endl; } return 0; }
/** unittest for oapackage * * Returns UNITTEST_SUCCESS if all tests are ok. * */ int oaunittest (int verbose, int writetests = 0, int randval = 0) { double t0 = get_time_ms (); const char *bstr = "OA unittest"; cprintf (verbose, "%s: start\n", bstr); srand (randval); int allgood = UNITTEST_SUCCESS; Combinations::initialize_number_combinations (20); /* constructors */ { cprintf (verbose, "%s: interaction matrices\n", bstr); array_link al = exampleArray (2); Eigen::MatrixXd m1 = array2xfeigen (al); Eigen::MatrixXd m2 = arraylink2eigen (array2xf (al)); Eigen::MatrixXd dm = m1 - m2; int sum = dm.sum (); myassert (sum == 0, "unittest error: construction of interaction matrices\n"); } cprintf(verbose, "%s: reduceConferenceTransformation\n", bstr); myassert(unittest_reduceConferenceTransformation()==0, "unittest unittest_reduceConferenceTransformation failed"); /* constructors */ { cprintf (verbose, "%s: array manipulation operations\n", bstr); test_array_manipulation (verbose); } /* double conference matrices */ { cprintf (verbose, "%s: double conference matrices\n", bstr); array_link al = exampleArray (36, verbose); myassert (al.is_conference (2), "check on double conference design type"); myassert (testLMC0checkDC (al, verbose >= 2), "testLMC0checkDC"); } /* conference matrices */ { cprintf (verbose, "%s: conference matrices\n", bstr); int N = 4; conference_t ctype (N, N, 0); arraylist_t kk; array_link al = ctype.create_root (); kk.push_back (al); for (int extcol = 2; extcol < N; extcol++) { kk = extend_conference (kk, ctype, 0); } myassert (kk.size () == 1, "unittest error: conference matrices for N=4\n"); } { cprintf (verbose, "%s: generators for conference matrix extensions\n", bstr); test_conference_candidate_generators (verbose); } { cprintf (verbose, "%s: conference matrix Fvalues\n", bstr); array_link al = exampleArray (22, 0); if (verbose >= 2) al.show (); if (0) { std::vector< int > f3 = al.FvaluesConference (3); if (verbose >= 2) { printf ("F3: "); display_vector (f3); printf ("\n"); } } const int N = al.n_rows; jstructconference_t js (N, 4); std::vector< int > f4 = al.FvaluesConference (4); std::vector< int > j4 = js.Jvalues (); if (verbose >= 2) { printf ("j4: "); display_vector (j4); printf ("\n"); printf ("F4: "); display_vector (f4); printf ("\n"); } myassert (j4[0] == 28, "unittest error: conference matricex F values: j4[0]\n"); myassert (f4[0] == 0, "unittest error: conference matricex F values: f4[0] \n"); myassert (f4[1] == 0, "unittest error: conference matricex F values: j4[1]\n"); } { cprintf (verbose, "%s: LMC0 check for arrays in C(4, 3)\n", bstr); array_link al = exampleArray (28, 1); if (verbose >= 2) al.showarray (); lmc_t r = LMC0check (al, verbose); if (verbose >= 2) printf ("LMC0check: result %d\n", r); myassert (r >= LMC_EQUAL, "LMC0 check\n"); al = exampleArray (29, 1); if (verbose >= 2) al.showarray (); r = LMC0check (al, verbose); if (verbose >= 2) printf ("LMC0check: result %d (LMC_LESS %d)\n", r, LMC_LESS); myassert (r == LMC_LESS, "LMC0 check of example array 29\n"); } { cprintf (verbose, "%s: LMC0 check\n", bstr); array_link al = exampleArray (31, 1); if (verbose >= 2) al.showarray (); conference_transformation_t T (al); for (int i = 0; i < 80; i++) { T.randomize (); array_link alx = T.apply (al); lmc_t r = LMC0check (alx, verbose); if (verbose >= 2) { printfd ("%d: transformed array: r %d\n", i, r); alx.showarray (); } if (alx == al) myassert (r >= LMC_EQUAL, "result should be LMC_MORE\n"); else { myassert (r == LMC_LESS, "result should be LMC_LESS\n"); } } } { cprintf (verbose, "%s: random transformation for conference matrices\n", bstr); array_link al = exampleArray (19, 1); conference_transformation_t T (al); // T.randomizerowflips(); T.randomize (); conference_transformation_t Ti = T.inverse (); array_link alx = Ti.apply (T.apply (al)); if (0) { printf ("input array:\n"); al.showarray (); T.show (); printf ("transformed array:\n"); T.apply (al).showarray (); Ti.show (); alx.showarray (); } myassert (alx == al, "transformation of conference matrix\n"); } /* constructors */ { cprintf (verbose, "%s: constructors\n", bstr); array_transformation_t t; conference_transformation_t ct; } /* J-characteristics */ { cprintf (verbose, "%s: J-characteristics\n", bstr); array_link al = exampleArray (8, 1); const int mm[] = {-1, -1, 0, 0, 8, 16, 0, -1}; for (int jj = 2; jj < 7; jj++) { std::vector< int > jx = al.Jcharacteristics (jj); int j5max = vectormax (jx, 0); if (verbose >= 2) { printf ("oaunittest: jj %d: j5max %d\n", jj, j5max); } if (j5max != mm[jj]) { printfd ("j5max %d (should be %d)\n", j5max, mm[jj]); allgood = UNITTEST_FAIL; return allgood; } } } { cprintf (verbose, "%s: array transformations\n", bstr); const int N = 9; const int t = 3; arraydata_t adataX (3, N, t, 4); array_link al (adataX.N, adataX.ncols, -1); al.create_root (adataX); if (checkTransformationInverse (al)) allgood = UNITTEST_FAIL; if (checkTransformationComposition (al, verbose >= 2)) allgood = UNITTEST_FAIL; al = exampleArray (5, 1); if (checkTransformationInverse (al)) allgood = UNITTEST_FAIL; if (checkTransformationComposition (al)) allgood = UNITTEST_FAIL; for (int i = 0; i < 15; i++) { al = exampleArray (18, 0); if (checkConferenceComposition (al)) allgood = UNITTEST_FAIL; if (checkConferenceInverse (al)) allgood = UNITTEST_FAIL; al = exampleArray (19, 0); if (checkConferenceComposition (al)) allgood = UNITTEST_FAIL; if (checkConferenceInverse (al)) allgood = UNITTEST_FAIL; } } { cprintf (verbose, "%s: rank \n", bstr); const int idx[10] = {0, 1, 2, 3, 4, 6, 7, 8, 9}; const int rr[10] = {4, 11, 13, 18, 16, 4, 4, 29, 29}; for (int ii = 0; ii < 9; ii++) { array_link al = exampleArray (idx[ii], 0); myassert (al.is2level (), "unittest error: input array is not 2-level\n"); int r = arrayrankColPivQR (array2xf (al)); int r3 = (array2xf (al)).rank (); myassert (r == r3, "unittest error: rank of array"); if (verbose >= 2) { al.showarray (); printf ("unittest: rank of array %d: %d\n", idx[ii], r); } myassert (rr[ii] == r, "unittest error: rank of example matrix\n"); } } { cprintf (verbose, "%s: Doptimize \n", bstr); const int N = 40; const int t = 0; arraydata_t arrayclass (2, N, t, 6); std::vector< double > alpha (3); alpha[0] = 1; alpha[1] = 1; alpha[2] = 0; int niter = 5000; double t00 = get_time_ms (); DoptimReturn rr = Doptimize (arrayclass, 10, alpha, 0, DOPTIM_AUTOMATIC, niter); array_t ss[7] = {3, 3, 2, 2, 2, 2, 2}; arraydata_t arrayclassmixed (ss, 36, t, 5); rr = Doptimize (arrayclassmixed, 10, alpha, 0, DOPTIM_AUTOMATIC, niter); cprintf (verbose, "%s: Doptimize time %.3f [s] \n", bstr, get_time_ms () - t00); } { cprintf (verbose, "%s: J-characteristics for conference matrix\n", bstr); array_link al = exampleArray (19, 0); std::vector< int > j2 = Jcharacteristics_conference (al, 2); std::vector< int > j3 = Jcharacteristics_conference (al, 3); myassert (j2[0] == 0, "j2 value incorrect"); myassert (j2[1] == 0, "j2 value incorrect"); myassert (std::abs (j3[0]) == 1, "j3 value incorrect"); if (verbose >= 2) { al.showarray (); printf ("j2: "); display_vector (j2); printf ("\n"); printf ("j3: "); display_vector (j3); printf ("\n"); } } { // test PEC sequence cprintf (verbose, "%s: PEC sequence\n", bstr); for (int ii = 0; ii < 5; ii++) { array_link al = exampleArray (ii, 0); std::vector< double > pec = PECsequence (al); printf ("oaunittest: PEC for array %d: ", ii); display_vector (pec); printf (" \n"); } } { cprintf (verbose, "%s: D-efficiency test\n", bstr); // D-efficiency near-zero test { array_link al = exampleArray (14); double D = al.Defficiency (); std::vector< double > dd = al.Defficiencies (); printf ("D %f, D (method 2) %f\n", D, dd[0]); assert (fabs (D - dd[0]) < 1e-4); } { array_link al = exampleArray (15); double D = al.Defficiency (); std::vector< double > dd = al.Defficiencies (); printf ("D %f, D (method 2) %f\n", D, dd[0]); assert (fabs (D - dd[0]) < 1e-4); assert (fabs (D - 0.335063) < 1e-3); } } arraydata_t adata (2, 20, 2, 6); OAextend oaextendx; oaextendx.setAlgorithm ((algorithm_t)MODE_ORIGINAL, &adata); std::vector< arraylist_t > aa (adata.ncols + 1); printf ("OA unittest: create root array\n"); create_root (&adata, aa[adata.strength]); /** Test extend of arrays **/ { cprintf (verbose, "%s: extend arrays\n", bstr); setloglevel (SYSTEM); for (int kk = adata.strength; kk < adata.ncols; kk++) { aa[kk + 1] = extend_arraylist (aa[kk], adata, oaextendx); printf (" extend: column %d->%d: %ld->%ld arrays\n", kk, kk + 1, aa[kk].size (), aa[kk + 1].size ()); } if (aa[adata.ncols].size () != 75) { printf ("extended ?? to %d arrays\n", (int)aa[adata.ncols].size ()); } myassert (aa[adata.ncols].size () == 75, "number of arrays is incorrect"); aa[adata.ncols].size (); setloglevel (QUIET); } { cprintf (verbose, "%s: test LMC check\n", bstr); array_link al = exampleArray (1, 1); lmc_t r = LMCcheckOriginal (al); myassert (r != LMC_LESS, "LMC check of array in normal form"); for (int i = 0; i < 20; i++) { array_link alx = al.randomperm (); if (alx == al) continue; lmc_t r = LMCcheckOriginal (alx); myassert (r == LMC_LESS, "randomized array cannot be in minimal form"); } } { /** Test dof **/ cprintf (verbose, "%s: test delete-one-factor reduction\n", bstr); array_link al = exampleArray (4); cprintf (verbose >= 2, "LMC: \n"); al.reduceLMC (); cprintf (verbose >= 2, "DOP: \n"); al.reduceDOP (); } arraylist_t lst; { /** Test different methods **/ cprintf (verbose, "%s: test 2 different methods\n", bstr); const int s = 2; arraydata_t adata (s, 32, 3, 10); arraydata_t adata2 (s, 32, 3, 10); OAextend oaextendx; oaextendx.setAlgorithm ((algorithm_t)MODE_ORIGINAL, &adata); OAextend oaextendx2; oaextendx2.setAlgorithm ((algorithm_t)MODE_LMC_2LEVEL, &adata2); printf ("OA unittest: test 2-level algorithm on %s\n", adata.showstr ().c_str ()); std::vector< arraylist_t > aa (adata.ncols + 1); create_root (&adata, aa[adata.strength]); std::vector< arraylist_t > aa2 (adata.ncols + 1); create_root (&adata, aa2[adata.strength]); setloglevel (SYSTEM); for (int kk = adata.strength; kk < adata.ncols; kk++) { aa[kk + 1] = extend_arraylist (aa[kk], adata, oaextendx); aa2[kk + 1] = extend_arraylist (aa2[kk], adata2, oaextendx2); printf (" extend: column %d->%d: %ld->%ld arrays, 2-level method %ld->%ld arrays\n", kk, kk + 1, (long) aa[kk].size (), (long)aa[kk + 1].size (), aa2[kk].size (), aa2[kk + 1].size ()); if (aa[kk + 1] != aa2[kk + 1]) { printf ("oaunittest: error: 2-level algorithm unequal to original algorithm\n"); exit (1); } } setloglevel (QUIET); lst = aa[8]; } { cprintf (verbose, "%s: rank calculation using rankStructure\n", bstr); for (int i = 0; i < 27; i++) { array_link al = exampleArray (i, 0); if (al.n_columns < 5) continue; al = exampleArray (i, 1); rankStructure rs; rs.verbose = 0; int r = array2xf (al).rank (); int rc = rs.rankxf (al); if (verbose >= 2) { printf ("rank of example array %d: %d %d\n", i, r, rc); if (verbose >= 3) { al.showproperties (); } } myassert (r == rc, "rank calculations"); } } { cprintf (verbose, "%s: test dtable creation\n", bstr); for (int i = 0; i < 4; i++) { array_link al = exampleArray (5); array_link dtable = createJdtable (al); } } { cprintf (verbose, "%s: test Pareto calculation\n", bstr); double t0x = get_time_ms (); int nn = lst.size (); for (int k = 0; k < 5; k++) { for (int i = 0; i < nn; i++) { lst.push_back (lst[i]); } } Pareto< mvalue_t< long >, long > r = parsePareto (lst, 1); cprintf (verbose, "%s: test Pareto %d/%d: %.3f [s]\n", bstr, r.number (), r.numberindices (), (get_time_ms () - t0x)); } { cprintf (verbose, "%s: check reduction transformation\n", bstr); array_link al = exampleArray (6).reduceLMC (); arraydata_t adata = arraylink2arraydata (al); LMCreduction_t reduction (&adata); reduction.mode = OA_REDUCE; reduction.init_state = COPY; OAextend oaextend; oaextend.setAlgorithm (MODE_ORIGINAL, &adata); array_link alr = al.randomperm (); array_link al2 = reduction.transformation->apply (al); lmc_t tmp = LMCcheck (alr, adata, oaextend, reduction); array_link alx = reduction.transformation->apply (alr); bool c = alx == al; if (!c) { printf ("oaunittest: error: reduction of randomized array failed!\n"); printf ("-- al \n"); al.showarraycompact (); printf ("-- alr \n"); alr.showarraycompact (); printf ("-- alx \n"); alx.showarraycompact (); allgood = UNITTEST_FAIL; } } { cprintf (verbose, "%s: reduce randomized array\n", bstr); array_link al = exampleArray (3); arraydata_t adata = arraylink2arraydata (al); LMCreduction_t reduction (&adata); for (int ii = 0; ii < 50; ii++) { reduction.transformation->randomize (); array_link al2 = reduction.transformation->apply (al); array_link alr = al2.reduceLMC (); if (0) { printf ("\n reduction complete:\n"); al2.showarray (); printf (" --->\n"); alr.showarray (); } bool c = (al == alr); if (!c) { printf ("oaunittest: error: reduction of randomized array failed!\n"); allgood = UNITTEST_FAIL; } } } /* Calculate symmetry group */ { cprintf (verbose, "%s: calculate symmetry group\n", bstr); array_link al = exampleArray (2); symmetry_group sg = al.row_symmetry_group (); assert (sg.permsize () == sg.permsize_large ().toLong ()); // symmetry_group std::vector< int > vv; vv.push_back (0); vv.push_back (0); vv.push_back (1); symmetry_group sg2 (vv); assert (sg2.permsize () == 2); if (verbose >= 2) printf ("sg2: %ld\n", sg2.permsize ()); assert (sg2.ngroups == 2); } /* Test efficiencies */ { cprintf (verbose, "%s: efficiencies\n", bstr); std::vector< double > d; int vb = 1; array_link al; if (1) { al = exampleArray (9, vb); al.showproperties (); d = al.Defficiencies (0, 1); if (verbose >= 2) printf (" efficiencies: D %f Ds %f D1 %f Ds0 %f\n", d[0], d[1], d[2], d[3]); if (fabs (d[0] - al.Defficiency ()) > 1e-10) { printf ("oaunittest: error: Defficiency not good!\n"); allgood = UNITTEST_FAIL; } } al = exampleArray (8, vb); al.showproperties (); d = al.Defficiencies (); if (verbose >= 2) printf (" efficiencies: D %f Ds %f D1 %f\n", d[0], d[1], d[2]); if (fabs (d[0] - al.Defficiency ()) > 1e-10) { printf ("oaunittest: error: Defficiency of examlple array 8 not good!\n"); } al = exampleArray (13, vb); if (verbose >= 3) { al.showarray (); al.showproperties (); } d = al.Defficiencies (0, 1); if (verbose >= 2) printf (" efficiencies: D %f Ds %f D1 %f\n", d[0], d[1], d[2]); if ((fabs (d[0] - 0.939014) > 1e-4) || (fabs (d[3] - 0.896812) > 1e-4) || (fabs (d[2] - 1) > 1e-4)) { printf ("ERROR: D-efficiencies of example array 13 incorrect! \n"); d = al.Defficiencies (2, 1); printf (" efficiencies: D %f Ds %f D1 %f Ds0 %f\n", d[0], d[1], d[2], d[3]); allgood = UNITTEST_FAIL; exit (1); } for (int ii = 11; ii < 11; ii++) { printf ("ii %d: ", ii); al = exampleArray (ii, vb); al.showarray (); al.showproperties (); d = al.Defficiencies (); if (verbose >= 2) printf (" efficiencies: D %f Ds %f D1 %f\n", d[0], d[1], d[2]); } } { cprintf (verbose, "%s: test robustness\n", bstr); array_link A (0, 8, 0); printf ("should return an error\n "); A.Defficiencies (); A = array_link (1, 8, 0); printf ("should return an error\n "); A.at (0, 0) = -2; A.Defficiencies (); } { cprintf (verbose, "%s: test nauty\n", bstr); array_link alr = exampleArray (7, 0); if (unittest_nautynormalform (alr, 1) == 0) { printf ("oaunittest: error: unittest_nautynormalform returns an error!\n"); } } #ifdef HAVE_BOOST if (writetests) { cprintf (verbose, "OA unittest: reading and writing of files\n"); boost::filesystem::path tmpdir = boost::filesystem::temp_directory_path (); boost::filesystem::path temp = boost::filesystem::unique_path ("test-%%%%%%%.oa"); const std::string tempstr = (tmpdir / temp).native (); if (verbose >= 2) printf ("generate text OA file: %s\n", tempstr.c_str ()); int nrows = 16; int ncols = 8; int narrays = 10; arrayfile_t afile (tempstr.c_str (), nrows, ncols, narrays, ATEXT); for (int i = 0; i < narrays; i++) { array_link al (nrows, ncols, array_link::INDEX_DEFAULT); afile.append_array (al); } afile.closefile (); arrayfile_t af (tempstr.c_str (), 0); std::cout << " " << af.showstr () << std::endl; af.closefile (); // check read/write of binary file arraylist_t ll0; ll0.push_back (exampleArray (7)); ll0.push_back (exampleArray (7).randomcolperm ()); writearrayfile (tempstr.c_str (), ll0, ABINARY); arraylist_t ll = readarrayfile (tempstr.c_str ()); myassert (ll0.size () == ll.size (), "read and write of arrays: size of list"); for (size_t i = 0; i < ll0.size (); i++) { myassert (ll0[i] == ll[i], "read and write of arrays: array unequal"); } ll0.resize (0); ll0.push_back (exampleArray (24)); writearrayfile (tempstr.c_str (), ll0, ABINARY_DIFFZERO); ll = readarrayfile (tempstr.c_str ()); myassert (ll0.size () == ll.size (), "read and write of arrays: size of list"); for (size_t i = 0; i < ll0.size (); i++) { myassert (ll0[i] == ll[i], "read and write of arrays: array unequal"); } } #endif { cprintf (verbose, "OA unittest: test nauty\n"); array_link al = exampleArray (5, 2); arraydata_t arrayclass = arraylink2arraydata (al); for (int i = 0; i < 20; i++) { array_link alx = al; alx.randomperm (); array_transformation_t t1 = reduceOAnauty (al); array_link alr1 = t1.apply (al); array_transformation_t t2 = reduceOAnauty (alx); array_link alr2 = t2.apply (alx); if (alr1 != alr2) printf ("oaunittest: error: Nauty reductions unequal!\n"); allgood = UNITTEST_FAIL; } } cprintf (verbose, "OA unittest: complete %.3f [s]!\n", (get_time_ms () - t0)); cprintf (verbose, "OA unittest: also run ptest.py to perform checks!\n"); if (allgood) { printf ("OA unittest: all tests ok\n"); return UNITTEST_SUCCESS; } else { printf ("OA unittest: ERROR!\n"); return UNITTEST_FAIL; } }
/////////////////////////////////////////////////////////////////////////////// // // init() is called whenever the cpi's instance data have changed. In that // case, it re-initializes the proxy directory instance which points into the // locally mounted sshfs name spaces, or into the local file system in // general. // // init() will generally throw if the idata->location points elsewhere. // init() is however assumed to be atomic, so it either succeeds, or it fails // but then leaves the object state unchanged. That way, the individual // methods don't need to attempt to recover from a failed init. The only side // effect can be an additionally mounted sshfs, which is getting cleaned up by // the adaptor d'tor (that cleanup is optional though). // // The single argument, the url 'save', is used to restore state on failure // void file_cpi_impl::init (void) { adaptor_instance_data_t adata (this); file_instance_data_t idata (this); if ( idata->location_.get_scheme () != "ssh" && idata->location_.get_scheme () != "any" ) { SAGA_LOG_DEBUG ("sshfs can not handle url:"); SAGA_LOG_DEBUG (idata->location_.get_string ().c_str ()); std::stringstream ss; ss << "Cannot handle URL scheme " << idata->location_.get_scheme () << " - can only handle schemas 'ssh' or 'any'." << std::endl; SAGA_ADAPTOR_THROW_NO_CONTEXT (ss.str ().c_str (), saga::adaptors::AdaptorDeclined); } // create a new api object from the changed instance data. bool success = false; saga::exception ex ("", saga::NoSuccess); saga::url new_url; try { new_url = adata->translate (s_, idata->location_); success = true; } catch ( const saga::exception & e ) { ex = e; } if ( success ) { try { f_ = saga::filesystem::file (adata->strip_session (s_), new_url, idata->mode_); } catch ( const saga::exception & e ) { std::stringstream ss; ss << "Cannot handle URL 5: \n\t" << e.what () << "\n"; SSH_ADAPTOR_RETHROW (e, ss.str ().c_str (), saga::BadParameter); } } else { try { new_url = adata->translate (s_, idata->location_); f_ = saga::filesystem::file (adata->strip_session (s_), new_url, idata->mode_); } catch ( const saga::exception & e ) { // FIXME: shouldn't we merge e and ex? std::stringstream ss; ss << "Cannot handle URL 6: \n\t" << ex.what () << "\n"; SSH_ADAPTOR_RETHROW (ex, ss.str ().c_str (), saga::BadParameter); } } }
// wait for the child process to terminate void job_cpi_impl::sync_wait (bool & ret, double timeout) { adaptor_data_type adata(this); drmaa_->wait_job(jobid_, (int)timeout); }
static const bfd_target * aout_adobe_callback (bfd *abfd) { struct internal_exec *execp = exec_hdr (abfd); asection *sect; struct external_segdesc ext[1]; char *section_name; char try_again[30]; /* Name and number. */ char *newname; int trynum; flagword flags; /* Architecture and machine type -- unknown in this format. */ bfd_set_arch_mach (abfd, bfd_arch_unknown, 0L); /* The positions of the string table and symbol table. */ obj_str_filepos (abfd) = N_STROFF (*execp); obj_sym_filepos (abfd) = N_SYMOFF (*execp); /* Suck up the section information from the file, one section at a time. */ for (;;) { bfd_size_type amt = sizeof (*ext); if (bfd_bread ( ext, amt, abfd) != amt) { if (bfd_get_error () != bfd_error_system_call) bfd_set_error (bfd_error_wrong_format); return NULL; } switch (ext->e_type[0]) { case N_TEXT: section_name = ".text"; flags = SEC_CODE | SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS; break; case N_DATA: section_name = ".data"; flags = SEC_DATA | SEC_LOAD | SEC_ALLOC | SEC_HAS_CONTENTS; break; case N_BSS: section_name = ".bss"; flags = SEC_DATA | SEC_HAS_CONTENTS; break; case 0: goto no_more_sections; default: (*_bfd_error_handler) (_("%B: Unknown section type in a.out.adobe file: %x\n"), abfd, ext->e_type[0]); goto no_more_sections; } /* First one is called ".text" or whatever; subsequent ones are ".text1", ".text2", ... */ bfd_set_error (bfd_error_no_error); sect = bfd_make_section_with_flags (abfd, section_name, flags); trynum = 0; while (!sect) { if (bfd_get_error () != bfd_error_no_error) /* Some other error -- slide into the sunset. */ return NULL; sprintf (try_again, "%s%d", section_name, ++trynum); sect = bfd_make_section_with_flags (abfd, try_again, flags); } /* Fix the name, if it is a sprintf'd name. */ if (sect->name == try_again) { amt = strlen (sect->name); newname = bfd_zalloc (abfd, amt); if (newname == NULL) return NULL; strcpy (newname, sect->name); sect->name = newname; } /* Assumed big-endian. */ sect->size = ((ext->e_size[0] << 8) | ext->e_size[1] << 8 | ext->e_size[2]); sect->vma = H_GET_32 (abfd, ext->e_virtbase); sect->filepos = H_GET_32 (abfd, ext->e_filebase); /* FIXME XXX alignment? */ /* Set relocation information for first section of each type. */ if (trynum == 0) switch (ext->e_type[0]) { case N_TEXT: sect->rel_filepos = N_TRELOFF (*execp); sect->reloc_count = execp->a_trsize; break; case N_DATA: sect->rel_filepos = N_DRELOFF (*execp); sect->reloc_count = execp->a_drsize; break; default: break; } } no_more_sections: adata (abfd).reloc_entry_size = sizeof (struct reloc_std_external); adata (abfd).symbol_entry_size = sizeof (struct external_nlist); adata (abfd).page_size = 1; /* Not applicable. */ adata (abfd).segment_size = 1; /* Not applicable. */ adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE; return abfd->xvec; }
void file_cpi_impl::sync_copy (saga::impl::void_t & ret, saga::url dest, int flags) { adaptor_data_t adata (this); file_instance_data_t idata (this); // check preconditions // We can only check coditions for local targets if ( saga::adaptors::utils::is_local_address (dest) ) { saga::filesystem::directory loc ("/"); if ( loc.exists (dest.get_path ()) ) { if ( ! (flags & saga::name_space::Overwrite) ) { std::stringstream ss; ss << "Target exists: " << dest; SAGA_ADAPTOR_THROW (ss.str (), saga::AlreadyExists); } } } std::string src (u_.get_string ()); std::string tgt (dest.get_string ()); CURLcode code; // get handle for input and output curl ops (see README) CURL * in = adata->get_curl_handle_in (); CURL * out = adata->get_curl_handle_out (); // create buffer file FILE * buf = ::fopen ("/tmp/curl-cache.dat", "w+"); ensure (NULL != buf, "fopen() failed: ", ::strerror (errno)); // read data into buffer code = curl_easy_setopt (in, CURLOPT_URL, src.c_str ()); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_setopt (in, CURLOPT_WRITEDATA, buf); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_perform (in); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); // data are in buffer - now rewind buffer, and copy data to target location ::rewind (buf); code = curl_easy_setopt (out, CURLOPT_URL, tgt.c_str ()); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_setopt (out, CURLOPT_VERBOSE, "true"); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_setopt (out, CURLOPT_USERPWD, "merzky:Z(I)nfandel"); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_setopt (out, CURLOPT_UPLOAD, "true"); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_setopt (out, CURLOPT_READDATA, buf); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); code = curl_easy_perform (out); ensure (0 == code, "Curl Error: ", curl_easy_strerror (code)); ::fclose (buf); // done :-) }