int cellGameGetParamInt(u32 id, mem32_t value) { cellGame.Warning("cellGameGetParamInt(id=%d, value_addr=0x%x)", id, value.GetAddr()); if(!value.IsGood()) return CELL_GAME_ERROR_PARAM; // TODO: Locate the PARAM.SFO. The following path is in most cases wrong. vfsFile f("/app_home/PARAM.SFO"); PSFLoader psf(f); if(!psf.Load(false)) return CELL_GAME_ERROR_FAILURE; switch(id) { case CELL_GAME_PARAMID_PARENTAL_LEVEL: value = psf.m_info.parental_lvl; break; case CELL_GAME_PARAMID_RESOLUTION: value = psf.m_info.resolution; break; case CELL_GAME_PARAMID_SOUND_FORMAT: value = psf.m_info.sound_format; break; default: return CELL_GAME_ERROR_INVALID_ID; } return CELL_OK; }
void addSaveDataEntry(std::vector<SaveDataEntry>& saveEntries, const std::string& saveDir) { // PSF parameters vfsFile f(saveDir + "/PARAM.SFO"); PSFLoader psf(f); if(!psf.Load(false)) return; // PNG icon std::string localPath; Emu.GetVFS().GetDevice(saveDir + "/ICON0.PNG", localPath); SaveDataEntry saveEntry; saveEntry.dirName = psf.GetString("SAVEDATA_DIRECTORY"); saveEntry.listParam = psf.GetString("SAVEDATA_LIST_PARAM"); saveEntry.title = psf.GetString("TITLE"); saveEntry.subtitle = psf.GetString("SUB_TITLE"); saveEntry.details = psf.GetString("DETAIL"); saveEntry.sizeKB = getSaveDataSize(saveDir)/1024; saveEntry.st_atime_ = 0; // TODO saveEntry.st_mtime_ = 0; // TODO saveEntry.st_ctime_ = 0; // TODO saveEntry.iconBuf = NULL; // TODO: Here should be the PNG buffer saveEntry.iconBufSize = 0; // TODO: Size of the PNG file saveEntry.isNew = false; saveEntries.push_back(saveEntry); }
int cellGameBootCheck(mem32_t type, mem32_t attributes, mem_ptr_t<CellGameContentSize> size, mem_list_ptr_t<u8> dirName) { cellGame.Warning("cellGameBootCheck(type_addr=0x%x, attributes_addr=0x%x, size_addr=0x%x, dirName_addr=0x%x)", type.GetAddr(), attributes.GetAddr(), size.GetAddr(), dirName.GetAddr()); if (!type.IsGood() || !attributes.IsGood() || !size.IsGood() || !dirName.IsGood()) { cellGame.Warning("cellGameBootCheck returns CELL_GAME_ERROR_PARAM. As a result size->hddFreeSizeKB may be 0."); return CELL_GAME_ERROR_PARAM; } // TODO: Only works for HDD games type = CELL_GAME_GAMETYPE_HDD; attributes = 0; size->hddFreeSizeKB = 40000000; //40 GB, TODO: Use the free space of the computer's HDD where RPCS3 is being run. size->sizeKB = CELL_GAME_SIZEKB_NOTCALC; size->sysSizeKB = 0; // TODO: Locate the PARAM.SFO. The following path may be wrong. vfsFile f("/app_home/PARAM.SFO"); PSFLoader psf(f); if(!psf.Load(false)) return CELL_GAME_ERROR_FAILURE; std::string titleId = psf.GetString("TITLE_ID"); Memory.WriteString(dirName.GetAddr(), titleId); return CELL_OK; }
int cellGameGetParamInt(u32 id, mem32_t value) { cellGame.Warning("cellGameGetParamInt(id=%d, value_addr=0x%x)", id, value.GetAddr()); if(!value.IsGood()) return CELL_GAME_ERROR_PARAM; // TODO: Locate the PARAM.SFO. The following path may be wrong. vfsFile f("/app_home/PARAM.SFO"); PSFLoader psf(f); if(!psf.Load(false)) return CELL_GAME_ERROR_FAILURE; switch(id) { case CELL_GAME_PARAMID_PARENTAL_LEVEL: value = psf.GetInteger("PARENTAL_LEVEL"); break; case CELL_GAME_PARAMID_RESOLUTION: value = psf.GetInteger("RESOLUTION"); break; case CELL_GAME_PARAMID_SOUND_FORMAT: value = psf.GetInteger("SOUND_FORMAT"); break; default: return CELL_GAME_ERROR_INVALID_ID; } return CELL_OK; }
int cellGameGetParamString(u32 id, mem_list_ptr_t<u8> buf, u32 bufsize) { cellGame.Warning("cellGameGetParamString(id=%d, buf_addr=0x%x, bufsize=%d)", id, buf.GetAddr(), bufsize); if(!buf.IsGood()) return CELL_GAME_ERROR_PARAM; // TODO: Locate the PARAM.SFO. The following path is in most cases wrong. vfsFile f("/app_home/PARAM.SFO"); PSFLoader psf(f); if(!psf.Load(false)) return CELL_GAME_ERROR_FAILURE; switch(id) { // WARNING: Is there any difference between all these "CELL_GAME_PARAMID_TITLE*" IDs? case CELL_GAME_PARAMID_TITLE: case CELL_GAME_PARAMID_TITLE_DEFAULT: case CELL_GAME_PARAMID_TITLE_JAPANESE: case CELL_GAME_PARAMID_TITLE_ENGLISH: case CELL_GAME_PARAMID_TITLE_FRENCH: case CELL_GAME_PARAMID_TITLE_SPANISH: case CELL_GAME_PARAMID_TITLE_GERMAN: case CELL_GAME_PARAMID_TITLE_ITALIAN: case CELL_GAME_PARAMID_TITLE_DUTCH: case CELL_GAME_PARAMID_TITLE_PORTUGUESE: case CELL_GAME_PARAMID_TITLE_RUSSIAN: case CELL_GAME_PARAMID_TITLE_KOREAN: case CELL_GAME_PARAMID_TITLE_CHINESE_T: case CELL_GAME_PARAMID_TITLE_CHINESE_S: case CELL_GAME_PARAMID_TITLE_FINNISH: case CELL_GAME_PARAMID_TITLE_SWEDISH: case CELL_GAME_PARAMID_TITLE_DANISH: case CELL_GAME_PARAMID_TITLE_NORWEGIAN: case CELL_GAME_PARAMID_TITLE_POLISH: case CELL_GAME_PARAMID_TITLE_PORTUGUESE_BRAZIL: case CELL_GAME_PARAMID_TITLE_ENGLISH_UK: Memory.WriteString(buf.GetAddr(), psf.m_info.name.Left(bufsize)); break; case CELL_GAME_PARAMID_TITLE_ID: Memory.WriteString(buf.GetAddr(), psf.m_info.serial.Left(bufsize)); break; case CELL_GAME_PARAMID_VERSION: Memory.WriteString(buf.GetAddr(), psf.m_info.fw.Left(bufsize)); break; case CELL_GAME_PARAMID_APP_VER: Memory.WriteString(buf.GetAddr(), psf.m_info.app_ver.Left(bufsize)); break; default: return CELL_GAME_ERROR_INVALID_ID; } return CELL_OK; }
/***********************************************************************//** * @brief Write point spread function into FITS table * * @param[in] table FITS binary table. * * Writes point spread function into a FITS binary @p table. * * @todo Add keywords. ***************************************************************************/ void GCTAPsfTable::write(GFitsBinTable& table) const { // Create a copy of the response table GCTAResponseTable psf(m_psf); // Write response table psf.write(table); // Return return; }
int cellGameGetParamString(u32 id, u32 buf_addr, u32 bufsize) { cellGame.Warning("cellGameGetParamString(id=%d, buf_addr=0x%x, bufsize=%d)", id, buf_addr, bufsize); if(!Memory.IsGoodAddr(buf_addr)) return CELL_GAME_ERROR_PARAM; // TODO: Locate the PARAM.SFO. The following path may be wrong. vfsFile f("/app_home/PARAM.SFO"); PSFLoader psf(f); if(!psf.Load(false)) return CELL_GAME_ERROR_FAILURE; std::string data; switch(id) { case CELL_GAME_PARAMID_TITLE: data = psf.GetString("TITLE"); break; // TODO: Is this value correct? case CELL_GAME_PARAMID_TITLE_DEFAULT: data = psf.GetString("TITLE"); break; case CELL_GAME_PARAMID_TITLE_JAPANESE: data = psf.GetString("TITLE_00"); break; case CELL_GAME_PARAMID_TITLE_ENGLISH: data = psf.GetString("TITLE_01"); break; case CELL_GAME_PARAMID_TITLE_FRENCH: data = psf.GetString("TITLE_02"); break; case CELL_GAME_PARAMID_TITLE_SPANISH: data = psf.GetString("TITLE_03"); break; case CELL_GAME_PARAMID_TITLE_GERMAN: data = psf.GetString("TITLE_04"); break; case CELL_GAME_PARAMID_TITLE_ITALIAN: data = psf.GetString("TITLE_05"); break; case CELL_GAME_PARAMID_TITLE_DUTCH: data = psf.GetString("TITLE_06"); break; case CELL_GAME_PARAMID_TITLE_PORTUGUESE: data = psf.GetString("TITLE_07"); break; case CELL_GAME_PARAMID_TITLE_RUSSIAN: data = psf.GetString("TITLE_08"); break; case CELL_GAME_PARAMID_TITLE_KOREAN: data = psf.GetString("TITLE_09"); break; case CELL_GAME_PARAMID_TITLE_CHINESE_T: data = psf.GetString("TITLE_10"); break; case CELL_GAME_PARAMID_TITLE_CHINESE_S: data = psf.GetString("TITLE_11"); break; case CELL_GAME_PARAMID_TITLE_FINNISH: data = psf.GetString("TITLE_12"); break; case CELL_GAME_PARAMID_TITLE_SWEDISH: data = psf.GetString("TITLE_13"); break; case CELL_GAME_PARAMID_TITLE_DANISH: data = psf.GetString("TITLE_14"); break; case CELL_GAME_PARAMID_TITLE_NORWEGIAN: data = psf.GetString("TITLE_15"); break; case CELL_GAME_PARAMID_TITLE_POLISH: data = psf.GetString("TITLE_16"); break; case CELL_GAME_PARAMID_TITLE_PORTUGUESE_BRAZIL: data = psf.GetString("TITLE_17"); break; case CELL_GAME_PARAMID_TITLE_ENGLISH_UK: data = psf.GetString("TITLE_18"); break; case CELL_GAME_PARAMID_TITLE_ID: data = psf.GetString("TITLE_ID"); break; case CELL_GAME_PARAMID_VERSION: data = psf.GetString("PS3_SYSTEM_VER"); break; case CELL_GAME_PARAMID_APP_VER: data = psf.GetString("APP_VER"); break; default: return CELL_GAME_ERROR_INVALID_ID; } data.resize(bufsize-1); Memory.WriteString(buf_addr, data.c_str()); return CELL_OK; }
void GameViewer::LoadPSF() { m_game_data.Clear(); for(uint i=0; i<m_games.GetCount(); ++i) { const wxString& path = m_games[i] + "\\" + "PARAM.SFO"; if(!wxFileExists(path)) continue; vfsLocalFile f(path); PSFLoader psf(f); if(!psf.Load(false)) continue; psf.m_info.root = m_games[i]; m_game_data.Add(new GameInfo(psf.m_info)); } m_columns.Update(m_game_data); }
/***********************************************************************//** * @brief Write point spread function into FITS binary table * * @param[in] table FITS binary table. * * Writes point spread function into FITS binary @p table. * * @todo Add necessary keywords. ***************************************************************************/ void GCTAPsf2D::write(GFitsBinTable& table) const { // Create a copy of the response table GCTAResponseTable psf(m_psf); // Convert sigma parameters back to degrees psf.scale(m_inx_sigma1, gammalib::rad2deg); psf.scale(m_inx_sigma2, gammalib::rad2deg); psf.scale(m_inx_sigma3, gammalib::rad2deg); // Write response table psf.write(table); // Return return; }
int cellGamePatchCheck(vm::ptr<CellGameContentSize> size, u32 reserved_addr) { cellGame->Warning("cellGamePatchCheck(size_addr=0x%x, reserved_addr=0x%x)", size.addr(), reserved_addr); if (reserved_addr != 0) { cellGame->Error("cellGamePatchCheck(): CELL_GAME_ERROR_PARAM"); return CELL_GAME_ERROR_PARAM; } if (size) { // TODO: Use the free space of the computer's HDD where RPCS3 is being run. size->hddFreeSizeKB = 40000000; // 40 GB // TODO: Calculate data size for patch data, if necessary. size->sizeKB = CELL_GAME_SIZEKB_NOTCALC; size->sysSizeKB = 0; } vfsFile f("/app_home/PARAM.SFO"); if (!f.IsOpened()) { cellGame->Error("cellGamePatchCheck(): CELL_GAME_ERROR_ACCESS_ERROR (cannot open PARAM.SFO)"); return CELL_GAME_ERROR_ACCESS_ERROR; } PSFLoader psf(f); if (!psf.Load(false)) { cellGame->Error("cellGamePatchCheck(): CELL_GAME_ERROR_ACCESS_ERROR (cannot read PARAM.SFO)"); return CELL_GAME_ERROR_ACCESS_ERROR; } std::string category = psf.GetString("CATEGORY"); if (category.substr(0, 2) != "GD") { cellGame->Error("cellGamePatchCheck(): CELL_GAME_ERROR_NOTPATCH"); return CELL_GAME_ERROR_NOTPATCH; } std::string titleId = psf.GetString("TITLE_ID"); contentInfo = "/dev_hdd0/game/" + titleId; usrdir = "/dev_hdd0/game/" + titleId + "/USRDIR"; return CELL_GAME_RET_OK; }
int cellGameGetParamString(u32 id, vm::ptr<char> buf, u32 bufsize) { cellGame->Warning("cellGameGetParamString(id=%d, buf_addr=0x%x, bufsize=%d)", id, buf.addr(), bufsize); // TODO: Access through cellGame***Check functions vfsFile f("/app_home/PARAM.SFO"); PSFLoader psf(f); if(!psf.Load(false)) return CELL_GAME_ERROR_FAILURE; std::string data; switch(id) { case CELL_GAME_PARAMID_TITLE: data = psf.GetString("TITLE"); break; // TODO: Is this value correct? case CELL_GAME_PARAMID_TITLE_DEFAULT: data = psf.GetString("TITLE"); break; case CELL_GAME_PARAMID_TITLE_JAPANESE: data = psf.GetString("TITLE_00"); break; case CELL_GAME_PARAMID_TITLE_ENGLISH: data = psf.GetString("TITLE_01"); break; case CELL_GAME_PARAMID_TITLE_FRENCH: data = psf.GetString("TITLE_02"); break; case CELL_GAME_PARAMID_TITLE_SPANISH: data = psf.GetString("TITLE_03"); break; case CELL_GAME_PARAMID_TITLE_GERMAN: data = psf.GetString("TITLE_04"); break; case CELL_GAME_PARAMID_TITLE_ITALIAN: data = psf.GetString("TITLE_05"); break; case CELL_GAME_PARAMID_TITLE_DUTCH: data = psf.GetString("TITLE_06"); break; case CELL_GAME_PARAMID_TITLE_PORTUGUESE: data = psf.GetString("TITLE_07"); break; case CELL_GAME_PARAMID_TITLE_RUSSIAN: data = psf.GetString("TITLE_08"); break; case CELL_GAME_PARAMID_TITLE_KOREAN: data = psf.GetString("TITLE_09"); break; case CELL_GAME_PARAMID_TITLE_CHINESE_T: data = psf.GetString("TITLE_10"); break; case CELL_GAME_PARAMID_TITLE_CHINESE_S: data = psf.GetString("TITLE_11"); break; case CELL_GAME_PARAMID_TITLE_FINNISH: data = psf.GetString("TITLE_12"); break; case CELL_GAME_PARAMID_TITLE_SWEDISH: data = psf.GetString("TITLE_13"); break; case CELL_GAME_PARAMID_TITLE_DANISH: data = psf.GetString("TITLE_14"); break; case CELL_GAME_PARAMID_TITLE_NORWEGIAN: data = psf.GetString("TITLE_15"); break; case CELL_GAME_PARAMID_TITLE_POLISH: data = psf.GetString("TITLE_16"); break; case CELL_GAME_PARAMID_TITLE_PORTUGUESE_BRAZIL: data = psf.GetString("TITLE_17"); break; case CELL_GAME_PARAMID_TITLE_ENGLISH_UK: data = psf.GetString("TITLE_18"); break; case CELL_GAME_PARAMID_TITLE_ID: data = psf.GetString("TITLE_ID"); break; case CELL_GAME_PARAMID_VERSION: data = psf.GetString("PS3_SYSTEM_VER"); break; case CELL_GAME_PARAMID_APP_VER: data = psf.GetString("APP_VER"); break; default: return CELL_GAME_ERROR_INVALID_ID; } if (data.size() >= bufsize) data.resize(bufsize - 1); memcpy(buf.get_ptr(), data.c_str(), data.size() + 1); return CELL_OK; }
void GameViewer::LoadPSF() { m_game_data.Clear(); for(uint i=0; i<m_games.GetCount(); ++i) { const wxString& path = m_path + m_games[i] + "/PARAM.SFO"; vfsFile f; if(!f.Open(path)) continue; PSFLoader psf(f); if(!psf.Load(false)) continue; psf.m_info.root = m_games[i]; m_game_data.Add(new GameInfo(psf.m_info)); } m_columns.Update(m_game_data); }
int cellGameContentPermit(mem_list_ptr_t<u8> contentInfoPath, mem_list_ptr_t<u8> usrdirPath) { cellGame.Warning("cellGameContentPermit(contentInfoPath_addr=0x%x, usrdirPath_addr=0x%x)", contentInfoPath.GetAddr(), usrdirPath.GetAddr()); if (!contentInfoPath.IsGood() || !usrdirPath.IsGood()) return CELL_GAME_ERROR_PARAM; // TODO: Locate the PARAM.SFO. The following path may be wrong. vfsFile f("/app_home/PARAM.SFO"); PSFLoader psf(f); if(!psf.Load(false)) return CELL_GAME_ERROR_FAILURE; std::string titleId = psf.GetString("TITLE_ID"); // TODO: Only works for HDD games Memory.WriteString(contentInfoPath.GetAddr(), "/dev_hdd0/game/"+titleId); Memory.WriteString(usrdirPath.GetAddr(), "/dev_hdd0/game/"+titleId+"/USRDIR"); return CELL_OK; }
int cellGameGetParamInt(u32 id, vm::ptr<be_t<u32>> value) { cellGame->Warning("cellGameGetParamInt(id=%d, value_addr=0x%x)", id, value.addr()); // TODO: Access through cellGame***Check functions vfsFile f("/app_home/PARAM.SFO"); PSFLoader psf(f); if(!psf.Load(false)) return CELL_GAME_ERROR_FAILURE; switch(id) { case CELL_GAME_PARAMID_PARENTAL_LEVEL: *value = psf.GetInteger("PARENTAL_LEVEL"); break; case CELL_GAME_PARAMID_RESOLUTION: *value = psf.GetInteger("RESOLUTION"); break; case CELL_GAME_PARAMID_SOUND_FORMAT: *value = psf.GetInteger("SOUND_FORMAT"); break; default: return CELL_GAME_ERROR_INVALID_ID; } return CELL_OK; }
int main(int argc, char *argv[]) { int c; while (EOF != (c = getopt(argc, argv, "d"))) switch (c) { case 'd': debuglevel = LOG_DEBUG; break; } // create a Chart factory CatalogPtr catalog = CatalogFactory::get(CatalogFactory::Combined, "/usr/local/starcatalogs"); TurbulencePointSpreadFunction psf(2); ChartFactory factory(catalog, psf, 14, 100); debug(LOG_DEBUG, DEBUG_LOG, 0, "chart factory created"); // create an Image Normalizer ImageNormalizer normalizer(factory); // prepare the initial transformation Projection projection(M_PI * 162 / 180, Point(838, 182), 0.98); debug(LOG_DEBUG, DEBUG_LOG, 0, "projection: %s", projection.toString().c_str()); // get the image from the input file FITSin in("andromeda-base.fits"); ImagePtr imageptr = in.read(); // apply the normalizer to the debug(LOG_DEBUG, DEBUG_LOG, 0, "apply normalizer"); RaDec center = normalizer(imageptr, projection); debug(LOG_DEBUG, DEBUG_LOG, 0, "true center: %s", center.toString().c_str()); debug(LOG_DEBUG, DEBUG_LOG, 0, "transformation: %s", projection.toString().c_str()); return EXIT_SUCCESS; }
// get_debug_command() // // Read a command from standard input. // This is useful when you have a debugger // which doesn't support calling into functions. // void get_debug_command() { ssize_t count; int i,j; bool gotcommand; intptr_t addr; char buffer[256]; nmethod *nm; methodOop m; tty->print_cr("You have entered the diagnostic command interpreter"); tty->print("The supported commands are:\n"); for ( i=0; ; i++ ) { if ( CommandList[i].code == CMDID_ILLEGAL ) break; tty->print_cr(" %s \n", CommandList[i].name ); } while ( 1 ) { gotcommand = false; tty->print("Please enter a command: "); count = scanf("%s", buffer) ; if ( count >=0 ) { for ( i=0; ; i++ ) { if ( CommandList[i].code == CMDID_ILLEGAL ) { if (!gotcommand) tty->print("Invalid command, please try again\n"); break; } if ( strcmp(buffer, CommandList[i].name) == 0 ) { gotcommand = true; switch ( CommandList[i].code ) { case CMDID_PS: ps(); break; case CMDID_PSS: pss(); break; case CMDID_PSF: psf(); break; case CMDID_FINDM: tty->print("Please enter the hex addr to pass to findm: "); scanf("%I64X", &addr); m = (methodOop)findm(addr); tty->print("findm(0x%I64X) returned 0x%I64X\n", addr, m); break; case CMDID_FINDNM: tty->print("Please enter the hex addr to pass to findnm: "); scanf("%I64X", &addr); nm = (nmethod*)findnm(addr); tty->print("findnm(0x%I64X) returned 0x%I64X\n", addr, nm); break; case CMDID_PP: tty->print("Please enter the hex addr to pass to pp: "); scanf("%I64X", &addr); pp((void*)addr); break; case CMDID_EXIT: exit(0); case CMDID_HELP: tty->print("Here are the supported commands: "); for ( j=0; ; j++ ) { if ( CommandList[j].code == CMDID_ILLEGAL ) break; tty->print_cr(" %s -- %s\n", CommandList[j].name, CommandList[j].description ); } break; case CMDID_QUIT: return; break; case CMDID_BPT: BREAKPOINT; break; case CMDID_VERIFY: verify();; break; case CMDID_THREADS: threads();; break; case CMDID_HSFIND: tty->print("Please enter the hex addr to pass to hsfind: "); scanf("%I64X", &addr); tty->print("Calling hsfind(0x%I64X)\n", addr); hsfind(addr); break; default: case CMDID_ILLEGAL: break; } } } } } }
/***********************************************************************//** * @brief Get observation container * * Get an observation container according to the user parameters. The method * supports loading of a individual FITS file or an observation definition * file in XML format. * * If the input filename is empty, the method checks for the existence of the * "expcube", "psfcube" and "bkgcube" parameters. If file names have been * specified, the method loads the files and creates a dummy events cube that * is appended to the observation container. * * If no file names are specified for the "expcube", "psfcube" or "bkgcube" * parameters, the method reads the necessary parameters to build a CTA * observation from scratch. * * The method sets m_append_cube = true and m_binned = true in case that * a stacked observation is requested (as detected by the presence of the * "expcube", "psfcube", and "bkgcube" parameters). In that case, it appended * a dummy event cube to the observation. ***************************************************************************/ void ctmodel::get_obs(void) { // Get the filename from the input parameters std::string filename = (*this)["inobs"].filename(); // If no observation definition file has been specified then read all // parameters that are necessary to create an observation from scratch if ((filename == "NONE") || (gammalib::strip_whitespace(filename) == "")) { // Get response cube filenames std::string expcube = (*this)["expcube"].filename(); std::string psfcube = (*this)["psfcube"].filename(); std::string bkgcube = (*this)["bkgcube"].filename(); // If the filenames are valid then build an observation from cube // response information if ((expcube != "NONE") && (psfcube != "NONE") && (bkgcube != "NONE") && (gammalib::strip_whitespace(expcube) != "") && (gammalib::strip_whitespace(psfcube) != "") && (gammalib::strip_whitespace(bkgcube) != "")) { // Get exposure, PSF and background cubes GCTACubeExposure exposure(expcube); GCTACubePsf psf(psfcube); GCTACubeBackground background(bkgcube); // Create energy boundaries GEbounds ebounds = create_ebounds(); // Create dummy sky map cube GSkyMap map("CAR","GAL",0.0,0.0,1.0,1.0,1,1,ebounds.size()); // Create event cube GCTAEventCube cube(map, ebounds, exposure.gti()); // Create CTA observation GCTAObservation cta; cta.events(cube); cta.response(exposure, psf, background); // Append observation to container m_obs.append(cta); // Signal that we are in binned mode m_binned = true; // Signal that we appended a cube m_append_cube = true; } // endif: cube response information was available // ... otherwise build an observation from IRF response information else { // Create CTA observation GCTAObservation cta = create_cta_obs(); // Set response set_obs_response(&cta); // Append observation to container m_obs.append(cta); } } // endif: filename was "NONE" or "" // ... otherwise we have a file name else { // If file is a FITS file then create an empty CTA observation // and load file into observation if (gammalib::is_fits(filename)) { // Allocate empty CTA observation GCTAObservation cta; // Load data cta.load(filename); // Set response set_obs_response(&cta); // Append observation to container m_obs.append(cta); // Signal that no XML file should be used for storage m_use_xml = false; } // ... otherwise load file into observation container else { // Load observations from XML file m_obs.load(filename); // For all observations that have no response, set the response // from the task parameters set_response(m_obs); // Set observation boundary parameters (emin, emax, rad) set_obs_bounds(m_obs); // Signal that XML file should be used for storage m_use_xml = true; } // endelse: file was an XML file } // Return return; }
int cellHddGameCheck(u32 version, vm::ptr<const char> dirName, u32 errDialog, vm::ptr<CellHddGameStatCallback> funcStat, u32 container) { cellSysutil.Warning("cellHddGameCheck(version=%d, dirName_addr=0x%x, errDialog=%d, funcStat_addr=0x%x, container=%d)", version, dirName.addr(), errDialog, funcStat.addr(), container); std::string dir = dirName.get_ptr(); if (dir.size() != 9) return CELL_HDDGAME_ERROR_PARAM; vm::var<CellHddGameSystemFileParam> param; vm::var<CellHddGameCBResult> result; vm::var<CellHddGameStatGet> get; vm::var<CellHddGameStatSet> set; get->hddFreeSizeKB = 40 * 1024 * 1024; // 40 GB, TODO: Use the free space of the computer's HDD where RPCS3 is being run. get->isNewData = CELL_HDDGAME_ISNEWDATA_EXIST; get->sysSizeKB = 0; // TODO get->st_atime__ = 0; // TODO get->st_ctime__ = 0; // TODO get->st_mtime__ = 0; // TODO get->sizeKB = CELL_HDDGAME_SIZEKB_NOTCALC; memcpy(get->contentInfoPath, ("/dev_hdd0/game/" + dir).c_str(), CELL_HDDGAME_PATH_MAX); memcpy(get->hddGamePath, ("/dev_hdd0/game/" + dir + "/USRDIR").c_str(), CELL_HDDGAME_PATH_MAX); if (!Emu.GetVFS().ExistsDir(("/dev_hdd0/game/" + dir).c_str())) { get->isNewData = CELL_HDDGAME_ISNEWDATA_NODIR; } else { // TODO: Is cellHddGameCheck really responsible for writing the information in get->getParam ? (If not, delete this else) vfsFile f(("/dev_hdd0/game/" + dir + "/PARAM.SFO").c_str()); PSFLoader psf(f); if (!psf.Load(false)) { return CELL_HDDGAME_ERROR_BROKEN; } get->getParam.parentalLevel = psf.GetInteger("PARENTAL_LEVEL"); get->getParam.attribute = psf.GetInteger("ATTRIBUTE"); get->getParam.resolution = psf.GetInteger("RESOLUTION"); get->getParam.soundFormat = psf.GetInteger("SOUND_FORMAT"); std::string title = psf.GetString("TITLE"); strcpy_trunc(get->getParam.title, title); std::string app_ver = psf.GetString("APP_VER"); strcpy_trunc(get->getParam.dataVersion, app_ver); strcpy_trunc(get->getParam.titleId, dir); for (u32 i=0; i<CELL_HDDGAME_SYSP_LANGUAGE_NUM; i++) { char key [16]; sprintf(key, "TITLE_%02d", i); title = psf.GetString(key); strcpy_trunc(get->getParam.titleLang[i], title); } } // TODO ? funcStat(result, get, set); if (result->result != CELL_HDDGAME_CBRESULT_OK && result->result != CELL_HDDGAME_CBRESULT_OK_CANCEL) { return CELL_HDDGAME_ERROR_CBRESULT; } // TODO ? return CELL_OK; }
int cellGameDataCheckCreate2(u32 version, vm::ptr<const char> dirName, u32 errDialog, vm::ptr<void(*)(vm::ptr<CellGameDataCBResult> cbResult, vm::ptr<CellGameDataStatGet> get, vm::ptr<CellGameDataStatSet> set)> funcStat, u32 container) { cellGame->Warning("cellGameDataCheckCreate(2)(version=0x%x, dirName_addr=0x%x, errDialog=0x%x, funcStat_addr=0x%x, container=%d)", version, dirName.addr(), errDialog, funcStat.addr(), container); if (version != CELL_GAMEDATA_VERSION_CURRENT || errDialog > 1) { cellGame->Error("cellGameDataCheckCreate(2)(): CELL_GAMEDATA_ERROR_PARAM"); return CELL_GAMEDATA_ERROR_PARAM; } // TODO: output errors (errDialog) const std::string dir = std::string("/dev_hdd0/game/") + dirName.get_ptr(); if (!Emu.GetVFS().ExistsDir(dir)) { cellGame->Todo("cellGameDataCheckCreate(2)(): creating directory '%s'", dir.c_str()); // TODO: create data return CELL_GAMEDATA_RET_OK; } vfsFile f(dir + "/PARAM.SFO"); if (!f.IsOpened()) { cellGame->Error("cellGameDataCheckCreate(2)(): CELL_GAMEDATA_ERROR_BROKEN (cannot open PARAM.SFO)"); return CELL_GAMEDATA_ERROR_BROKEN; } PSFLoader psf(f); if (!psf.Load(false)) { cellGame->Error("cellGameDataCheckCreate(2)(): CELL_GAMEDATA_ERROR_BROKEN (cannot read PARAM.SFO)"); return CELL_GAMEDATA_ERROR_BROKEN; } // TODO: use memory container vm::var<CellGameDataCBResult> cbResult; vm::var<CellGameDataStatGet> cbGet; vm::var<CellGameDataStatSet> cbSet; cbGet.value() = {}; // TODO: Use the free space of the computer's HDD where RPCS3 is being run. cbGet->hddFreeSizeKB = 40000000; //40 GB cbGet->isNewData = CELL_GAMEDATA_ISNEWDATA_NO; strcpy_trunc(cbGet->contentInfoPath, dir); strcpy_trunc(cbGet->gameDataPath, dir + "/USRDIR"); // TODO: set correct time cbGet->st_atime_ = 0; cbGet->st_ctime_ = 0; cbGet->st_mtime_ = 0; // TODO: calculate data size, if necessary cbGet->sizeKB = CELL_GAMEDATA_SIZEKB_NOTCALC; cbGet->sysSizeKB = 0; cbGet->getParam.attribute = CELL_GAMEDATA_ATTR_NORMAL; cbGet->getParam.parentalLevel = psf.GetInteger("PARENTAL_LEVEL"); strcpy_trunc(cbGet->getParam.dataVersion, psf.GetString("APP_VER")); strcpy_trunc(cbGet->getParam.titleId, psf.GetString("TITLE_ID")); strcpy_trunc(cbGet->getParam.title, psf.GetString("TITLE")); // TODO: write lang titles funcStat(cbResult, cbGet, cbSet); if (cbSet->setParam) { // TODO: write PARAM.SFO from cbSet cellGame->Todo("cellGameDataCheckCreate(2)(): writing PARAM.SFO parameters (addr=0x%x)", cbSet->setParam.addr()); } switch ((s32)cbResult->result) { case CELL_GAMEDATA_CBRESULT_OK_CANCEL: // TODO: do not process game data cellGame->Warning("cellGameDataCheckCreate(2)(): callback returned CELL_GAMEDATA_CBRESULT_OK_CANCEL"); case CELL_GAMEDATA_CBRESULT_OK: return CELL_GAMEDATA_RET_OK; case CELL_GAMEDATA_CBRESULT_ERR_NOSPACE: // TODO: process errors, error message and needSizeKB result cellGame->Error("cellGameDataCheckCreate(2)(): callback returned CELL_GAMEDATA_CBRESULT_ERR_NOSPACE"); return CELL_GAMEDATA_ERROR_CBRESULT; case CELL_GAMEDATA_CBRESULT_ERR_BROKEN: cellGame->Error("cellGameDataCheckCreate(2)(): callback returned CELL_GAMEDATA_CBRESULT_ERR_BROKEN"); return CELL_GAMEDATA_ERROR_CBRESULT; case CELL_GAMEDATA_CBRESULT_ERR_NODATA: cellGame->Error("cellGameDataCheckCreate(2)(): callback returned CELL_GAMEDATA_CBRESULT_ERR_NODATA"); return CELL_GAMEDATA_ERROR_CBRESULT; case CELL_GAMEDATA_CBRESULT_ERR_INVALID: cellGame->Error("cellGameDataCheckCreate(2)(): callback returned CELL_GAMEDATA_CBRESULT_ERR_INVALID"); return CELL_GAMEDATA_ERROR_CBRESULT; default: cellGame->Error("cellGameDataCheckCreate(2)(): callback returned unknown error (code=0x%x)"); return CELL_GAMEDATA_ERROR_CBRESULT; } }
int main() { init_python_api(); Py_InitModule("testmod", no_methods); run_python_string("import server"); run_python_string("import testmod"); run_python_string("from atlas import Operation"); run_python_string("class TestEntity(server.Thing):\n" " def look_operation(self, op): pass\n" " def delete_operation(self, op):\n" " raise AssertionError, 'deliberate'\n" " def tick_operation(self, op):\n" " raise AssertionError, 'deliberate'\n" " def talk_operation(self, op):\n" " return 'invalid result'\n" " def set_operation(self, op):\n" " return Operation('sight')\n" " def move_operation(self, op):\n" " return Operation('sight') + Operation('move')\n" " def test_hook(self, ent): pass\n"); run_python_string("testmod.TestEntity=TestEntity"); // PyObject * package_name = PyString_FromString("testmod"); // PyObject * testmod = PyImport_Import(package_name); // Py_DECREF(package_name); // assert(testmod); PythonScriptFactory psf("testmod", "TestEntity"); Entity * e = new Entity("1", 1); int ret = psf.addScript(e); assert(ret == 0); OpVector res; Atlas::Objects::Operation::Look op1; e->operation(op1, res); Atlas::Objects::Operation::Create op2; e->operation(op2, res); Atlas::Objects::Operation::Delete op3; e->operation(op3, res); Atlas::Objects::Operation::Talk op4; e->operation(op4, res); Atlas::Objects::Operation::Set op5; e->operation(op5, res); Atlas::Objects::Operation::Move op6; e->operation(op6, res); Atlas::Objects::Operation::Tick op7; e->operation(op7, res); Script * script = e->script(); assert(script != 0); assert(script != &noScript); script->hook("nohookfunction", e); script->hook("test_hook", e); delete e; shutdown_python_api(); return 0; }
main (int argc, char *argv[]) { int i, j,k,y,z,I,J; const int RPUP = 100; /* resolution elements along pupil radius */ const int SZ = 2*RPUP*2*RPUP; /* size for 1D vectors to hold 2D data */ const int blur = 1; /* widen each phase pixel by +/- blur */ const int det_size = 50; /* # image pixels in x and y */ const int Npixels = det_size * det_size; char *mask = argv[3]; char *tmp, c[2] = {5,0}; int napts,cols, /* # of rows, cols in .phs file */ *vmask, /* vectorized poly_mask */ rng, rms_calc; float *phs, *zrn, **xyp, /* hold all xy,phase values */ **xy, /* xy aperture coords */ **ppimg, /* XPM image array */ sum, sum2, mean, resid_rms, /* summing registers for rms calculation */ *mode_rms, *cmode_rms, *Px, *Py, *Pphs, *detx, *dety, *detI, **psfimg, pix_size, field, ds; zrn = vector (1, ZPOLY); readVector (argv[2], zrn, ZPOLY); /* read in zernike poly coeffs */ fileDim (argv[1], &napts, &cols); xyp = matrix (1, napts, 1, 3); readMatrix (argv[1], xyp, napts, 3); /* read in x,y,raw phase values */ vmask = ivector (1, ZPOLY); /* convert the string mask to an integer vector mask */ tmp = mask; for (i=1;i<=ZPOLY;i++) { c[0] = *tmp++; vmask[i] = atoi(c); /* atoi needs a string! */ vmask[i] = (vmask[i] == 0) ? 1 : 0; /* invert vmask */ } field = atof(argv[5]); ds = atof(argv[4]); rng = atoi(argv[6]); rms_calc =atoi(argv[7]); pix_size = field*um_as/det_size; /* strip xy coords from the xyp array */ xy = matrix (1,napts, 1,2); for (i=1;i<=napts;i++) { xy[i][1] = xyp[i][1]; xy[i][2] = xyp[i][2]; } /* using mask, subtract desired mode phases from the raw phases */ phs = vector (1, napts); /* get mode phases to subtract */ createPhaseVector (zrn, xy, napts, phs, vmask); for (i=1;i<=napts;i++) xyp[i][3] -= phs[i]; /* do phase subtraction of zernike modes from the raw phases. */ /* make the initial XPM grid, and set all pixels to transparent */ ppimg = matrix(1,2*RPUP,1,2*RPUP); for (i=-RPUP;i<RPUP;i++) for (j=-RPUP;j<RPUP;j++) ppimg[i+RPUP+1][j+RPUP+1] = -100000; /* map xy coords into the XPM image */ /* put in the discrete phase points by writing over the appropriate * locations. */ for (k=1;k<=napts;k++) { I = xyp[k][1]*(float)RPUP * .95; J = xyp[k][2]*(float)RPUP * .95; /* keep the image inside the array indices (not very clean for now) */ /* if (i > RPUP-1) i = RPUP-1; if (i < -RPUP) i = -RPUP; if (j > RPUP-1) j = RPUP-1; if (j < -RPUP) j = -RPUP; ppimg[i+RPUP+1][j+RPUP+1] = xyp[k][3]; */ /* the above creates a single pixel in the image which is too * small--need to blur each one out to the surrounding pixels */ for (y=-blur;y<=blur;y++) { i = I + y; for (z=-blur; z<=blur;z++) { j = J + z; ppimg[i+RPUP+1][j+RPUP+1] = xyp[k][3]; } } } makeXPM (ppimg, 2*RPUP, 2*RPUP, 0, 100, 1, "wavefront.xpm"); /* return the rms values via the pipe */ /* calc the residual rms */ sum = sum2 = 0; for (i=1;i<=napts;i++) { sum += xyp[i][3]; sum2 += xyp[i][3] * xyp[i][3]; } mean = sum/napts; resid_rms = sqrt (sum2/napts - 2*mean*mean + mean*mean); if (rms_calc == 0) /* get all mode rms errors */ { mode_rms = vector (1, ZPOLY); cmode_rms = vector (1, 7); phaseRMS (xy, napts, zrn, mode_rms); cmode_rms[1] = hypot (mode_rms[1], mode_rms[2]); /*tilt*/ cmode_rms[2] = mode_rms[3]; cmode_rms[3] = hypot (mode_rms[4], mode_rms[5]); /*astig*/ cmode_rms[4] = hypot (mode_rms[6], mode_rms[7]); /*coma*/ cmode_rms[5] = mode_rms[8]; cmode_rms[6] = hypot (mode_rms[9], mode_rms[10]); /*trefoil*/ cmode_rms[7] = hypot (mode_rms[11], mode_rms[12]); /*quad astig*/ for (i=1;i<=7;i++) printf ("%5.0f ", cmode_rms[i]); } printf ("%5.0f", resid_rms); /* this section sets up the data needed for the PSF image calculation and * production of the XPM image. */ /* break up pupil coords into vectors (required by psf.c), and re-scale to * the actual entrance aperture size. NOTE: The pointers passed are * strange because psf() has 0-based arrays. */ Px = vector (1, napts); Py = vector (1, napts); Pphs = vector(1, napts); for (i=1;i<=napts;i++) { Px[i] = xyp[i][1] * ERAD; /* re-scale pupil coords */ Py[i] = xyp[i][2] * ERAD; Pphs[i] = xyp[i][3]/1000; /* convert phases from nm to um */ } detx = vector (1, Npixels); dety = vector (1, Npixels); detI = vector (1, Npixels); /* define the detector coordinates */ k=1; for (i= -det_size/2;i<det_size/2;i++) for (j= -det_size/2;j<det_size/2;j++) { detx[k] = i*pix_size; dety[k++] = j*pix_size; } if (k - 1 != Npixels) {printf ("detector messed up\n"); return (0); } psf (FL, ds, 0.8, napts, &Pphs[1], &Px[1], &Py[1], Npixels, &detI[1], &detx[1], &dety[1]); /* now make the psf image */ psfimg = matrix (1, det_size, 1, det_size); k=1; for (i= -det_size/2;i<det_size/2;i++) for (j= -det_size/2;j<det_size/2;j++) { psfimg[i + det_size/2 +1][j +det_size/2 + 1] = detI[k++]; } /* writeMatrix ("psfimg", psfimg, det_size, det_size); */ makeXPM (psfimg, det_size, det_size, 0, rng, 3, "psf.xpm"); free_vector (zrn, 1, ZPOLY); free_ivector (vmask, 1, ZPOLY); free_matrix (xyp,1,napts,1,3); free_matrix (xy, 1, napts, 1, 2); free_vector (phs, 1, napts); free_matrix (ppimg,1,2*RPUP,1,2*RPUP); if (rms_calc == 0) { free_vector (mode_rms, 1, ZPOLY); free_vector (cmode_rms, 1, 7); } free_vector (Px, 1, napts); free_vector (Py, 1, napts); free_vector (Pphs, 1, napts); free_vector (detx, 1, Npixels); free_vector (dety, 1, Npixels); free_vector (detI, 1, Npixels); free_matrix (psfimg, 1, det_size, 1, det_size); return (0); }
/***********************************************************************//** * @brief Return instrument response to elliptical source * * @param[in] event Observed event. * @param[in] source Source. * @param[in] obs Observation (not used). * @return Instrument response to elliptical source. * * Returns the instrument response to a specified elliptical source. ***************************************************************************/ double GCTAResponseCube::irf_elliptical(const GEvent& event, const GSource& source, const GObservation& obs) const { // Initialise IRF double irf = 0.0; // Get pointer to CTA event bin if (!event.is_bin()) { std::string msg = "The current event is not a CTA event bin. " "This method only works on binned CTA data. Please " "make sure that a CTA observation containing binned " "CTA data is provided."; throw GException::invalid_value(G_IRF_RADIAL, msg); } const GCTAEventBin* bin = static_cast<const GCTAEventBin*>(&event); // Get event attribute references const GSkyDir& obsDir = bin->dir().dir(); const GEnergy& obsEng = bin->energy(); const GTime& obsTime = bin->time(); // Get pointer to elliptical model const GModelSpatialElliptical* model = static_cast<const GModelSpatialElliptical*>(source.model()); // Compute angle between model centre and measured photon direction and // position angle (radians) double rho_obs = model->dir().dist(obsDir); double posangle_obs = model->dir().posang(obsDir); // Get livetime (in seconds) double livetime = exposure().livetime(); // Continue only if livetime is >0 and if we're sufficiently close to // the model centre to get a non-zero response if ((livetime > 0.0) && (rho_obs <= model->theta_max()+psf().delta_max())) { // Get exposure irf = exposure()(obsDir, obsEng); // Continue only if exposure is positive if (irf > 0.0) { // Recover effective area from exposure irf /= livetime; // Get PSF component irf *= psf_elliptical(model, rho_obs, posangle_obs, obsDir, obsEng, obsTime); // Apply deadtime correction irf *= exposure().deadc(); } // endif: exposure was positive } // endif: we were sufficiently close and livetime >0 // Compile option: Check for NaN/Inf #if defined(G_NAN_CHECK) if (gammalib::is_notanumber(irf) || gammalib::is_infinite(irf)) { std::cout << "*** ERROR: GCTAResponseCube::irf_elliptical:"; std::cout << " NaN/Inf encountered"; std::cout << " irf=" << irf; std::cout << std::endl; } #endif // Return IRF value return irf; }
/***********************************************************************//** * @brief Return instrument response to point source * * @param[in] event Observed event. * @param[in] source Source. * @param[in] obs Observation (not used). * @return Instrument response to point source. * * Returns the instrument response to a specified point source. ***************************************************************************/ double GCTAResponseCube::irf_ptsrc(const GEvent& event, const GSource& source, const GObservation& obs) const { // Initialise IRF double irf = 0.0; // Get pointer to model source model const GModelSpatialPointSource* ptsrc = static_cast<const GModelSpatialPointSource*>(source.model()); // Get point source direction GSkyDir srcDir = ptsrc->dir(); // Get pointer on CTA event bin if (!event.is_bin()) { std::string msg = "The current event is not a CTA event bin. " "This method only works on binned CTA data. Please " "make sure that a CTA observation containing binned " "CTA data is provided."; throw GException::invalid_value(G_IRF_PTSRC, msg); } const GCTAEventBin* bin = static_cast<const GCTAEventBin*>(&event); // Determine angular separation between true and measured photon // direction in radians double delta = bin->dir().dir().dist(srcDir); // Get maximum angular separation for PSF (in radians) double delta_max = psf().delta_max(); // Get livetime (in seconds) double livetime = exposure().livetime(); // Continue only if livetime is >0 and if we're sufficiently close // to the PSF if ((livetime > 0.0) && (delta <= delta_max)) { // Get exposure irf = exposure()(srcDir, source.energy()); // Multiply-in PSF if (irf > 0.0) { // Recover effective area from exposure irf /= livetime; // Get PSF component irf *= psf()(srcDir, delta, source.energy()); // Apply deadtime correction irf *= exposure().deadc(); } // endif: exposure was non-zero } // endif: we were sufficiently close to PSF and livetime >0 // Compile option: Check for NaN/Inf #if defined(G_NAN_CHECK) if (gammalib::is_notanumber(irf) || gammalib::is_infinite(irf)) { std::cout << "*** ERROR: GCTAResponseCube::irf_ptsrc:"; std::cout << " NaN/Inf encountered"; std::cout << " irf=" << irf; std::cout << std::endl; } #endif // Return IRF value return irf; }
/***********************************************************************//** * @brief Integrate Psf over radial model * * @param[in] model Radial model. * @param[in] delta_mod Angle between model centre and measured photon * direction (radians). * @param[in] obsDir Observed event direction. * @param[in] srcEng True photon energy. * @param[in] srcTime True photon arrival time. * * Integrates the product of the spatial model and the point spread * function over the true photon arrival direction using * * \f[ * \int_{\delta_{\rm min}}^{\delta_{\rm max}} * \sin \delta \times {\rm Psf}(\delta) \times * \int_{\phi_{\rm min}}^{\phi_{\rm max}} * S_{\rm p}(\delta, \phi | E, t) d\phi d\delta * \f] * * where * \f$S_{\rm p}(\delta, \phi | E, t)\f$ is the radial spatial model, * \f${\rm Psf}(\delta)\f$ is the point spread function, * \f$\delta\f$ is angular distance between the true and the measured * photon direction, and * \f$\phi\f$ is the position angle around the observed photon direction * measured counterclockwise from the connecting line between the model * centre and the observed photon arrival direction. ***************************************************************************/ double GCTAResponseCube::psf_radial(const GModelSpatialRadial* model, const double& delta_mod, const GSkyDir& obsDir, const GEnergy& srcEng, const GTime& srcTime) const { // Set number of iterations for Romberg integration. // These values have been determined after careful testing, see // https://cta-redmine.irap.omp.eu/issues/1291 static const int iter_delta = 5; static const int iter_phi = 6; // Initialise value double value = 0.0; // Get maximum Psf radius (radians) double psf_max = psf().delta_max(); // Get maximum model radius (radians) double theta_max = model->theta_max(); // Set offset angle integration range (radians) double delta_min = (delta_mod > theta_max) ? delta_mod - theta_max : 0.0; double delta_max = delta_mod + theta_max; if (delta_max > psf_max) { delta_max = psf_max; } // Setup integration kernel. We take here the observed photon arrival // direction as the true photon arrival direction because the PSF does // not vary significantly over a small region. cta_psf_radial_kern_delta integrand(this, model, obsDir, srcEng, srcTime, delta_mod, theta_max, iter_phi); // Integrate over model's zenith angle GIntegral integral(&integrand); integral.fixed_iter(iter_delta); // Setup integration boundaries std::vector<double> bounds; bounds.push_back(delta_min); bounds.push_back(delta_max); // If the integration range includes a transition between full // containment of Psf within model and partial containment, then // add a boundary at this location double transition_point = theta_max - delta_mod; if (transition_point > delta_min && transition_point < delta_max) { bounds.push_back(transition_point); } // Integrate kernel value = integral.romberg(bounds, iter_delta); // Compile option: Check for NaN/Inf #if defined(G_NAN_CHECK) if (gammalib::is_notanumber(value) || gammalib::is_infinite(value)) { std::cout << "*** ERROR: GCTAResponseCube::psf_radial:"; std::cout << " NaN/Inf encountered"; std::cout << " (value=" << value; std::cout << ", delta_min=" << delta_min; std::cout << ", delta_max=" << delta_max << ")"; std::cout << std::endl; } #endif // Return integral return value; }
/***********************************************************************//** * @brief Return instrument response * * @param[in] event Observed event. * @param[in] photon Incident photon. * @param[in] obs Observation (not used). * @return Instrument response. ***************************************************************************/ double GCTAResponseCube::irf(const GEvent& event, const GPhoton& photon, const GObservation& obs) const { // Retrieve event instrument direction const GCTAInstDir& dir = retrieve_dir(G_IRF, event); // Get event attributes const GSkyDir& obsDir = dir.dir(); //const GEnergy& obsEng = event.energy(); // Get photon attributes const GSkyDir& srcDir = photon.dir(); const GEnergy& srcEng = photon.energy(); //const GTime& srcTime = photon.time(); // Determine angular separation between true and measured photon // direction in radians double delta = obsDir.dist(srcDir); // Get maximum angular separation for PSF (in radians) double delta_max = psf().delta_max(); // Initialise IRF value double irf = 0.0; // Get livetime (in seconds) double livetime = exposure().livetime(); // Continue only if livetime is >0 and if we're sufficiently close // to the PSF if ((livetime > 0.0) && (delta <= delta_max)) { // Get exposure irf = exposure()(srcDir, srcEng); // Multiply-in PSF if (irf > 0.0) { // Get PSF component irf *= psf()(srcDir, delta, srcEng); // Divide by livetime irf /= livetime; // Apply deadtime correction irf *= exposure().deadc(); } // endif: Aeff was non-zero } // endif: we were sufficiently close to PSF and livetime was >0 // Compile option: Check for NaN/Inf #if defined(G_NAN_CHECK) if (gammalib::is_notanumber(irf) || gammalib::is_infinite(irf)) { std::cout << "*** ERROR: GCTAResponseCube::irf:"; std::cout << " NaN/Inf encountered"; std::cout << " irf=" << irf; std::cout << std::endl; } #endif // Return IRF value return irf; }
int cellHddGameCheck(u32 version, u32 dirName_addr, u32 errDialog, mem_func_ptr_t<CellHddGameStatCallback> funcStat, u32 container) { cellSysutil.Warning("cellHddGameCheck(version=%d, dirName_addr=0x%xx, errDialog=%d, funcStat_addr=0x%x, container=%d)", version, dirName_addr, errDialog, funcStat, container); if (!Memory.IsGoodAddr(dirName_addr) || !funcStat.IsGood()) return CELL_HDDGAME_ERROR_PARAM; std::string dirName = Memory.ReadString(dirName_addr).ToStdString(); if (dirName.size() != 9) return CELL_HDDGAME_ERROR_PARAM; MemoryAllocator<CellHddGameSystemFileParam> param; MemoryAllocator<CellHddGameCBResult> result; MemoryAllocator<CellHddGameStatGet> get; MemoryAllocator<CellHddGameStatSet> set; get->hddFreeSizeKB = 40000000; // 40 GB, TODO: Use the free space of the computer's HDD where RPCS3 is being run. get->isNewData = CELL_HDDGAME_ISNEWDATA_EXIST; get->sysSizeKB = 0; // TODO get->st_atime__ = 0; // TODO get->st_ctime__ = 0; // TODO get->st_mtime__ = 0; // TODO get->sizeKB = CELL_HDDGAME_SIZEKB_NOTCALC; memcpy(get->contentInfoPath, ("/dev_hdd0/game/"+dirName).c_str(), CELL_HDDGAME_PATH_MAX); memcpy(get->hddGamePath, ("/dev_hdd0/game/"+dirName+"/USRDIR").c_str(), CELL_HDDGAME_PATH_MAX); if (!Emu.GetVFS().ExistsDir(("/dev_hdd0/game/"+dirName).c_str())) { get->isNewData = CELL_HDDGAME_ISNEWDATA_NODIR; } else { // TODO: Is cellHddGameCheck really responsible for writing the information in get->getParam ? (If not, delete this else) vfsFile f(("/dev_hdd0/game/"+dirName+"/PARAM.SFO").c_str()); PSFLoader psf(f); if (!psf.Load(false)) { return CELL_HDDGAME_ERROR_BROKEN; } get->getParam.parentalLevel = psf.m_info.parental_lvl; get->getParam.attribute = psf.m_info.attr; get->getParam.resolution = psf.m_info.resolution; get->getParam.soundFormat = psf.m_info.sound_format; memcpy(get->getParam.title, psf.m_info.name.mb_str(), CELL_HDDGAME_SYSP_TITLE_SIZE); memcpy(get->getParam.dataVersion, psf.m_info.app_ver.mb_str(), CELL_HDDGAME_SYSP_VERSION_SIZE); memcpy(get->getParam.titleId, dirName.c_str(), CELL_HDDGAME_SYSP_TITLEID_SIZE); for (u32 i=0; i<CELL_HDDGAME_SYSP_LANGUAGE_NUM; i++) { memcpy(get->getParam.titleLang[i], psf.m_info.name.mb_str(), CELL_HDDGAME_SYSP_TITLE_SIZE); // TODO: Get real titleLang name } } // TODO ? funcStat(result.GetAddr(), get.GetAddr(), set.GetAddr()); if (result->result != CELL_HDDGAME_CBRESULT_OK && result->result != CELL_HDDGAME_CBRESULT_OK_CANCEL) return CELL_HDDGAME_ERROR_CBRESULT; // TODO ? return CELL_OK; }
/***********************************************************************//** * @brief Integrate Psf over radial model * * @param[in] model Radial model. * @param[in] rho_obs Angle between model centre and measured photon direction * (radians). * @param[in] obsDir Observed event direction. * @param[in] srcEng True photon energy. * @param[in] srcTime True photon arrival time. * * Integrates the product of the spatial model and the point spread * function over the true photon arrival direction using * * \f[ * \int_{\rho_{\rm min}}^{\rho_{\rm max}} * \sin \rho \times S_{\rm p}(\rho | E, t) \times * \int_{\omega_{\rm min}}^{\omega_{\rm max}} * {\rm Psf}(\rho, \omega) d\omega d\rho * \f] * * where * \f$S_{\rm p}(\rho | E, t)\f$ is the radial spatial model, * \f${\rm Psf}(\rho, \omega)\f$ is the point spread function, * \f$\rho\f$ is the radial distance from the model centre, and * \f$\omega\f$ is the position angle around the model centre measured * counterclockwise from the connecting line between the model centre and * the observed photon arrival direction. ***************************************************************************/ double GCTAResponseCube::psf_radial(const GModelSpatialRadial* model, const double& rho_obs, const GSkyDir& obsDir, const GEnergy& srcEng, const GTime& srcTime) const { // Set number of iterations for Romberg integration. // These values have been determined after careful testing, see // https://cta-redmine.irap.omp.eu/issues/1299 static const int iter_rho = 5; static const int iter_phi = 5; // Initialise value double irf = 0.0; // Get maximum PSF radius (radians) double delta_max = psf().delta_max(); // Set zenith angle integration range for radial model (radians) double rho_min = (rho_obs > delta_max) ? rho_obs - delta_max : 0.0; double rho_max = rho_obs + delta_max; double src_max = model->theta_max(); if (rho_max > src_max) { rho_max = src_max; } // Perform zenith angle integration if interval is valid if (rho_max > rho_min) { // Setup integration kernel. We take here the observed photon arrival // direction as the true photon arrival direction because the PSF does // not vary significantly over a small region. cta_psf_radial_kern_rho integrand(this, model, obsDir, srcEng, srcTime, rho_obs, delta_max, iter_phi); // Integrate over model's zenith angle GIntegral integral(&integrand); integral.fixed_iter(iter_rho); // Setup integration boundaries std::vector<double> bounds; bounds.push_back(rho_min); bounds.push_back(rho_max); // If the integration range includes a transition between full // containment of model within Psf and partial containment, then // add a boundary at this location double transition_point = delta_max - rho_obs; if (transition_point > rho_min && transition_point < rho_max) { bounds.push_back(transition_point); } // If we have a shell model then add an integration boundary for the // shell radius as a function discontinuity will occur at this // location const GModelSpatialRadialShell* shell = dynamic_cast<const GModelSpatialRadialShell*>(model); if (shell != NULL) { double shell_radius = shell->radius() * gammalib::deg2rad; if (shell_radius > rho_min && shell_radius < rho_max) { bounds.push_back(shell_radius); } } // Integrate kernel irf = integral.romberg(bounds, iter_rho); // Compile option: Check for NaN/Inf #if defined(G_NAN_CHECK) if (gammalib::is_notanumber(irf) || gammalib::is_infinite(irf)) { std::cout << "*** ERROR: GCTAResponseCube::psf_radial:"; std::cout << " NaN/Inf encountered"; std::cout << " (irf=" << irf; std::cout << ", rho_min=" << rho_min; std::cout << ", rho_max=" << rho_max << ")"; std::cout << std::endl; } #endif } // endif: integration interval is valid // Return PSF return irf; }
/***********************************************************************//** * @brief Test binned observation handling for a specific dataset * * @param[in] datadir Directory of test data. * @param[in] irf Instrument response function. * * Verifies the ability to handle binned Fermi/LAT data. ***************************************************************************/ void TestGLATObservation::test_one_binned_obs(const std::string& datadir, const std::string& irf) { // Set filenames std::string lat_cntmap = datadir+"/cntmap.fits"; std::string lat_srcmap = datadir+"/srcmap.fits"; std::string lat_expmap = datadir+"/binned_expmap.fits"; std::string lat_ltcube = datadir+"/ltcube.fits"; std::string lat_bin_xml = datadir+"/obs_binned.xml"; std::string file1 = "test_lat_obs_binned.xml"; // Declare observations GObservations obs; GLATObservation run; // Determine number of bins and events in counts map GFits cntmap(lat_cntmap); GFitsImage* image = cntmap.image(0); double nevents = 0.0; int nsize = image->size(); for (int i = 0; i < nsize; ++i) { nevents += image->pixel(i); } cntmap.close(); // Try loading event list GLATEventCube cube(lat_cntmap); test_value(cube.number(), nevents, "Test number of events in cube."); // Load LAT binned observation from counts map test_try("Load LAT binned observation"); try { run.load_binned(lat_cntmap, "", ""); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Reload LAT binned observation from source map test_try("Reload LAT binned observation"); try { run.load_binned(lat_srcmap, "", ""); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Add observation (twice) to data test_try("Append observation twice"); try { run.id("0001"); obs.append(run); run.id("0002"); obs.append(run); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Loop over all events using iterator const GEvents* events = run.events(); int num = 0; int sum = 0; for (int i = 0; i < events->size(); ++i) { num++; sum += (int)((*events)[i]->counts()); } test_value(sum, nevents, 1.0e-20, "Test event iterator (counts)"); test_value(num, nsize, 1.0e-20, "Test event iterator (bins)"); // Test mean PSF test_try("Test mean PSF"); try { run.load_binned(lat_srcmap, lat_expmap, lat_ltcube); run.response(irf, lat_caldb); GSkyDir dir; GLATMeanPsf psf(dir, run); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Test XML loading test_try("Test XML loading"); try { setenv("CALDB", lat_caldb.c_str(), 1); obs = GObservations(lat_bin_xml); obs.save(file1); test_try_success(); } catch (std::exception &e) { test_try_failure(e); } // Exit test return; }
int cellGameBootCheck(vm::ptr<be_t<u32>> type, vm::ptr<be_t<u32>> attributes, vm::ptr<CellGameContentSize> size, vm::ptr<char[CELL_GAME_DIRNAME_SIZE]> dirName) { cellGame->Warning("cellGameBootCheck(type_addr=0x%x, attributes_addr=0x%x, size_addr=0x%x, dirName_addr=0x%x)", type.addr(), attributes.addr(), size.addr(), dirName.addr()); if (size) { // TODO: Use the free space of the computer's HDD where RPCS3 is being run. size->hddFreeSizeKB = 40000000; // 40 GB // TODO: Calculate data size for HG and DG games, if necessary. size->sizeKB = CELL_GAME_SIZEKB_NOTCALC; size->sysSizeKB = 0; } vfsFile f("/app_home/PARAM.SFO"); if (!f.IsOpened()) { cellGame->Error("cellGameBootCheck(): CELL_GAME_ERROR_ACCESS_ERROR (cannot open PARAM.SFO)"); return CELL_GAME_ERROR_ACCESS_ERROR; } PSFLoader psf(f); if (!psf.Load(false)) { cellGame->Error("cellGameBootCheck(): CELL_GAME_ERROR_ACCESS_ERROR (cannot read PARAM.SFO)"); return CELL_GAME_ERROR_ACCESS_ERROR; } std::string category = psf.GetString("CATEGORY"); if (category.substr(0, 2) == "DG") { *type = CELL_GAME_GAMETYPE_DISC; *attributes = 0; // TODO if (dirName) strcpy_trunc(*dirName, ""); // ??? contentInfo = "/dev_bdvd/PS3_GAME"; usrdir = "/dev_bdvd/PS3_GAME/USRDIR"; } else if (category.substr(0, 2) == "HG") { std::string titleId = psf.GetString("TITLE_ID"); *type = CELL_GAME_GAMETYPE_HDD; *attributes = 0; // TODO if (dirName) strcpy_trunc(*dirName, titleId); contentInfo = "/dev_hdd0/game/" + titleId; usrdir = "/dev_hdd0/game/" + titleId + "/USRDIR"; } else if (category.substr(0, 2) == "GD") { std::string titleId = psf.GetString("TITLE_ID"); *type = CELL_GAME_GAMETYPE_DISC; *attributes = CELL_GAME_ATTRIBUTE_PATCH; // TODO if (dirName) strcpy_trunc(*dirName, titleId); // ??? contentInfo = "/dev_bdvd/PS3_GAME"; usrdir = "/dev_bdvd/PS3_GAME/USRDIR"; } else { cellGame->Error("cellGameBootCheck(): CELL_GAME_ERROR_FAILURE (unknown CATEGORY)"); return CELL_GAME_ERROR_FAILURE; } return CELL_GAME_RET_OK; }
/***********************************************************************//** * @brief Integrate Psf over elliptical model * * @param[in] model Elliptical model. * @param[in] rho_obs Angle between model centre and measured photon direction * (radians). * @param[in] posangle_obs Position angle of measured photon direction with * respect to model centre (radians). * @param[in] obsDir Observed event direction. * @param[in] srcEng True photon energy. * @param[in] srcTime True photon arrival time. * * Integrates the product of the spatial model and the point spread * function over the true photon arrival direction using * * \f[ * \int_{\rho_{\rm min}}^{\rho_{\rm max}} * \sin \rho \times * \int_{\omega} * S_{\rm p}(\rho, \omega | E, t) \times * {\rm Psf}(\rho, \omega) d\omega d\rho * \f] * * where * \f$S_{\rm p}(\rho, \omega | E, t)\f$ is the elliptical spatial model, * \f${\rm Psf}(\rho, \omega)\f$ is the point spread function, * \f$\rho\f$ is the radial distance from the model centre, and * \f$\omega\f$ is the position angle around the model centre measured * counterclockwise from the connecting line between the model centre and * the observed photon arrival direction. ***************************************************************************/ double GCTAResponseCube::psf_elliptical(const GModelSpatialElliptical* model, const double& rho_obs, const double& posangle_obs, const GSkyDir& obsDir, const GEnergy& srcEng, const GTime& srcTime) const { // Set number of iterations for Romberg integration. // These values have been determined after careful testing, see // https://cta-redmine.irap.omp.eu/issues/1299 static const int iter_rho = 5; static const int iter_phi = 5; // Initialise value double irf = 0.0; // Get maximum PSF radius (radians) double delta_max = psf().delta_max(); // Get the ellipse boundary (radians). Note that these are NOT the // parameters of the ellipse but of a boundary ellipse that is used // for computing the relevant omega angle intervals for a given angle // rho. The boundary ellipse takes care of the possibility that the // semiminor axis is larger than the semimajor axis double semimajor; // Will be the larger axis double semiminor; // Will be the smaller axis double posangle; // Will be the corrected position angle double aspect_ratio; // Ratio between smaller/larger axis of model if (model->semimajor() >= model->semiminor()) { aspect_ratio = (model->semimajor() > 0.0) ? model->semiminor() / model->semimajor() : 0.0; posangle = model->posangle() * gammalib::deg2rad; } else { aspect_ratio = (model->semiminor() > 0.0) ? model->semimajor() / model->semiminor() : 0.0; posangle = model->posangle() * gammalib::deg2rad + gammalib::pihalf; } semimajor = model->theta_max(); semiminor = semimajor * aspect_ratio; // Set zenith angle integration range for elliptical model double rho_min = (rho_obs > delta_max) ? rho_obs - delta_max : 0.0; double rho_max = rho_obs + delta_max; if (rho_max > semimajor) { rho_max = semimajor; } // Perform zenith angle integration if interval is valid if (rho_max > rho_min) { // Setup integration kernel. We take here the observed photon arrival // direction as the true photon arrival direction because the PSF does // not vary significantly over a small region. cta_psf_elliptical_kern_rho integrand(this, model, semimajor, semiminor, posangle, obsDir, srcEng, srcTime, rho_obs, posangle_obs, delta_max, iter_phi); // Integrate over model's zenith angle GIntegral integral(&integrand); integral.fixed_iter(iter_rho); // Setup integration boundaries std::vector<double> bounds; bounds.push_back(rho_min); bounds.push_back(rho_max); // Kluge: add this transition point as this allows to fit the test // case without any stalls. Not clear why this is the case, maybe // simply because the rho integral gets cut down into one more // sub-interval which may increase precision and smoothed the // likelihood contour double transition_point = delta_max - rho_obs; if (transition_point > rho_min && transition_point < rho_max) { bounds.push_back(transition_point); } // If the integration range includes the semiminor boundary, then // add an integration boundary at that location if (semiminor > rho_min && semiminor < rho_max) { bounds.push_back(semiminor); } // Integrate kernel irf = integral.romberg(bounds, iter_rho); // Compile option: Check for NaN/Inf #if defined(G_NAN_CHECK) if (gammalib::is_notanumber(irf) || gammalib::is_infinite(irf)) { std::cout << "*** ERROR: GCTAResponseCube::psf_elliptical:"; std::cout << " NaN/Inf encountered"; std::cout << " (irf=" << irf; std::cout << ", rho_min=" << rho_min; std::cout << ", rho_max=" << rho_max << ")"; std::cout << std::endl; } #endif } // endif: integration interval is valid // Return PSF return irf; }