//------------------------------------------------------------------------
//--- prints parameters on screen ----------------------------------------
//------------------------------------------------------------------------
void JetCorrectorParameters::printScreen() const
{
  std::cout<<"--------------------------------------------"<<std::endl;
  std::cout<<"////////  PARAMETERS: //////////////////////"<<std::endl;
  std::cout<<"--------------------------------------------"<<std::endl;
  std::cout<<"Number of binning variables:   "<<definitions().nBinVar()<<std::endl;
  std::cout<<"Names of binning variables:    ";
  for(unsigned i=0;i<definitions().nBinVar();i++)
    std::cout<<definitions().binVar(i)<<" ";
  std::cout<<std::endl;
  std::cout<<"--------------------------------------------"<<std::endl;
  std::cout<<"Number of parameter variables: "<<definitions().nParVar()<<std::endl;
  std::cout<<"Names of parameter variables:  ";
  for(unsigned i=0;i<definitions().nParVar();i++)
    std::cout<<definitions().parVar(i)<<" ";
  std::cout<<std::endl;
  std::cout<<"--------------------------------------------"<<std::endl;
  std::cout<<"Parametrization Formula:       "<<definitions().formula()<<std::endl;
  if (definitions().isResponse())
    std::cout<<"Type (Response or Correction): "<<"Response"<<std::endl;
  else
    std::cout<<"Type (Response or Correction): "<<"Correction"<<std::endl;
  std::cout<<"Correction Level:              "<<definitions().level()<<std::endl;
  std::cout<<"--------------------------------------------"<<std::endl;
  std::cout<<"------- Bin contents -----------------------"<<std::endl;
  for(unsigned i=0;i<size();i++)
    {
      for(unsigned j=0;j<definitions().nBinVar();j++)
        std::cout<<record(i).xMin(j)<<" "<<record(i).xMax(j)<<" ";
      std::cout<<record(i).nParameters()<<" ";
      for(unsigned j=0;j<record(i).nParameters();j++)
        std::cout<<record(i).parameter(j)<<" ";
      std::cout<<std::endl;
    }
}
/// Find process definitions and instantiate SipxProcess objects for each.
void SipxProcessManager::instantiateProcesses(const OsPath& processDefinitionDirectory)
{
   OsFileIterator definitions(processDefinitionDirectory);
   OsPath    processDefinitionFile;
   OsStatus  iteratorStatus;

   Os::Logger::instance().log(FAC_SUPERVISOR, PRI_DEBUG,"SipxProcessManager::instantiateProcesses searching %s",
                 processDefinitionDirectory.data()
                 );

   for ( iteratorStatus = definitions.findFirst(processDefinitionFile,
                                                PROCESS_DEFINITION_NAME_PATTERN,
                                                OsFileIterator::FILES);
         OS_SUCCESS == iteratorStatus;
         iteratorStatus = definitions.findNext(processDefinitionFile)
        )
   {
      OsPath processDefinitionPath( processDefinitionDirectory
                                   +OsPath::separator
                                   +processDefinitionFile
                                   );
      Os::Logger::instance().log(FAC_SUPERVISOR, PRI_DEBUG,"SipxProcessManager::instantiateProcesses reading %s",
                    processDefinitionPath.data()
                    );

      SipxProcess::createFromDefinition(processDefinitionPath);
   }
}
//------------------------------------------------------------------------
//--- JetCorrectorParameters constructor ---------------------------------
//--- reads the member variables from a string ---------------------------
//------------------------------------------------------------------------
JetCorrectorParameters::JetCorrectorParameters(const std::string& fFile, const std::string& fSection)
{
  std::ifstream input(fFile.c_str());
  std::string currentSection = "";
  std::string line;
  std::string currentDefinitions = "";
  while (std::getline(input,line))
    {
      std::string section = getSection(line);
      std::string tmp = getDefinitions(line);
      if (!section.empty() && tmp.empty())
        {
          currentSection = section;
          continue;
        }
      if (currentSection == fSection)
        {
          if (!tmp.empty())
            {
              currentDefinitions = tmp;
              continue;
            }
          Definitions definitions(currentDefinitions);
          if (!(definitions.nBinVar()==0 && definitions.formula()==""))
            mDefinitions = definitions;
          Record record(line,mDefinitions.nBinVar());
          bool check(true);
          for(unsigned i=0;i<mDefinitions.nBinVar();++i)
            if (record.xMin(i)==0 && record.xMax(i)==0)
              check = false;
          if (record.nParameters() == 0)
            check = false;
          if (check)
            mRecords.push_back(record);
        }
    }
  if (currentDefinitions=="")
    handleError("JetCorrectorParameters","No definitions found!!!");
  if (mRecords.empty() && currentSection == "") mRecords.push_back(Record());
  if (mRecords.empty() && currentSection != "")
    {
      std::stringstream sserr;
      sserr<<"the requested section "<<fSection<<" doesn't exist!";
      handleError("JetCorrectorParameters",sserr.str());
    }
  std::sort(mRecords.begin(), mRecords.end());
  valid_ = true;
}
	bool execute(const Definition* def) {
		if (getOption(BoolType::GUARANTEE_NO_REC_AGG)) { return false; }
		auto voc = Vocabulary("wrapper_voc");
		for(auto s: FormulaUtils::collectSymbols(def)){
			voc.add(s);
		}
		auto theory = new Theory("wrapper_theory", &voc, {});
		auto newdef = def->clone();
		theory->add(newdef);
		DefinitionUtils::splitDefinitions(theory);
		_result = false;
		for (auto d : theory->definitions()) {
			_def = d;
			d->accept(this);
		}
		theory->recursiveDelete();
		return _result;
	}
 EntityDefinitionManager::EntityDefinitionGroups EntityDefinitionManager::groups(EntityDefinition::Type type, SortOrder order) {
     EntityDefinitionGroups groups;
     EntityDefinitionList list = definitions(type, order);
     EntityDefinitionList ungrouped;
     
     EntityDefinitionList::const_iterator it, end;
     for (it = list.begin(), end = list.end(); it != end; ++it) {
         EntityDefinition* definition = *it;
         const String groupName = definition->groupName();
         if (groupName.empty())
             ungrouped.push_back(definition);
         else
             groups[groupName].push_back(definition);
     }
     
     for (it = ungrouped.begin(), end = ungrouped.end(); it != end; ++it) {
         EntityDefinition* definition = *it;
         const String shortName = Utility::capitalize(definition->shortName());
         EntityDefinitionGroups::iterator groupIt = groups.find(shortName);
         if (groupIt == groups.end())
             groups["Misc"].push_back(definition);
         else
             groupIt->second.push_back(definition);
     }
     
     EntityDefinitionGroups::iterator groupIt, groupEnd;
     for (groupIt = groups.begin(), groupEnd = groups.end(); groupIt != groupEnd; ++groupIt) {
         EntityDefinitionList& definitions = groupIt->second;
         if (order == Usage)
             std::sort(definitions.begin(), definitions.end(), CompareEntityDefinitionsByUsage());
         else
             std::sort(definitions.begin(), definitions.end(), CompareEntityDefinitionsByName(true));
     }
     
     return groups;
 }
