int16 ScriptInterpreter::getGameVar(uint variable) { debug(0, "ScriptInterpreter::getGameVar(%d{%s})", variable, getVarName(variable)); switch (variable) { case 0: return _vm->_mouseDisabled; case 1: return _vm->_mouseY; case 2: return _vm->_mouseX; case 3: return _vm->_mouseButton; case 4: return _vm->_screen->_verbLineY; case 5: return _vm->_screen->_verbLineX; case 6: return _vm->_screen->_verbLineWidth; case 7: return _vm->_screen->_verbLineCount; case 8: return _vm->_screen->_verbLineNum; case 9: return _vm->_screen->_talkTextItemNum; case 10: return _vm->_screen->_talkTextY; case 11: return _vm->_screen->_talkTextX; case 12: return _vm->_screen->_talkTextFontColor; case 13: return _vm->_cameraY; case 14: return _vm->_cameraX; case 15: return _vm->_walkSpeedY; case 16: return _vm->_walkSpeedX; case 17: return _vm->_flag01; case 18: return _vm->_sceneResIndex; case 19: return _vm->_guiHeight; case 20: return _vm->_sceneHeight; case 21: return _vm->_sceneWidth; default: warning("Getting unimplemented game variable %s (%d)", getVarName(variable), variable); return 0; } }
QString MMD_Polynomial::getTextView_Term4Complex( long i, UniWord coef, int ishead ) { if( coef.getComplex().imag() == 0.0 ) return getTextView_Term( i, UniWord( CDSRReal( coef.getComplex().real() ) ), ishead ); QString s_sign = _T(""), s_coef = _T(""), s_x = _T(""), s_pow = _T(""); QString result = _T(""); if( !ishead ) s_sign = _T("+"); QString s_r, s_i, s_s; s_coef = QString( _T("(") ) + ::getTextView_Complex2StrPart( getSmbTable(), coef.getComplex(), s_r, s_i, s_s ) + QString( _T(")") ); if( !::_is_null( term_pow[ i ] ) ) { if( s_coef.length() ) s_x = QString( _T("*") ) + getVarName(); else s_x = getVarName(); if( !::_is_number_one( term_pow[ i ] ) ) s_pow = QString( _T("^") ) + term_pow[ i ].getTextView( getSmbTable() ); } result = s_sign + s_coef + s_x + s_pow; return result; }
static void printRange(Client cntxt, MalBlkPtr mb, Range rng, int idx){ (void) rng; mnstr_printf(cntxt->fdout,"[%3d] %5s used=%d\tlcst=%s\t ", idx, getVarName(mb,idx), rng[idx].used, (rng[idx].lcst? getVarName(mb,rng[idx].lcst):"")); mnstr_printf(cntxt->fdout,"hcst=%s\tsource %s ", (rng[idx].hcst? getVarName(mb,rng[idx].hcst):""), (rng[idx].srcvar?getVarName(mb,rng[idx].srcvar):"")); mnstr_printf(cntxt->fdout,"\tlu=%d\tr=%d", rng[idx].lastupdate, rng[idx].lastrange); mnstr_printf(cntxt->fdout,"\n"); }
int displayTpl(char *filename){ FILE *tpl; char puffer[TPL_BUFFER]; char rePuffer[TPL_BUFFER]; char replaceVar[REPLACE_BUFFER]; int pufferlen, i, countBackSlash; int pufferCount = 0; tpl = fopen(filename, "r"); if(tpl == NULL){ perror("Could not open template file"); return 1; } while(!feof(tpl)){ fgets(puffer, TPL_BUFFER, tpl); puffer[TPL_BUFFER-1] = '\0'; pufferlen = strlen(puffer); countBackSlash = 0; for(i = 0; i < pufferlen; i++){ if(puffer[i] == '{'){ if(puffer[i+1] == '$'){ if(countBackSlash % 2 != 0) continue; getVarName(&puffer[i+2], replaceVar, REPLACE_BUFFER * sizeof(char), &i); i++; if(inputVar(rePuffer, &pufferCount, replaceVar) == 0); }else{ if(countBackSlash % 2 != 0) continue; getVarName(&puffer[i+1], replaceVar, REPLACE_BUFFER * sizeof(char), &i); //i++; callPlugin(rePuffer, &pufferCount, replaceVar); } }else if(puffer[i] == '\\'){ countBackSlash++; }else{ for(; countBackSlash > 0; countBackSlash--){ addRePuffer(rePuffer, &pufferCount, '\\'); } addRePuffer(rePuffer, &pufferCount, puffer[i]); } } printf("%s\n", rePuffer); rePuffer[0] = '\0'; pufferCount = 0; } fclose(tpl); }
void UniformFloat::applyUpdate(HdlProgram& prgm) { float buffer[16]; for(int k=0; k<data.size(); k++) buffer[k] = data[k]->value(); prgm.modifyVar( getVarName(), type, buffer ); }
Value* interpereteFloatOperator(Token *t, Value *v2, Value *v3){ switch ((int)t->extra){ case ADDITION: *((float*)v2->extra) += *((float*)v3->extra); break; case SUBTRACTION: *((float*)v2->extra) -= *((float*)v3->extra); break; case MULTIPLICATION: *((float*)v2->extra) *= *((float*)v3->extra); break; case DIVISION: *((float*)v2->extra) /= *((float*)v3->extra); break; case EQUALITY: case INEQUALITY: case GREATER_THAN: case GREATER_OR_EQUAL: case LESS_THAN: case LESS_OR_EQUAL: v2->type = INTEGER; *((int*)v2->extra) = comparef((int)t->extra, *((float*)v2->extra), *((float*)v3->extra)); break; case PRE_INC: case PRE_DEC: case POST_INC: case POST_DEC: { v2 = v3; float old_val = *((float*)v2->extra); float new_val; if ((int)t->extra == POST_INC || (int)t->extra == PRE_INC){ new_val = old_val + 1.0f; } else{ new_val = old_val - 1.0f; } interpreteAssignment(getVarName((int)t->firstChild->extra), FLOAT, &new_val); if ((int)t->extra == PRE_INC || (int)t->extra == PRE_DEC){ *((float*)v2->extra) = new_val; } } break; case NEGATE: v2 = v3; *((float*)v2->extra) = -*((float*)v2->extra); break; case PLUS: v2 = v3; break; default: PERROR(""); break; } return v2; }
unsigned int getVarIndex(const char *varName) { for(unsigned int i=0;i<getNumVars();i++) { if(strcmp(getVarName(i), varName)==0) { return i; } } cout << "Var name: " << varName << " not found" << endl; throw std::runtime_error("Var name does not exist"); }
void UniformFloat::readFrom(HdlProgram& prgm) { float buffer[16]; prgm.getVar( getVarName(), buffer); for(int k=0; k<data.size(); k++) data[k]->setValue(buffer[k]); }
// UniformInteger UniformInteger::UniformInteger(const std::string& name, GLenum _type, int n, int m, bool _un) : UniformObject(name), un(_un), item(NULL), layout(this), type(_type) { //std::cout << "UniformInteger::UniformInteger : " << this << std::endl; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { data.push_back(new QSpinBox); if(un) data.back()->setRange(0, std::numeric_limits<int>::max()); else data.back()->setRange(std::numeric_limits<int>::min(), std::numeric_limits<int>::max()); if(n>1 && m>1 && i==j) data.back()->setValue(1); else data.back()->setValue(0); layout.addWidget(data.back(), i, j); QObject::connect(data.back(), SIGNAL(valueChanged(int)), this, SLOT(declareUpdate(void))); } } // Build item : item = new QTreeWidgetItem(NodeVarInteger); item->setData(0, Qt::UserRole, QVariant::fromValue<UniformObject*>( reinterpret_cast<UniformObject*>(this) )); if(un) item->setText(0, tr("%1 [%2x%3xunsigned]").arg(getVarName().c_str()).arg(n).arg(m) ); else item->setText(0, tr("%1 [%2x%3xint]").arg(getVarName().c_str()).arg(n).arg(m) ); // Set possible external links : if(n==1 && m==3) { allowedExternalValueLink[ColorLastClick] = true; allowedExternalValueLink[ColorCurrent] = true; allowedExternalValueLink[ColorLastRelease] = true; } }
// UniformUnknown UniformUnknown::UniformUnknown(const std::string& name, const QString& message) : UniformObject(name), layout(this), label(message, this) { //std::cout << "UniformUnknown::UniformUnknown : " << this << std::endl; item = new QTreeWidgetItem(NodeVarUnknown); item->setData(0, Qt::UserRole, QVariant::fromValue<UniformObject*>( reinterpret_cast<UniformObject*>(this) )); layout.addWidget(&label); item->setText(0, tr("%1 [x]").arg(getVarName().c_str())); }
void UniformInteger::readFrom(HdlProgram& prgm) { if(un) { unsigned int buffer[16]; prgm.getVar( getVarName(), buffer); for(int k=0; k<data.size(); k++) data[k]->setValue(buffer[k]); } else { int buffer[16]; prgm.getVar( getVarName(), buffer); for(int k=0; k<data.size(); k++) data[k]->setValue(buffer[k]); } }
void UniformInteger::applyUpdate(HdlProgram& prgm) { if(un) { unsigned int buffer[16]; for(int k=0; k<data.size(); k++) buffer[k] = data[k]->value(); prgm.modifyVar( getVarName(), type, buffer ); } else { int buffer[16]; for(int k=0; k<data.size(); k++) buffer[k] = data[k]->value(); prgm.modifyVar( getVarName(), type, buffer ); } }
QString MMD_Polynomial::getTextView_Term( long i, UniWord coef, int ishead ) { QString s_sign = _T(""), s_coef = _T(""), s_x = _T(""), s_pow = _T(""); QString result = _T(""); if( ::_is_null( coef ) ) { if( getTermCount() == 1 ) result = coef.getTextView( getSmbTable() ); return result; } if( !::_is_negative_number( coef ) && !ishead ) s_sign = _T("+"); if( ::_is_number_one( coef ) && !::_is_null( term_pow[ i ] ) ) { if( ::_is_negative_number( coef ) ) s_sign = _T("-"); } else { s_coef = coef.getTextView( getSmbTable() ); } if( !::_is_null( term_pow[ i ] ) ) { if( s_coef.length() ) s_x = QString( _T("*") ) + getVarName(); else s_x = getVarName(); if( !::_is_number_one( term_pow[ i ] ) ) s_pow = QString( _T("^") ) + term_pow[ i ].getTextView( getSmbTable() ); } result = s_sign + s_coef + s_x + s_pow; return result; }
/* the MAL beautifier is meant to simplify correlation of MAL variables and * the columns in the underlying database. * If the status is set, then we consider the instruction DONE and the result variables * should be shown as well. */ static str shortRenderingTerm(MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int idx) { str s, nme; BAT *b; ValRecord *val; char *cv =0; int varid = getArg(p,idx); size_t len = BUFSIZ; s= GDKmalloc(len); if( s == NULL) return NULL; *s = 0; if( isVarConstant(mb,varid) ){ val =&getVarConstant(mb, varid); if ((cv = VALformat(val)) == NULL) { GDKfree(s); return NULL; } if (strlen(cv) >= len) { char *nbuf; len = strlen(cv); nbuf = GDKrealloc(s, len + 1); if (nbuf == NULL) { GDKfree(s); GDKfree(cv); return NULL; } s = nbuf; } snprintf(s,len + 1,"%s",cv); } else { val = &stk->stk[varid]; if ((cv = VALformat(val)) == NULL) { GDKfree(s); return NULL; } nme = getVarName(mb, varid); if ( isaBatType(getArgType(mb,p,idx))){ b = BBPquickdesc(stk->stk[varid].val.bval, true); snprintf(s,BUFSIZ,"%s["BUNFMT"]" ,nme, b?BATcount(b):0); } else snprintf(s,BUFSIZ,"%s=%s ",nme,cv); } GDKfree(cv); return s; }
vector<CfgVariable*> *VehicleParamsEx::getVariableList() { if(varList) return varList; varList = new vector<CfgVariable*>; varList->push_back(new CfgVariable(V_FLOAT, &frictionToFront, getVarName(frictionToFront))); varList->push_back(new CfgVariable(V_FLOAT, &frictionToSide, getVarName(frictionToSide))); varList->push_back(new CfgVariable(V_FLOAT, &wheelSuspension, getVarName(wheelSuspension))); varList->push_back(new CfgVariable(V_FLOAT, &springRestitution, getVarName(springRestitution))); varList->push_back(new CfgVariable(V_FLOAT, &springDamping, getVarName(springDamping))); varList->push_back(new CfgVariable(V_FLOAT, &springBias, getVarName(springBias))); varList->push_back(new CfgVariable(V_FLOAT, &maxBrakeForce, getVarName(maxBrakeForce))); varList->push_back(new CfgVariable(V_VEC3, &massCenter, getVarName(massCenter))); return varList; }
// UniformFloat UniformFloat::UniformFloat(const std::string& name, GLenum _type, int n, int m) : UniformObject(name), item(NULL), layout(this), type(_type) { //std::cout << "UniformFloat::UniformFloat : " << this << std::endl; for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { data.push_back(new QDoubleSpinBox); data.back()->setRange(-std::numeric_limits<double>::max(), std::numeric_limits<double>::max()); data.back()->setDecimals(3); if(n>1 && m>1 && i==j) data.back()->setValue(1.0); else data.back()->setValue(0.0); layout.addWidget(data.back(), i, j); QObject::connect(data.back(), SIGNAL(valueChanged(double)), this, SLOT(declareUpdate(void))); } } // Build item : item = new QTreeWidgetItem(NodeVarFloatingPoint); item->setData(0, Qt::UserRole, QVariant::fromValue<UniformObject*>( reinterpret_cast<UniformObject*>(this) )); item->setText(0, tr("%1 [%2x%3xfloat]").arg(getVarName().c_str()).arg(n).arg(m) ); // Set possible external links : if(n==1 && m==2) { allowedExternalValueLink[LastClick] = true; allowedExternalValueLink[CurrentPosition] = true; allowedExternalValueLink[LastRelease] = true; allowedExternalValueLink[VectorCurrent] = true; allowedExternalValueLink[LastVector] = true; } else if(n==1 && m==3) { allowedExternalValueLink[ColorLastClick] = true; allowedExternalValueLink[ColorCurrent] = true; allowedExternalValueLink[ColorLastRelease] = true; } }
ResoStruct getResponseResolutionMC( const std::string& outputdir, TTree* tree, float LYSF[], const std::string& name ) { std::string fullVarName = getVarName(LYSF); TH1D* h1 = new TH1D( name.c_str(), "", 500, 0., 500. ); tree->Project( name.c_str(), fullVarName.c_str() ); TF1* f1 = new TF1( Form("f1_%s", name.c_str()), "gaus", 100., 500.); FitTools::doSingleFit( h1, f1, outputdir, name ); ResoStruct rs = getRespAndReso( f1, 0. ); return rs; }
static str MDBgetFrame(BAT *b, BAT*bn, Client cntxt, MalBlkPtr mb, MalStkPtr s, int depth) { ValPtr v; int i; char *buf = 0; if (depth > 0) return MDBgetFrame(b,bn, cntxt, mb, s->up, depth - 1); if (s != 0) for (i = 0; i < s->stktop; i++, v++) { v = &s->stk[i]; ATOMformat(v->vtype, VALptr(v), &buf); BUNappend(b, getVarName(mb, i), FALSE); BUNappend(bn, buf, FALSE); GDKfree(buf); buf = NULL; } return MAL_SUCCEED; }
ResoStruct getResponseResolutionMC( const std::string& outputdir, TTree* tree, float LYSF[], const std::string& name ) { std::string fullVarName = getVarName(LYSF); //fullVarName += " + Ebgo"; //fullVarName = "Ebgo"; //fullVarName = "Eact"; TH1D* h1 = new TH1D( name.c_str(), "", 500, 0., 500. ); //tree->Project( name.c_str(), fullVarName.c_str(), "Escint>0.2"); tree->Project( name.c_str(), fullVarName.c_str(), "Escint>0.2 && Ehodo >0.1" ); TF1* f1 = new TF1( Form("f1_%s", name.c_str()), "gaus", 50., 500.); FitTools::doSingleFit( h1, f1, outputdir, name,5.,1.5 ); ResoStruct rs = getRespAndReso( f1, 0. ); return rs; }
//processes a statement void processString(char *str){ Var *tmp = variables, *var1, *var2; int varLen, opLen, isNumeric, var3; char *lValue, *op, *rValue; lValue = getVarName(str); varLen = strlen(lValue); op = getOp(str, varLen); opLen = strlen(op); rValue = getRValue(str, varLen, opLen); var1 = getVar(lValue); isNumeric = isnumeric(rValue); if(1 == isNumeric){ var3 = atoi(rValue); } else{ var2 = getVar(rValue); var3 = var2->value; } switch(op[0]){ case '+': var1->value+=var3; break; case '-': var1->value-=var3; break; case '*': var1->value*=var3; break; case '/': var1->value/=var3; break; } }
/* the MAL beautifier is meant to simplify correlation of MAL variables and * the columns in the underlying database. * If the status is set, then we consider the instruction DONE and the result variables * should be shown as well. */ static str shortRenderingTerm(MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int idx) { str s, nme; BAT *b; ValRecord *val; char *cv =0; int varid = getArg(p,idx); s= GDKmalloc(BUFSIZ); if( s == NULL) return NULL; *s = 0; if( isVarConstant(mb,varid) ){ val =&getVarConstant(mb, varid); VALformat(&cv, val); snprintf(s,BUFSIZ,"%s",cv); } else { val = &stk->stk[varid]; VALformat(&cv, val); nme = getSTC(mb, varid); if( nme == NULL) nme = getVarName(mb, varid); if ( isaBatType(getArgType(mb,p,idx))){ b = BBPquickdesc(abs(stk->stk[varid].val.ival),TRUE); snprintf(s,BUFSIZ,"%s["BUNFMT"]" ,nme, b?BATcount(b):0); } else if( cv) snprintf(s,BUFSIZ,"%s=%s ",nme,cv); else snprintf(s,BUFSIZ,"%s ",nme); } GDKfree(cv); return s; }
void ScriptInterpreter::setGameVar(uint variable, int16 value) { debug(0, "ScriptInterpreter::setGameVar(%d{%s}, %d)", variable, getVarName(variable), value); switch (variable) { case 0: _vm->_mouseDisabled = value; CursorMan.showMouse(value == 0); break; case 3: _vm->_mouseButton = value; break; case 4: _vm->_screen->_verbLineY = value; break; case 5: _vm->_screen->_verbLineX = value; break; case 6: _vm->_screen->_verbLineWidth = value; break; case 7: _vm->_screen->_verbLineCount = value; break; case 8: _vm->_screen->_verbLineNum = value; break; case 9: _vm->_screen->_talkTextItemNum = value; break; case 10: _vm->_screen->_talkTextY = value; break; case 11: _vm->_screen->_talkTextX = value; break; case 12: _vm->_screen->_talkTextFontColor = value; break; case 13: _vm->_cameraY = value; break; case 14: _vm->_cameraX = value; break; case 15: _vm->_walkSpeedY = value; break; case 16: _vm->_walkSpeedX = value; break; case 17: _vm->_flag01 = value != 0; break; case 18: _vm->_sceneResIndex = value; break; case 19: _vm->_guiHeight = value; break; case 20: _vm->_sceneHeight = value; break; case 21: _vm->_sceneWidth = value; break; case 1: case 2: default: warning("Setting unimplemented game variable %s (%d) to %d", getVarName(variable), variable, value); break; } }
TriPod::TriPod(IVehicle *vehicle, string fname, bool FrontTriPod) { m_tractor = true; m_vehicle = vehicle; m_triPodDimms = new TriPodDimms; m_isLifted = false; m_attachedDevice = NULL; m_attachedTrailer = NULL; m_jointTopPodDevice = NULL; m_jointBottomLeftPodDevice = NULL; m_jointBottomRightPodDevice = NULL; m_jointTrailer = NULL; string topPodModel; string bottomPodModel; m_triPodDimms->getVariableList()->push_back(new CfgVariable(V_STRING, &topPodModel, getVarName(topPodModel))); m_triPodDimms->getVariableList()->push_back(new CfgVariable(V_STRING, &bottomPodModel, getVarName(bottomPodModel))); CfgLoader(fname, m_triPodDimms->getVariableList()); m_objTop = new Surface(topPodModel, new Material(MT_DEFAULT, "wood.jpg"), Vec3(0, 0, 0)); m_objBottom = new Surface(bottomPodModel, new Material(MT_DEFAULT, "wood.jpg"), Vec3(0, 0, 0)); NxVec3 actorTopPos = NxVec3(m_vehicle->getVehicleController()->getVehicleParams()->posTriPodBack) + NxVec3(m_triPodDimms->posTopPodTractorConnector); NxVec3 actorBottomPos = NxVec3(m_vehicle->getVehicleController()->getVehicleParams()->posTriPodBack) + NxVec3(m_triPodDimms->posBottomPodTractorConnector); NxVec3 actorTopDimm = NxVec3(m_objTop->boundingBox.getWidth()/2, m_objTop->boundingBox.getHeight()/2, m_objTop->boundingBox.getDepth()/2); NxVec3 actorBottomDimm = NxVec3(m_objBottom->boundingBox.getWidth()/2, m_objBottom->boundingBox.getHeight()/2, m_objBottom->boundingBox.getDepth()/2); /*m_actorTop = core.dynamics->createBox(actorTopPos, actorTopDimm, 1); m_actorBottom = core.dynamics->createBox(actorBottomPos, actorBottomDimm, 1);*/ m_actorTop = core.dynamics->createBox(actorTopPos, NxVec3(D3DXVec3Length(&Vec3(m_triPodDimms->posTopPodTractorConnector - m_triPodDimms->posTopPodDeviceConnector))/2, 0.1f, 0.1f), 500); m_actorBottom = core.dynamics->createBox(actorBottomPos, NxVec3(D3DXVec3Length(&Vec3(m_triPodDimms->posBottomPodTractorConnector - m_triPodDimms->posBottomPodDeviceConnector))/2, 0.1f, m_triPodDimms->width / 2), 500); /*m_triPodDimms->posTopPodDeviceConnector.x -= 0.2f; m_triPodDimms->posBottomPodDeviceConnector.x -= 0.2f;*/ /*SetActorCollisionGroup(m_actorTop, GROUP_COLLIDABLE_NON_PUSHABLE); SetActorCollisionGroup(m_actorBottom, GROUP_COLLIDABLE_NON_PUSHABLE);*/ SetActorCollisionGroup(m_actorTop, GROUP_COLLIDABLE_NON_PUSHABLE); SetActorCollisionGroup(m_actorBottom, GROUP_COLLIDABLE_NON_PUSHABLE); core.game->getWorld()->addToWorld(m_objTop, NO_COLLISION, 0, GROUP_NON_COLLIDABLE, NULL, 1); core.game->getWorld()->addToWorld(m_objBottom, NO_COLLISION, 0, GROUP_NON_COLLIDABLE, NULL, 1); m_frontPod = FrontTriPod; if(!m_frontPod) { float highLimit = D3DX_PI * 0.12f; float lowLimit = D3DX_PI * -0.1f; m_jointMotorTop = new NxMotorDesc(0, NX_MAX_REAL, 0); m_jointMotorBottom = new NxMotorDesc(0, NX_MAX_REAL, 0); Vec3 newPosTop = m_vehicle->getVehicleController()->getBackJointPoint() + (m_triPodDimms->posTopPod) - m_triPodDimms->posTopPodTractorConnector; Vec3 newPosBottom = m_vehicle->getVehicleController()->getBackJointPoint() + (m_triPodDimms->posBottomPod) - m_triPodDimms->posBottomPodTractorConnector; Vec3 moveTop = m_vehicle->getVehicleController()->getBackJointPoint() + (m_triPodDimms->posTopPod);// - m_triPodDimms->posTopPodTractorConnector; Vec3 moveBottom = m_vehicle->getVehicleController()->getBackJointPoint() + (m_triPodDimms->posBottomPod);// - m_triPodDimms->posBottomPodTractorConnector; /*Vec3 moveTop = Vec3(actorTopPos.x, actorTopPos.y, actorTopPos.z) - m_vehicle->getVehicleController()->getBackJointPoint(); Vec3 moveBottom = Vec3(actorBottomPos.x, actorBottomPos.y, actorBottomPos.z) - m_vehicle->getVehicleController()->getBackJointPoint();*/ /*m_actorTop->setGlobalPosition(m_actorTop->getGlobalPosition() + NxVec3(moveTop)); m_actorBottom->setGlobalPosition(m_actorBottom->getGlobalPosition() + NxVec3(moveBottom));*/ m_actorTop->setGlobalPosition(NxVec3(newPosTop)); m_actorBottom->setGlobalPosition(NxVec3(newPosBottom)); NxRevoluteJointDesc revDescTop; revDescTop.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescTop.actor[1] = m_actorTop; revDescTop.localNormal[0] = NxVec3(0, 1, 0); revDescTop.localNormal[1] = NxVec3(0, 1, 0); revDescTop.limit.high.value = highLimit; revDescTop.limit.low.value = lowLimit; revDescTop.setGlobalAxis(NxVec3(0, 0, 1)); //The direction of the axis the bodies revolve around. revDescTop.setGlobalAnchor(NxVec3(moveTop)); //Reference point that the axis passes through. revDescTop.projectionMode = NX_JPM_POINT_MINDIST; revDescTop.projectionDistance = 0.1f; revDescTop.motor = *m_jointMotorTop; revDescTop.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointTop = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescTop); /*NxRevoluteJointDesc revDescBottom; revDescBottom.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescBottom.actor[1] = m_actorBottom; revDescBottom.localNormal[0] = NxVec3(0, 1, 0); revDescBottom.localNormal[1] = NxVec3(0, 1, 0); revDescBottom.limit.high.value = highLimit; revDescBottom.limit.low.value = lowLimit; revDescBottom.setGlobalAxis(NxVec3(0, 0, 1)); //The direction of the axis the bodies revolve around. revDescBottom.setGlobalAnchor(NxVec3(moveBottom)); //Reference point that the axis passes through. revDescBottom.motor = *m_jointMotorBottom; revDescBottom.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; //m_jointBottom = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescBottom);*/ Vec3 leftPos = Vec3(0, 0, m_triPodDimms->width/2); Mat temp; m_actorTop->getGlobalPose().getColumnMajor44((NxF32*)&temp); temp._41 = 0; temp._42 = 0; temp._43 = 0; D3DXVec3TransformCoord(&leftPos, &leftPos, &temp); NxRevoluteJointDesc revDescBottom; revDescBottom.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescBottom.actor[1] = m_actorBottom; revDescBottom.localNormal[0] = NxVec3(0, 1, 0); revDescBottom.localNormal[1] = NxVec3(0, 1, 0); revDescBottom.limit.high.value = highLimit; revDescBottom.limit.low.value = lowLimit; revDescBottom.setGlobalAxis(NxVec3(0, 0, 1)); //The direction of the axis the bodies revolve around. revDescBottom.setGlobalAnchor(NxVec3(moveBottom + leftPos)); //Reference point that the axis passes through. revDescBottom.projectionMode = NX_JPM_POINT_MINDIST; revDescBottom.projectionDistance = 0.1f; revDescBottom.motor = *m_jointMotorBottom; revDescBottom.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointBottomLeft = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescBottom); NxRevoluteJointDesc revDescBottom1; revDescBottom1.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescBottom1.actor[1] = m_actorBottom; revDescBottom1.localNormal[0] = NxVec3(0, 1, 0); revDescBottom1.localNormal[1] = NxVec3(0, 1, 0); revDescBottom1.setGlobalAxis(NxVec3(0, 0, 1)); //The direction of the axis the bodies revolve around. revDescBottom1.setGlobalAnchor(NxVec3(moveBottom - leftPos)); revDescBottom1.limit.high.value = highLimit; revDescBottom1.limit.low.value = lowLimit; revDescBottom1.projectionMode = NX_JPM_POINT_MINDIST; revDescBottom1.projectionDistance = 0.1f; revDescBottom1.motor = *m_jointMotorBottom; revDescBottom1.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointBottomRight = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescBottom1); } else { Vec3 switchVec; switchVec = m_triPodDimms->posBottomPodDeviceConnector; m_triPodDimms->posBottomPodDeviceConnector = m_triPodDimms->posBottomPodTractorConnector; m_triPodDimms->posBottomPodTractorConnector = switchVec; switchVec = m_triPodDimms->posTopPodDeviceConnector; m_triPodDimms->posTopPodDeviceConnector = m_triPodDimms->posTopPodTractorConnector; m_triPodDimms->posTopPodTractorConnector = switchVec; float highLimit = D3DX_PI * 0.12f; float lowLimit = D3DX_PI * -0.1f; m_jointMotorTop = new NxMotorDesc(0, NX_MAX_REAL, 0); m_jointMotorBottom = new NxMotorDesc(0, NX_MAX_REAL, 0); Vec3 newPosTop = m_vehicle->getVehicleController()->getFrontJointPoint() + (m_triPodDimms->posTopPod) - m_triPodDimms->posTopPodTractorConnector; Vec3 newPosBottom = m_vehicle->getVehicleController()->getFrontJointPoint() + (m_triPodDimms->posBottomPod) - m_triPodDimms->posBottomPodTractorConnector; Vec3 moveTop = m_vehicle->getVehicleController()->getFrontJointPoint() + (m_triPodDimms->posTopPod);// - m_triPodDimms->posTopPodTractorConnector; Vec3 moveBottom = m_vehicle->getVehicleController()->getFrontJointPoint() + (m_triPodDimms->posBottomPod);// - m_triPodDimms->posBottomPodTractorConnector; /*Vec3 moveTop = Vec3(actorTopPos.x, actorTopPos.y, actorTopPos.z) - m_vehicle->getVehicleController()->getBackJointPoint(); Vec3 moveBottom = Vec3(actorBottomPos.x, actorBottomPos.y, actorBottomPos.z) - m_vehicle->getVehicleController()->getBackJointPoint();*/ /*m_actorTop->setGlobalPosition(m_actorTop->getGlobalPosition() + NxVec3(moveTop)); m_actorBottom->setGlobalPosition(m_actorBottom->getGlobalPosition() + NxVec3(moveBottom));*/ m_actorTop->setGlobalPosition(NxVec3(newPosTop)); m_actorBottom->setGlobalPosition(NxVec3(newPosBottom)); NxRevoluteJointDesc revDescTop; revDescTop.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescTop.actor[1] = m_actorTop; revDescTop.localNormal[0] = NxVec3(0, 1, 0); revDescTop.localNormal[1] = NxVec3(0, 1, 0); revDescTop.limit.high.value = highLimit; revDescTop.limit.low.value = lowLimit; revDescTop.setGlobalAxis(NxVec3(0, 0, -1)); //The direction of the axis the bodies revolve around. revDescTop.setGlobalAnchor(NxVec3(moveTop)); //Reference point that the axis passes through. revDescTop.projectionMode = NX_JPM_POINT_MINDIST; revDescTop.projectionDistance = 0.1f; revDescTop.motor = *m_jointMotorTop; revDescTop.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointTop = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescTop); Vec3 leftPos = Vec3(0, 0, m_triPodDimms->width/2); Mat temp; m_actorTop->getGlobalPose().getColumnMajor44((NxF32*)&temp); temp._41 = 0; temp._42 = 0; temp._43 = 0; D3DXVec3TransformCoord(&leftPos, &leftPos, &temp); NxRevoluteJointDesc revDescBottom; revDescBottom.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescBottom.actor[1] = m_actorBottom; revDescBottom.localNormal[0] = NxVec3(0, 1, 0); revDescBottom.localNormal[1] = NxVec3(0, 1, 0); revDescBottom.limit.high.value = highLimit; revDescBottom.limit.low.value = lowLimit; revDescBottom.setGlobalAxis(NxVec3(0, 0, -1)); //The direction of the axis the bodies revolve around. revDescBottom.setGlobalAnchor(NxVec3(moveBottom + leftPos)); //Reference point that the axis passes through. revDescBottom.projectionMode = NX_JPM_POINT_MINDIST; revDescBottom.projectionDistance = 0.1f; revDescBottom.motor = *m_jointMotorBottom; revDescBottom.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointBottomLeft = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescBottom); NxRevoluteJointDesc revDescBottom1; revDescBottom1.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescBottom1.actor[1] = m_actorBottom; revDescBottom1.localNormal[0] = NxVec3(0, 1, 0); revDescBottom1.localNormal[1] = NxVec3(0, 1, 0); revDescBottom1.setGlobalAxis(NxVec3(0, 0, -1)); //The direction of the axis the bodies revolve around. revDescBottom1.setGlobalAnchor(NxVec3(moveBottom - leftPos)); revDescBottom1.limit.high.value = highLimit; revDescBottom1.limit.low.value = lowLimit; revDescBottom1.projectionMode = NX_JPM_POINT_MINDIST; revDescBottom1.projectionDistance = 0.1f; revDescBottom1.motor = *m_jointMotorBottom; revDescBottom1.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointBottomRight = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescBottom1); } lift(); update(); }
str OPTevaluateImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { InstrPtr p; int i, k, limit, *alias = 0, barrier; MalStkPtr env = NULL; int profiler; int debugstate = cntxt->itrace, actions = 0, constantblock = 0; int *assigned = 0, use; char buf[256]; lng usec = GDKusec(); str msg = MAL_SUCCEED; (void)stk; (void)pci; if ( mb->inlineProp ) return MAL_SUCCEED; cntxt->itrace = 0; #ifdef DEBUG_OPT_EVALUATE fprintf(stderr, "Constant expression optimizer started\n"); #endif assigned = (int*) GDKzalloc(sizeof(int) * mb->vtop); if (assigned == NULL) throw(MAL,"optimzier.evaluate", SQLSTATE(HY001) MAL_MALLOC_FAIL); alias = (int*)GDKzalloc(mb->vsize * sizeof(int) * 2); /* we introduce more */ if (alias == NULL){ GDKfree(assigned); throw(MAL,"optimzier.evaluate", SQLSTATE(HY001) MAL_MALLOC_FAIL); } // arguments are implicitly assigned by context p = getInstrPtr(mb, 0); for ( k =p->retc; k < p->argc; k++) assigned[getArg(p,k)]++; limit = mb->stop; for (i = 1; i < limit; i++) { p = getInstrPtr(mb, i); // The double count emerging from a barrier exit is ignored. if (! blockExit(p) || (blockExit(p) && p->retc != p->argc)) for ( k =0; k < p->retc; k++) if ( p->retc != p->argc || p->token != ASSIGNsymbol ) assigned[getArg(p,k)]++; } for (i = 1; i < limit && cntxt->mode != FINISHCLIENT; i++) { p = getInstrPtr(mb, i); // to avoid management of duplicate assignments over multiple blocks // we limit ourselves to evaluation of the first assignment only. use = assigned[getArg(p,0)] == 1 && !(p->argc == p->retc && blockExit(p)); for (k = p->retc; k < p->argc; k++) if (alias[getArg(p, k)]) getArg(p, k) = alias[getArg(p, k)]; #ifdef DEBUG_OPT_EVALUATE fprintInstruction(stderr , mb, 0, p, LIST_MAL_ALL); #endif /* be aware that you only assign once to a variable */ if (use && p->retc == 1 && OPTallConstant(cntxt, mb, p) && !isUnsafeFunction(p)) { barrier = p->barrier; p->barrier = 0; profiler = malProfileMode; /* we don't trace it */ malProfileMode = 0; if ( env == NULL) { env = prepareMALstack(mb, 2 * mb->vsize); if (!env) { msg = createException(MAL,"optimizer.evaluate", SQLSTATE(HY001) MAL_MALLOC_FAIL); goto wrapup; } env->keepAlive = TRUE; } msg = reenterMAL(cntxt, mb, i, i + 1, env); malProfileMode= profiler; p->barrier = barrier; #ifdef DEBUG_OPT_EVALUATE fprintf(stderr, "#retc var %s\n", getVarName(mb, getArg(p, 0))); fprintf(stderr, "#result:%s\n", msg == MAL_SUCCEED ? "ok" : msg); #endif if (msg == MAL_SUCCEED) { int nvar; ValRecord cst; actions++; cst.vtype = 0; VALcopy(&cst, &env->stk[getArg(p, 0)]); /* You may not overwrite constants. They may be used by * other instructions */ nvar = getArg(p, 1) = defConstant(mb, getArgType(mb, p, 0), &cst); if (nvar >= env->stktop) { VALcopy(&env->stk[getArg(p, 1)], &getVarConstant(mb, getArg(p, 1))); env->stktop = getArg(p, 1) + 1; } alias[getArg(p, 0)] = getArg(p, 1); p->argc = 2; p->token = ASSIGNsymbol; clrFunction(p); p->barrier = barrier; /* freeze the type */ setVarFixed(mb,getArg(p,1)); setVarUDFtype(mb,getArg(p,1)); #ifdef DEBUG_OPT_EVALUATE {str tpename; fprintf(stderr, "Evaluated new constant=%d -> %d:%s\n", getArg(p, 0), getArg(p, 1), tpename = getTypeName(getArgType(mb, p, 1))); GDKfree(tpename); } #endif } else { /* if there is an error, we should postpone message handling, as the actual error (eg. division by zero ) may not happen) */ #ifdef DEBUG_OPT_EVALUATE fprintf(stderr, "Evaluated %s\n", msg); #endif freeException(msg); msg= MAL_SUCCEED; mb->errors = 0; } } constantblock += blockStart(p) && OPTallConstant(cntxt, mb, p); /* default */ } // produces errors in SQL when enabled if ( constantblock) msg = OPTremoveUnusedBlocks(cntxt, mb); cntxt->itrace = debugstate; /* Defense line against incorrect plans */ /* Plan is unaffected */ chkTypes(cntxt->usermodule, mb, FALSE); chkFlow(mb); chkDeclarations(mb); /* keep all actions taken as a post block comment */ usec = GDKusec()- usec; snprintf(buf,256,"%-20s actions=%2d time=" LLFMT " usec","evaluate",actions,usec); newComment(mb,buf); if( actions >= 0) addtoMalBlkHistory(mb); wrapup: if ( env) freeStack(env); if(assigned) GDKfree(assigned); if(alias) GDKfree(alias); return msg; }
static str renderTerm(MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int idx, int flg) { char *buf =0; char *nme =0; int nameused = 0; size_t len = 0, maxlen = BUFSIZ; ValRecord *val = 0; char *cv =0; str tpe; int showtype = 0, closequote=0; int varid = getArg(p,idx); buf = GDKzalloc(maxlen); if( buf == NULL) { addMalException(mb, "renderTerm:Failed to allocate"); return NULL; } // show the name when required or is used if ((flg & LIST_MAL_NAME) && !isVarConstant(mb,varid) && !isVarTypedef(mb,varid)) { nme = getVarName(mb,varid); len +=snprintf(buf, maxlen, "%s", nme); nameused =1; } // show the value when required or being a constant if( ((flg & LIST_MAL_VALUE) && stk != 0) || isVarConstant(mb,varid) ){ if (nameused){ strcat(buf + len,"="); len++; } // locate value record if (isVarConstant(mb,varid)){ val = &getVarConstant(mb, varid); showtype= getVarType(mb,varid) != TYPE_str && getVarType(mb,varid) != TYPE_bit; } else if( stk) val = &stk->stk[varid]; if ((cv = VALformat(val)) == NULL) { addMalException(mb, "renderTerm:Failed to allocate"); GDKfree(buf); return NULL; } if (len + strlen(cv) >= maxlen) { char *nbuf= GDKrealloc(buf, maxlen =len + strlen(cv) + BUFSIZ); if( nbuf == 0){ GDKfree(buf); GDKfree(cv); addMalException(mb,"renderTerm:Failed to allocate"); return NULL; } buf = nbuf; } if( strcmp(cv,"nil") == 0){ strcat(buf+len,cv); len += strlen(buf+len); GDKfree(cv); showtype = showtype || getBatType(getVarType(mb,varid)) > TYPE_str || ((isVarUDFtype(mb,varid) || isVarTypedef(mb,varid)) && isVarConstant(mb,varid)) || isaBatType(getVarType(mb,varid)); } else{ if ( !isaBatType(getVarType(mb,varid)) && getBatType(getVarType(mb,varid)) > TYPE_str ){ closequote = 1; strcat(buf+len,"\""); len++; } strcat(buf+len,cv); len += strlen(buf+len); GDKfree(cv); if( closequote ){ strcat(buf+len,"\""); len++; } showtype = showtype || closequote > TYPE_str || ((isVarUDFtype(mb,varid) || isVarTypedef(mb,varid) || (flg & (LIST_MAL_REMOTE | LIST_MAL_TYPE))) && isVarConstant(mb,varid)) || (isaBatType(getVarType(mb,varid)) && idx < p->retc); if (stk && isaBatType(getVarType(mb,varid)) && stk->stk[varid].val.bval ){ BAT *d= BBPquickdesc(stk->stk[varid].val.bval, true); if( d) len += snprintf(buf+len,maxlen-len,"[" BUNFMT "]", BATcount(d)); } } } // show the type when required or frozen by the user // special care should be taken with constants, they may have been casted if ((flg & LIST_MAL_TYPE) || (isVarUDFtype(mb, varid) && idx < p->retc) || isVarTypedef(mb,varid) || showtype){ strcat(buf + len,":"); len++; tpe = getTypeName(getVarType(mb, varid)); len += snprintf(buf+len,maxlen-len,"%s",tpe); GDKfree(tpe); } if( len >= maxlen) addMalException(mb,"renderTerm:Value representation too large"); return buf; }
int main( int argc, char* argv[]) { std::string tag = "V00"; if( argc>1 ) { std::string tag_str(argv[1]); tag = tag_str; } DrawTools::setStyle(); TFile* file_mc = TFile::Open("EEShash_491MeV_10000ev_smear.root"); TFile* file_data = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_259_beam.root", tag.c_str())); TTree* tree_data = (TTree*)file_data->Get("posTree"); TTree* tree_mc = (TTree*)file_mc->Get("EEShash"); std::string outputdir = "ResolutionStudiesPlots_"+tag; std::string mkdir_command = "mkdir -p " + outputdir; system( mkdir_command.c_str() ); TF1* f1_data = FitTools::fitSingleElectronPeak( outputdir, "data", tree_data ); ResoStruct rs_data = getRespAndReso(f1_data, 0.01); float LYSF_ideal[] = {1., 1., 1., 1., 1., 1., 1., 1., 1., 1.}; float LYSF_real [] = {0.85, 0.94, 0.95, 0.98, 1.00, 1.02, 1.05, 1.05, 1.05, 0.74}; float LYSF_hole [] = {0.85, 0.94, 0.95, 0.98, 1.00, 0.00, 1.05, 1.05, 1.05, 0.74}; ResoStruct rs_ideal = getResponseResolutionMC( outputdir, tree_mc, LYSF_ideal, "ideal" ); ResoStruct rs_real = getResponseResolutionMC( outputdir, tree_mc, LYSF_real, "real" ); ResoStruct rs_hole = getResponseResolutionMC( outputdir, tree_mc, LYSF_hole, "hole" ); std::cout << std::endl; std::cout << "* DATA: " << std::endl; std::cout << "reso: " << rs_data.reso << " +/- " << rs_data.reso_error << std::endl; std::cout << "Sres: " << rs_data.Sres << " +/- " << rs_data.Sres_error << std::endl; std::cout << "MC reso ideal: "<< rs_ideal.reso << " +/- " << rs_ideal.reso_error << std::endl; std::cout << "MC reso real: " << rs_real .reso << " +/- " << rs_real .reso_error << std::endl; std::cout << "MC reso hole: " << rs_hole .reso << " +/- " << rs_hole .reso_error << std::endl; std::cout << "MC Sres ideal: " << rs_ideal.Sres << " +/- " << rs_ideal.Sres_error << std::endl; std::cout << "MC Sres real: " << rs_real .Sres << " +/- " << rs_real .Sres_error << std::endl; std::cout << "MC Sres hole: " << rs_hole .Sres << " +/- " << rs_hole .Sres_error << std::endl; std::cout << std::endl; std::cout << "-> Adding photostatistics to MC (25% QE): " << std::endl; ResoStruct rs_ideal_ps = addPhotoStatistics( rs_ideal, 0.25 ); ResoStruct rs_real_ps = addPhotoStatistics( rs_real, 0.25 ); ResoStruct rs_hole_ps = addPhotoStatistics( rs_hole, 0.25 ); std::cout << "MC reso ideal: "<< rs_ideal_ps.reso << " +/- " << rs_ideal_ps.reso_error << std::endl; std::cout << "MC reso real: " << rs_real_ps .reso << " +/- " << rs_real_ps .reso_error << std::endl; std::cout << "MC reso hole: " << rs_hole_ps .reso << " +/- " << rs_hole_ps .reso_error << std::endl; std::cout << "MC Sres ideal: " << rs_ideal_ps.Sres << " +/- " << rs_ideal_ps.Sres_error << std::endl; std::cout << "MC Sres real: " << rs_real_ps .Sres << " +/- " << rs_real_ps .Sres_error << std::endl; std::cout << "MC Sres hole: " << rs_hole_ps .Sres << " +/- " << rs_hole_ps .Sres_error << std::endl; std::cout << "-> Adding photostatistics to MC (15% QE): " << std::endl; rs_ideal_ps = addPhotoStatistics( rs_ideal, 0.15 ); rs_real_ps = addPhotoStatistics( rs_real, 0.15 ); rs_hole_ps = addPhotoStatistics( rs_hole, 0.15 ); std::cout << "MC reso ideal: "<< rs_ideal_ps.reso << " +/- " << rs_ideal_ps.reso_error << std::endl; std::cout << "MC reso real: " << rs_real_ps .reso << " +/- " << rs_real_ps .reso_error << std::endl; std::cout << "MC reso hole: " << rs_hole_ps .reso << " +/- " << rs_hole_ps .reso_error << std::endl; std::cout << "MC Sres ideal: " << rs_ideal_ps.Sres << " +/- " << rs_ideal_ps.Sres_error << std::endl; std::cout << "MC Sres real: " << rs_real_ps .Sres << " +/- " << rs_real_ps .Sres_error << std::endl; std::cout << "MC Sres hole: " << rs_hole_ps .Sres << " +/- " << rs_hole_ps .Sres_error << std::endl; // FIRST: DIAGONAL13 SCAN TFile* file_mc_3x3y = TFile::Open("EEShash_491MeV_10000ev_smear_3x3y.root"); TFile* file_mc_6x6y = TFile::Open("EEShash_491MeV_10000ev_smear_6x6y.root"); TFile* file_mc_9x9y = TFile::Open("EEShash_491MeV_10000ev_smear_9x9y.root"); TFile* file_mc_11p3x11p3y = TFile::Open("EEShash_491MeV_10000ev_smear_11p3x11p3y.root"); TTree* tree_mc_3x3y = (TTree*)file_mc_3x3y->Get("EEShash"); TTree* tree_mc_6x6y = (TTree*)file_mc_6x6y->Get("EEShash"); TTree* tree_mc_9x9y = (TTree*)file_mc_9x9y->Get("EEShash"); TTree* tree_mc_11p3x11p3y = (TTree*)file_mc_11p3x11p3y->Get("EEShash"); //TFile* file_data_3x3y = TFile::Open("AnalysisTrees_V00/Reco_BTF_141_20140430-183508_beam.root"); //TFile* file_data_6x6y = TFile::Open("AnalysisTrees_V00/Reco_BTF_143_20140430-191455_beam.root"); //TFile* file_data_9x9y = TFile::Open("AnalysisTrees_V00/Reco_BTF_167_20140430-210839_beam.root"); //TFile* file_data_11p3x11p3y = TFile::Open("AnalysisTrees_V00/Reco_BTF_219_20140501-092151_beam.root"); //TTree* tree_data_3x3y = (TTree*)file_data_3x3y->Get("recoTree"); //TTree* tree_data_6x6y = (TTree*)file_data_6x6y->Get("recoTree"); //TTree* tree_data_9x9y = (TTree*)file_data_9x9y->Get("recoTree"); //TTree* tree_data_11p3x11p3y = (TTree*)file_data_11p3x11p3y->Get("recoTree"); TFile* file_data_3x3y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_141_beam.root", tag.c_str())); TFile* file_data_6x6y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_143_beam.root", tag.c_str())); TFile* file_data_9x9y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_167_beam.root", tag.c_str())); TFile* file_data_11p3x11p3y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_219_beam.root", tag.c_str())); TTree* tree_data_3x3y = (TTree*)file_data_3x3y->Get("posTree"); TTree* tree_data_6x6y = (TTree*)file_data_6x6y->Get("posTree"); TTree* tree_data_9x9y = (TTree*)file_data_9x9y->Get("posTree"); TTree* tree_data_11p3x11p3y = (TTree*)file_data_11p3x11p3y->Get("posTree"); std::vector<LateralScanStruct> lss_diag; lss_diag.push_back( LateralScanStruct(0., tree_data, tree_mc) ); lss_diag.push_back( LateralScanStruct(3.*sqrt(2.), tree_data_3x3y, tree_mc_3x3y) ); lss_diag.push_back( LateralScanStruct(6.*sqrt(2.), tree_data_6x6y, tree_mc_6x6y) ); lss_diag.push_back( LateralScanStruct(9.*sqrt(2.), tree_data_9x9y, tree_mc_9x9y) ); lss_diag.push_back( LateralScanStruct(11.3*sqrt(2.), tree_data_11p3x11p3y, tree_mc_11p3x11p3y) ); std::string fullVarName_mc = getVarName(LYSF_hole); drawLateralScan( outputdir, "diag13", lss_diag, "Diagonal", fullVarName_mc ); // SECOND: DIAGONAL02 SCAN //TFile* file_data_d02_3x3y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_94_beam.root", tag.c_str())); //TFile* file_data_d02_6x6y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_96_beam.root", tag.c_str())); //TFile* file_data_d02_9x9y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_98_beam.root", tag.c_str())); //TFile* file_data_d02_m9xm9y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_171_beam.root", tag.c_str())); //TFile* file_data_d02_m6xm6y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_173_beam.root", tag.c_str())); //TFile* file_data_d02_m3xm3y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_176_beam.root", tag.c_str())); TFile* file_data_d02_9x9y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_171_beam.root", tag.c_str())); TFile* file_data_d02_6x6y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_173_beam.root", tag.c_str())); TFile* file_data_d02_3x3y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_176_beam.root", tag.c_str())); TTree* tree_data_d02_3x3y = (TTree*)file_data_d02_3x3y->Get("posTree"); TTree* tree_data_d02_6x6y = (TTree*)file_data_d02_6x6y->Get("posTree"); TTree* tree_data_d02_9x9y = (TTree*)file_data_d02_9x9y->Get("posTree"); //TTree* tree_data_d02_m3xm3y = (TTree*)file_data_d02_m3xm3y->Get("posTree"); //TTree* tree_data_d02_m6xm6y = (TTree*)file_data_d02_m6xm6y->Get("posTree"); //TTree* tree_data_d02_m9xm9y = (TTree*)file_data_d02_m9xm9y->Get("posTree"); std::vector<LateralScanStruct> lss_diag02; lss_diag02.push_back( LateralScanStruct(0., tree_data, tree_mc) ); lss_diag02.push_back( LateralScanStruct(3.*sqrt(2.), tree_data_d02_3x3y, tree_mc_3x3y) ); lss_diag02.push_back( LateralScanStruct(6.*sqrt(2.), tree_data_d02_6x6y, tree_mc_6x6y) ); lss_diag02.push_back( LateralScanStruct(9.*sqrt(2.), tree_data_d02_9x9y, tree_mc_9x9y) ); //lss_diag02.push_back( LateralScanStruct(-3.*sqrt(2.), tree_data_d02_m3xm3y, tree_mc_3x3y) ); //lss_diag02.push_back( LateralScanStruct(-6.*sqrt(2.), tree_data_d02_m6xm6y, tree_mc_6x6y) ); //lss_diag02.push_back( LateralScanStruct(-9.*sqrt(2.), tree_data_d02_m9xm9y, tree_mc_9x9y) ); drawLateralScan( outputdir, "diag02", lss_diag02, "Diagonal", fullVarName_mc ); // THIRD: HORIZONTAL SCAN TFile* file_mc_2x0y = TFile::Open("EEShash_491MeV_10000ev_smear_2x0y.root"); TFile* file_mc_4x0y = TFile::Open("EEShash_491MeV_10000ev_smear_4x0y.root"); TFile* file_mc_6x0y = TFile::Open("EEShash_491MeV_10000ev_smear_6x0y.root"); TFile* file_mc_8x0y = TFile::Open("EEShash_491MeV_10000ev_smear_8x0y.root"); TFile* file_mc_10x0y = TFile::Open("EEShash_491MeV_10000ev_smear_10x0y.root"); TFile* file_mc_12x0y = TFile::Open("EEShash_491MeV_10000ev_smear_12x0y.root"); TTree* tree_mc_2x0y = (TTree*)file_mc_2x0y ->Get("EEShash"); TTree* tree_mc_4x0y = (TTree*)file_mc_4x0y ->Get("EEShash"); TTree* tree_mc_6x0y = (TTree*)file_mc_6x0y ->Get("EEShash"); TTree* tree_mc_8x0y = (TTree*)file_mc_8x0y ->Get("EEShash"); TTree* tree_mc_10x0y = (TTree*)file_mc_10x0y->Get("EEShash"); TTree* tree_mc_12x0y = (TTree*)file_mc_12x0y->Get("EEShash"); TFile* file_data_12x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_144_20140430-200741_beam.root", tag.c_str())); TFile* file_data_10x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_145_20140430-201024_beam.root", tag.c_str())); TFile* file_data_8x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_146_20140430-201243_beam.root", tag.c_str())); TFile* file_data_6x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_147_20140430-201509_beam.root", tag.c_str())); TFile* file_data_4x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_148_20140430-201719_beam.root", tag.c_str())); TFile* file_data_2x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_149_20140430-201913_beam.root", tag.c_str())); TFile* file_data_m2x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_151_20140430-202639_beam.root", tag.c_str())); TFile* file_data_m4x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_152_20140430-202852_beam.root", tag.c_str())); TFile* file_data_m6x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_153_20140430-203054_beam.root", tag.c_str())); TFile* file_data_m8x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_154_20140430-203255_beam.root", tag.c_str())); TFile* file_data_m10x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_155_20140430-203551_beam.root", tag.c_str())); TFile* file_data_m12x0y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_156_20140430-203818_beam.root", tag.c_str())); TTree* tree_data_2x0y = (TTree*)file_data_2x0y ->Get("posTree"); TTree* tree_data_4x0y = (TTree*)file_data_4x0y ->Get("posTree"); TTree* tree_data_6x0y = (TTree*)file_data_6x0y ->Get("posTree"); TTree* tree_data_8x0y = (TTree*)file_data_8x0y ->Get("posTree"); TTree* tree_data_10x0y = (TTree*)file_data_10x0y ->Get("posTree"); TTree* tree_data_12x0y = (TTree*)file_data_12x0y ->Get("posTree"); TTree* tree_data_m2x0y = (TTree*)file_data_m2x0y ->Get("posTree"); TTree* tree_data_m4x0y = (TTree*)file_data_m4x0y ->Get("posTree"); TTree* tree_data_m6x0y = (TTree*)file_data_m6x0y ->Get("posTree"); TTree* tree_data_m8x0y = (TTree*)file_data_m8x0y ->Get("posTree"); TTree* tree_data_m10x0y = (TTree*)file_data_m10x0y->Get("posTree"); TTree* tree_data_m12x0y = (TTree*)file_data_m12x0y->Get("posTree"); std::vector<LateralScanStruct> lss_horiz; lss_horiz.push_back( LateralScanStruct(0., tree_data, tree_mc) ); lss_horiz.push_back( LateralScanStruct(2., tree_data_2x0y, tree_mc_2x0y) ); lss_horiz.push_back( LateralScanStruct(4., tree_data_4x0y, tree_mc_4x0y) ); lss_horiz.push_back( LateralScanStruct(6., tree_data_6x0y, tree_mc_6x0y) ); lss_horiz.push_back( LateralScanStruct(8., tree_data_8x0y, tree_mc_8x0y) ); lss_horiz.push_back( LateralScanStruct(10., tree_data_10x0y, tree_mc_10x0y) ); lss_horiz.push_back( LateralScanStruct(12., tree_data_12x0y, tree_mc_12x0y) ); lss_horiz.push_back( LateralScanStruct(-2., tree_data_m2x0y, tree_mc_2x0y) ); lss_horiz.push_back( LateralScanStruct(-4., tree_data_m4x0y, tree_mc_4x0y) ); lss_horiz.push_back( LateralScanStruct(-6., tree_data_m6x0y, tree_mc_6x0y) ); lss_horiz.push_back( LateralScanStruct(-8., tree_data_m8x0y, tree_mc_8x0y) ); lss_horiz.push_back( LateralScanStruct(-10., tree_data_m10x0y, tree_mc_10x0y) ); lss_horiz.push_back( LateralScanStruct(-12., tree_data_m12x0y, tree_mc_12x0y) ); drawLateralScan( outputdir, "horiz", lss_horiz, "Horizontal", fullVarName_mc ); // FOURTH: VERTICAL SCAN TFile* file_data_0x2y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_160_20140430-204719_beam.root", tag.c_str())); TFile* file_data_0x4y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_159_20140430-204525_beam.root", tag.c_str())); TFile* file_data_0x6y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_158_20140430-204306_beam.root", tag.c_str())); TFile* file_data_0x8y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_157_20140430-204053_beam.root", tag.c_str())); TFile* file_data_0xm2y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_162_20140430-205129_beam.root", tag.c_str())); TFile* file_data_0xm4y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_163_20140430-205337_beam.root", tag.c_str())); TFile* file_data_0xm6y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_164_20140430-205542_beam.root", tag.c_str())); TFile* file_data_0xm8y = TFile::Open(Form("PosAnTrees_%s/PosAn_BTF_165_20140430-205756_beam.root", tag.c_str())); TTree* tree_data_0x2y = (TTree*)file_data_0x2y ->Get("posTree"); TTree* tree_data_0x4y = (TTree*)file_data_0x4y ->Get("posTree"); TTree* tree_data_0x6y = (TTree*)file_data_0x6y ->Get("posTree"); TTree* tree_data_0x8y = (TTree*)file_data_0x8y ->Get("posTree"); TTree* tree_data_0xm2y = (TTree*)file_data_0xm2y ->Get("posTree"); TTree* tree_data_0xm4y = (TTree*)file_data_0xm4y ->Get("posTree"); TTree* tree_data_0xm6y = (TTree*)file_data_0xm6y ->Get("posTree"); TTree* tree_data_0xm8y = (TTree*)file_data_0xm8y ->Get("posTree"); std::vector<LateralScanStruct> lss_vert; lss_vert.push_back( LateralScanStruct(0., tree_data, tree_mc) ); lss_vert.push_back( LateralScanStruct(2., tree_data_0x2y, tree_mc_2x0y) ); lss_vert.push_back( LateralScanStruct(4., tree_data_0x4y, tree_mc_4x0y) ); lss_vert.push_back( LateralScanStruct(6., tree_data_0x6y, tree_mc_6x0y) ); lss_vert.push_back( LateralScanStruct(8., tree_data_0x8y, tree_mc_8x0y) ); lss_vert.push_back( LateralScanStruct(-2., tree_data_0xm2y, tree_mc_2x0y) ); lss_vert.push_back( LateralScanStruct(-4., tree_data_0xm4y, tree_mc_4x0y) ); lss_vert.push_back( LateralScanStruct(-6., tree_data_0xm6y, tree_mc_6x0y) ); lss_vert.push_back( LateralScanStruct(-8., tree_data_0xm8y, tree_mc_8x0y) ); drawLateralScan( outputdir, "vert", lss_vert, "Vertical", fullVarName_mc ); return 0; }
LensFlare::LensFlare(string fname) { m_flares = new Flare[11]; string texture0 = ""; string texture1 = ""; string texture2 = ""; string texture3 = ""; string texture4 = ""; string texture5 = ""; string texture6 = ""; string texture7 = ""; string texture8 = ""; string texture9 = ""; string texture10 = ""; float dist0; float dist1; float dist2; float dist3; float dist4; float dist5; float dist6; float dist7; float dist8; float dist9; float dist10; vector<CfgVariable*> vars; vars.push_back(new CfgVariable(V_STRING, &texture0, getVarName(texture0))); vars.push_back(new CfgVariable(V_STRING, &texture1, getVarName(texture1))); vars.push_back(new CfgVariable(V_STRING, &texture2, getVarName(texture2))); vars.push_back(new CfgVariable(V_STRING, &texture3, getVarName(texture3))); vars.push_back(new CfgVariable(V_STRING, &texture4, getVarName(texture4))); vars.push_back(new CfgVariable(V_STRING, &texture5, getVarName(texture5))); vars.push_back(new CfgVariable(V_STRING, &texture6, getVarName(texture6))); vars.push_back(new CfgVariable(V_STRING, &texture7, getVarName(texture7))); vars.push_back(new CfgVariable(V_STRING, &texture8, getVarName(texture8))); vars.push_back(new CfgVariable(V_STRING, &texture9, getVarName(texture9))); vars.push_back(new CfgVariable(V_STRING, &texture10, getVarName(texture10))); vars.push_back(new CfgVariable(V_FLOAT, &dist0, getVarName(dist0))); vars.push_back(new CfgVariable(V_FLOAT, &dist1, getVarName(dist1))); vars.push_back(new CfgVariable(V_FLOAT, &dist2, getVarName(dist2))); vars.push_back(new CfgVariable(V_FLOAT, &dist3, getVarName(dist3))); vars.push_back(new CfgVariable(V_FLOAT, &dist4, getVarName(dist4))); vars.push_back(new CfgVariable(V_FLOAT, &dist5, getVarName(dist5))); vars.push_back(new CfgVariable(V_FLOAT, &dist6, getVarName(dist6))); vars.push_back(new CfgVariable(V_FLOAT, &dist7, getVarName(dist7))); vars.push_back(new CfgVariable(V_FLOAT, &dist8, getVarName(dist8))); vars.push_back(new CfgVariable(V_FLOAT, &dist9, getVarName(dist9))); vars.push_back(new CfgVariable(V_FLOAT, &dist10, getVarName(dist10))); CfgLoader(fname, &vars); if(texture0 != "") { m_flares[0].texture = gEngine.resMgr->load<Texture>(texture0); m_flares[0].distance = dist0; } if(texture1 != "") { m_flares[1].texture = gEngine.resMgr->load<Texture>(texture1); m_flares[1].distance = dist1; } if(texture2 != "") { m_flares[2].texture = gEngine.resMgr->load<Texture>(texture2); m_flares[2].distance = dist2; } if(texture3 != "") { m_flares[3].texture = gEngine.resMgr->load<Texture>(texture3); m_flares[3].distance = dist3; } if(texture4 != "") { m_flares[4].texture = gEngine.resMgr->load<Texture>(texture4); m_flares[4].distance = dist4; } if(texture5 != "") { m_flares[5].texture = gEngine.resMgr->load<Texture>(texture5); m_flares[5].distance = dist5; } if(texture6 != "") { m_flares[6].texture = gEngine.resMgr->load<Texture>(texture6); m_flares[6].distance = dist6; } if(texture7 != "") { m_flares[7].texture = gEngine.resMgr->load<Texture>(texture7); m_flares[7].distance = dist7; } if(texture8 != "") { m_flares[8].texture = gEngine.resMgr->load<Texture>(texture8); m_flares[8].distance = dist8; } if(texture9 != "") { m_flares[9].texture = gEngine.resMgr->load<Texture>(texture9); m_flares[9].distance = dist9; } if(texture10 != "") { m_flares[10].texture = gEngine.resMgr->load<Texture>(texture10); m_flares[10].distance = dist10; } }
int OPTevaluateImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) { InstrPtr p; int i, k, limit, *alias, barrier; MalStkPtr env = NULL; int profiler; str msg; int debugstate = cntxt->itrace, actions = 0, constantblock = 0; int *assigned, setonce; cntxt->itrace = 0; (void)stk; (void)pci; if (varGetProp(mb, getArg(mb->stmt[0], 0), inlineProp) != NULL) return 0; (void)cntxt; OPTDEBUGevaluate mnstr_printf(cntxt->fdout, "Constant expression optimizer started\n"); assigned = (int*) GDKzalloc(sizeof(int) * mb->vtop); if (assigned == NULL) return 0; alias = (int*)GDKzalloc(mb->vsize * sizeof(int) * 2); /* we introduce more */ if (alias == NULL){ GDKfree(assigned); return 0; } // arguments are implicitly assigned by context p = getInstrPtr(mb, 0); for ( k =p->retc; k < p->argc; k++) assigned[getArg(p,k)]++; limit = mb->stop; for (i = 1; i < limit; i++) { p = getInstrPtr(mb, i); // The double count emerging from a barrier exit is ignored. if (! blockExit(p) || (blockExit(p) && p->retc != p->argc)) for ( k =0; k < p->retc; k++) assigned[getArg(p,k)]++; } for (i = 1; i < limit; i++) { p = getInstrPtr(mb, i); for (k = p->retc; k < p->argc; k++) if (alias[getArg(p, k)]) getArg(p, k) = alias[getArg(p, k)]; // to avoid management of duplicate assignments over multiple blocks // we limit ourselfs to evaluation of the first assignment only. setonce = assigned[getArg(p,0)] == 1; OPTDEBUGevaluate printInstruction(cntxt->fdout, mb, 0, p, LIST_MAL_ALL); constantblock += blockStart(p) && OPTallConstant(cntxt,mb,p); /* be aware that you only assign once to a variable */ if (setonce && p->retc == 1 && OPTallConstant(cntxt, mb, p) && !isUnsafeFunction(p)) { barrier = p->barrier; p->barrier = 0; profiler = malProfileMode; /* we don't trace it */ malProfileMode = 0; if ( env == NULL) { env = prepareMALstack(mb, 2 * mb->vsize ); env->keepAlive = TRUE; } msg = reenterMAL(cntxt, mb, i, i + 1, env); malProfileMode= profiler; p->barrier = barrier; OPTDEBUGevaluate { mnstr_printf(cntxt->fdout, "#retc var %s\n", getVarName(mb, getArg(p, 0))); mnstr_printf(cntxt->fdout, "#result:%s\n", msg == MAL_SUCCEED ? "ok" : msg); } if (msg == MAL_SUCCEED) { int nvar; ValRecord cst; actions++; cst.vtype = 0; VALcopy(&cst, &env->stk[getArg(p, 0)]); /* You may not overwrite constants. They may be used by * other instructions */ nvar = getArg(p, 1) = defConstant(mb, getArgType(mb, p, 0), &cst); if (nvar >= env->stktop) { VALcopy(&env->stk[getArg(p, 1)], &getVarConstant(mb, getArg(p, 1))); env->stktop = getArg(p, 1) + 1; } alias[getArg(p, 0)] = getArg(p, 1); p->argc = 2; p->token = ASSIGNsymbol; clrFunction(p); p->barrier = barrier; /* freeze the type */ setVarFixed(mb,getArg(p,1)); setVarUDFtype(mb,getArg(p,1)); OPTDEBUGevaluate { mnstr_printf(cntxt->fdout, "Evaluated new constant=%d -> %d:%s\n", getArg(p, 0), getArg(p, 1), getTypeName(getArgType(mb, p, 1))); } } else {
Value* interpereteValue(Token *t){ Value *v = NULL, *v2 = NULL, *v3 = NULL; if(t==NULL) return NULL; int nValueBuffOld=nValueBuff; int nValueExtraBuffOld = nValueExtraBuff; switch (t->type){ default: PERRORTOK("", t); v=interpereteValue(t->firstChild); break; case VALUE: v=interpereteValue(t->firstChild); break; case ASSIGNMENT: { interpereteValue(t->firstChild->nextSibling); v2 = valueBuff + nValueBuff; v = interpreteAssignment(getVarName((int)t->firstChild->extra), v2->type, v2->extra); break; } case VARIABLE: { std::string name(getVarName((int)t->extra)); v2 = getVal(name); v = valueBuff+nValueBuff++; switch(v2->type){ case INTEGER: v->type = INTEGER; v->extra = valueExtraBuff+nValueExtraBuff; *((int*)v->extra) = *((int*)v2->extra); nValueExtraBuff+=sizeof(int); break; case FLOAT: v->type = FLOAT; v->extra = valueExtraBuff+nValueExtraBuff; *((float*)v->extra) = *((float*)v2->extra); nValueExtraBuff+=sizeof(float); break; case STRING: v->type = STRING; v->extra = valueExtraBuff+nValueExtraBuff; strcpy((char*)v->extra, (char*)v2->extra); nValueExtraBuff+=strlen((char*)v->extra)+1; break; } } break; case STRING: v = valueBuff+nValueBuff++; v->type = STRING; v->extra = valueExtraBuff+nValueExtraBuff; strcpy((char*)v->extra, (char*)t->extra); nValueExtraBuff+=strlen((char*)v->extra)+1; break; case INTEGER: v = valueBuff+nValueBuff++; v->type = INTEGER; v->extra = valueExtraBuff+nValueExtraBuff; *((int*)v->extra) = *((int*)t->extra); nValueExtraBuff+=sizeof(int); break; case FLOAT: v = valueBuff+nValueBuff++; v->type = FLOAT; v->extra = valueExtraBuff+nValueExtraBuff; *((float*)v->extra) = *((float*)t->extra); nValueExtraBuff+=sizeof(float); break; case OPERATOR: v3 = valueBuff + nValueBuff - 1; if (!isOperatorSingle((int)t->extra)) { v2 = valueBuff+nValueBuff-2; int type = (int)t->extra; if(v2->type < v3->type){ convert(v2, (int)v3->type); }else if(v2->type > v3->type){ convert(v3, (int)v2->type); } } switch (v3->type){ case STRING: v = interpereteStringOperator(t, v2, v3); break; case FLOAT: v = interpereteFloatOperator(t, v2, v3); break; case INTEGER: v = interpereteIntegerOperator(t, v2, v3); break; } if (!isOperatorSingle((int)t->extra)) nValueBuff--; break; case FUNC_DEF: { FuncDefExtra *extra = (FuncDefExtra*)t->extra; std::string name(getVarName((int)extra->name->extra)); v2 = getVal(name); v2->type = FUNC_DEF; v2->extra = t; } break; case FUNC_CALL: { FuncCallExtra *extra = (FuncCallExtra*)t->extra; std::string name(getVarName((int)extra->name->extra)); if (name == "print") { printValues(extra->values); } else if (name == "scan") { scanValue(); } else { Value *val = getVal(name); currentStack++; Token *funcDefToken = (Token*)val->extra; FuncDefExtra *defExtra = (FuncDefExtra*)funcDefToken->extra; Token *t_val = extra->values; Token *t_def = defExtra->parameters; while (t_val) { interpereteValue(t_val->firstChild); v2 = valueBuff + nValueBuff; interpreteAssignment(getVarName((int)t_def->extra), v2->type, v2->extra); t_val = t_val->nextSibling; t_def = t_def->nextSibling; } interpreteFlow(defExtra->func_body); currentStack--; } } break; } v2 = interpereteValue(t->nextSibling); nValueBuff = nValueBuffOld; nValueExtraBuff = nValueExtraBuffOld; return v2?v2:v; }
static TToken getToken() { oSrcString = sSrcString; int ch = getNextChar(); bool verbStr=false; switch (ch) { case EOFCH: case 0: currTok = tEnd; break; case L',': currTok = tComma; break; case L'+': currTok = tPlus; break; case L'-': currTok = tMinus; break; case L'*': currTok = tMul; break; case L'/': currTok = tDiv; break; case L'(': currTok = tLp; break; case L')': currTok = tRp; break; case L'^': if ((ch = getChar()) == L'^') currTok = tBoolXor; else { putBack(ch); currTok = tBitXor; } break; case L'~': if ((ch = getChar()) != L' ') { putBack(ch); currTok = tBitNot; break; } putBack(ch); //???? currTok = tEnd; break; case L'|': if ((ch = getChar()) == L'|') currTok = tBoolOr; else { putBack(ch); currTok = tBitOr; } break; case L'&': if ((ch = getChar()) == L'&') currTok = tBoolAnd; else { putBack(ch); currTok = tBitAnd; } break; case L'=': if ((ch = getChar()) == L'=') currTok = tEq; else { putBack(ch); currTok = tLet; } break; case L'>': switch ((ch = getChar())) { case L'=': currTok = tGe; break; case L'>': currTok = tBitShr; break; default: putBack(ch); currTok = tGt; break; } break; case L'<': switch (ch = getChar()) { case L'=': currTok = tLe; break; case L'<': currTok = tBitShl; break; default: putBack(ch); currTok = tLt; break; } break; case L'!': if ((ch = getChar()) != L'=') { putBack(ch); currTok = tNot; break; } else currTok = tNe; break; case L'@': ch = getChar(); if (ch != L'"') { putBack(ch); break; } verbStr=true; case L'\"': { TToken __currTok = tNo; currVar = L""; while (((ch = getChar()) != EOFCH)) { if (ch == L'\"') { if (verbStr) { ch = getChar(); if (ch != L'\"') { putBack(ch); break; } } else break; } if (ch == L'\\' && !verbStr) { switch (ch = getChar()) { case L'a' : ch = L'\a'; break; case L'b' : ch = L'\b'; break; case L'f' : ch = L'\f'; break; case L'n' : ch = L'\n'; break; case L'r' : ch = L'\r'; break; case L't' : ch = L'\t'; break; case L'v' : ch = L'\v'; break; case L'\'': ch = L'\''; break; case L'\"': ch = L'\"'; break; case L'\\': ch = L'\\'; break; case L'0': case L'1': case L'2': case L'3': case L'4': case L'5': case L'6': case L'7': // octal: \d \dd \ddd { BYTE n = ch - L'0'; if ((unsigned int)(ch = getChar()) >= L'0' && (unsigned int)ch < L'8') { n = 8 * n + ch - L'0'; if ((unsigned int)(ch = getChar()) >= L'0' && (unsigned int)ch < L'8') n = 8 * n + ch - L'0'; else putBack(ch); } else putBack(ch); ch = n; break; } case L'x': { if (iswxdigit(ch = getChar())) { wchar_t value=hex2ch(ch); for (int ii=0; ii<3; ii++) { if (iswxdigit(ch = getChar())) { value=(value<<4)|hex2ch(ch); } else { putBack(ch); break; } } ch = value; } else { keyMacroParseError(err_Bad_Hex_Control_Char,--sSrcString,pSrcString); __currTok = tEnd; } break; } default: { keyMacroParseError(err_Bad_Control_Char,--sSrcString,pSrcString); __currTok = tEnd; break; } } } if (__currTok != tNo) break; currVar.AppendStr((wchar_t)ch); } if (__currTok == tNo) currTok = tStr; else currTok = __currTok; break; } case L'.': { ch = getChar(); if (iswdigit(ch)) { putBack(ch); ch=L'.'; } else { currTok = tEnd; //??? break; } } case L'0': case L'1': case L'2': case L'3': case L'4': case L'5': case L'6': case L'7': case L'8': case L'9': { static wchar_t buffer[256]; wchar_t *ptrbuffer=buffer; bool isNum = false; bool isHex = false; bool isE = false; bool isPoint = false; int ch2; for (;;) { *ptrbuffer++=(wchar_t)ch; switch (ch) { case L'x': case L'X': if (ptrbuffer == buffer + 2) { ch = getChar(); if (iswxdigit(ch)) { isHex=true; putBack(ch); } else { putBack(ch); isNum=true; break; } } break; case L'.': if (isPoint || isE) { isNum=true; break; } isPoint=true; break; case L'e': case L'E': if (isHex) break; if (isE) { isNum=true; break; } isE=true; ch2 = getChar(); if (ch2 == L'-' || ch2 == L'+') { int ch3=getChar(); if (iswdigit(ch3)) { *ptrbuffer++=(wchar_t)ch2; *ptrbuffer++=(wchar_t)ch3; } else { putBack(ch3); // !iswdigit putBack(ch2); // -+ putBack(ch); // eE } } else if (!iswdigit(ch2)) { putBack(ch2); // !iswdigit putBack(ch); // eE } else putBack(ch); break; case L'a': case L'A': case L'b': case L'B': case L'c': case L'C': case L'd': case L'D': case L'f': case L'F': if (!isHex) { isNum=true; break; } case L'0': case L'1': case L'2': case L'3': case L'4': case L'5': case L'6': case L'7': case L'8': case L'9': //isNum=true; break; default: isNum=true; break; } if (isNum) break; ch = getChar(); } if (ch != EOFCH) putBack(ch); *ptrbuffer++=(wchar_t)0; bool CheckIntNumber=true; if (buffer[0]) { if (!(buffer[1] == L'x' || buffer[1] == L'X')) { for (ptrbuffer=buffer; *ptrbuffer ; ptrbuffer++) { if (*ptrbuffer == L'e' || *ptrbuffer == L'E' || *ptrbuffer == L'.') { CheckIntNumber=false; break; } else if (!iswdigit(*ptrbuffer)) break; } } } else CheckIntNumber=false; if (CheckIntNumber) { currVar = _wcstoi64(buffer,&ptrbuffer,0); currTok = tInt; } else { currVar = wcstod(buffer,&ptrbuffer); currTok = tFloat; } break; } case L'%': ch = getChar(); if ((IsAlphaNum(ch) || ch == L'_') || (ch == L'%' && (IsAlphaNum(*sSrcString) || *sSrcString == L'_'))) { getVarName(ch); putBack(ch); currTok = tVar; } else keyMacroParseError(err_Var_Expected,L""); // BUG nameString break; default: { if (IsAlpha(ch)) // || ch == L'_' ???? { TToken __currTok = tNo; getFarName(ch); if (ch == L' ') { while (ch == L' ') ch = getNextChar(); } if (ch == L'(') //!!!! а пробелы пропустить? ДА! __currTok = tFunc; else { putBack(ch); for (int i = 0 ; i < MKeywordsSize ; i++) if (!StrCmpI(nameString, MKeywords[i].Name)) { FARVar = MKeywords[i].Value; __currTok = tFARVar; break; } if (__currTok == tNo) { if (IsProcessFunc || currTok == tFunc || currTok == tLt) // TODO: уточнить { if (KeyNameMacroToKey(nameString) == -1 && KeyNameToKey(nameString) == -1 && checkMacroConst(nameString)) __currTok = tConst; else { DWORD k=KeyNameToKey(nameString); if (k != (DWORD)-1) { currVar = (__int64)k; __currTok = tInt; //?? } else { keyMacroParseError(err_Var_Expected,oSrcString,pSrcString,nameString); } } } else { if (KeyNameMacroToKey(nameString) == -1) { if (KeyNameToKey(nameString) == -1) { if (checkMacroConst(nameString)) __currTok = tConst; else keyMacroParseError(err_Unrecognized_keyword,nameString); } else { currVar = (__int64)KeyNameToKey(nameString); __currTok = tInt; //?? } } } } } if (__currTok != tNo) currTok=__currTok; } else currTok = tEnd; break; } } return currTok; }