P1(PUBLIC pascal trap, void, SystemMenu, LONGINT, menu) { INTEGER i; DCtlHandle dctlh; for (i = 0; i < CW(UnitNtryCnt); ++i) { dctlh = MR(MR(UTableBase)[i].p); if (HxX(dctlh, dCtlMenu) == MBarEnable) { menu = CL(menu); Control(itorn(i), accMenu, (Ptr) &menu); /*-->*/ break; } } }
P0(PUBLIC pascal trap, void, SystemTask) { DCtlHandle dctlh; INTEGER i; for (i = 0; i < CW(UnitNtryCnt); ++i) { dctlh = MR(MR(UTableBase)[i].p); if ((HxX(dctlh, dCtlFlags) & CWC(NEEDTIMEBIT)) && TickCount() >= Hx(dctlh, dCtlCurTicks)) { Control(itorn(i), accRun, (Ptr) 0); HxX(dctlh, dCtlCurTicks) = CL(Hx(dctlh, dCtlCurTicks) + Hx(dctlh, dCtlDelay)); } } }
P serialize_member( const T& t, P end, const member_if<ML, MR, RU>& memb ) { typedef typename ML::type typeL; if ( !( _get_value(t, ML()) == typeL() ) ) return serialize_member( t, end, ML() ); return serialize_member( t, end, MR() ); }
void Riccati ( ElementalMatrix<F>& WPre, ElementalMatrix<F>& X, SignCtrl<Base<F>> ctrl ) { DEBUG_CSE DistMatrixReadProxy<F,F,MC,MR> WProx( WPre ); auto& W = WProx.Get(); const Grid& g = W.Grid(); Sign( W, ctrl ); const Int n = W.Height()/2; DistMatrix<F> WTL(g), WTR(g), WBL(g), WBR(g); PartitionDownDiagonal ( W, WTL, WTR, WBL, WBR, n ); // (ML, MR) = sgn(W) - I ShiftDiagonal( W, F(-1) ); // Solve for X in ML X = -MR DistMatrix<F> ML(g), MR(g); PartitionRight( W, ML, MR, n ); MR *= -1; ls::Overwrite( NORMAL, ML, MR, X ); }
A1(PUBLIC trap, OSErrRET, NMInstall, NMRecPtr, nmptr) { /* The multiple beeps and delays that used to be here make OpenProlog * really irritating to use. */ SysBeep(5); if (MR(nmptr->nmResp)) { if ((LONGINT) nmptr->nmResp == (LONGINT) CLC (-1)) NMRemove(nmptr); else { LONGINT saved0, saved1, saved2, savea0, savea1; ROMlib_hook(notify_procnumber); saved0 = EM_D0; saved1 = EM_D1; saved2 = EM_D2; savea0 = EM_A0; savea1 = EM_A1; PUSHADDR((LONGINT) (long) US_TO_SYN68K(nmptr)); CALL_EMULATOR((syn68k_addr_t) CL((long) nmptr->nmResp)); EM_D0 = saved0; EM_D1 = saved1; EM_D2 = saved2; EM_A0 = savea0; EM_A1 = savea1; } } return noErr; }
int OCCFace::revolve(OCCBase *shape, OCCStruct3d p1, OCCStruct3d p2, double angle) { try { const TopoDS_Shape& shp = shape->getShape(); // Only accept Edge or Wire TopAbs_ShapeEnum type = shp.ShapeType(); if (type != TopAbs_EDGE && type != TopAbs_WIRE) { StdFail_NotDone::Raise("Expected Edge or Wire"); } gp_Dir direction(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z); gp_Ax1 axisOfRevolution(gp_Pnt(p1.x, p1.y, p1.z), direction); BRepPrimAPI_MakeRevol MR(shp, axisOfRevolution, angle, Standard_False); if (!MR.IsDone()) { StdFail_NotDone::Raise("Failed in revolve operation");; } this->setShape(MR.Shape()); // possible fix shape if (!this->fixShape()) StdFail_NotDone::Raise("Shapes not valid"); } catch(Standard_Failure &err) { Handle_Standard_Failure e = Standard_Failure::Caught(); const Standard_CString msg = e->GetMessageString(); if (msg != NULL && strlen(msg) > 1) { setErrorMessage(msg); } else { setErrorMessage("Failed to revolve"); } return 0; } return 1; }
P2(PUBLIC pascal trap, void, SystemClick, EventRecord *, evp, WindowPtr, wp) { Point p; LONGINT pointaslong, val; Rect bounds; LONGINT templ; if (wp) { p.h = CW(evp->where.h); p.v = CW(evp->where.v); if (PtInRgn (p, WINDOW_STRUCT_REGION (wp))) { pointaslong = ((LONGINT)p.v << 16)|(unsigned short)p.h; val = WINDCALL((WindowPtr) wp, wHit, pointaslong); switch (val) { case wInContent: if (WINDOW_HILITED_X (wp)) { templ = (LONGINT) (long) RM(evp); Control (WINDOW_KIND (wp), accEvent, (Ptr) &templ); } else SelectWindow(wp); break; case wInDrag: bounds.top = CW (CW (MBarHeight) + 4); bounds.left = CW (CW (GD_BOUNDS (MR (TheGDevice)).left) + 4); bounds.bottom = CW (CW (GD_BOUNDS (MR (TheGDevice)).bottom) - 4); bounds.right = CW (CW (GD_BOUNDS (MR (TheGDevice)).right) - 4); DragWindow(wp, p, &bounds); break; case wInGoAway: if (TrackGoAway(wp, p)) CloseDeskAcc (WINDOW_KIND (wp)); break; } } else { if (DeskHook) { ROMlib_hook(desk_deskhooknumber); EM_D0 = -1; EM_A0 = (LONGINT) (long) US_TO_SYN68K(evp); CALL_EMULATOR((syn68k_addr_t) (long) CL((long) DeskHook)); } } } }
PRIVATE GWorldPtr gworld_from_pict (PicHandle ph) { GWorldPtr retval; retval = NULL; if (ph) { CGrafPtr save_port; GDHandle save_device; Rect r; OSErr err; GetGWorld (&save_port, &save_device); save_port = MR (save_port); save_device = MR (save_device); r = HxX (ph, picFrame); err = NewGWorld (&retval, 32, &r, NULL, NULL, keepLocal); if (retval) { PixMapHandle pm; retval = MR (retval); SetGWorld (retval, NULL); pm = GetGWorldPixMap (retval); LockPixels (pm); DrawPicture (ph, &r); #if 0 #warning THIS INTERFERES WITH PICT PASTING { char *p; EraseRect (&r); p = GetPixBaseAddr (pm); memset (p, 0x00, 4 * RECT_HEIGHT(&r) * RECT_WIDTH (&r)); memset (p, 0xFF, 4 * RECT_HEIGHT(&r) * RECT_WIDTH (&r) / 2); } #endif UnlockPixels (pm); } SetGWorld (save_port, save_device); } return retval; }
P3(PUBLIC pascal trap, LONGINT, PutScrap, LONGINT, len, ResType, rest, Ptr, p) { OSErr retval; LONGINT l, swappedlen; INTEGER f; LONGINT *lp; if (Cx(ScrapState) < 0) { retval = ZeroScrap(); if (retval != noErr) /*-->*/ return(retval); } #if defined(X) || defined(NEXTSTEP) || defined (SDL) PutScrapX(rest, len, (char *) p, CW (ScrapCount)); #endif /* defined(X) */ if (Cx(ScrapState) == 0) { retval = FSOpen(MR(ScrapName), CW (BootDrive), &f); if (retval != noErr) /*-->*/ return(retval); SetFPos(f, fsFromStart, (LONGINT)Cx(ScrapSize)); l = 4; rest = CL(rest); FSWriteAll(f, &l, (Ptr) &rest); l = 4; swappedlen = CL(len); FSWriteAll(f, &l, (Ptr) &swappedlen); l = len = (len + 1) & -2L; FSWriteAll(f, &len, p); FSClose(f); } else { SetHandleSize(MR(ScrapHandle), (Size)Cx(ScrapSize) + 8); if (MemErr != noErr) /*-->*/ return CW(MemErr); /* alignment stuff */ lp = (LONGINT *)((char *)STARH(MR(ScrapHandle)) + Cx(ScrapSize)); *lp++ = CL(rest); *lp++ = CL(len); len = (len + 1) & -2L; PtrAndHand(p, MR(ScrapHandle), (Size)len); } ScrapSize = CL(CL(ScrapSize) + 8 + len); return noErr; }
void mat_set(Matrix* Mat, int l, float val) { int i,j,k; for(i=0; i<Mat->mrows; i++) for(j=0; j<Mat->mcols; j++) for(k=0; k<Mat->mdeps; k++) MR(Mat,l,i,j,k)= val; }
void mat_set_init(Matrix* Mat) { int i,j,k,l; float tt; for(i=0; i<Mat->mrows; i++) for(j=0; j<Mat->mcols; j++) for(k=0; k<Mat->mdeps; k++) MR(Mat,0,i,j,k)= (float)(i*i) /(float)((Mat->mrows - 1)*(Mat->mrows - 1)); }
P1(PUBLIC pascal trap, BOOLEAN, SystemEvent, EventRecord *, evp) { BOOLEAN retval; WindowPeek wp; INTEGER rn; DCtlHandle dctlh; LONGINT templ; if (SEvtEnb) { wp = 0; switch (evp->what) { default: case CWC(nullEvent): case CWC(mouseDown): case CWC(networkEvt): case CWC(driverEvt): case CWC(app1Evt): case CWC(app2Evt): case CWC(app3Evt): case CWC(app4Evt): break; case CWC(mouseUp): case CWC(keyDown): case CWC(keyUp): case CWC(autoKey): wp = (WindowPeek) FrontWindow(); break; case CWC(updateEvt): case CWC(activateEvt): wp = (WindowPeek) MR(evp->message); break; case CWC(diskEvt): /* NOTE: I think the code around toolevent.c:277 should really be here. I'm not going to get all excited about it right now though. */ break; } if (wp) { rn = WINDOW_KIND (wp); if ((retval = rn < 0)) { dctlh = rntodctlh(rn); if (Hx(dctlh, dCtlEMask) & (1 << CW(evp->what))) { templ = (LONGINT) (long) RM(evp); Control(rn, accEvent, (Ptr) &templ); } } } else retval = FALSE; } else retval = FALSE; return retval; }
P0(PUBLIC pascal trap, LONGINT, UnloadScrap) { OSErr retval; INTEGER f; LONGINT l = Cx(ScrapSize); if (Cx(ScrapState) > 0) { retval = cropen(&f); if (retval != noErr) /*-->*/ return(retval); HLock(MR(ScrapHandle)); retval = FSWriteAll(f, &l, STARH(MR(ScrapHandle))); HUnlock(MR(ScrapHandle)); if (retval != noErr) /*-->*/ return(retval); retval = FSClose(f); if (retval != noErr) /*-->*/ return(retval); ScrapState = 0; } return noErr; }
PUBLIC void check_lists (void) { ll_elem **pp; for (pp = &ll_head; *pp; pp = &(*pp)->next) { GrafPtr gp; gp = HxP((*pp)->list, port); if (gp != (*pp)->orig_port) (*pp)->lastTextProc = MR(gp->grafProcs)->textProc; } }
A2(PUBLIC, OSErr, ROMlib_serialopen, ParmBlkPtr, pbp, /* INTERNAL */ DCtlPtr, dcp) { OSErr err; auto DCtlPtr otherp; /* auto due to old compiler bug */ hiddenh h; #if defined (LINUX) || defined (NEXTSTEP) const char *devname, *tempname; LONGINT fd, ourpid, theirpid, newfd, oumask; #endif err = noErr; if (!(dcp->dCtlFlags & CWC(OPENBIT))) { h = (hiddenh) NewHandle(sizeof(hidden)); dcp->dCtlStorage = (Handle) RM(h); otherp = otherdctl(pbp); if (otherp && (otherp->dCtlFlags & CWC(OPENBIT))) { *STARH(h) = *STARH((hiddenh) (long) MR(otherp->dCtlStorage)); dcp->dCtlFlags |= CWC(OPENBIT); } else { #if defined (LINUX) || defined (NEXTSTEP) err = permErr; if ((devname = specialname(pbp, &lockname, &tempname))) { oumask = umask(0); if (!tempname) err = noErr; else if ((fd = Uopen(tempname, O_BINARY|O_CREAT|O_WRONLY, 0666L)) >= 0) { ourpid = getpid(); if (write(fd, &ourpid, sizeof(ourpid)) == sizeof(ourpid)) { if (Ulink(tempname, lockname) == 0) err = noErr; else { if ((newfd = Uopen(lockname, O_BINARY|O_RDWR, 0)) >= 0) { if (read(newfd, &theirpid, sizeof(theirpid)) == sizeof(theirpid)) if ((kill(theirpid, 0) != 0) && errno == ESRCH) { err = noErr; Uunlink(lockname); Ulink(tempname, lockname); } close(newfd); } } Uunlink(tempname); } close(fd); } umask(oumask); } #endif if (err == noErr) { #if defined (LINUX) || defined (NEXTSTEP) HxX(h, fd) = ROMlib_priv_open(devname, O_BINARY|O_RDWR); if (HxX(h, fd) < 0) err = HxX(h, fd); /* error return piggybacked */ else { #if defined(TERMIO) err = ioctl(HxX(h, fd), TCGETA, &HxX(h, state)) < 0 ? ROMlib_maperrno() : noErr; #else if (ioctl(HxX(h, fd), TIOCGETP, &HxX(h, sgttyb)) < 0 || ioctl(HxX(h, fd), TIOCGETC, &HxX(h, tchars)) < 0 || ioctl(HxX(h, fd), TIOCLGET, &HxX(h, lclmode)) < 0) err = ROMlib_maperrno(); #endif #else HxX(h, fd) = (CW(pbp->cntrlParam.ioCRefNum) == AINREFNUM || CW(pbp->cntrlParam.ioCRefNum) == AOUTREFNUM) ? 0 : 1; #endif dcp->dCtlFlags |= CWC(OPENBIT); SerReset(CW(pbp->cntrlParam.ioCRefNum), (CW(pbp->cntrlParam.ioCRefNum) == AINREFNUM || CW(pbp->cntrlParam.ioCRefNum) == AOUTREFNUM) ? CW(SPPortA) : CW(SPPortB)); #if defined (LINUX) || defined (NEXTSTEP) } #endif } } } #if defined(SERIALDEBUG) warning_trace_info("serial open returning %d", (LONGINT) err); #endif DOCOMPLETION(pbp, err); }
P unserialize_member( T& t, P beg, P end, member_if<ML, MR, true>, bool& unserialized ) { return unserialize_member(t, beg, end, MR(), unserialized); }
bool SparseMatrixTest(const size_t & size, const C_FLOAT64 & sparseness, const unsigned C_INT32 & seed, const bool & RMP, const bool & dgemmFlag, const bool & SMP, const bool & CCMP) { size_t i, j, l, loop = 1; CRandom * pRandom = CRandom::createGenerator(CRandom::mt19937, seed); // If the sparseness is not specified we expect 4 metabolites per reaction C_FLOAT64 Sparseness = sparseness; if (Sparseness == 0.0) Sparseness = 4.0 / size; CMatrix< C_FLOAT64 > M(size - 3, size); CSparseMatrix S(size - 3, size); CMatrix< C_FLOAT64 > MM(size, size + 3); CSparseMatrix Ss(size, size + 3); C_FLOAT64 tmp; for (i = 0; i < size - 3; i++) for (j = 0; j < size; j++) { if (pRandom->getRandomCC() < Sparseness) S(i, j) = (pRandom->getRandomCC() - 0.5) * 100.0; } for (i = 0; i < size; i++) for (j = 0; j < size + 3; j++) { if (pRandom->getRandomCC() < Sparseness) Ss(i, j) = (pRandom->getRandomCC() - 0.5) * 100.0; } M = S; MM = Ss; CCompressedColumnFormat C(S); CCompressedColumnFormat CC(Ss); std::cout << "Memory requirements for sparseness:\t" << Sparseness << std::endl; tmp = (C_FLOAT64) sizeof(CMatrix< C_FLOAT64 >) + size * size * sizeof(C_FLOAT64); std::cout << "Matrix(" << size << "x" << size << "):\t" << tmp << std::endl; C_FLOAT64 tmp2 = (C_FLOAT64) sizeof(CSparseMatrix) + 2 * size * sizeof(std::vector<CSparseMatrixElement *>) + 2 * size * sizeof(C_FLOAT64) + S.numNonZeros() * sizeof(CSparseMatrixElement); std::cout << "Sparse(" << size << "x" << size << "):\t" << tmp2 << std::endl; std::cout << "Sparse/Matrix:\t" << tmp2 / tmp << std::endl; tmp2 = (C_FLOAT64) sizeof(CCompressedColumnFormat) + 2 * C.numNonZeros() * sizeof(C_FLOAT64) + (size + 1) * sizeof(C_FLOAT64); std::cout << "CompressedColumnFormat(" << size << "x" << size << "):\t" << tmp2 << std::endl; std::cout << "CompressedColumnFormat/Matrix:\t" << tmp2 / tmp << std::endl << std::endl; CCopasiTimer CPU(CCopasiTimer::PROCESS); CCopasiTimer WALL(CCopasiTimer::WALL); if (RMP) { // Regular Matrix Product CPU.start(); WALL.start(); for (l = 0; l < loop; l++) { CMatrix< C_FLOAT64 > MR(M.numRows(), MM.numCols()); const C_FLOAT64 *pTmp1, *pTmp2, *pTmp4, *pTmp5; const C_FLOAT64 *pEnd1, *pEnd2, *pEnd4; C_FLOAT64 *pTmp3; size_t LDA = M.numCols(); size_t LDB = MM.numCols(); pTmp1 = M.array(); pEnd1 = pTmp1 + M.numRows() * LDA; pEnd2 = MM.array() + LDB; pTmp3 = MR.array(); for (; pTmp1 < pEnd1; pTmp1 += LDA) for (pTmp2 = MM.array(); pTmp2 < pEnd2; pTmp2++, pTmp3++) { *pTmp3 = 0.0; for (pTmp4 = pTmp1, pTmp5 = pTmp2, pEnd4 = pTmp4 + LDA; pTmp4 < pEnd4; pTmp4++, pTmp5 += LDB) * pTmp3 += *pTmp4 **pTmp5; } } CPU.calculateValue(); WALL.calculateValue(); std::cout << "Matrix * Matrix:\t"; CPU.print(&std::cout); std::cout << "\t"; WALL.print(&std::cout); std::cout << std::endl; } if (dgemmFlag) { CPU.start(); WALL.start(); for (l = 0; l < loop; l++) { CMatrix< C_FLOAT64 > dgemmR(M.numRows(), MM.numCols()); char T = 'N'; C_INT m = (C_INT) MM.numCols(); /* LDA, LDC */ C_INT n = (C_INT) M.numRows(); C_INT k = (C_INT) M.numCols(); /* LDB */ C_FLOAT64 Alpha = 1.0; C_FLOAT64 Beta = 0.0; dgemm_(&T, &T, &m, &n, &k, &Alpha, MM.array(), &m, M.array(), &k, &Beta, dgemmR.array(), &m); } /* for (i = 0; i < MR.numRows(); i++) for (j = 0; j < MR.numCols(); j++) assert(fabs(MR(i, j) - dgemmR(i, j)) <= 100.0 * std::numeric_limits< C_FLOAT64 >::epsilon() * fabs(MR(i, j))); */ CPU.calculateValue(); WALL.calculateValue(); std::cout << "dgemm(Matrix, Matrix):\t"; CPU.print(&std::cout); std::cout << "\t"; WALL.print(&std::cout); std::cout << std::endl; } // Sparse Matrix Product if (SMP) { CPU.start(); WALL.start(); for (l = 0; l < loop; l++) { CSparseMatrix SR(S.numRows(), Ss.numCols()); C_FLOAT64 Tmp; std::vector< std::vector< CSparseMatrixElement * > >::const_iterator itRow; std::vector< std::vector< CSparseMatrixElement * > >::const_iterator endRow; std::vector< CSparseMatrixElement * >::const_iterator itRowElement; std::vector< CSparseMatrixElement * >::const_iterator endRowElement; std::vector< std::vector< CSparseMatrixElement * > >::const_iterator itCol; std::vector< std::vector< CSparseMatrixElement * > >::const_iterator endCol; std::vector< CSparseMatrixElement * >::const_iterator itColElement; std::vector< CSparseMatrixElement * >::const_iterator endColElement; for (itRow = S.getRows().begin(), endRow = S.getRows().end(); itRow != endRow; ++itRow) { endRowElement = itRow->end(); for (itCol = Ss.getColumns().begin(), endCol = Ss.getColumns().end(); itCol != endCol; ++itCol) { Tmp = 0; itRowElement = itRow->begin(); itColElement = itCol->begin(); endColElement = itCol->end(); while (itRowElement != endRowElement && itColElement != endColElement) { while (itRowElement != endRowElement && (*itRowElement)->col() < (*itColElement)->row()) ++itRowElement; if (itRowElement == endRowElement) break; while (itColElement != endColElement && (*itColElement)->row() < (*itRowElement)->col()) ++itColElement; if (itColElement == endColElement) break; if ((*itRowElement)->col() != (*itColElement)->row()) continue; Tmp += **itRowElement ***itColElement; ++itRowElement; ++itColElement; } if (fabs(Tmp) < SR.getTreshold()) continue; SR.insert((*itRow->begin())->row(), (*itCol->begin())->col(), Tmp); } } } CPU.calculateValue(); WALL.calculateValue(); std::cout << "Sparse * Sparse:\t"; CPU.print(&std::cout); std::cout << "\t"; WALL.print(&std::cout); std::cout << std::endl; /* for (i = 0; i < MR.numRows(); i++) for (j = 0; j < MR.numCols(); j++) assert(fabs(MR(i, j) - SR(i, j)) < SR.getTreshold()); */ } // Compressed Column Format Product if (CCMP) { CPU.start(); WALL.start(); for (l = 0; l < loop; l++) { CSparseMatrix TmpR(C.numRows(), CC.numCols()); CCompressedColumnFormat CR(C.numRows(), CC.numCols(), 0); C_FLOAT64 Tmp; size_t imax = CR.numRows(); size_t jmax = CR.numCols(); C_FLOAT64 * pColElement, * pEndColElement; size_t * pColElementRow, * pEndColElementRow; size_t * pColStart; CCompressedColumnFormat::const_row_iterator itRowElement; CCompressedColumnFormat::const_row_iterator endRowElement = C.endRow(0); for (j = 0, pColStart = CC.getColumnStart(); j < jmax; j++, pColStart++) { for (i = 0; i < imax; i++) { Tmp = 0; itRowElement = C.beginRow(i); pColElement = CC.getValues() + *pColStart; pEndColElement = CC.getValues() + *(pColStart + 1); pColElementRow = CC.getRowIndex() + *pColStart; pEndColElementRow = CC.getRowIndex() + *(pColStart + 1); while (itRowElement != endRowElement && pColElement != pEndColElement) { while (itRowElement != endRowElement && itRowElement.getColumnIndex() < *pColElementRow) ++itRowElement; if (!(itRowElement != endRowElement)) break; while (pColElement != pEndColElement && *pColElementRow < itRowElement.getColumnIndex()) { ++pColElement; ++pColElementRow; } if (pColElement == pEndColElement) break; if (itRowElement.getColumnIndex() != *pColElementRow) continue; Tmp += *itRowElement **pColElement; ++itRowElement; ++pColElement; ++pColElementRow; } if (fabs(Tmp) < TmpR.getTreshold()) continue; TmpR.insert(i, j, Tmp); } } CR = TmpR; } CPU.calculateValue(); WALL.calculateValue(); std::cout << "Compressed * Compressed:\t"; CPU.print(&std::cout); std::cout << "\t"; WALL.print(&std::cout); std::cout << std::endl; /* for (i = 0; i < MR.numRows(); i++) for (j = 0; j < MR.numCols(); j++) assert(fabs(MR(i, j) - TmpR(i, j)) < SR.getTreshold()); */ } std::cout << std::endl; std::cout << std::endl; return true; }
P3(PUBLIC pascal trap, LONGINT, GetScrap, Handle, h, ResType, rest, LONGINT *, off) { OSErr retval; LONGINT l = 0, incr, s, ltoread, restlen[2]; unsigned char *p; int found; INTEGER f; Handle temph; #if !defined (LETGCCWAIL) s = 0; #endif /* LETGCCWAIL */ if (h) temph = 0; else { temph = NewHandle((Size) 0); h = temph; } #if defined(X) || defined(NEXTSTEP) || defined (SDL) s = GetScrapX(rest, (char **) h); if (s >= 0) { *off = 0; /* ack... could mess people up */ /*-->*/ RETURN(s); } #endif /* defined(X) */ if (Cx(ScrapState) < 0) { retval = ZeroScrap(); if (retval != noErr) /*-->*/ RETURN(retval); } if (ScrapState == 0) { retval = FSOpen(MR(ScrapName), CW (BootDrive), &f); if (retval != noErr) /*-->*/ RETURN(retval); found = FALSE; while (l < Cx(ScrapSize) && !found) { ltoread = 8; FSReadAll(f, <oread, (Ptr) restlen); s = CL(restlen[1]); if (rest == CL(restlen[0])) found = TRUE; else { incr = (8 + s + 1) & ~1L; l += incr; SetFPos(f, fsFromMark, incr); } } if (l >= Cx(ScrapSize)) { FSClose(f); /*-->*/ RETURN(noTypeErr); } ReallocHandle(h, s); if (MemErr != noErr) /*-->*/ RETURN(CW(MemErr)); HLock(h); ltoread = s; FSReadAll(f, <oread, STARH(h)); HUnlock(h); FSClose(f); } else { HLock(MR(ScrapHandle)); p = MR(*(unsigned char **)MR(ScrapHandle)); #if 1 || !defined(QUADALIGN) while (l < Cx(ScrapSize) && rest != CL(*(LONGINT *)p)) { s = CL (*((LONGINT *) p + 1)); incr = (8 + s + 1) & ~1L; l += incr; p += incr; } if (l >= Cx(ScrapSize)) { HUnlock(MR(ScrapHandle)); /*-->*/ RETURN(noTypeErr); } s = CL (*((LONGINT *)p + 1)); #else /* QUADALIGN */ while (l < Cx(ScrapSize) && rest != SNAGLONG(p)) { incr = 8 + ((s = SNAGLONG(p + sizeof(LONGINT))) + 1) & -2L; l += incr; p += incr; } if (l >= Cx(ScrapSize)) { HUnlock(MR(ScrapHandle)); /*-->*/ RETURN(noTypeErr); } s = *((LONGINT *)p + 1); #endif /* QUADALIGN */ PtrToXHand((Ptr) (p+8), h, s); HUnlock(MR(ScrapHandle)); } *off = CL(l+8); RETURN(s); }
PRIVATE GWorldPtr gworld_from_surface (SDL_Surface *surfp) { GWorldPtr retval; retval = NULL; if (surfp) { QDErr err; int surf_depth; CTabHandle ctab; ctab = NULL; surf_depth = SDL_Surface_depth (surfp); switch (surf_depth) { case 8: ctab = ctab_from_surface (surfp); break; case 32: break; default: warning_unexpected ("surf_depth = %d", surf_depth); surf_depth = 0; break; } if (surf_depth) { int n_lines; int pixels_per_line; Rect r; n_lines = SDL_Surface_height (surfp); pixels_per_line = SDL_Surface_width (surfp); r.top = CWC (0); r.left = CWC (0); r.bottom = CW (n_lines); r.right = CW (pixels_per_line); { CGrafPtr save_port; GDHandle save_device; GetGWorld (&save_port, &save_device); save_port = MR (save_port); save_device = MR (save_device); err = NewGWorld (&retval, surf_depth, &r, ctab, NULL, keepLocal); SetGWorld (save_port, save_device); } if (retval) { PixMapHandle pm; retval = MR (retval); pm = GetGWorldPixMap (retval); LockPixels (pm); SDL_LockSurface (surfp); switch (surf_depth) { case 8: { uint8 *ip, *eip; uint8 *op; int rowbytes; int pitch; pitch = SDL_Surface_pitch (surfp); rowbytes = PIXMAP_ROWBYTES (pm); ip = SDL_Surface_pixels (surfp); op = (typeof (op)) GetPixBaseAddr (pm); eip = ip + n_lines * pitch; for (; ip != eip; ip += pitch, op += rowbytes) memcpy (op, ip, rowbytes); break; } case 32: { sdl_pixel24 *ip; mac_pixel32 *op; op = (typeof (op)) GetPixBaseAddr (pm); ip = SDL_Surface_pixels (surfp); memcpy (op, ip, n_lines * pixels_per_line * sizeof *op); break; } default: warning_unexpected ("surf_depth = %d", surf_depth); break; } SDL_UnlockSurface (surfp); UnlockPixels (pm); } } } return retval; }
A2(PUBLIC, OSErr, ROMlib_serialprime, ParmBlkPtr, pbp, /* INTERNAL */ DCtlPtr, dcp) { OSErr err; hiddenh h; char *buf; size_t req_count; buf = (char *) MR (pbp->ioParam.ioBuffer); req_count = CL (pbp->ioParam.ioReqCount); err = noErr; if (!(dcp->dCtlFlags & CWC(OPENBIT))) err = notOpenErr; else { #if defined(SERIALDEBUG) warning_trace_info ("serial prime code %d", (LONGINT) (CW(pbp->ioParam.ioTrap) & 0xFF)); #endif h = (hiddenh) MR(dcp->dCtlStorage); switch (CW(pbp->ioParam.ioTrap) & 0xFF) { case aRdCmd: if (CW(pbp->cntrlParam.ioCRefNum) != AINREFNUM && CW(pbp->cntrlParam.ioCRefNum) != BINREFNUM) err = readErr; else { /* this may have to be changed since we aren't looking for parity and framing errors */ #if defined (LINUX) || defined (NEXTSTEP) pbp->ioParam.ioActCount = CL(read(HxX(h, fd), buf, req_count)); #elif defined (MSDOS) || defined (CYGWIN32) pbp->ioParam.ioActCount = CL(serial_bios_read(HxX(h, fd), buf, req_count)); #else #warning not sure what to do here #endif #if defined(SERIALDEBUG) warning_trace_info ("serial prime read %d bytes, first is 0x%0x", (LONGINT) CL(pbp->ioParam.ioActCount), (LONGINT) (unsigned char) buf[0]); #endif } break; case aWrCmd: if (CW(pbp->cntrlParam.ioCRefNum) != AOUTREFNUM && CW(pbp->cntrlParam.ioCRefNum) != BOUTREFNUM) err = writErr; else { #if defined(SERIALDEBUG) warning_trace_info ("serial prime writing %d bytes, first is 0x%0x", (LONGINT) req_count, (LONGINT) (unsigned char) buf[0]); #endif #if defined (LINUX) || defined (NEXTSTEP) pbp->ioParam.ioActCount = CL(write(HxX(h, fd), buf, req_count)); #elif defined (MSDOS) || defined (CYGWIN32) pbp->ioParam.ioActCount = CL( serial_bios_write(HxX(h, fd), buf, req_count)); #else #warning not sure what to do here #endif } break; default: err = badUnitErr; break; } } #if defined(SERIALDEBUG) warning_trace_info ("serial prime returning %d", (LONGINT) err); #endif DOCOMPLETION(pbp, err); }
at::Mat homographyToPose(at::real fx, at::real fy, at::real tagSize, const at::Mat& horig, bool openGLStyle) { // flip the homography along the Y axis to align the // conventional image coordinate system (y=0 at the top) with // the conventional camera coordinate system (y=0 at the // bottom). at::Mat h = horig; at::Mat F = at::Mat::eye(3,3); F(1,1) = F(2,2) = -1; h = F * horig; at::Mat M(4,4); M(0,0) = h(0,0) / fx; M(0,1) = h(0,1) / fx; M(0,3) = h(0,2) / fx; M(1,0) = h(1,0) / fy; M(1,1) = h(1,1) / fy; M(1,3) = h(1,2) / fy; M(2,0) = h(2,0); M(2,1) = h(2,1); M(2,3) = h(2,2); // Compute the scale. The columns of M should be made to be // unit vectors. This is over-determined, so we take the // geometric average. at::real scale0 = sqrt(sq(M(0,0)) + sq(M(1,0)) + sq(M(2,0))); at::real scale1 = sqrt(sq(M(0,1)) + sq(M(1,1)) + sq(M(2,1))); at::real scale = sqrt(scale0*scale1); M *= 1.0/scale; // recover sign of scale factor by noting that observations must // occur in front of the camera. if (M(2,3) > 0) { M *= -1; } // The bottom row should always be [0 0 0 1]. M(3,0) = 0; M(3,1) = 0; M(3,2) = 0; M(3,3) = 1; // recover third rotation vector by crossproduct of the other two // rotation vectors at::Vec3 a( M(0,0), M(1,0), M(2,0) ); at::Vec3 b( M(0,1), M(1,1), M(2,1) ); at::Vec3 ab = a.cross(b); M(0,2) = ab[0]; M(1,2) = ab[1]; M(2,2) = ab[2]; // pull out just the rotation component so we can normalize it. at::Mat R(3,3); for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { R(i,j) = M(i,j); } } // polar decomposition, R = (UV')(VSV') cv::SVD svd(R); at::Mat MR = svd.u * svd.vt; if (!openGLStyle) { MR = F * MR; } for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { M(i,j) = MR(i,j); } } // Scale the results based on the scale in the homography. The // homography assumes that tags span from -1 to +1, i.e., that // they are two units wide (and tall). for (int i = 0; i < 3; i++) { at::real scl = openGLStyle ? 1 : F(i,i); M(i,3) *= scl * tagSize / 2; } return M; }
void mx6_dram_cfg(const struct mx6_ddr_sysinfo *i, const struct mx6_mmdc_calibration *c, const struct mx6_ddr3_cfg *m) { volatile struct mmdc_p_regs *mmdc0; volatile struct mmdc_p_regs *mmdc1; u32 reg; u8 tcke, tcksrx, tcksre, txpdll, taofpd, taonpd, trrd; u8 todtlon, taxpd, tanpd, tcwl, txp, tfaw, tcl; u8 todt_idle_off = 0x4; /* from DDR3 Script Aid spreadsheet */ u16 trcd, trc, tras, twr, tmrd, trtp, trp, twtr, trfc, txs, txpr; u16 CS0_END; u16 tdllk = 0x1ff; /* DLL locking time: 512 cycles (JEDEC DDR3) */ u8 coladdr; int clkper; /* clock period in picoseconds */ int clock; /* clock freq in mHz */ int cs; mmdc0 = (struct mmdc_p_regs *)MMDC_P0_BASE_ADDR; mmdc1 = (struct mmdc_p_regs *)MMDC_P1_BASE_ADDR; /* MX6D/MX6Q: 1066 MHz memory clock, clkper = 1.894ns = 1894ps */ if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D)) { clock = 528; tcwl = 4; } /* MX6S/MX6DL: 800 MHz memory clock, clkper = 2.5ns = 2500ps */ else { clock = 400; tcwl = 3; } clkper = (1000*1000)/clock; /* ps */ todtlon = tcwl; taxpd = tcwl; tanpd = tcwl; tcwl = tcwl; switch (m->density) { case 1: /* 1Gb per chip */ trfc = DIV_ROUND_UP(110000, clkper) - 1; txs = DIV_ROUND_UP(120000, clkper) - 1; break; case 2: /* 2Gb per chip */ trfc = DIV_ROUND_UP(160000, clkper) - 1; txs = DIV_ROUND_UP(170000, clkper) - 1; break; case 4: /* 4Gb per chip */ trfc = DIV_ROUND_UP(260000, clkper) - 1; txs = DIV_ROUND_UP(270000, clkper) - 1; break; case 8: /* 8Gb per chip */ trfc = DIV_ROUND_UP(350000, clkper) - 1; txs = DIV_ROUND_UP(360000, clkper) - 1; break; default: /* invalid density */ printf("invalid chip density\n"); hang(); break; } txpr = txs; switch (m->mem_speed) { case 800: txp = DIV_ROUND_UP(MAX(3*clkper, 7500), clkper) - 1; tcke = DIV_ROUND_UP(MAX(3*clkper, 7500), clkper) - 1; if (m->pagesz == 1) { tfaw = DIV_ROUND_UP(40000, clkper) - 1; trrd = DIV_ROUND_UP(MAX(4*clkper, 10000), clkper) - 1; } else { tfaw = DIV_ROUND_UP(50000, clkper) - 1; trrd = DIV_ROUND_UP(MAX(4*clkper, 10000), clkper) - 1; } break; case 1066: txp = DIV_ROUND_UP(MAX(3*clkper, 7500), clkper) - 1; tcke = DIV_ROUND_UP(MAX(3*clkper, 5625), clkper) - 1; if (m->pagesz == 1) { tfaw = DIV_ROUND_UP(37500, clkper) - 1; trrd = DIV_ROUND_UP(MAX(4*clkper, 7500), clkper) - 1; } else { tfaw = DIV_ROUND_UP(50000, clkper) - 1; trrd = DIV_ROUND_UP(MAX(4*clkper, 10000), clkper) - 1; } break; case 1333: txp = DIV_ROUND_UP(MAX(3*clkper, 6000), clkper) - 1; tcke = DIV_ROUND_UP(MAX(3*clkper, 5625), clkper) - 1; if (m->pagesz == 1) { tfaw = DIV_ROUND_UP(30000, clkper) - 1; trrd = DIV_ROUND_UP(MAX(4*clkper, 6000), clkper) - 1; } else { tfaw = DIV_ROUND_UP(45000, clkper) - 1; trrd = DIV_ROUND_UP(MAX(4*clkper, 7500), clkper) - 1; } break; case 1600: txp = DIV_ROUND_UP(MAX(3*clkper, 6000), clkper) - 1; tcke = DIV_ROUND_UP(MAX(3*clkper, 5000), clkper) - 1; if (m->pagesz == 1) { tfaw = DIV_ROUND_UP(30000, clkper) - 1; trrd = DIV_ROUND_UP(MAX(4*clkper, 6000), clkper) - 1; } else { tfaw = DIV_ROUND_UP(40000, clkper) - 1; trrd = DIV_ROUND_UP(MAX(4*clkper, 7500), clkper) - 1; } break; default: printf("invalid memory speed\n"); hang(); break; } txpdll = DIV_ROUND_UP(MAX(10*clkper, 24000), clkper) - 1; tcl = DIV_ROUND_UP(m->trcd, clkper/10) - 3; tcksre = DIV_ROUND_UP(MAX(5*clkper, 10000), clkper); tcksrx = tcksre; taonpd = DIV_ROUND_UP(2000, clkper) - 1; taofpd = taonpd; trp = DIV_ROUND_UP(m->trcd, clkper/10) - 1; trcd = trp; trc = DIV_ROUND_UP(m->trcmin, clkper/10) - 1; tras = DIV_ROUND_UP(m->trasmin, clkper/10) - 1; twr = DIV_ROUND_UP(15000, clkper) - 1; tmrd = DIV_ROUND_UP(MAX(12*clkper, 15000), clkper) - 1; twtr = ROUND(MAX(4*clkper, 7500)/clkper, 1) - 1; trtp = twtr; CS0_END = ((4*i->cs_density) <= 120) ? (4*i->cs_density)+7 : 127; debug("density:%d Gb (%d Gb per chip)\n", i->cs_density, m->density); debug("clock: %dMHz (%d ps)\n", clock, clkper); debug("memspd:%d\n", m->mem_speed); debug("tcke=%d\n", tcke); debug("tcksrx=%d\n", tcksrx); debug("tcksre=%d\n", tcksre); debug("taofpd=%d\n", taofpd); debug("taonpd=%d\n", taonpd); debug("todtlon=%d\n", todtlon); debug("tanpd=%d\n", tanpd); debug("taxpd=%d\n", taxpd); debug("trfc=%d\n", trfc); debug("txs=%d\n", txs); debug("txp=%d\n", txp); debug("txpdll=%d\n", txpdll); debug("tfaw=%d\n", tfaw); debug("tcl=%d\n", tcl); debug("trcd=%d\n", trcd); debug("trp=%d\n", trp); debug("trc=%d\n", trc); debug("tras=%d\n", tras); debug("twr=%d\n", twr); debug("tmrd=%d\n", tmrd); debug("tcwl=%d\n", tcwl); debug("tdllk=%d\n", tdllk); debug("trtp=%d\n", trtp); debug("twtr=%d\n", twtr); debug("trrd=%d\n", trrd); debug("txpr=%d\n", txpr); debug("CS0_END=%d\n", CS0_END); debug("ncs=%d\n", i->ncs); debug("Rtt_wr=%d\n", i->rtt_wr); debug("Rtt_nom=%d\n", i->rtt_nom); debug("SRT=%d\n", m->SRT); debug("tcl=%d\n", tcl); debug("twr=%d\n", twr); /* * board-specific configuration: * These values are determined empirically and vary per board layout * see: * appnote, ddr3 spreadsheet */ mmdc0->mpwldectrl0 = c->p0_mpwldectrl0; mmdc0->mpwldectrl1 = c->p0_mpwldectrl1; mmdc0->mpdgctrl0 = c->p0_mpdgctrl0; mmdc0->mpdgctrl1 = c->p0_mpdgctrl1; mmdc0->mprddlctl = c->p0_mprddlctl; mmdc0->mpwrdlctl = c->p0_mpwrdlctl; if (i->dsize > 1) { mmdc1->mpwldectrl0 = c->p1_mpwldectrl0; mmdc1->mpwldectrl1 = c->p1_mpwldectrl1; mmdc1->mpdgctrl0 = c->p1_mpdgctrl0; mmdc1->mpdgctrl1 = c->p1_mpdgctrl1; mmdc1->mprddlctl = c->p1_mprddlctl; mmdc1->mpwrdlctl = c->p1_mpwrdlctl; } /* Read data DQ Byte0-3 delay */ mmdc0->mprddqby0dl = (u32)0x33333333; mmdc0->mprddqby1dl = (u32)0x33333333; if (i->dsize > 0) { mmdc0->mprddqby2dl = (u32)0x33333333; mmdc0->mprddqby3dl = (u32)0x33333333; } if (i->dsize > 1) { mmdc1->mprddqby0dl = (u32)0x33333333; mmdc1->mprddqby1dl = (u32)0x33333333; mmdc1->mprddqby2dl = (u32)0x33333333; mmdc1->mprddqby3dl = (u32)0x33333333; } /* MMDC Termination: rtt_nom:2 RZQ/2(120ohm), rtt_nom:1 RZQ/4(60ohm) */ reg = (i->rtt_nom == 2) ? 0x00011117 : 0x00022227; mmdc0->mpodtctrl = reg; if (i->dsize > 1) mmdc1->mpodtctrl = reg; /* complete calibration */ reg = (1 << 11); /* Force measurement on delay-lines */ mmdc0->mpmur0 = reg; if (i->dsize > 1) mmdc1->mpmur0 = reg; /* Step 1: configuration request */ mmdc0->mdscr = (u32)(1 << 15); /* config request */ /* Step 2: Timing configuration */ reg = (trfc << 24) | (txs << 16) | (txp << 13) | (txpdll << 9) | (tfaw << 4) | tcl; mmdc0->mdcfg0 = reg; reg = (trcd << 29) | (trp << 26) | (trc << 21) | (tras << 16) | (1 << 15) | /* trpa */ (twr << 9) | (tmrd << 5) | tcwl; mmdc0->mdcfg1 = reg; reg = (tdllk << 16) | (trtp << 6) | (twtr << 3) | trrd; mmdc0->mdcfg2 = reg; reg = (taofpd << 27) | (taonpd << 24) | (tanpd << 20) | (taxpd << 16) | (todtlon << 12) | (todt_idle_off << 4); mmdc0->mdotc = reg; mmdc0->mdasp = CS0_END; /* CS addressing */ /* Step 3: Configure DDR type */ reg = (i->cs1_mirror << 19) | (i->walat << 16) | (i->bi_on << 12) | (i->mif3_mode << 9) | (i->ralat << 6); mmdc0->mdmisc = reg; /* Step 4: Configure delay while leaving reset */ reg = (txpr << 16) | (i->sde_to_rst << 8) | (i->rst_to_cke << 0); mmdc0->mdor = reg; /* Step 5: Configure DDR physical parameters (density and burst len) */ coladdr = m->coladdr; if (m->coladdr == 8) /* 8-bit COL is 0x3 */ coladdr += 4; else if (m->coladdr == 12) /* 12-bit COL is 0x4 */ coladdr += 1; reg = (m->rowaddr - 11) << 24 | /* ROW */ (coladdr - 9) << 20 | /* COL */ (1 << 19) | /* Burst Length = 8 for DDR3 */ (i->dsize << 16); /* DDR data bus size */ mmdc0->mdctl = reg; /* Step 6: Perform ZQ calibration */ reg = (u32)0xa1390001; /* one-time HW ZQ calib */ mmdc0->mpzqhwctrl = reg; if (i->dsize > 1) mmdc1->mpzqhwctrl = reg; /* Step 7: Enable MMDC with desired chip select */ reg = mmdc0->mdctl | (1 << 31) | /* SDE_0 for CS0 */ ((i->ncs == 2) ? 1 : 0) << 30; /* SDE_1 for CS1 */ mmdc0->mdctl = reg; /* Step 8: Write Mode Registers to Init DDR3 devices */ for (cs = 0; cs < i->ncs; cs++) { /* MR2 */ reg = (i->rtt_wr & 3) << 9 | (m->SRT & 1) << 7 | ((tcwl - 3) & 3) << 3; mmdc0->mdscr = (u32)MR(reg, 2, 3, cs); /* MR3 */ mmdc0->mdscr = (u32)MR(0, 3, 3, cs); /* MR1 */ reg = ((i->rtt_nom & 1) ? 1 : 0) << 2 | ((i->rtt_nom & 2) ? 1 : 0) << 6; mmdc0->mdscr = (u32)MR(reg, 1, 3, cs); reg = ((tcl - 1) << 4) | /* CAS */ (1 << 8) | /* DLL Reset */ ((twr - 3) << 9); /* Write Recovery */ /* MR0 */ mmdc0->mdscr = (u32)MR(reg, 0, 3, cs); /* ZQ calibration */ reg = (1 << 10); mmdc0->mdscr = (u32)MR(reg, 0, 4, cs); } /* Step 10: Power down control and self-refresh */ reg = (tcke & 0x7) << 16 | 5 << 12 | /* PWDT_1: 256 cycles */ 5 << 8 | /* PWDT_0: 256 cycles */ 1 << 6 | /* BOTH_CS_PD */ (tcksrx & 0x7) << 3 | (tcksre & 0x7); mmdc0->mdpdc = reg; mmdc0->mapsr = (u32)0x00011006; /* ADOPT power down enabled */ /* Step 11: Configure ZQ calibration: one-time and periodic 1ms */ mmdc0->mpzqhwctrl = (u32)0xa1390003; if (i->dsize > 1) mmdc1->mpzqhwctrl = (u32)0xa1390003; /* Step 12: Configure and activate periodic refresh */ reg = (1 << 14) | /* REF_SEL: Periodic refresh cycles of 32kHz */ (7 << 11); /* REFR: Refresh Rate - 8 refreshes */ mmdc0->mdref = reg; /* Step 13: Deassert config request - init complete */ mmdc0->mdscr = (u32)0x00000000; /* wait for auto-ZQ calibration to complete */ mdelay(1); }
RooWorkspace* makeInvertedANFit(TTree* tree, float forceSigma=-1, bool constrainMu=false, float forceMu=-1) { RooWorkspace *ws = new RooWorkspace("ws",""); std::vector< TString (*)(TString, RooRealVar&, RooWorkspace&) > bkgPdfList; bkgPdfList.push_back(makeSingleExp); bkgPdfList.push_back(makeDoubleExp); #if DEBUG==0 //bkgPdfList.push_back(makeTripleExp); bkgPdfList.push_back(makeModExp); bkgPdfList.push_back(makeSinglePow); bkgPdfList.push_back(makeDoublePow); bkgPdfList.push_back(makePoly2); bkgPdfList.push_back(makePoly3); #endif RooRealVar mgg("mgg","m_{#gamma#gamma}",103,160,"GeV"); mgg.setBins(38); mgg.setRange("sideband_low", 103,120); mgg.setRange("sideband_high",131,160); mgg.setRange("signal",120,131); RooRealVar MR("MR","",0,3000,"GeV"); MR.setBins(60); RooRealVar Rsq("t1Rsq","",0,1,"GeV"); Rsq.setBins(20); RooRealVar hem1_M("hem1_M","",-1,2000,"GeV"); hem1_M.setBins(40); RooRealVar hem2_M("hem2_M","",-1,2000,"GeV"); hem2_M.setBins(40); RooRealVar ptgg("ptgg","p_{T}^{#gamma#gamma}",0,500,"GeV"); ptgg.setBins(50); RooDataSet data("data","",tree,RooArgSet(mgg,MR,Rsq,hem1_M,hem2_M,ptgg)); RooDataSet* blind_data = (RooDataSet*)data.reduce("mgg<121 || mgg>130"); std::vector<TString> tags; //fit many different background models for(auto func = bkgPdfList.begin(); func != bkgPdfList.end(); func++) { TString tag = (*func)("bonly",mgg,*ws); tags.push_back(tag); ws->pdf("bonly_"+tag+"_ext")->fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE),RooFit::Range("sideband_low,sideband_high")); RooFitResult* bres = ws->pdf("bonly_"+tag+"_ext")->fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE),RooFit::Range("sideband_low,sideband_high")); bres->SetName(tag+"_bonly_fitres"); ws->import(*bres); //make blinded fit RooPlot *fmgg_b = mgg.frame(); blind_data->plotOn(fmgg_b,RooFit::Range("sideband_low,sideband_high")); TBox blindBox(121,fmgg_b->GetMinimum()-(fmgg_b->GetMaximum()-fmgg_b->GetMinimum())*0.015,130,fmgg_b->GetMaximum()); blindBox.SetFillColor(kGray); fmgg_b->addObject(&blindBox); ws->pdf("bonly_"+tag+"_ext")->plotOn(fmgg_b,RooFit::LineColor(kRed),RooFit::Range("Full"),RooFit::NormRange("sideband_low,sideband_high")); fmgg_b->SetName(tag+"_blinded_frame"); ws->import(*fmgg_b); delete fmgg_b; //set all the parameters constant RooArgSet* vars = ws->pdf("bonly_"+tag)->getVariables(); RooFIter iter = vars->fwdIterator(); RooAbsArg* a; while( (a = iter.next()) ){ if(string(a->GetName()).compare("mgg")==0) continue; static_cast<RooRealVar*>(a)->setConstant(kTRUE); } //make the background portion of the s+b fit (*func)("b",mgg,*ws); RooRealVar sigma(tag+"_s_sigma","",5,0,100); if(forceSigma!=-1) { sigma.setVal(forceSigma); sigma.setConstant(true); } RooRealVar mu(tag+"_s_mu","",126,120,132); if(forceMu!=-1) { mu.setVal(forceMu); mu.setConstant(true); } RooGaussian sig(tag+"_sig_model","",mgg,mu,sigma); RooRealVar Nsig(tag+"_sb_Ns","",5,0,100); RooRealVar Nbkg(tag+"_sb_Nb","",100,0,100000); RooRealVar HiggsMass("HiggsMass","",125.1); RooRealVar HiggsMassError("HiggsMassError","",0.24); RooGaussian HiggsMassConstraint("HiggsMassConstraint","",mu,HiggsMass,HiggsMassError); RooAddPdf fitModel(tag+"_sb_model","",RooArgList( *ws->pdf("b_"+tag), sig ),RooArgList(Nbkg,Nsig)); RooFitResult* sbres; RooAbsReal* nll; if(constrainMu) { fitModel.fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); sbres = fitModel.fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); nll = fitModel.createNLL(data,RooFit::NumCPU(4),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); } else { fitModel.fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE)); sbres = fitModel.fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE)); nll = fitModel.createNLL(data,RooFit::NumCPU(4),RooFit::Extended(kTRUE)); } sbres->SetName(tag+"_sb_fitres"); ws->import(*sbres); ws->import(fitModel); RooPlot *fmgg = mgg.frame(); data.plotOn(fmgg); fitModel.plotOn(fmgg); ws->pdf("b_"+tag+"_ext")->plotOn(fmgg,RooFit::LineColor(kRed),RooFit::Range("Full"),RooFit::NormRange("Full")); fmgg->SetName(tag+"_frame"); ws->import(*fmgg); delete fmgg; RooMinuit(*nll).migrad(); RooPlot *fNs = Nsig.frame(0,25); fNs->SetName(tag+"_Nsig_pll"); RooAbsReal *pll = nll->createProfile(Nsig); //nll->plotOn(fNs,RooFit::ShiftToZero(),RooFit::LineColor(kRed)); pll->plotOn(fNs); ws->import(*fNs); delete fNs; RooPlot *fmu = mu.frame(125,132); fmu->SetName(tag+"_mu_pll"); RooAbsReal *pll_mu = nll->createProfile(mu); pll_mu->plotOn(fmu); ws->import(*fmu); delete fmu; } RooArgSet weights("weights"); RooArgSet pdfs_bonly("pdfs_bonly"); RooArgSet pdfs_b("pdfs_b"); RooRealVar minAIC("minAIC","",1E10); //compute AIC stuff for(auto t = tags.begin(); t!=tags.end(); t++) { RooAbsPdf *p_bonly = ws->pdf("bonly_"+*t); RooAbsPdf *p_b = ws->pdf("b_"+*t); RooFitResult *sb = (RooFitResult*)ws->obj(*t+"_bonly_fitres"); RooRealVar k(*t+"_b_k","",p_bonly->getParameters(RooArgSet(mgg))->getSize()); RooRealVar nll(*t+"_b_minNll","",sb->minNll()); RooRealVar Npts(*t+"_b_N","",blind_data->sumEntries()); RooFormulaVar AIC(*t+"_b_AIC","2*@0+2*@1+2*@1*(@1+1)/(@2-@1-1)",RooArgSet(nll,k,Npts)); ws->import(AIC); if(AIC.getVal() < minAIC.getVal()) { minAIC.setVal(AIC.getVal()); } //aicExpSum+=TMath::Exp(-0.5*AIC.getVal()); //we will need this precomputed for the next step pdfs_bonly.add(*p_bonly); pdfs_b.add(*p_b); } ws->import(minAIC); //compute the AIC weight float aicExpSum=0; for(auto t = tags.begin(); t!=tags.end(); t++) { RooFormulaVar *AIC = (RooFormulaVar*)ws->obj(*t+"_b_AIC"); aicExpSum+=TMath::Exp(-0.5*(AIC->getVal()-minAIC.getVal())); //we will need this precomputed for the next step } std::cout << "aicExpSum: " << aicExpSum << std::endl; for(auto t = tags.begin(); t!=tags.end(); t++) { RooFormulaVar *AIC = (RooFormulaVar*)ws->obj(*t+"_b_AIC"); RooRealVar *AICw = new RooRealVar(*t+"_b_AICWeight","",TMath::Exp(-0.5*(AIC->getVal()-minAIC.getVal()))/aicExpSum); if( TMath::IsNaN(AICw->getVal()) ) {AICw->setVal(0);} ws->import(*AICw); std::cout << *t << ": " << AIC->getVal()-minAIC.getVal() << " " << AICw->getVal() << std::endl; weights.add(*AICw); } RooAddPdf bonly_AIC("bonly_AIC","",pdfs_bonly,weights); RooAddPdf b_AIC("b_AIC","",pdfs_b,weights); //b_AIC.fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE),RooFit::Range("sideband_low,sideband_high")); //RooFitResult* bres = b_AIC.fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE),RooFit::Range("sideband_low,sideband_high")); //bres->SetName("AIC_b_fitres"); //ws->import(*bres); //make blinded fit RooPlot *fmgg_b = mgg.frame(RooFit::Range("sideband_low,sideband_high")); blind_data->plotOn(fmgg_b,RooFit::Range("sideband_low,sideband_high")); TBox blindBox(121,fmgg_b->GetMinimum()-(fmgg_b->GetMaximum()-fmgg_b->GetMinimum())*0.015,130,fmgg_b->GetMaximum()); blindBox.SetFillColor(kGray); fmgg_b->addObject(&blindBox); bonly_AIC.plotOn(fmgg_b,RooFit::LineColor(kRed),RooFit::Range("Full"),RooFit::NormRange("sideband_low,sideband_high")); fmgg_b->SetName("AIC_blinded_frame"); ws->import(*fmgg_b); delete fmgg_b; #if 1 RooRealVar sigma("AIC_s_sigma","",5,0,100); if(forceSigma!=-1) { sigma.setVal(forceSigma); sigma.setConstant(true); } RooRealVar mu("AIC_s_mu","",126,120,132); if(forceMu!=-1) { mu.setVal(forceMu); mu.setConstant(true); } RooGaussian sig("AIC_sig_model","",mgg,mu,sigma); RooRealVar Nsig("AIC_sb_Ns","",5,0,100); RooRealVar Nbkg("AIC_sb_Nb","",100,0,100000); RooRealVar HiggsMass("HiggsMass","",125.1); RooRealVar HiggsMassError("HiggsMassError","",0.24); RooGaussian HiggsMassConstraint("HiggsMassConstraint","",mu,HiggsMass,HiggsMassError); RooAddPdf fitModel("AIC_sb_model","",RooArgList( b_AIC, sig ),RooArgList(Nbkg,Nsig)); RooFitResult* sbres; RooAbsReal *nll; if(constrainMu) { fitModel.fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); sbres = fitModel.fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); nll = fitModel.createNLL(data,RooFit::NumCPU(4),RooFit::Extended(kTRUE),RooFit::ExternalConstraints(RooArgSet(HiggsMassConstraint))); } else { fitModel.fitTo(data,RooFit::Strategy(0),RooFit::Extended(kTRUE)); sbres = fitModel.fitTo(data,RooFit::Strategy(2),RooFit::Save(kTRUE),RooFit::Extended(kTRUE)); nll = fitModel.createNLL(data,RooFit::NumCPU(4),RooFit::Extended(kTRUE)); } assert(nll!=0); sbres->SetName("AIC_sb_fitres"); ws->import(*sbres); ws->import(fitModel); RooPlot *fmgg = mgg.frame(); data.plotOn(fmgg); fitModel.plotOn(fmgg); ws->pdf("b_AIC")->plotOn(fmgg,RooFit::LineColor(kRed),RooFit::Range("Full"),RooFit::NormRange("Full")); fmgg->SetName("AIC_frame"); ws->import(*fmgg); delete fmgg; RooMinuit(*nll).migrad(); RooPlot *fNs = Nsig.frame(0,25); fNs->SetName("AIC_Nsig_pll"); RooAbsReal *pll = nll->createProfile(Nsig); //nll->plotOn(fNs,RooFit::ShiftToZero(),RooFit::LineColor(kRed)); pll->plotOn(fNs); ws->import(*fNs); delete fNs; RooPlot *fmu = mu.frame(125,132); fmu->SetName("AIC_mu_pll"); RooAbsReal *pll_mu = nll->createProfile(mu); pll_mu->plotOn(fmu); ws->import(*fmu); delete fmu; std::cout << "min AIC: " << minAIC.getVal() << std::endl; for(auto t = tags.begin(); t!=tags.end(); t++) { RooFormulaVar *AIC = (RooFormulaVar*)ws->obj(*t+"_b_AIC"); RooRealVar *AICw = ws->var(*t+"_b_AICWeight"); RooRealVar* k = ws->var(*t+"_b_k"); printf("%s & %0.0f & %0.2f & %0.2f \\\\\n",t->Data(),k->getVal(),AIC->getVal()-minAIC.getVal(),AICw->getVal()); //std::cout << k->getVal() << " " << AIC->getVal()-minAIC.getVal() << " " << AICw->getVal() << std::endl; } #endif return ws; }
void CODE50(char far *COM) {static char RR; static char RX; static int R1,R2,B2,IS; static char BD; static char DD; static unsigned int DDD; static long *RR1; static long *RR2; static long *REZ; static long RREZ; static unsigned long URREZ; static unsigned long URREZ_AL; static unsigned long URREZ_WORK; static unsigned long URREZ2; static unsigned long URREZ3; static unsigned int FLA; static unsigned long uRREZ; static unsigned long *URR1; static unsigned long *URR2; static unsigned long ADRESS; static long double F_W1; static long double F_W2; static long double F_W3; static long double F_W4; static unsigned long R_1; static unsigned long R_2; static unsigned long DEL_DEL; static int psw_cc; #define B1 B2 #define I2 RX #define X2 R2 GET_OPERAND_RX; FORWARD_PSW; /*FORW_PSW();*/ switch(COM[0]) { case 0x50: // if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } // Chk_adrw; // PUT_WORD(ADRESS,R[R1]); /* ST */ T(); break; case 0x51: T00(COM[0]); break; case 0x52: T00(COM[0]); break; case 0x53: T00(COM[0]); break; case 0x54: // if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } Chk_adrw; //URR1=&R[R1];URREZ=GET_WORD(ADRESS); /* N */ //*(URR1)=*(URR1)&URREZ; //R[R1]&=GET_WORD(ADRESS); #ifdef DTA_370 URREZ=GET_WORD(ADRESS); Dtaret; if ((R[R1]&=URREZ)==0) PSW_CC=0; else PSW_CC=1; #else if ((R[R1]&=GET_WORD(ADRESS))==0) PSW_CC=0; else PSW_CC=1; #endif //T(); break; case 0x55: //if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } Chk_adrw; URR1=&R[R1];URREZ=GET_WORD(ADRESS); /* CL */ Dtaret; URR2=&URREZ; if (*(URR1)==*(URR2)) PSW_CC=0; else if (*(URR1) < *(URR2)) PSW_CC=1; else PSW_CC=2; //T(); break; case 0x56: //if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } Chk_adrw; URREZ=GET_WORD(ADRESS); /* O */ Dtaret; if ((R[R1]|=URREZ)==0) PSW_CC=0; else PSW_CC=1; //T(); break; case 0x57: //if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } Chk_adrw; URREZ=GET_WORD(ADRESS); /* X */ Dtaret; if ((R[R1]^=URREZ)==0) PSW_CC=0; else PSW_CC=1; //T(); break; case 0x58: if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } // // Chk_adrw; //#ifdef DTA_370 // URREZ=GET_WORD(ADRESS); // Dtaret; // R[R1]=URREZ; // break; /* L */ //#else // R[R1]=GET_WORD(ADRESS);break; /* L */ //#endif T(); case 0x59: //if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } Chk_adrw; RREZ=GET_WORD(ADRESS); /* C */ Dtaret; if (((signed long)(R[R1]))==RREZ) PSW_CC=0; ///else /// {FLA=_FLAGS; /// if (FLA&0x0080) /*<0*/ PSW_CC=1; /// else /*>0*/ PSW_CC=2; /// } else if (((signed long)(R[R1]))<RREZ) PSW_CC=1; else PSW_CC=2; break; case 0x5a: //if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } Chk_adrw; RR1=&R[R1]; RREZ=GET_WORD(ADRESS); /* A */ // if (TraceOutCmd) // { // fprintf(TraceOutCmd,"REG =%lx ADR=%lx VAl =%lx ",*RR1,ADRESS,RREZ); // } Dtaret; *(RR1)+=RREZ; #include "ds360sr.c" //T(); break; case 0x5b: //if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } Chk_adrw; RR1=&R[R1];RREZ=GET_WORD(ADRESS); /* S */ Dtaret; *(RR1)+= -RREZ; #include "ds360sr.c" //T(); break; case 0x5c: //if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } /* M */ Chk_adrw; R1&=0xfe; uRREZ=GET_WORD(ADRESS); Dtaret; MR(&R[R1],&R[R1+1],&uRREZ); //T(); break; case 0x5d: /* D */ //if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } Chk_adrw; R1&=0xfe; DEL_DEL=GET_WORD(ADRESS); Dtaret; DR(&R[R1],&R[R1+1],&DEL_DEL); //T(); break; case 0x5e: //if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } Chk_adrw; /* AL */ #ifdef DTA_370 RREZ=(signed long)GET_WORD(ADRESS); Dtaret; ((signed long)R[R1])+=RREZ; #else ((signed long)R[R1])+=(signed long)GET_WORD(ADRESS); #endif #include "DS360ALR.C" //T(); break; case 0x5f: //if (ADRESs&0x3) // {RQ_PRG=6; // RETURN=1; // break; // } /* SL */ Chk_adrw; #ifdef DTA_370 RREZ=(signed long)GET_WORD(ADRESS); Dtaret; ((signed long)R[R1])+=(-RREZ); #else ((signed long)R[R1])+=(-(signed long)GET_WORD(ADRESS)); #endif #include "DS360ALR.C" //T(); break; } }
}; SprxPatch psp_emulator_patches[] = { // Sets psp mode as opossed to minis mode. Increases compatibility, removes text protection and makes most savedata work { psp_set_psp_mode_offset, LI(R4, 0), &condition_psp_iso }, { 0 } }; SprxPatch emulator_api_patches[] = { // Read umd patches { psp_read, STDU(SP, 0xFF90, SP), &condition_psp_iso }, { psp_read+4, MFLR(R0), &condition_psp_iso }, { psp_read+8, STD(R0, 0x80, SP), &condition_psp_iso }, { psp_read+0x0C, MR(R8, R7), &condition_psp_iso }, { psp_read+0x10, MR(R7, R6), &condition_psp_iso }, { psp_read+0x14, MR(R6, R5), &condition_psp_iso }, { psp_read+0x18, MR(R5, R4), &condition_psp_iso }, { psp_read+0x1C, MR(R4, R3), &condition_psp_iso }, { psp_read+0x20, LI(R3, SYSCALL8_OPCODE_READ_PSP_UMD), &condition_psp_iso }, { psp_read+0x24, LI(R11, 8), &condition_psp_iso }, { psp_read+0x28, SC, &condition_psp_iso }, { psp_read+0x2C, LD(R0, 0x80, SP), &condition_psp_iso }, { psp_read+0x30, MTLR(R0), &condition_psp_iso }, { psp_read+0x34, ADDI(SP, SP, 0x70), &condition_psp_iso }, { psp_read+0x38, BLR, &condition_psp_iso }, // Read header patches { psp_read+0x3C, STDU(SP, 0xFF90, SP), &condition_psp_iso }, { psp_read+0x40, MFLR(R0), &condition_psp_iso }, { psp_read+0x44, STD(R0, 0x80, SP), &condition_psp_iso },
static Patch kernel_patches[] = { { patch_data1_offset, 0x01000000 }, { patch_func8 + patch_func8_offset1, LI(R3, 0) }, // force lv2open return 0 // disable calls in lv2open to lv1_send_event_locally which makes the system crash { patch_func8 + patch_func8_offset2, NOP }, { patch_func9 + patch_func9_offset, NOP }, // 4.30 - watch: additional call after // psjailbreak, PL3, etc destroy this function to copy their code there. // We don't need that, but let's dummy the function just in case that patch is really necessary { mem_base2, LI(R3, 1) }, { mem_base2 + 4, BLR }, // sys_sm_shutdown, for ps2 let's pass to copy_from_user a fourth parameter { shutdown_patch_offset, MR(R6, R31) }, { module_sdk_version_patch_offset, NOP }, // User thread prio hack (needed for netiso) { user_thread_prio_patch, NOP }, { user_thread_prio_patch2, NOP }, // ODE Protection removal (needed for CFW 4.60+) { lic_patch, LI(R3, 1) }, { ode_patch, LI(R3, 0) }, { ode_patch+4, STD(R3, 0, R9) }, }; #define N_KERNEL_PATCHES (sizeof(kernel_patches) / sizeof(Patch))
A1(PRIVATE, INTEGER *, findid, INTEGER, id) { int i; INTEGER *ip; for (i = CW(*(INTEGER *) MR(DSAlertTab)), ip = (INTEGER *) MR(DSAlertTab) + 1; i > 0 && CW(*ip) != id; --i, ip = (INTEGER *) ((char *) ip + CW(ip[1]) + 2 * sizeof(INTEGER))) ; return i > 0 ? ip : (INTEGER *) 0; }
A1(PRIVATE, OSErr, cropen, INTEGER *, fp) { OSErr retval; retval = FSOpen(MR(ScrapName), CW (BootDrive), fp); if (retval == fnfErr) { retval = Create(MR(ScrapName), CW (BootDrive), TICK("MACS"), TICK("CLIP")); if (retval != noErr) return(retval); return(FSOpen(MR(ScrapName), CW (BootDrive), fp)); } return(retval); }
A0(PUBLIC, LONGINT, ROMlib_ZeroScrap) { OSErr retval; INTEGER f; THz saveZone; if (Cx(ScrapState) < 0) { ScrapCount = 0; saveZone = TheZone; TheZone = SysZone; ScrapHandle = RM(NewHandle((Size)0)); TheZone = saveZone; ScrapState = CWC (1); ScrapName = RM((StringPtr) "\016Clipboard File"); } else if (Cx(ScrapState) == 0) { retval = cropen(&f); if (retval != noErr) return retval; retval = SetEOF(f, (LONGINT)0); if (retval != noErr) return retval; FSClose(f); } else if (Cx(ScrapState) > 0) SetHandleSize(MR(ScrapHandle), (Size)0); ScrapSize = 0; ScrapCount = CW(CW(ScrapCount) + 1); return noErr; }
P0(PUBLIC pascal trap, LONGINT, LoadScrap) { OSErr retval; INTEGER f; LONGINT l = Cx(ScrapSize); if (ScrapState == 0) { retval = FSOpen(MR(ScrapName), CW (BootDrive), &f); if (retval != noErr) return(retval); HUnlock(MR(ScrapHandle)); ReallocHandle(MR(ScrapHandle), (Size)Cx(ScrapSize)); if (MemErr != noErr) /*-->*/ return Cx(MemErr); HLock(MR(ScrapHandle)); retval = FSReadAll(f, &l, STARH(MR(ScrapHandle))); HUnlock(MR(ScrapHandle)); if (retval != noErr) return(retval); SetEOF(f, (LONGINT) 0); FSClose(f); ScrapState = CWC (1); } return(Cx(ScrapState) > 0 ? noErr : noScrapErr); }