//------------------------------------------------------------------------
//--- prints parameters on file ----------------------------------------
//------------------------------------------------------------------------
void JetCorrectorParameters::printFile(const std::string& fFileName) const
{
  std::ofstream txtFile;
  txtFile.open(fFileName.c_str());
  txtFile.setf(std::ios::right);
  txtFile<<"{"<<definitions().nBinVar()<<std::setw(15);
  for(unsigned i=0;i<definitions().nBinVar();i++)
    txtFile<<definitions().binVar(i)<<std::setw(15);
  txtFile<<definitions().nParVar()<<std::setw(15);
  for(unsigned i=0;i<definitions().nParVar();i++)
    txtFile<<definitions().parVar(i)<<std::setw(15);
  txtFile<<std::setw(definitions().formula().size()+15)<<definitions().formula()<<std::setw(15);
  if (definitions().isResponse())
    txtFile<<"Response"<<std::setw(15);
  else
    txtFile<<"Correction"<<std::setw(15);
  txtFile<<definitions().level()<<"}"<<"\n";
  for(unsigned i=0;i<size();i++)
    {
      for(unsigned j=0;j<definitions().nBinVar();j++)
        txtFile<<record(i).xMin(j)<<std::setw(15)<<record(i).xMax(j)<<std::setw(15);
      txtFile<<record(i).nParameters()<<std::setw(15);
      for(unsigned j=0;j<record(i).nParameters();j++)
        txtFile<<record(i).parameter(j)<<std::setw(15);
      txtFile<<"\n";
    }
  txtFile.close();
}
Esempio n. 7
0
int main1()
{
char ch;
clrscr();
printf("\n");
textcolor(CYAN);
cprintf("         Solutions to Basic Electronics");
printf("\n\n");
textcolor(MAGENTA);
cprintf("                         - S.P.Prathyush");
printf("\n\n\n");
textcolor(WHITE);
cprintf("         Enter The Topic");
printf("\n\n\t 1.Half Wave Rectifier \n\t 2.Full Wave Rectifier \n\t 3.Bridge Rectifier \n\t 4.Transistor \n\t 5.Solve by Equations \n\t 6.Definitions \n\t 7.Question Paper Pattern \n\t 8.Syllabus \n\t 9.Reference");
gotoxy(40,7);
printf(" Special Features:");
gotoxy(40,9);
printf(" a.Formula List");
gotoxy(40,10);
printf(" b.Features");
gotoxy(40,11);
printf(" c.View Credits");
printf("\n\n\t");
textcolor(YELLOW);
gotoxy(35,23);
cprintf(" Press Q to Quit ");
printf("\n\n\t");
gotoxy(35,24);
cprintf(" Enter Your Choice : ");
textcolor(WHITE);
printf("");
date();
ch=getche();
switch(ch)
{
case '1':
HWR();
break;

case '2':
FWR();
break;

case '3':
Bridge();
break;

case '4':
Transistor();
break;

case '5':
Equations();
break;

case '6':
definitions();
break;

case '7':
pattern();
break;

case '8':
syllabus();
break;

case '9':
reference();
break;

case 'a':
Formula();
break;

case 'b':
Features();
break;

case 'c':
credits();
break;

case 'Q':
exit(ch-'Q');
break;

default:
printf("\n\n\t");
textcolor(RED+BLINK);
cprintf(" Invalid Choice");
invalid();
getch();
end1();
break;
}
return 0;
}
Esempio n. 8
0
int main()
{
	/*
	std::string test =
		"int main()\n"
		"{\n"
		"    int i = 1;\n"
		"    float f = 1.0;\n"
		"    vec4 v4;\n"
		"    i = 2;\n"
		"    i = 3 * 4;\n"
		"    v4 = v4 * 7.0;\n"
		//"    int main = 1;\n"
		//"    int i = 8;\n"
		//"    1 += 2;\n"
		"    v4 *= 1;\n"
		//"    i = j;\n"
		"    return i;\n"
		"}";
	*/

	/*
	std::string test =
		"export void main()\n"
		"{\n"
		"	g_projected_position = g_projection * g_view * g_model * g_position;\n"
		"	g_projected_position[0] /= g_projected_position[3];\n"
		"	g_projected_position[1] /= g_projected_position[3];\n"
		"	g_projected_position[2] /= g_projected_position[3];\n"
		"	g_world_position = normalize(g_model * g_normal);\n"
		"	return;\n"
		"}\n";
	*/

	/*
	std::string test =
		"export void main()\n"
		"{\n"
		"	vec4 directionToLight = g_light0_position - g_world_position;\n"
		"	float lightDistance = length(directionToLight);\n"
		"\n"
		"	directionToLight = normalize(directionToLight);\n"
		"\n"
		"	vec4 ambient;\n"
		"	ambient[0] = 0.2;\n"
		"	ambient[1] = 0.2;\n"
		"	ambient[2] = 0.2;\n"
		"\n"
		"	vec4 diffuse;\n"
		"	diffuse[0] = 1.0;\n"
		"	diffuse[1] = 1.0;\n"
		"	diffuse[2] = 1.0;\n"
		"\n"
		"	float dp = dot(g_world_normal, directionToLight);\n"
		"	float clamped = clamp(dp, 0.0, dp);\n"
		"\n"
		"	float k = 0.1;\n"
		"	float attenuation = 1.0 / (lightDistance * k);\n"
		"\n"
		"	vec4 colour = ambient + (diffuse * clamped * attenuation);\n"
		"\n"
		"	g_colour[0] = clamp(colour[0], 0.0, 1.0);\n"
		"	g_colour[1] = clamp(colour[1], 0.0, 1.0);\n"
		"	g_colour[2] = clamp(colour[2], 0.0, 1.0);\n"
		"\n"
		"	return;\n"
		"}\n";
	*/

	std::string test =
		"export void main()\n"
		"{\n"
		"	int x = 100;\n"
		"	int y = 200;\n"
		"	float f = 1.0;\n"
		"\n"
		"	if (x < y)\n"
		"		{ x = 1; }\n"
		"	else if (x > 0)\n"
		"		{ y = 2; }\n"
		//"	if (f >= 100.0)\n"
		"	else\n"
		"		{ f = 100.0; }\n"
		"\n"
		"	return;\n"
		"}\n";

	tokeniser::TextStream text(test);
	tokeniser::TokenDefinitions definitions(CreateDefinitions());

	tokeniser::TokenStream tokens(text, definitions);

	std::string error;

	if (! tokens.Parse(error))
		return 1;

	tokeniser::Token errorToken;
	//SyntaxTree tree(ProgramContext::VertexShaderContext());
	SyntaxTree tree(ProgramContext::FragmentShaderContext());

	if (! tree.Parse(tokens.GetTokens(), error, errorToken))
	{
		if (errorToken.m_type == static_cast<int>(TokenType::EndOfInput))
		{
			std::cout << error << " at end of input\n";
			return 1;
		}

		std::string line = text.GetLineText(errorToken.m_line);
		std::string spaces(6, ' ');

		for (uint32_t i = 0; i < (errorToken.m_column - 1); ++i)
		{
			if (line[i] == '\t')
				spaces.append(1, '\t');
			else
				spaces.append(1, ' ');
		}

		std::string message;

		if (errorToken.m_line > 1)
		{
			message += FormatLine(text, errorToken.m_line - 1);
		}

		message += FormatLine(text, errorToken.m_line);
		message += spaces + "^ " + error + "\n";

		std::string after = FormatLine(text, errorToken.m_line + 1);

		if (! after.empty())
		{
			message += "\n";
			message += after;
		}

		std::cout << message;
		return 1;
	}

	ShadyObject object(0x1000);

	CodeGenerator generator(object.GetStart(),
		ProgramContext::FragmentShaderContext(), tree.GetSymbolTable(), tree.GetFunctionTable());

	generator.Generate(&object, tree.GetRoot());

	return 0;
}
Esempio n. 9
0
void upgradeFrom3_0()
{
    // 3.0 had process definition files in /etc/sipxpbx/process.d
    UtlString oldProcessDefinitionDirectory =
        SipXecsService::Path(SipXecsService::ConfigurationDirType, "process-old.d");

    OsSysLog::add(FAC_SUPERVISOR, PRI_DEBUG,"upgradeFrom3_0: searching '%s'",
                  oldProcessDefinitionDirectory.data()
                 );

    if ( !OsFileSystem::exists( oldProcessDefinitionDirectory) )
    {
        return;
    }

    OsFileIterator definitions(oldProcessDefinitionDirectory);
    OsPath    oldProcessDefinitionFile;
    bool okToRemoveDir = true;   // set to false if any pre-4.0 process file cannot be upgraded
    for ( OsStatus iteratorStatus = definitions.findFirst(oldProcessDefinitionFile,
                                    OLD_PROCESS_DEFINITION_NAME_PATTERN,
                                    OsFileIterator::FILES);
            OS_SUCCESS == iteratorStatus;
            iteratorStatus = definitions.findNext(oldProcessDefinitionFile)
        )
    {
        OsPath oldProcessDefinitionPath( oldProcessDefinitionDirectory
                                         +OsPath::separator
                                         +oldProcessDefinitionFile
                                       );
        OsSysLog::add(FAC_SUPERVISOR, PRI_INFO,"upgradeFrom3_0: reading pre-4.0 process def '%s'",
                      oldProcessDefinitionPath.data()
                     );

        // read the process name and the watchdog enable setting,
        // and enable the process if necessary
        TiXmlDocument processDefinitionDoc(oldProcessDefinitionPath);

        bool definitionValid = true;
        UtlString errorMsg;
        if ( processDefinitionDoc.LoadFile() )
        {
            TiXmlElement *subroot = processDefinitionDoc.RootElement();
            if (subroot != NULL)
            {
                bool bEnabled=false;
                const char *enableString = subroot->Attribute("enable");
                if (enableString == NULL || strcmp(enableString, "true")==0)
                {
                    bEnabled=true;
                }

                TiXmlElement* processDefElement = subroot->FirstChildElement("process_definitions");
                if (processDefElement)
                {
                    TiXmlNode *pGroupNode = processDefElement->FirstChild("group");
                    if (pGroupNode)
                    {
                        TiXmlElement *processElement = pGroupNode->FirstChildElement("process");
                        if (processElement)
                        {
                            const char *pMsg = processElement->Attribute("name");
                            UtlString processName = pMsg;

                            // enable or disable process based on setting in old process def file
                            SipxProcess* newProcess;
                            if ((newProcess=SipxProcessManager::getInstance()->findProcess(processName)))
                            {
                                if (bEnabled)
                                {
                                    OsSysLog::add(FAC_SUPERVISOR, PRI_NOTICE,
                                                  "upgradeFrom3_0: enabling process '%s'", processName.data());
                                    newProcess->enable();
                                }
                                else
                                {
                                    OsSysLog::add(FAC_SUPERVISOR, PRI_NOTICE,
                                                  "upgradeFrom3_0: disabling process '%s'", processName.data());
                                    newProcess->disable();
                                }

                                if (OS_SUCCESS == OsFileSystem::remove(oldProcessDefinitionPath))
                                {
                                    OsSysLog::add(FAC_SUPERVISOR, PRI_NOTICE,
                                                  "upgradeFrom3_0: removing pre-4.0 process def file '%s'",
                                                  oldProcessDefinitionPath.data());
                                }
                                else
                                {
                                    OsSysLog::add(FAC_SUPERVISOR, PRI_ERR,
                                                  "upgradeFrom3_0: failed to remove pre-4.0 process def file '%s'",
                                                  oldProcessDefinitionPath.data());
                                }
                            }
                            else
                            {
                                OsSysLog::add(FAC_SUPERVISOR, PRI_ERR,
                                              "upgradeFrom3_0: could not find process '%s'", processName.data());
                                okToRemoveDir = false;
                            }
                        }
                        else
                        {
                            definitionValid = false;
                        }
                    }
                    else
                    {
                        definitionValid = false;
                    }
                }
                else
                {
                    definitionValid = false;
                }
            }
            else
            {
                definitionValid = false;
            }
        }
        else
        {
            definitionValid = false;
        }

        if ( !definitionValid )
        {
            // Invalid document format.  Log the issue and continue to the next process xml file.
            XmlErrorMsg(processDefinitionDoc, errorMsg);
            OsSysLog::add(FAC_SUPERVISOR, PRI_ERR,
                          "upgradeFrom3_0: ignoring invalid pre-4.0 process xml file '%s' (%s)",
                          oldProcessDefinitionFile.data(), errorMsg.data());
            okToRemoveDir = false;
        }
    }

    // remove the old process defn directory (succeeds only if it is empty)
    if (OS_SUCCESS == OsFileSystem::remove(oldProcessDefinitionDirectory))
    {
        OsSysLog::add(FAC_SUPERVISOR, PRI_NOTICE,
                      "upgradeFrom3_0: all process data has been migrated from "
                      "pre-4.0 process def directory '%s', "
                      "and the directory has been deleted.",
                      oldProcessDefinitionDirectory.data());
    }
    else
    {
        // rmdir may fail because files still exist (e.g. editor backup files).
        // Log whether upgrade succeeded or not.
        if ( okToRemoveDir )
        {
            OsSysLog::add(FAC_SUPERVISOR, PRI_NOTICE,
                          "upgradeFrom3_0: all process data has been migrated from "
                          "pre-4.0 process def directory '%s', "
                          "and the directory may safely be deleted.",
                          oldProcessDefinitionDirectory.data());
        }
        else
        {
            OsSysLog::add(FAC_SUPERVISOR, PRI_WARNING,
                          "upgradeFrom3_0: some process data could not be migrated from "
                          "pre-4.0 process def directory '%s'. ",
                          oldProcessDefinitionDirectory.data());
        }
    }
}