void DialogAutomationManager::OnReload(wxCommandEvent &event) { int selid = script_list->GetFirstSelected(); AssAutomationFilter *filter = (AssAutomationFilter*)script_list->GetItemData(selid); AutomationScript *script = filter->GetScript(); wxFileName sfname(script->filename); if (sfname.FileExists()) { AutomationScript *newscript; try { AutomationScriptFile *sfile = AutomationScriptFile::CreateFromFile(sfname.GetFullPath()); newscript = new AutomationScript(sfile); delete sfile; } catch (AutomationError &err) { wxMessageBox(wxString::Format(_T("Error reloading Automation script '%s'.\r\nThe old version has been retained.\r\n\r\n%s"), sfname.GetFullPath().c_str(), err.message.c_str()), _T("Error reloading Automation script"), wxOK | wxICON_ERROR, this); return; } newscript->configuration = script->configuration; delete filter; delete script; AssAutomationFilter *newfilter = new AssAutomationFilter(newscript); script_list->DeleteItem(selid); AddScriptToList(newfilter); script_list->Select(0); } else { wxMessageBox(_T("The script file could not be found on disk. If you want to remove the script, please use the Remove button."), _T("Error reloading Automation script"), wxOK|wxICON_EXCLAMATION, this); } }
int gr_mesh_cmd(lua_State* L) { GRLUA_DEBUG_CALL; gr_node_ud* data = (gr_node_ud*)lua_newuserdata(L, sizeof(gr_node_ud)); data->node = 0; const char* name = luaL_checkstring(L, 1); const char* obj_fname = luaL_checkstring(L, 2); std::string sfname( obj_fname ); // Use a dictionary structure to make sure every mesh is loaded // at most once. auto i = mesh_map.find( sfname ); Mesh *mesh = nullptr; if( i == mesh_map.end() ) { mesh = new Mesh( obj_fname ); } else { mesh = i->second; } data->node = new GeometryNode( name, mesh ); luaL_getmetatable(L, "gr.node"); lua_setmetatable(L, -2); return 1; }
void DialogAutomationManager::EditScript(AutomationScript *script) { if (!script) { wxMessageBox(_T("DialogAutomationManager::EditScript() called without a valid script object. Sloppy programming? You can probably blame jfs."), _T("Blame Canada!"), wxOK|wxICON_ERROR); return; } wxFileName sfname(script->filename); if (!sfname.FileExists()) { wxMessageBox(_T("The script file \"%s\" does not exist, and thus cannot be edited."), _T("Automation warning"), wxOK|wxICON_WARNING); return; } wxString editor; if (!Options.IsDefined(_T("automation script editor")) || wxGetKeyState(WXK_SHIFT)) { wxMessageBox(_T("You have not selected a script editor yet. Please select your script editor in the next window. It's recommended to use an editor with syntax highlighting for Lua scripts."), _T("Aegisub"), wxOK|wxICON_INFORMATION); #if defined(__WINDOWS__) editor = wxFileSelector(_T("Select script editor"), _T(""), _T("C:\\Windows\\Notepad.exe"), _T("exe"), _T("Execatuables (*.exe)|*.exe|All files (*.*)|*.*"), wxOPEN|wxFILE_MUST_EXIST); #elif defined(__APPLE__) editor = wxFileSelector(_T("Select script editor"), _T(""), _T("/Applications/TextEdit.app"), _T("app"), _T("Applications (*.app)|*.app|All files (*.*)|*.*"), wxOPEN|wxFILE_MUST_EXIST); #else char *env_editor = getenv("EDITOR"); wxString editor(env_editor ? env_editor : "/usr/bin/gvim", wxConvLocal); editor = wxFileSelector(_T("Select script editor"), _T(""), editor, _T(""), _T("All files (*)|*"), wxOPEN|wxFILE_MUST_EXIST); #endif if (editor.empty()) return; Options.SetText(_T("automation script editor"), editor); Options.Save(); } else { editor = Options.AsText(_T("automation script editor")); } wxWCharBuffer editorbuf = editor.c_str(), sfnamebuf = sfname.GetFullPath().c_str(); wchar_t **cmdline = new wchar_t*[5]; #ifndef __APPLE__ cmdline[0] = editorbuf.data(); cmdline[1] = sfnamebuf.data(); cmdline[2] = 0; #else cmdline[0] = _T("/usr/bin/open"); cmdline[1] = _T("-a"); cmdline[2] = editorbuf.data(); cmdline[3] = sfnamebuf.data(); cmdline[4] = 0; #endif long res = wxExecute(cmdline); delete cmdline; if (!res) { wxMessageBox(_T("Some error occurred trying to launch the external editor. Sorry!"), _T("Automation Error"), wxOK|wxICON_ERROR); } }
void DialogAutomationManager::OnCreate(wxCommandEvent &event) { wxString path = Options.AsText(_T("Last open automation path")); wxString sfnames = wxFileSelector(_("Create Automation script"), path, _T("*.lua"), _T("lua"), _T("Automation Lua scripts (*.lua)|*.lua|All files (*.*)|*.*"), wxSAVE|wxOVERWRITE_PROMPT, this); if (sfnames.empty()) return; Options.SetText(_T("Last open automation path"), sfnames); wxFileName sfname(sfnames); if (sfname.FileExists()) { if (!wxRemoveFile(sfnames)) { wxMessageBox(_T("The old file by this name could not be deleted."), _T("Error creating Automation script"), wxOK|wxICON_ERROR, this); return; } } wxTextFile file; file.Create(sfnames); file.AddLine(_T("-- Aegisub Automation script")); file.AddLine(_T("")); file.AddLine(_T("-- You should change these two lines")); file.AddLine(wxString::Format(_T("name = \"%s\""), sfname.GetName().c_str())); file.AddLine(_T("description = \"New Automation script\"")); file.AddLine(_T("")); file.AddLine(_T("-- Enter the configuration settings here, if needed. Refer to the manual for details")); file.AddLine(_T("configuration = {}")); file.AddLine(_T("")); file.AddLine(_T("-- You should NOT change this line!")); file.AddLine(_T("version, kind = 3, 'basic_ass'")); file.AddLine(_T("")); file.AddLine(_T("-- You should write your script in this function (don't change its name!)")); file.AddLine(_T("function process_lines(meta, styles, lines, config)")); file.AddLine(_T("\t-- For now, just return the subtitles as-is, no changes")); file.AddLine(_T("\treturn lines")); file.AddLine(_T("end")); file.AddLine(_T("")); file.Write(wxTextFileType_None, wxConvUTF8); file.Close(); AutomationScriptFile *sfile = AutomationScriptFile::CreateFromFile(sfnames); AutomationScript *script = new AutomationScript(sfile); AssAutomationFilter *filter = new AssAutomationFilter(script); AddScriptToList(filter); delete sfile; EditScript(script); }
void TmpFileImpl::open() { close(); String sfname("/tmp/owtmpfileXXXXXX"); size_t len = sfname.length(); m_filename = new char[len + 1]; strncpy(m_filename, sfname.c_str(), len); m_filename[len] = '\0'; static Mutex tmpfileMutex; MutexLock tmpfileML(tmpfileMutex); m_hdl = mkstemp(m_filename); if (m_hdl == -1) { delete[] m_filename; m_filename = NULL; OW_THROW_ERRNO_MSG(IOException, "mkstemp failed"); } }
/*ARGSUSED*/ void dosetspath(Char **v, struct command *c) { int i; short j; char *s; sitepath_t p[MAXSITE]; struct sf *st; /* * sfname() on AIX G9.9 at least, mallocs too pointers p, q * then does the equivalent of while (*p++ == *q++) continue; * and then tries to free(p,q) them! Congrats to the wizard who * wrote that one. I bet he tested it really well too. * Sooo, we set dont_free :-) */ dont_free = 1; for (i = 0, v++; *v && *v[0] != '\0'; v++, i++) { s = short2str(*v); if (isdigit(*s)) p[i] = atoi(s); else if (strcmp(s, "LOCAL") == 0) p[i] = NULLSITE; else if ((st = sfctype(s)) != NULL) p[i] = SPATH_CPU | st->sf_ccode; else if ((j = getxid(s)) != -1) p[i] = SPATH_CPU | j; else if ((st = sfname(s)) != NULL) p[i] = st->sf_id; else { setname(s); stderror(ERR_NAME | ERR_STRING, CGETS(23, 1, "Bad cpu/site name")); } if (i == MAXSITE - 1) stderror(ERR_NAME | ERR_STRING, CGETS(23, 2, "Site path too long")); } if (setspath(p, i) == -1) stderror(ERR_SYSTEM, "setspath", strerror(errno)); dont_free = 0; }
/*ARGSUSED*/ void domigrate(Char **v, struct command *c) { struct sf *st; char *s; Char *cp; struct process *pp; int err1 = 0; int pid = 0; siteno_t new_site = 0; pchild_disabled++; cleanup_push(&pchild_disabled, disabled_cleanup); if (setintr) { pintr_disabled++; cleanup_push(&pintr_disabled, disabled_cleanup); } ++v; if (*v[0] == '-') { /* * Do the -site. */ s = short2str(&v[0][1]); /* * see comment in setspath() */ dont_free = 1; if ((st = sfname(s)) == NULL) { dont_free = 0; setname(s); stderror(ERR_NAME | ERR_STRING, CGETS(23, 7, "Site not found")); } dont_free = 0; new_site = st->sf_id; ++v; } if (!*v || *v[0] == '\0') { if (migratepid(0, new_site) == -1) err1++; } else { Char **globbed; v = glob_all_or_error(v); globbed = v; cleanup_push(globbed, blk_cleanup); while (v && (cp = *v)) { if (*cp == '%') { pp = pfind(cp); if (kill3(- pp->p_jobid, SIGMIGRATE, new_site) < 0) { xprintf("%S: %s\n", cp, strerror(errno)); err1++; } } else if (!(Isdigit(*cp) || *cp == '-')) stderror(ERR_NAME | ERR_JOBARGS); else { pid = atoi(short2str(cp)); if (migratepid(pid, new_site) == -1) err1++; } v++; } cleanup_until(globbed); } done: cleanup_until(&pchild_disabled); if (err1) stderror(ERR_SILENT); }
void sim() { Int_t nev = -1; Int_t run = 0; Int_t nskip = 0; const char *fname; // char fnaneopt[1024]; const char *esdname; const char *trgname; const char *embrun; const char *runtype; const char *fnameopt; if (gSystem->Getenv("DC_RUN")) { run = atoi(gSystem->Getenv("DC_RUN")); } if (gSystem->Getenv("DC_RAWFILE")) { fname = gSystem->Getenv("DC_RAWFILE"); } else { printf("DC_RAWFILE is not set and is needed!!!"); return; } if (gSystem->Getenv("DC_ESDFILE")) { esdname = gSystem->Getenv("DC_ESDFILE"); } else { printf("DC_ESDFILE is not set and is needed!!!"); return; } if (gSystem->Getenv("DC_NEVENTS")) { nev = atoi(gSystem->Getenv("DC_NEVENTS")); // gSystem->Exec("echo ${DC_NEVENTS} > ${DC_NEVENTS}_${DC_NEVENTS}_0_${DC_NEVENTS}.stat"); // moved after selection! } if (gSystem->Getenv("DC_EEVENT")) { nskip = atoi(gSystem->Getenv("DC_EEVENT")); } if (gSystem->Getenv("DC_TRGNAME")) { trgname = gSystem->Getenv("DC_TRGNAME"); printf("Looking for %s\n",trgname); } else { printf("DC_TRGNAME not set, will embedd in all events!!!"); return; } if (gSystem->Getenv("CONFIG_EMBEDDING")) { embrun = gSystem->Getenv("CONFIG_EMBEDDING"); } else { printf("CONFIG_EMBEDDING is not set and is needed"); return; } if (gSystem->Getenv("CONFIG_RUN_TYPE")) { runtype = gSystem->Getenv("CONFIG_RUN_TYPE"); } else { printf("CONFIG_RUN_TYPE is not set and is needed"); return; } TString sfname(fname); printf("sim.C: running in %s mode on run %d for %d events and skipping %d esd events\n",embrun,run,nev,nskip); printf("sim.C: rawfile %s and esdfile %s \n",sfname.Data(),esdname); AliSimulation simulator; // BACKGROUND: Convert raw data to SDigits if (!(strcmp(embrun,"kBackground"))){ AliCDBManager *cdbm = AliCDBManager::Instance(); cdbm->SetDefaultStorage("alien://Folder=/alice/data/2011/OCDB"); cdbm->SetRun(run); AliGRPManager grpM; grpM.ReadGRPEntry(); grpM.SetMagField(); printf("Field is locked now. It cannot be changed in Config.C\n"); simulator.SetMakeSDigits("MUON ITS"); // only physics events sfname += "?EventType=7"; // select one trigger ... if (trgname){ AliCDBEntry *grp_ctp = cdbm->Get("GRP/CTP/Config",run); AliTriggerConfiguration *trg_conf = (AliTriggerConfiguration *)grp_ctp->GetObject(); trg_conf->Print(); TObjArray trg_masks = trg_conf->GetClasses(); // Reference!!! std::vector<unsigned char> triggerconfs; for(Int_t iobj = 0; iobj < trg_masks.GetEntriesFast(); iobj++){ AliTriggerClass *trg_class = (AliTriggerClass*)trg_masks.UncheckedAt(iobj); AliTriggerCluster *trg_clust = (AliTriggerCluster *)trg_class->GetCluster(); // printf("%s %s \n",trg_class->GetName(),trgname); if(TString(trg_class->GetName()).Contains(trgname)){ printf("We will embed into events containing this trigger name(mask): %s(%d)\n",trg_class->GetName(),trg_class->GetMask()); char triggerbuf[256]; sprintf(triggerbuf, "?Trigger=%d", trg_class->GetMask()); sfname += triggerbuf; // triggerconfs.push_back(trg_class->GetMask()); } } // Int_t itrg = 0; // printf("Number of Trigger Clusters including MUON: %d\n", (Int_t)triggerconfs.size()); // for(std::vector<unsigned char>::iterator it = triggerconfs.begin(); it < triggerconfs.end(); it++) // printf("Trigger Mask %d for MUON: %d\n", itrg++, *it); // filestring += "?EventType=7"; // char triggerbuf[256]; // Int_t triggerval = 0; // for(std::vector<unsigned char>::iterator it = triggerconfs.begin(); it < triggerconfs.end(); it++) // triggerval += *it; // sprintf(triggerbuf, "?Trigger=%d", triggerval); // filestring += triggerbuf; // This line does the trigger selection. It has to be uncommented if one wants to apply trigger selection } printf("Filename: %s\n", sfname.Data()); Int_t iSelEvents = simulator.ConvertRaw2SDigits(sfname.Data(),esdname,nev,nskip); gSystem->Setenv("DC_NEVENTS",Form("%d",iSelEvents)); gSystem->Exec("echo $DC_NEVENTS > selev.log"); // gSystem->Exec("echo ${DC_NEVENTS} > ${DC_NEVENTS}_${DC_NEVENTS}_0_${DC_NEVENTS}.stat"); // done in simrun.C gSystem->Exec("echo in sim.C $DC_NEVENTS"); return; } // Signal: pure signal if (!(strcmp(embrun,"kSignal"))){ if (!gSystem->Getenv("DC_NEVENTS")) { printf("DC_NEVENTS is not set and is needed at this step!!!"); return; } AliCDBManager *cdbm = AliCDBManager::Instance(); cdbm->SetDefaultStorage("alien://Folder=/alice/data/2011/OCDB"); cdbm->SetRun(run); AliGRPManager grpM; grpM.ReadGRPEntry(); grpM.SetMagField(); printf("Field is locked now. It cannot be changed in Config.C\n"); simulator.SetRunGeneration(kFALSE); simulator.SetMakeSDigits(""); simulator.SetMakeDigitsFromHits(""); } // MERGED: Simulate signal and merge with background if (!(strcmp(embrun,"kMerged"))){ simulator.SetRunGeneration(kTRUE); simulator.SetMakeSDigits("MUON ITS"); simulator.EmbedInto("Background/galice.root",1); // THE OCDB PART simulator.SetDefaultStorage("alien://Folder=/alice/data/2011/OCDB"); // Read GRP Data from RAW simulator.SetSpecificStorage("GRP/GRP/Data","alien://Folder=/alice/data/2011/OCDB"); } simulator.SetRunSimulation(kTRUE); simulator.SetMakeDigits("MUON ITS"); simulator.SetRunHLT(""); // simulator.SetRunHLT("libAliHLTMUON.so chains=dHLT-sim"); simulator.SetRunQA(":"); // simulator.SetRunQA("MUON:ALL"); // Mag.field from OCDB simulator.UseMagFieldFromGRP(); // THE OCDB PART // MUON // simulator.SetSpecificStorage("MUON/Calib/Gains","alien://Folder=/alice/simulation/2008/v4-15-Release/Ideal/"); simulator.SetSpecificStorage("MUON/Align/Data","alien://Folder=/alice/simulation/2008/v4-15-Release/Full/"); // MUON Trigger // simulator.SetSpecificStorage("MUON/Calib/GlobalTriggerCrateConfig","alien://folder=/alice/simulation/2008/v4-15-Release/Ideal"); // simulator.SetSpecificStorage("MUON/Calib/LocalTriggerBoardMasks","alien://folder=/alice/simulation/2008/v4-15-Release/Ideal"); // simulator.SetSpecificStorage("MUON/Calib/RegionalTriggerConfig","alien://folder=/alice/simulation/2008/v4-15-Release/Ideal"); // simulator.SetSpecificStorage("MUON/Calib/TriggerEfficiency","alien://folder=/alice/simulation/2008/v4-15-Release/Full"); // The rest simulator.Run(nev); }