//=====     MAIN ENTRY POINT     =====
int main()
{
	//Construct data link layer
	DataLinkLayer dll;

	//Construct 8 frames
	Frame input1(192,1);
	Frame input2(194,2);
	Frame input3(196,3);
	Frame input4(198,4);
	Frame input5(200,5);
	Frame input6(202,6);
	Frame input7(204,7);
	Frame input8(207,8);

	//Decode four frames and check list

//	dll.processFrame(input5);
//	dll.processFrame(input6);

//	char input;
//	while(1)
//	{
//	std::cin >> input;
//	if(input=='a')
//		dll.checkToken();
//	if(input=='b')
//		dll.processFrame(input2);
//	}
}
//---------------------------------------------------------------------------
int __stdcall validate(Block *aBlock)
{
	if((aBlock->input.size() == 0) && (aBlock->output.size() == 0))
	{
		BlockInput input1("input1");
		input1.allowedTypes.push_back("Bitmap1bit");
		input1.allowedTypes.push_back("Bitmap4bit");
		input1.allowedTypes.push_back("Bitmap8bit");
		input1.allowedTypes.push_back("Bitmap16bit");
		input1.allowedTypes.push_back("Bitmap24bit");
		input1.allowedTypes.push_back("Bitmap32bit");
		input1.setDescription("Domyœlne wejœcie");
		input1.setErrorCode(1);
		input1.setErrorDescription("Brak obiektu na wejœciu");
		aBlock->input.push_back(input1);

		BlockOutput output1("output1");
		output1.setOutputType("Bitmap24bit");
		output1.setDescription("Domyœlne wyjœcie");
		output1.setErrorCode(1);
		output1.setErrorDescription("Brak obiektu na wejœciu");
		aBlock->output.push_back(output1);

		return 2;
	}
	else
	{
		if(aBlock->input[0].getConnectedType().IsEmpty())
		{
			aBlock->input[0].setErrorCode(1);
			aBlock->input[0].setErrorDescription("Brak obiektu na wejœciu");
			aBlock->output[0].setErrorCode(1);
			aBlock->output[0].setErrorDescription("Brak obiektu na wejœciu");
			aBlock->output[0].setOutputType("Bitmap24bit");
			return 1;
		} 
		else
		{
			if (aBlock->output[0].getOutputType()!= aBlock->input[0].getConnectedType())
			{
				aBlock->output[0].setOutputType(aBlock->input[0].getConnectedType());
				aBlock->input[0].setErrorCode(0);
				aBlock->output[0].setErrorCode(0);
				aBlock->input[0].setErrorDescription("");
				aBlock->output[0].setErrorDescription("");
				return 1;
			}
			else if(aBlock->input[0].getErrorCode() != 0 || aBlock->output[0].getErrorCode() != 0)
			{
				aBlock->input[0].setErrorCode(0);
				aBlock->output[0].setErrorCode(0);
				aBlock->input[0].setErrorDescription("");
				aBlock->output[0].setErrorDescription("");
				return 1;
			}
			else 
				return 0;
		}
	}
}
bool xml_pcl_io::read_from_file(std::string filename, std::list<planner::polygon_with_normals>& clusters )
{
    TiXmlDocument doc(filename);
    bool loadOkay = doc.LoadFile();
    if (!loadOkay)
    {
        printf("Failed to load file \"%s\"\n", filename.c_str());
        return false;
    }

    pcl::StreamReader reader;
    int t = doc.Type();
    if (t!=TiXmlNode::TINYXML_DOCUMENT)
    {
        printf("Expected a document at the beginning of the file %s, found something else \n",filename.c_str());
        return false;
    }


    TiXmlNode* pcl_array=doc.FirstChild("augmented_pcl_list");
    if (pcl_array==NULL || pcl_array->Type()!=TiXmlNode::TINYXML_ELEMENT)
    {
        printf("Could not find element %s into file %s\n","augmented_pcl_list",filename.c_str());
        return false;
    }

    TiXmlNode* augmented_pcl;
    for ( augmented_pcl = pcl_array->FirstChild(); augmented_pcl != 0; augmented_pcl = augmented_pcl->NextSibling())
    {
        t=augmented_pcl->Type();
        if (t==TiXmlNode::TINYXML_ELEMENT && augmented_pcl->ValueStr()=="augmented_pcl")
        {
            planner::polygon_with_normals polygon;
            TiXmlNode* single_pcl=augmented_pcl->FirstChild("xyzrgbanormal");
            if (single_pcl==NULL)
                printf("found an %s element without a %s child, xml is malformed \n","augmented_pcl_list","augmented_pcl");
            std::string pointcloud=single_pcl->FirstChild()->ToText()->Value();
            pcl::PointCloud<pcl::PointXYZRGBNormal>::Ptr temp(new pcl::PointCloud<pcl::PointXYZRGBNormal>);
            std::istringstream input(pointcloud);
            reader.read(input,*temp);
            polygon.normals=temp;

            single_pcl=augmented_pcl->FirstChild("border");
            if (single_pcl==NULL)
                printf("found an %s element without a %s child, xml is malformed \n","augmented_pcl_list","border");
            pointcloud=single_pcl->FirstChild()->ToText()->Value();
            pcl::PointCloud<pcl::PointXYZ>::Ptr temp1(new pcl::PointCloud<pcl::PointXYZ>);
            std::istringstream input1(pointcloud);
            reader.read(input1,*temp1);
            polygon.border=temp1;
            clusters.push_back(polygon);
        }
        else
            printf("child of %s ignored since it is not an element, is the xml version different?\n","augmented_pcl_list");
    }
    return true;
}
Beispiel #4
0
static const char*
unbind_valued_parameterized_output_action ()
{
    automaton1 binder_instance;
    automaton1 output_instance;
    automaton1 input1_instance;
    automaton1 input2_instance;
    ioa::automaton_handle<automaton1> binder_handle (0);
    ioa::automaton_handle<automaton1> output_handle (1);
    ioa::automaton_handle<automaton1> input1_handle (2);
    ioa::automaton_handle<automaton1> input2_handle (3);

    int output_parameter = 123;
    int input_parameter = 345;

    ioa::action<automaton1, automaton1::p_v_output_action> output (output_handle, &automaton1::p_v_output, output_parameter, ioa::parameterized ());
    ioa::action<automaton1, automaton1::up_v_input_action> input1 (input1_handle, &automaton1::up_v_input);
    ioa::action<automaton1, automaton1::p_v_input_action> input2 (input2_handle, &automaton1::p_v_input, input_parameter, ioa::parameterized ());

    ioa::binding<automaton1::p_v_output_action> binding;
    int binding1;
    binding.bind (output_instance, output, input1_instance, input1, binder_handle, &binding1);
    int binding2;
    binding.bind (output_instance, output, input2_instance, input2, binder_handle, &binding2);

    binding.execute ();

    mu_assert (output_instance.p_v_output.state);
    mu_assert (output_instance.p_v_output.last_parameter == output_parameter);
    mu_assert (input1_instance.up_v_input.value == 9845);
    mu_assert (input2_instance.p_v_input.value == 9845);
    mu_assert (input2_instance.p_v_input.last_parameter == input_parameter);

    binding.unbind (binder_handle, &binding1);

    mu_assert (!binding.empty ());
    mu_assert (binding.involves_output (output));
    mu_assert (!binding.involves_binding (output, input1, binder_handle));
    mu_assert (binding.involves_binding (output, input2, binder_handle));
    mu_assert (!binding.involves_input (input1));
    mu_assert (binding.involves_input (input2));
    mu_assert (!binding.involves_input_automaton (input1_handle));
    mu_assert (binding.involves_input_automaton (input2_handle));

    binding.unbind (binder_handle, &binding2);

    mu_assert (binding.empty ());
    mu_assert (!binding.involves_output (output));
    mu_assert (!binding.involves_binding (output, input1, binder_handle));
    mu_assert (!binding.involves_binding (output, input2, binder_handle));
    mu_assert (!binding.involves_input (input1));
    mu_assert (!binding.involves_input (input2));
    mu_assert (!binding.involves_input_automaton (input1_handle));
    mu_assert (!binding.involves_input_automaton (input2_handle));

    return 0;
}
Beispiel #5
0
int ifuGetString(const char *mesg1, char *buffer1, const char *mesg2, char *buffer2,
     const char *mesg3, char *buffer3, const char *mesg4, char *buffer4)
  {
  int l = strlen(mesg1);
  if((int)strlen(mesg2)>l)
    {
    l = strlen(mesg2);
    }
  if((int)strlen(mesg3)>l)
    {
    l = strlen(mesg3);
    }
  if((int)strlen(mesg4)>l)
    {
    l = strlen(mesg4);
    }

  Fl_Window window(270+l*8,10+25+10+25+10+25+10+25+10+35);
  Fl_Input input1(10+l*8, 10, 250, 25, mesg1);
  input1.value(buffer1);
  Fl_Input input2(10+l*8, 10+25+10, 250, 25, mesg2);
  input2.value(buffer2);
  Fl_Input input3(10+l*8, 10+25+10+25+10, 250, 25, mesg3);
  input3.value(buffer3);
  Fl_Input input4(10+l*8, 10+25+10+25+10+25+10, 250, 25, mesg4);
  input4.value(buffer4);
  Fl_Button cancel(60, 10+25+10+25+10+25+10+25+10, 80, 25, "Cancel");
  Fl_Return_Button ok(150, 10+25+10+25+10+25+10+25+10, 80, 25, "OK");
  window.hotspot(&ok);
  window.end();
  window.set_modal();
  window.show();
  for (;;)
    {
    Fl::wait();
    Fl_Widget *o;
    while ((o = Fl::readqueue()))
      {
      if (o == &ok)
        {
        strcpy(buffer1,input1.value());
        strcpy(buffer2,input2.value());
        strcpy(buffer3,input3.value());
        strcpy(buffer4,input4.value());
        return 1;
        }
      else
        {
        if (o == &cancel || o == &window)
          {
          return 0;
          }
        }
      }
    }
  }
int __stdcall validate(Block *aBlock)
{
	if((aBlock->input.size() == 0) && (aBlock->output.size() == 0))
	{
		BlockInput input1("input1");
		input1.allowedTypes.push_back("Bitmap1bit");
		input1.allowedTypes.push_back("Bitmap4bit");
		input1.allowedTypes.push_back("Bitmap8bit");
		input1.allowedTypes.push_back("Bitmap16bit");
		input1.allowedTypes.push_back("Bitmap24bit");
		input1.allowedTypes.push_back("Bitmap32bit");
		input1.setDescription("Domyœlne wejœcie");
		input1.setErrorCode(1);
		input1.setErrorDescription("Brak obiektu na wejsciu");
		aBlock->input.push_back(input1);

		BlockOutput output1("output1");
		output1.setOutputType("Bitmap1bit");
		output1.setDescription("Domyœlne wyjœcie");
		output1.setErrorCode(1);
		output1.setErrorDescription("Brak obiektu na wejsciu");
		aBlock->output.push_back(output1);

	// wstepna konfiguracja (nastepna modyfikacja mozliwa w oknie konfigu bloczka)
		aBlock->getConfig()->addInt("limitB",0);
		aBlock->getConfig()->addInt("mode",0);
		return 2;
	}
	else
	{
		if(aBlock->input[0].getConnectedType().IsEmpty())
		{
			aBlock->input[0].setErrorCode(1);
			aBlock->input[0].setErrorDescription("Brak obiektu na wejsciu");
			aBlock->output[0].setErrorCode(1);
			aBlock->output[0].setErrorDescription("Brak obiektu na wejsciu");
			aBlock->output[0].setOutputType("Bitmap1bit");
			return 1;
		}
		else
		{
			if(aBlock->input[0].getErrorCode() != 0 || aBlock->output[0].getErrorCode() != 0)
			{
				aBlock->input[0].setErrorCode(0);
				aBlock->output[0].setErrorCode(0);
				aBlock->input[0].setErrorDescription("");
				aBlock->output[0].setErrorDescription("");
				return 1;
			}
			else 
				return 0;
		}
	}
}
Beispiel #7
0
 void ParameterOperator::execute(DataProvider& provider)
 {
     Id2DataPair input1(INPUT_1);
     Id2DataPair input2(INPUT_2);
     
     provider.receiveInputData(input1 && input2);
     
     // execute...
     
     Id2DataPair output1(OUTPUT_1, input1.data());
     Id2DataPair output2(OUTPUT_2, input2.data());
     provider.sendOutputData(output1 && output2);
 }
Beispiel #8
0
void RunPP(const char *jobid="test")
{
  Int_t nev=99999999;

  //TString input0("/star/u/russcher/gamma/analysis/data/pp05/ppProduction.root");
  TString input0("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_0.root");
  TString input1("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_1.root");
  TString input2("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_2.root");
  TString input3("/star/u/russcher/gamma/analysis/data/pp05/ppProduction_rcf_3.root");
  TString input4("/star/u/russcher/gamma/analysis/data/pp05/ppProductionMinBias.root");

  TString outdir("/star/u/russcher/gamma/analysis/output/pp05/");
  TString psout("pi0_pp05.ps");
  TString psout2("eta_pp05.ps");
  TString rootout("pi0_pp05.root");
  psout.Prepend(jobid);
  rootout.Prepend(jobid);
  TString command("mkdir ");
  command.Append(outdir.Data());
  command.Append(jobid);
  gSystem->Exec(command.Data());
  cout<<endl<<"storing results in: "<<command.Data()<<endl<<endl;
  outdir.Append(jobid);
  outdir.Append("/");

  psout.Prepend(outdir.Data());
  psout2.Prepend(outdir.Data());
  rootout.Prepend(outdir.Data());

  gSystem->Load("$HOME/MyEvent/MyEvent.so");
  gSystem->Load("$HOME/gamma/analysis/lib/AnaCuts.so");
  gSystem->Load("$HOME/gamma/analysis/lib/EventMixer.so");
  gSystem->Load("$HOME/gamma/analysis/lib/Pi0Analysis.so");
  

  Pi0Analysis *pi0=new Pi0Analysis(psout.Data(),psout2.Data(),"pp05");
  pi0->setMC(kFALSE);
  pi0->init(rootout.Data());
  
  pi0->make(nev,input0.Data());
  pi0->make(nev,input1.Data());
  pi0->make(nev,input2.Data());
  pi0->make(nev,input3.Data());
  pi0->printPrescales();
  cout<<"****** starting with minbias *********"<<endl;
  pi0->make(nev,input4.Data());
  pi0->printPrescales();

  pi0->getYield();
  pi0->finish();
}
Beispiel #9
0
void GeometryExporter::createLooseEdgeList(Object *ob,
                                           Mesh   *me,
                                           std::string& geom_id)
{

	MEdge *medges = me->medge;
	int totedges  = me->totedge;
	int edges_in_linelist = 0;
	std::vector<unsigned int> edge_list;
	int index;

	// Find all loose edges in Mesh 
	// and save vertex indices in edge_list
	for (index = 0; index < totedges; index++) 
	{
		MEdge *edge = &medges[index];

		if (edge->flag & ME_LOOSEEDGE)
		{
			edges_in_linelist += 1;
			edge_list.push_back(edge->v1);
			edge_list.push_back(edge->v2);
		}
	}

	if (edges_in_linelist > 0)
	{
		// Create the list of loose edges
		COLLADASW::Lines lines(mSW);

		lines.setCount(edges_in_linelist);


		COLLADASW::InputList &til = lines.getInputList();
			
		// creates <input> in <lines> for vertices 
		COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0);
		til.push_back(input1);

		lines.prepareToAppendValues();

		for (index = 0; index < edges_in_linelist; index++) 
		{
			lines.appendValues(edge_list[2 * index + 1]);
			lines.appendValues(edge_list[2 * index]);
		}
		lines.finish();
	}

}
	int CircuitObject::output_value() const
	{
		if(type() == "SWITCH")
			return _output_value;
		else if(type() == "NOT")
		{
			// Return the logical negation of the input
			if(input1()->output_value() == 0)
				return 1;
			else
				return 0;
		}
		else if(type() == "AND")
		{
			// Return 1 if all of the inputs are 1
			if(input1()->output_value() == 1 &&
			   input2()->output_value() == 1)
				return 1;
			else
				return 0;
		}
		else if(type() == "OR")
		{
			// Return 1 if any of the inputs are 1
			if(input1()->output_value() == 1 ||
			   input2()->output_value() == 1)
				return 1;
			else
				return 0;
		}
		else if(type() == "EXIT")
		{
			// Just return the input
			return input1()->output_value();
		}
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  Transform tests
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
TEST(simple1,counting)
{
    bolt::amp::counting_iterator<int> iter(0);
    bolt::amp::counting_iterator<int> iter2=iter+1024;
    std::vector<int> input1(1024);
    std::vector<int> input2(1024);
    std::vector<int> stdOutput(1024);
     std::vector<int> boltOutput(1024);
     for(int i=0 ; i< 1024;i++)
     {
         input1[i] = i;
     }
    input2 = input1;
    std::transform( input1.begin(), input1.end(), input2.begin(), stdOutput.begin(), bolt::amp::plus<int>());
    bolt::amp::transform(iter,iter2,input1.begin(),boltOutput.begin(),bolt::amp::plus<int>());
    cmpArrays( stdOutput, boltOutput, 1024 );
}
Beispiel #12
0
 void TestOperator::execute(DataProvider& provider)
 {
     if(m_throwException)
     {
         throw InternalError("Funny exception.");
     }
         
     Id2DataPair input1(INPUT_1);
     Id2DataPair input2(INPUT_2);
     
     provider.receiveInputData(input1 && input2);
     
      // execute...
     m_numExecutes++;
     boost::this_thread::sleep_for(boost::chrono::milliseconds(m_sleepTime));
     
     Id2DataPair output1(OUTPUT_1, input1.data());
     Id2DataPair output2(OUTPUT_2, input2.data());
     provider.sendOutputData(output1 && output2);
 }
TEST(simple1,Serial_counting)
{
    bolt::amp::counting_iterator<int> iter(0);
    bolt::amp::counting_iterator<int> iter2=iter+1024;
    std::vector<int> input1(1024);
    std::vector<int> input2(1024);
    std::vector<int> stdOutput(1024);
     std::vector<int> boltOutput(1024);
     for(int i=0 ; i< 1024;i++)
     {
         input1[i] = i;
     }
    input2 = input1;

    bolt::amp::control ctl = bolt::amp::control::getDefault( );
    ctl.setForceRunMode(bolt::amp::control::SerialCpu);

    std::transform( input1.begin(), input1.end(), input2.begin(), stdOutput.begin(), bolt::amp::plus<int>());
    bolt::amp::transform(ctl, iter,iter2,input1.begin(),boltOutput.begin(),bolt::amp::plus<int>());
    cmpArrays( stdOutput, boltOutput, 1024 );
}
/**
 * Tests that configuring inputs to be filtered succeeds.
 *
 * This test actually tests everything except that the actual FPGA
 * implementation works as intended.  We configure the FPGA and then query it to
 * make sure that the acutal configuration matches.
 */
TEST(DigitalGlitchFilterTest, BasicTest) {
  DigitalInput input1(1);
  DigitalInput input2(2);
  DigitalInput input3(3);
  DigitalInput input4(4);
  Encoder encoder5(5, 6);
  Counter counter7(7);

  // Check that we can make a single filter and set the period.
  DigitalGlitchFilter filter1;
  filter1.Add(&input1);
  filter1.SetPeriodNanoSeconds(4200);

  // Check that we can make a second filter with 2 inputs.
  DigitalGlitchFilter filter2;
  filter2.Add(&input2);
  filter2.Add(&input3);
  filter2.SetPeriodNanoSeconds(97100);

  // Check that we can make a third filter with an input, an encoder, and a
  // counter.
  DigitalGlitchFilter filter3;
  filter3.Add(&input4);
  filter3.Add(&encoder5);
  filter3.Add(&counter7);
  filter3.SetPeriodNanoSeconds(167800);

  // Verify that the period was properly set for all 3 filters.
  EXPECT_EQ(4200u, filter1.GetPeriodNanoSeconds());
  EXPECT_EQ(97100u, filter2.GetPeriodNanoSeconds());
  EXPECT_EQ(167800u, filter3.GetPeriodNanoSeconds());

  // Clean up.
  filter1.Remove(&input1);
  filter2.Remove(&input2);
  filter2.Remove(&input3);
  filter3.Remove(&input4);
  filter3.Remove(&encoder5);
  filter3.Remove(&counter7);
}
//---------------------------------------------------------------------------
int __stdcall validate(Block *aBlock)
{
	// brak wyjscia, jedno wejscie
	if(aBlock->input.size() == 0)
	{
		BlockInput input1("input1");
		input1.allowedTypes.push_back("Bitmap1bit");
		input1.allowedTypes.push_back("Bitmap4bit");
		input1.allowedTypes.push_back("Bitmap8bit");
		input1.allowedTypes.push_back("Bitmap16bit");
		input1.allowedTypes.push_back("Bitmap24bit");
		input1.allowedTypes.push_back("Bitmap32bit");
		input1.setDescription("Domyœlne wejœcie");
		input1.setErrorCode(1);
		input1.setErrorDescription("Brak obiektu na wejœciu");
		aBlock->input.push_back(input1);

		aBlock->getConfig()->addString("bitrate","Bitmap24bit");
		aBlock->getConfig()->addString("path","");
		return 2;
	}
	else
	{
		if(aBlock->input[0].getConnectedType().IsEmpty())
		{
			aBlock->input[0].setErrorCode(1);
			aBlock->input[0].setErrorDescription("Brak obiektu na wejœciu");
			return 1;
		}
		else if(aBlock->input[0].getErrorCode() != 0)
		{
			aBlock->input[0].setErrorCode(0);
			aBlock->input[0].setErrorDescription("");
			return 1;
		}
		else
			return 0;
	}
}
Beispiel #16
0
ScalarType opencl_convolve(std::vector<ScalarType>& in1,
                           std::vector<ScalarType>& in2,
                           unsigned int /*row*/, unsigned int /*col*/, unsigned int /*batch_size*/)
{
    //if(in1.size() > 2048) return -1;
    viennacl::vector<ScalarType> input1(in1.size());
    viennacl::vector<ScalarType> input2(in2.size());
    viennacl::vector<ScalarType> output(in1.size());

    viennacl::fast_copy(in1, input1);
    viennacl::fast_copy(in2, input2);

    viennacl::linalg::convolve(input1, input2, output);

    viennacl::backend::finish();
    std::vector<ScalarType> res(in1.size());
    viennacl::fast_copy(output, res);

    std::vector<ScalarType> ref(in1.size());
    convolve_ref(in1, in2, ref);

    return diff_max(res, ref);
}
TEST_F(ConstantFoldingTest, FoldVectorCrossProduct)
{
    const std::string &shaderString =
        "#version 300 es\n"
        "precision mediump float;\n"
        "out vec3 my_Vec3;"
        "void main() {\n"
        "   const vec3 v3 = cross(vec3(1.0f, 1.0f, 1.0f), vec3(1.0f, -1.0f, 1.0f));\n"
        "   my_Vec3 = v3;\n"
        "}\n";
    compile(shaderString);
    std::vector<float> input1(3, 1.0f);
    ASSERT_FALSE(constantVectorFoundInAST(input1));
    std::vector<float> input2;
    input2.push_back(1.0f);
    input2.push_back(-1.0f);
    input2.push_back(1.0f);
    ASSERT_FALSE(constantVectorFoundInAST(input2));
    std::vector<float> result;
    result.push_back(2.0f);
    result.push_back(0.0f);
    result.push_back(-2.0f);
    ASSERT_TRUE(constantVectorFoundInAST(result));
}
Beispiel #18
0
void mbfit(){

  gROOT->ProcessLine(".x /home/jholzbau/rootlogon.C");

  TString var = "setfit";

  TH1::SetDefaultSumw2();

  //Plan is to plot SET for CAFE and PMCS, Then with SET-MBSET for PMCS vs CAFE, Then with scaled MBSET (event by event depending on SET or MBSET value or something)


   //run3 files
  // TString rootfile1 = "/prj_root/7055/wmass2/jenny/pythia_zee_run2b3_default_tree_20130703_152033/pythia_zee_run2b3_default_tree_20130703_152033_20130703_152344_23/ZRootTree3.root"; 
   //   TString rootfile2 = "/prj_root/7055/wmass2/jenny/mbtreecafe2/WMASS_MC_RUN2B3_zee_ovl_12p8M_1372882719_default_tree2_20130703151839-15902467.d0cabsrv1.fnal.gov/ZRootTree2.root";
  //TString rootfile1 = "/prj_root/7055/wmass2/jenny/pythia_zee_run2b3_default_tree_20130703_152033/run3.root";
  //TString rootfile1 = "/prj_root/7055/wmass2/jenny/pythia_zee_run2b3_default_tree_vtxcut_redo_20130716_142720/result.root";


  //  TString rootfile1 = "/prj_root/7055/wmass2/jenny/pythia_zee_run2b3_default_tree_vtxcut_redo_20130726_085527/tree.root";
 TString rootfile1 = "/prj_root/7055/wmass2/jenny/pythia_zee_run2b3_mbtest_inclusiveweight_NEWmblib_pow04mbprob_TREE_20130726_085527/tree.root";
  TString rootfile2 = "/prj_root/7055/wmass2/jenny/mbtreecafe2/run3.root";


 Double_t xmin = 0;
 Double_t xmax = 300;
 Int_t nbin = 250;
 
 TH1D *tcafe = new TH1D("topcafe", "topcafe",  nbin, xmin, xmax);
 TH1D *tpmcs = new TH1D("toppmcs", "toppmcs",  nbin, xmin, xmax);
 TH1D *tpmcsd = new TH1D("toppmcsd", "toppmcsd",  nbin, xmin, xmax);
 TH1D *tpmcsmb = new TH1D("toppmcsmb", "toppmcsmb",  nbin, xmin, xmax);
 TH1D *tpmcsother = new TH1D("toppmcsother", "toppmcsother",  nbin, xmin, xmax);

 TH1D *tcafesum = new TH1D("topcafesum", "topcafesum",  nbin, xmin, xmax);
 TH1D *tpmcssum = new TH1D("toppmcssum", "toppmcssum",  nbin, xmin, xmax);
 TH1D *tpmcsmbsum = new TH1D("toppmcsmbsum", "toppmcsmbsum",  nbin, xmin, xmax);
 TH1D *tpmcsothersum = new TH1D("toppmcsothersum", "toppmcsothersum",  nbin, xmin, xmax);

 TH1D *t = new TH1D("top", "top",  nbin, xmin, xmax);
 TH1D *b = new TH1D("bottom", "bottom",  nbin, xmin, xmax);


 TH2D *mbandset = new TH2D("mbandset", "mbandset", nbin, xmin, xmax, nbin, xmin, xmax);
 TH2D *otherandset = new TH2D("otherandset", "otherandset", nbin, xmin, xmax, nbin, xmin, xmax);


 TH1D *cafemb = new TH1D("cafemb", "cafemb",  500, 0, 125);
 TH1D *pmcsmb = new TH1D("pmcsmb", "pmcsmb",  500, 0, 125);
 TH1D *ratio = new TH1D("ratio", "ratio",   500, 0, 125);

  //TH1D *t = new TH1D("top", "top",  100, 0, 150);
  //TH1D *b = new TH1D("bottom", "bottom",  100, 0, 150);
  
  TTree *tree1(0);
  TFile *input1(0);
  TTree *tree2(0);
  TFile *input2(0);
  

 if (!gSystem->AccessPathName( rootfile1 )) {
   cout << "accessing " << rootfile1 << endl;
   input1 = TFile::Open( rootfile1 );
 } 
 else{
   cout<< "problem accessing "<<rootfile1<< endl;
   exit(0);
 }

 tree1 = (TTree*)input1->Get(TreeName1);

 int nentries = tree1->GetEntries();
 cout<<nentries<<" in tree"<<endl;

if (!gSystem->AccessPathName( rootfile2 )) {
   cout << "accessing " << rootfile2 << endl;
   input2 = TFile::Open( rootfile2 );
 } 
 else{
   cout<< "problem accessing "<<rootfile2<< endl;
   exit(0);
 }

 tree2 = (TTree*)input2->Get(TreeName2);

 int nentries2 = tree2->GetEntries();
 cout<<nentries2<<" in tree"<<endl;

 // if(nentries > 1000000) nentries = 1000000;
 // if(nentries > 630000) nentries = 630000;
 // if(nentries2 > 630000) nentries2 = 630000;
 // if(nentries2 > 1000000) nentries2 = 1000000;
 
 float em_e[10];
 float em_pt[10];
float em_eta[10];
float em_phi[10];
float em_deteta[10];

 tree2->SetBranchAddress("em_pt", em_pt);
 tree2->SetBranchAddress("em_e", em_e);
 tree2->SetBranchAddress("em_eta", em_eta);
 tree2->SetBranchAddress("em_phi", em_phi);
 tree2->SetBranchAddress("em_deteta", em_deteta);


   
   // for (int j = 0; j < nentries2; j++){
   //   tree2->GetEntry(j);
   // tree2->GetLeaf("nelec")->GetValue(0) > 0 && 
   //   if((fabs(em_deteta[0]) < 1.1 ) && (fabs(em_deteta[1]) < 1.1 ) && tree2->GetLeaf("Ptz")->GetValue(0) < 3  && tree2->GetLeaf("Luminosity")->GetValue(0)  < 3){
   //     tcafe->Fill(tree2->GetLeaf("ScalarEt")->GetValue(0));
   //     tcafesum->Fill(tree2->GetLeaf("ScalarEt")->GetValue(0), tree2->GetLeaf("ScalarEt")->GetValue(0));
   //   }
   // }

 float em_e1[10];
 float em_pt1[10];
float em_eta1[10];
float em_phi1[10];
float em_deteta1[10];

 tree1->SetBranchAddress("em_pt", em_pt1);
 tree1->SetBranchAddress("em_e", em_e1);
 tree1->SetBranchAddress("em_eta", em_eta1);
 tree1->SetBranchAddress("em_phi", em_phi1);
 tree1->SetBranchAddress("em_deteta", em_deteta1);

 // cout<<"here"<<endl;
 // nentries = 100000;
 double pmcsmbz = 0;
 double pmcsset = 0;
 double test = 0;
 double test2 = 0;
 double test3 = 0;
 double wgt = 0;
 for (int i = 0; i < nentries; i++){

   //Need to do an iterative correction.  Start with scale, adjust mb.  then apply linear correction, refit. etc.  This way approximation that cafe and pmcs set is the same during subtraction is better

   //Should be able to do cafe-pmcs and use weight on mb to make mb account for difference in shape (neg weight issue? scale first?)

   tree1->GetEntry(i);
   if((fabs(em_deteta1[0]) < 1.1 ) && (fabs(em_deteta1[1]) < 1.1 ) && tree1->GetLeaf("Ptz")->GetValue(0) < 3 && tree1->GetLeaf("Luminosity")->GetValue(0) < 20){
   // cout<<i<<" of "<<nentries<<endl;
   //  cout<<tree1->GetLeaf("ScalarEt")->GetValue(0)<<"  "<<ratiotest->FindBin(tree1->GetLeaf("ScalarEt")->GetValue(0))<<endl;
   //  cout<<ratiotest->GetBinContent(ratiotest->FindBin(tree1->GetLeaf("ScalarEt")->GetValue(0)))<<endl;
     // cout<<ratiotest->GetBinContent(20)<<endl;
     pmcsmbz =  tree1->GetLeaf("MBScalarEt")->GetValue(0);
     wgt =1;
     // if(tree1->GetLeaf("MBScalarEt")->GetValue(0) < 5 ){
     //  if (tree1->GetLeaf("MBScalarEt")->GetValue(0) < 2.5 && tree1->GetLeaf("MBScalarEt")->GetValue(0) > 0.5) wgt = 2.5/tree1->GetLeaf("MBS//calarEt")->GetValue(0);
     // else wgt = tree1->GetLeaf("MBScalarEt")->GetValue(0)/5.0;
     // }
if (tree1->GetLeaf("MBScalarEt")->GetValue(0) > 0.5 && tree1->GetLeaf("MBScalarEt")->GetValue(0) < 5 ){
     wgt =  1.3;
 }
     /**
//fixes 30-50 GeV part of curve
if(tree1->GetLeaf("MBScalarEt")->GetValue(0) < 10 ){
wgt =0.5;
}
     **/

     //  wgt = 0;
     //}else if (tree1->GetLeaf("MBScalarEt")->GetValue(0) < 1 ){
     //  wgt = 1 + int(gRandom->Gaus(1,2));
       //  cout<<gRandom->Gaus(2.5,2)<<endl;
     // }


     // }else if  (tree1->GetLeaf("MBScalarEt")->GetValue(0) < 10 ){
     //   wgt = 2.0;
     // }

     // wgt = TMath::Power(pmcsmbz, 0.5/(10/(TMath::Sqrt(pmcsmbz)))) ;
     // wgt = TMath::Power(pmcsmbz, 0.5/(10/(TMath::Sqrt(pmcsmbz)))) + 0.2*pmcsmbz;// + pmcsmbz - 0.09*pmcsmbz*pmcsmbz;
     //  wgt = (TMath::Power(pmcsmbz, 0.5)* (0.5  * (1. + TMath::Erf((pmcsmbz-.5)/(TMath::Sqrt(2)*5))))) / ((1+TMath::Exp(-1*TMath::Power(pmcsmbz/2, 2.0))));
     //wgt = int( (TMath::Power(pmcsmbz, 0.4)) );
     // wgt = (TMath::Power(pmcsmbz, 0.70 - tree1->GetLeaf("Luminosity")->GetValue(0)/50));
   
       // if(tree1->GetLeaf("MBScalarEt")->GetValue(0) < 15){
       //	 wgt = wgt*2.0/tree1->GetLeaf("MBScalarEt")->GetValue(0);
       //}

     // / (0.5  * (1. + TMath::Erf((pmcsmbz-.5)/(TMath::Sqrt(2)*1.0))));
       
       // + (0.5  * (1. + TMath::Erf((pmcsmbz-.5)/(TMath::Sqrt(2)*5)))); //0.5 is good for upper region, 0.75 for middle
     //cout<<TMath::Power(pmcsmbz, 0.5/(10/(TMath::Sqrt(pmcsmbz))))<<"  "<<(0.01  * (1. + TMath::Erf((pmcsmbz-5)/(TMath::Sqrt(2)))))<<endl;
     //wgt = 0.582  * (1. + TMath::Erf((pmcsmbz-1.0935)/(TMath::Sqrt(2)*4.3111)));
     // wgt = wgt*(0.53  * (1. + TMath::Erf((pmcsmbz-0.288)/(TMath::Sqrt(2)*4.0453))));
     //  wgt = wgt*(0.489  * (1. + TMath::Erf((pmcsmbz+0.305)/(TMath::Sqrt(2)*4.89144))));
     /**
	//works ok-ish but doesn't work as weight (obviously...)
     pmcsmbz =  tree1->GetLeaf("MBScalarEt")->GetValue(0)*1.5;
     pmcsmbz = pmcsmbz*(0.544657  * (1. + TMath::Erf((pmcsmbz-0.6808)/(TMath::Sqrt(2)*3.18052))));
     pmcsmbz = pmcsmbz*(0.530694  * (1. + TMath::Erf((pmcsmbz-0.726896)/(TMath::Sqrt(2)*1.0429))));
     pmcsmbz = pmcsmbz*(0.480563  * (1. + TMath::Erf((pmcsmbz-0.321864)/(TMath::Sqrt(2)*0.536511))));
     **/

     //    pmcsmbz = pmcsmbz*(0.342784  * (1. + TMath::Erf((pmcsmbz-0.167683)/(TMath::Sqrt(2)*0.540161))));
     //pmcsmbz =   pmcsmbz*(0.9587 + 0.00365*pmcsmbz);
     //  pmcsmbz =   pmcsmbz*(0.903 + 0.007296*pmcsmbz + 0.00003*pmcsmbz*pmcsmbz - 0.00000119*pmcsmbz*pmcsmbz*pmcsmbz);//*ratiotest2->FindBin(tree1->GetLeaf("MBScalarEt")->GetValue(0));
     //  if (tree1->GetLeaf("ScalarEt")->GetValue(0) > 30) pmcsmbz =  tree1->GetLeaf("MBScalarEt")->GetValue(0)*1.0*(0.42 + 0.0071*tree1->GetLeaf("ScalarEt")->GetValue(0));//*ratiotest->GetBinContent(ratiotest->FindBin(tree1->GetLeaf("MBScalarEt")->GetValue(0)));//1.4;
     //cout<<pmcsmbz<<endl;
     //  pmcsmbz = pmcsmbz/(-0.00249 - (0.0003136*pmcsmbz) + (0.00121*pmcsmbz*pmcsmbz));
     //  if (pmcsmbz < 50) pmcsmbz = pmcsmbz/(-0.00005 - (0.00196*pmcsmbz) + (0.00132*pmcsmbz*pmcsmbz));
     //cout<<pmcsmbz<<" new "<<endl;
     //below way over corrects...  obviously not compensating for "other" correctly...
     // if (pmcsmbz > 0) pmcsmbz = pmcsmbz* ((0.5  * (1. + TMath::Erf((pmcsmbz-8.36)/(TMath::Sqrt(2)*4.9)))));
     // if (pmcsmbz > 0) pmcsmbz = TMath::Sqrt(pmcsmbz);// * (1/(0.5  * (1. + TMath::Erf((pmcsmbz-8.36)/(sqrt(2)*4.9)))));
     //  else pmcsmbz = 0;

     pmcsset = tree1->GetLeaf("ScalarEt")->GetValue(0) - tree1->GetLeaf("MBScalarEt")->GetValue(0) + pmcsmbz;

     tpmcs->Fill(pmcsset, wgt);//minus mb plus mb
     tpmcsd->Fill(pmcsset);
     tpmcsother->Fill(pmcsset -pmcsmbz, wgt);
     tpmcsmb->Fill(pmcsmbz, wgt);
     pmcsmb->Fill(pmcsmbz, wgt);

     tpmcssum->Fill(pmcsset, pmcsset);//minus mb plus mb
     tpmcsothersum->Fill(pmcsset, pmcsset -pmcsmbz);
     tpmcsmbsum->Fill(pmcsset, pmcsmbz);

     test += pmcsset;
     test2 += pmcsset -pmcsmbz;
     test3 += pmcsmbz;
     //cout<<pmcsset<<"  "<<pmcsset -pmcsmbz<<"  "<<pmcsmbz<<endl;
     b->Fill(pmcsset, pmcsmbz);
     t->Fill(pmcsset, pmcsmbz - pmcsset);

     mbandset->Fill(pmcsset, pmcsmbz, wgt);
     otherandset->Fill(pmcsset, pmcsset -pmcsmbz, wgt);
     //   tpmcs->Fill(pmcsmbz);
       //   tpmcs->Fill((pmcsset - pmcsmbz) + (pmcsmbz*(1.25 + 0.005*pmcsmbz- 0.0002*pmcsmbz*pmcsmbz)));

       // tpmcs->Fill((pmcsset - pmcsmbz)  + (pmcsmbz + (0.052 - 0.019*pmcsmbz+ 0.0018*pmcsmbz*pmcsmbz)));

       // tpmcs->Fill((pmcsset - pmcsmbz)  + (pmcsmbz * (0.052 - 0.019*pmcsmbz+ 0.0018*pmcsmbz*pmcsmbz)));

       // tpmcs->Fill((pmcsset - pmcsmbz)  + (1.6*pmcsmbz + (0.2 - 0.065*pmcsmbz+ 0.0023*pmcsmbz*pmcsmbz)));

       //uncomment top before using
       //  tpmcs->Fill((pmcsset - pmcsmbz)  + (pmcsmbz * (1.018 + 0.0319*pmcsmbz - 0.00228*pmcsmbz*pmcsmbz + 0.00008*pmcsmbz*pmcsmbz*pmcsmbz)));

   }
 }

 TH1D *tmp;
 int binz = 0;
 for (int j = 0; j < nentries2; j++){
   tree2->GetEntry(j);
   // tree2->GetLeaf("nelec")->GetValue(0) > 0 && 
   if((fabs(em_deteta[0]) < 1.1 ) && (fabs(em_deteta[1]) < 1.1 ) && tree2->GetLeaf("Ptz")->GetValue(0) < 3  && tree2->GetLeaf("Luminosity")->GetValue(0)  < 20){
     tcafe->Fill(tree2->GetLeaf("ScalarEt")->GetValue(0));
     tcafesum->Fill(tree2->GetLeaf("ScalarEt")->GetValue(0), tree2->GetLeaf("ScalarEt")->GetValue(0));

     binz = tpmcs->FindBin(tree2->GetLeaf("ScalarEt")->GetValue(0));
     tmp = otherandset->ProjectionY("test"+j, binz, binz, "");
     cafemb->Fill(tree2->GetLeaf("ScalarEt")->GetValue(0) - tmp->GetRandom());
   }
 }
 // for(int i = 0; i < nbin+1; i++){
 //   tmp = otherandset->ProjectionY("test"+i, i, i, "");
 //   cafemb->Fill(tcafe->GetXaxis()->GetBinCenter(i) - tmp->GetRandom());
 // }
 TCanvas *c5 = new TCanvas("c5","c5",800,800);
 cafemb->Draw();
 pmcsmb->Scale(cafemb->Integral()/pmcsmb->Integral());
 pmcsmb->SetLineColor(kBlue);
 pmcsmb->Draw("same");
 c5->Update();

 TCanvas *c4 = new TCanvas("c4","c4",800,800);
 tpmcsmbsum->Scale(tcafesum->Integral()/tpmcssum->Integral());//orget enertries?
 tpmcsothersum->Scale(tcafesum->Integral()/tpmcssum->Integral());
 tpmcssum->Scale(tcafesum->Integral()/tpmcssum->Integral());
 tpmcssum->Draw();
 tcafesum->SetMarkerColor(kRed);
 tcafesum->SetLineColor(kRed);
 tcafesum->Draw("same");
 
 tpmcsmbsum->SetLineColor(kBlue);
 tpmcsmbsum->Draw("same");
 tpmcsothersum->SetLineColor(kGreen);
 tpmcsothersum->Draw("same");

 c4->Update();
 c4->Print("PlotSETPTPMCS_RecoVarAfterFITSUM_"+var+".eps");
 c4->Print("PlotSETPTPMCS_RecoVarAfterFITSUM_"+var+".gif");


 TCanvas *c3 = new TCanvas("c3","c3",800,800);
  tpmcsmb->Scale(tcafe->Integral()/tpmcs->Integral());
  tpmcsother->Scale(tcafe->Integral()/tpmcs->Integral());
   tpmcs->Scale(tcafe->Integral()/tpmcs->Integral());
   tpmcsd->Scale(tcafe->Integral()/tpmcsd->Integral());
 tpmcs->Draw();

 tpmcsd->SetMarkerColor(kMagenta);
 tpmcsd->SetLineColor(kMagenta);
 tpmcsd->Draw("same");

 tcafe->SetMarkerColor(kRed);
 tcafe->SetLineColor(kRed);
 tcafe->Draw("same");
 
 tpmcsmb->SetLineColor(kBlue);
 tpmcsmb->Draw("same");
 tpmcsother->SetLineColor(kGreen);
 tpmcsother->Draw("same");

 cout<<test<<"  "<<test2<<"  "<<test3<<endl;
 cout<<tpmcs->Integral()<<"  "<<tpmcsmb->Integral()<<"  "<<tpmcsother->Integral()<<endl;

 c3->Update();
 c3->Print("PlotSETPTPMCS_RecoVarAfterFIT_"+var+".eps");
 c3->Print("PlotSETPTPMCS_RecoVarAfterFIT_"+var+".gif");

  TCanvas *c1 = new TCanvas("c1","c1",800,800);
  t->Scale(tcafe->Integral()/t->Integral());
 //Would have to randomly get a SET value from CAFe distribution (treat it like pdf) and subtract the setother from PMCS to get cafemb, event by event.
 // for(int i = 0; i < nbin+1; i++){
 //  t->SetBinContent(i, tcafe->GetXaxis()->GetBinCenter() - t->GetXaxis()->GetBinCenter()

  t->Add(tcafe);
   b->Scale(t->Integral()/b->Integral());
  b->Draw();
  t->SetMarkerColor(kRed);
  t->SetLineColor(kRed);
  t->Draw("same");

  c1->Update();
  c1->Print("PlotSETPTPMCS_MB_"+var+".eps");
  c1->Print("PlotSETPTPMCS_MB_"+var+".gif");

 TCanvas *c2 = new TCanvas("c2","c2",800,800);
 //for ratio want (cafe(set+mbset) - pmcs(set))/pmcsmb
 // ratio->Divide(t, b,1.0,1.0,"B");
  // ratio->Divide(tpmcs, tcafe,1.0,1.0,"B");
 ratio->Divide(cafemb, pmcsmb,1.0,1.0,"B");
 ratio->Draw();

 TF1 *func = new TF1("func",fitexp,0,125,3);
 // func->SetParameter(0, 0.0);
 // func->SetParameter(1, 30000);
 // func->SetParameter(2, 300000);
 // func->SetParameter(3, 0.1);

  func->SetParameter(0, 10.0);
   func->SetParameter(1, 10.0);
   func->SetParameter(2, 0.6);
   //  func->SetParameter(2, 0.0015);
   //  func->SetParameter(3, 0.0015);

 // func->FixParameter(0, 11);
 //  func->FixParameter(1, 40);
 // func->FixParameter(2, 250000);
 //func->FixParameter(3, 5);
 

// t->Fit("func", "+R");
// t->Draw();

   ratio->Fit("func", "+R");
   ratio->Draw();

 c2->Update();
 c2->Print("PlotSETPTPMCS_Ratio_"+var+".eps");
 c2->Print("PlotSETPTPMCS_Ratio_"+var+".gif");


 TCanvas *c6 = new TCanvas("c6","c6",800,800);
 mbandset->Draw("colz");

  c6->Update();
  c6->Print("PlotSETPTPMCS_MBandSET_"+var+".eps");
  c6->Print("PlotSETPTPMCS_MBandSET_"+var+".gif");



}
Beispiel #19
0
// powerful because it handles both cases when there is material and when there's not
void GeometryExporter::createPolylist(short material_index,
                                      bool has_uvs,
                                      bool has_color,
                                      Object *ob,
                                      Mesh *me,
                                      std::string& geom_id,
                                      std::vector<BCPolygonNormalsIndices>& norind)
{

	MPoly *mpolys = me->mpoly;
	MLoop *mloops = me->mloop;
	int totpolys  = me->totpoly;

	// <vcount>
	int i;
	int faces_in_polylist = 0;
	std::vector<unsigned long> vcount_list;

	// count faces with this material
	for (i = 0; i < totpolys; i++) {
		MPoly *p = &mpolys[i];
		
		if (p->mat_nr == material_index) {
			faces_in_polylist++;
			vcount_list.push_back(p->totloop);
		}
	}

	// no faces using this material
	if (faces_in_polylist == 0) {
		fprintf(stderr, "%s: material with index %d is not used.\n", id_name(ob).c_str(), material_index);
		return;
	}
		
	Material *ma = ob->totcol ? give_current_material(ob, material_index + 1) : NULL;
	COLLADASW::Polylist polylist(mSW);
		
	// sets count attribute in <polylist>
	polylist.setCount(faces_in_polylist);
		
	// sets material name
	if (ma) {
		std::string material_id = get_material_id(ma);
		std::ostringstream ostr;
		ostr << translate_id(material_id);
		polylist.setMaterial(ostr.str());
	}
			
	COLLADASW::InputList &til = polylist.getInputList();
		
	// creates <input> in <polylist> for vertices 
	COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0);
		
	// creates <input> in <polylist> for normals
	COLLADASW::Input input2(COLLADASW::InputSemantic::NORMAL, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL), 1);
		
	til.push_back(input1);
	til.push_back(input2);
		
	// if mesh has uv coords writes <input> for TEXCOORD
	int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
	int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE)-1;
	for (i = 0; i < num_layers; i++) {
		if (!this->export_settings->active_uv_only || i == active_uv_index) {

			// char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i);
			COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD,
									makeUrl(makeTexcoordSourceId(geom_id, i, this->export_settings->active_uv_only)),
									2, // this is only until we have optimized UV sets
									(this->export_settings->active_uv_only) ? 0 : i  // only_active_uv exported -> we have only one set
									);
			til.push_back(input3);
		}
	}

	int totlayer_mcol = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL);
	if (totlayer_mcol > 0) {
		int map_index = 0;

		for (int a = 0; a < totlayer_mcol; a++) {
			char *layer_name = bc_CustomData_get_layer_name(&me->ldata, CD_MLOOPCOL, a);
			COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR,
			                        makeUrl(makeVertexColorSourceId(geom_id, layer_name)),
			                        (has_uvs) ? 3 : 2,  // all color layers have same index order
			                        map_index           // set number equals color map index
			                        );
			til.push_back(input4);
			map_index++;
		}
	}
		
	// sets <vcount>
	polylist.setVCountList(vcount_list);
		
	// performs the actual writing
	polylist.prepareToAppendValues();
	
	// <p>
	int texindex = 0;
	for (i = 0; i < totpolys; i++) {
		MPoly *p = &mpolys[i];
		int loop_count = p->totloop;

		if (p->mat_nr == material_index) {
			MLoop *l = &mloops[p->loopstart];
			BCPolygonNormalsIndices normal_indices = norind[i];

			for (int j = 0; j < loop_count; j++) {
				polylist.appendValues(l[j].v);
				polylist.appendValues(normal_indices[j]);
				if (has_uvs)
					polylist.appendValues(texindex + j);

				if (has_color)
					polylist.appendValues(texindex + j);
			}
		}

		texindex += loop_count;
	}
		
	polylist.finish();
}
void EfficiencyTreePlotLum(){

  //should be tree output from wmass program, maybe this would work better?
  //cafe wmass_analysis/config/cafe_runIIb.config.runIIb Input: ../WMASSskimRUN2B_3and4_caftrees_2EM___from_EMinclusive_PASS5_fix_84_of_84.root

  TString rootfile = "/prj_root/5007/wz2_write/jenny/NewEff_lumi_tree/neweff_pass56_lumitree.root";

   TH1::SetDefaultSumw2();
   TCanvas *c1 = new TCanvas("c1","c1",800,800);
  //.x /home/jholzbau/rootlogon.C
  // TH1::SetDefaultSumw2();
  // TH1::Sumw2();
 Int_t nentries = 999;
 TTree *tree(0);
 TFile *input1(0);

 if (!gSystem->AccessPathName( rootfile )) {
   cout << "accessing " << rootfile << endl;
   input1 = TFile::Open( rootfile );
 } 
 else{
   cout<< "problem accessing "<<rootfile<< endl;
   exit(0);
 }

 tree = (TTree*)input1->Get(TreeName);
 nentries = tree->GetEntries();
 cout<<nentries<<" in tree"<<endl;
 /**`
  Int_t run;  				
  Int_t evt;  				
  Int_t triglist;
  Float_t lumi;			 
  Float_t mee;			  
  Float_t probe_pt;  			  
  Int_t probe_chg;  			  
  Float_t probe_eta;  
  Int_t probe_trackmatch25;
  Int_t probe_trackmatch27;
  Float_t tag_pt;  			  
  Int_t tag_chg;  			  
  Float_t tag_eta;  
  Int_t tag_trackmatch25;
  Int_t tag_trackmatch27;
  Int_t pass_27;
  Int_t pass_25;
**/
 TH1F *htp225 = new TH1F("Pt_EM_Probe_Trig_v16_25","Pt_EM_Probe_Trig_v16_25", 100, 0, 12);
 TH1F *htp227 = new TH1F("Pt_EM_Probe_Trig_v16_25","Pt_EM_Probe_Trig_v16_27_7", 100, 0, 12);
 TH1F *htp227c = new TH1F("Pt_EM_Probe_Trig_v16_25","Pt_EM_Probe_Trig_v16_27", 100, 0, 12);

 TH1F *hp225 = new TH1F("Pt_EM_Probe_Trig_TT_v16_25","Pt_EM_Probe_Trig_TT_v16_25", 100, 0, 12);
 TH1F *hp227 = new TH1F("Pt_EM_Probe_Trig_TT_v16_25","Pt_EM_Probe_Trig_TT_v16_27_7", 100, 0, 12);
 TH1F *hp227c = new TH1F("Pt_EM_Probe_Trig_TT_v16_25","Pt_EM_Probe_Trig_TT_v16_27", 100, 0, 12);

 for (int i = 0; i < nentries; i++){
   tree->GetEntry(i);
   if(tree->GetLeaf("lumi")->GetValue(0) >= 0 && tree->GetLeaf("lumi")->GetValue(0) < 12){
     //   bkgdvar.push_back((float)tree->GetLeaf(var)->GetValue(0));
     if(tree->GetLeaf("pass_25")->GetValue(0) == 1 && tree->GetLeaf("triglist")->GetValue(0) == 6 && tree->GetLeaf("tag_trackmatch25")->GetValue(0) == 1){
       htp225->Fill((float)tree->GetLeaf("lumi")->GetValue(0));
       if(tree->GetLeaf("probe_trackmatch25")->GetValue(0) == 1){
	 hp225->Fill((float)tree->GetLeaf("lumi")->GetValue(0));
       }
     }
     
     if(tree->GetLeaf("pass_27")->GetValue(0) == 1 && tree->GetLeaf("triglist")->GetValue(0) == 7 && tree->GetLeaf("tag_trackmatch27")->GetValue(0) == 1){
       htp227->Fill((float)tree->GetLeaf("lumi")->GetValue(0));
       if(tree->GetLeaf("probe_trackmatch27")->GetValue(0) == 1){
	 hp227->Fill((float)tree->GetLeaf("lumi")->GetValue(0));
       }
     }
     if(tree->GetLeaf("pass_27")->GetValue(0) == 1 && tree->GetLeaf("triglist")->GetValue(0) == 6 && tree->GetLeaf("tag_trackmatch27")->GetValue(0) == 1){
       htp227c->Fill((float)tree->GetLeaf("lumi")->GetValue(0));
       if(tree->GetLeaf("probe_trackmatch27")->GetValue(0) == 1){
	 hp227c->Fill((float)tree->GetLeaf("lumi")->GetValue(0));
       }
     }
   }else{
     cout<<tree->GetLeaf("lumi")->GetValue(0)<<endl;
   }

 }
 //   examples: if h1 is an existing TH1F histogram with 100 bins
 //     Double_t xbins[25] = {...} array of low-edges (xbins[25] is the upper edge of last bin
 //     h1->Rebin(24,"hnew",xbins);  //creates a new variable bin size histogram hnew

 //because weights are re-set during bin merger, the uncertainties are wrong for this way of merging bins!!!
						    //by refilling histo with (bin center, old bin content)
 
 Double_t xbins[8] = {0,2,4,5,6,7,8,12};
 //Double_t xbins[3] = {0,7,12};
 TH1F *hp25 =  (TH1F*) hp225->Rebin(7, "hp25", xbins);
 TH1F *hp27 =  (TH1F*) hp227->Rebin(7, "hp27", xbins);
 TH1F *hp27c =  (TH1F*) hp227c->Rebin(7, "hp27c", xbins);

 TH1F *htp25 =  (TH1F*) htp225->Rebin(7, "htp25", xbins);
 TH1F *htp27 =  (TH1F*) htp227->Rebin(7, "htp27", xbins);
 TH1F *htp27c =  (TH1F*) htp227c->Rebin(7, "htp27c", xbins);


  hp225 = hp25;
  hp227 = hp27;
  hp227c = hp27c;
  
  htp225 = htp25;
  htp227 = htp27;
  htp227c = htp27c;
 

  //h_efficiency = h_after_selection
  //h_efficiency.Divide(h_after_selection,h_before_selection,1.0,1.0,"B")
  
  // hp225->Divide(htp225);
  // hp227->Divide(htp227);
  //hp227c->Divide(htp227c);

  hp225->Divide(hp225, htp225,1.0,1.0,"B");

  hp227->Divide(hp227, htp227,1.0,1.0,"B");
  hp227c->Divide(hp227c, htp227c,1.0,1.0,"B");

 hp225->SetMarkerSize(1);
 hp227->SetMarkerSize(1);
 hp227c->SetMarkerSize(1);
 hp225->SetMarkerStyle(20);
 hp227->SetMarkerStyle(20);
 hp227c->SetMarkerStyle(20);
 hp225->SetMarkerColor(kBlack);
 hp227->SetMarkerColor(kRed);
 hp227c->SetMarkerColor(kGreen);


 hp227->SetLineColor(kRed);
 hp227c->SetLineColor(kGreen);

TLegend *legend = new TLegend(0.40,0.3,0.75,0.5);
 legend->SetBorderSize(0);
  legend->SetFillColor(0);
legend->AddEntry(hp225,"25GeV, triglist6", "lp");
legend->AddEntry(hp227c,"27GeV, triglist6", "lp");
legend->AddEntry(hp227,"27GeV, triglist7", "lp");


  hp225->Draw("pe");
  hp227->Draw("SAME pe");
  hp227c->Draw("SAME pe");
  legend->Draw("SAME");
  
  //xmin, xmax, numpar  range only used if R option specified in fit
  TF1 *func = new TF1("func",fitf,0,7,2);
  TF1 *func2 = new TF1("func2",fitf,0,100, 2);
 TF1 *func3 = new TF1("func3",fitf,0,7,2);

  func->SetLineColor(kBlack);

  //# Turn-on curve parameterization: 0.5 * eff_p2 * (1. + TMath::Erf((pT-eff_p0)/(sqrt(2)*eff_p1)))*(1. + TMath::Erf((pT-eff_p4)/(sqrt(2)*eff_p3)))
  //# below are Hengne's new trigger eff parameters
  //TrigEff_P0:   23.61, 20.74, 23.74, 24.91, 24.4146, 24.5361, 26.5549
  //TrigEff_P1:   2.208, 0.5023, 1.266, 1.61, 0.974658, 0.784704, 0.975321
  //TrigEff_P2:   2.273, 0.4874, 1.261, 2.306, 0.4981099, 0.496889, 0.492516
  //TrigEff_P3:   1795, 23.65, 635.7, 970.5, 14.6902, 21.647, 13.0815
  //TrigEff_P4:   1455, -7.366, 222, 821.8, -2.12041, -15.0317, 9.483 

  func->SetParameter(0, 1);
  func->SetParameter(1, 0);

  func2->SetParameter(0, 1);
  func2->SetParameter(1, 0);

  func3->SetParameter(0, 1);
  func3->SetParameter(1, 0);

  // func->SetParameters(500,hp225->GetMean(),hp225->GetRMS());
  //func->SetParNames("Constant","Mean_value","Sigma");
  hp225->Fit("func", "+");

c1->Print("PlotLumiEff25_lumi012.eps");
c1->Print("PlotLumiEff25_lumi012.gif");

  func2->SetLineColor(kRed);
 hp227->Fit("func2", "+");


c1->Print("PlotLumiEff27_lumi012.eps");
c1->Print("PlotLumiEff27_lumi012.gif");

  func3->SetLineColor(kGreen);
 hp227c->Fit("func3", "+");

  // hp225->Fit("pol2");
  
//c1->Update();
gPad->Update();
c1->Update();
c1->Print("PlotLumiEff27c_lumi012.eps");
c1->Print("PlotLumiEff27c_lumi012.gif");

  hp225->Draw("pe");
  hp227->Draw("SAME pe");
  hp227c->Draw("SAME pe");
  legend->Draw("SAME");

c1->Print("PlotLumiEffAll_lumi012.eps");
c1->Print("PlotLumiEffAll_lumi012.gif");

// htp227->Draw();
//gPad->Update();
//c1->Update();

  //  c1->Print("PlotEff_2b34.eps");
  //  c1->Print("PlotEff_2b34.gif");

  //c1->Print("PlotEffPt_2b34.eps");
  // c1->Print("PlotEffPt_2b34.gif");
  // c1->Print("PlotEffLumi_2b4.eps");
  // c1->Print("PlotEffLumi_2b4.gif");

  
// input1->Close();
}
Beispiel #21
0
int main( int argc, char** argv)
{
    if( argc != 3)
    {
        std::cerr << "Usage: "<<argv[0]<<" [file1.nc file2.nc]\n";
        return -1;
    }
    std::cout << "Compare "<<argv[1]<<" with "<<argv[2]<<"\n";
    //////////////////////////////open nc files//////////////////////////////////
    file::NC_Error_Handle err;
    int ncid1, ncid2;
    err = nc_open( argv[1], NC_NOWRITE, &ncid1);
    err = nc_open( argv[2], NC_NOWRITE, &ncid2);
    
    int dimIDs1[3], dimIDs2[3], timeID1, timeID2;
    int numDims1=3, numDims2=3;

    err = nc_inq_dimid( ncid1, "time", &timeID1);
    err = nc_inq_dimid( ncid2, "time", &timeID2);
    err = nc_inq_dimid( ncid1, "x", &dimIDs1[0]);
    err = nc_inq_dimid( ncid2, "x", &dimIDs2[0]);
    err = nc_inq_dimid( ncid1, "y", &dimIDs1[1]);
    err = nc_inq_dimid( ncid2, "y", &dimIDs2[1]);
    try{ err = nc_inq_dimid( ncid1, "z", &dimIDs1[2]);}
    catch( file::NC_Error) { numDims1=2; }
    try{ err = nc_inq_dimid( ncid2, "z", &dimIDs2[2]);}
    catch( file::NC_Error) { numDims2=2; }
    if( numDims1 != numDims2)
    {
        std::cerr << "Files not of same dimensionality!!\n";
        return -1;
    }
    size_t length1[numDims1+1], length2[numDims2+1];
    err = nc_inq_dimlen(ncid1, timeID1, &length1[numDims1]);
    err = nc_inq_dimlen(ncid2, timeID2, &length2[numDims2]);
    for(int i=0; i<numDims1; i++)
    {
        err = nc_inq_dimlen(ncid1, dimIDs1[i], &length1[i]);
        err = nc_inq_dimlen(ncid2, dimIDs2[i], &length2[i]);
    }
    for( int i=0; i<numDims1+1; i++)
    {
        std::cout << "Dimension "<<i<<" has "<<length1[i]<<" points!\n";
        if( length1[i] != length2[i])
        {
            std::cerr << "Dimension lengths not equal!! "<<length1[i]<<" "<<length2[i]<<"\n";
            return -1;
        }
    }
    int dataID1, dataID2;
    try{
        err = nc_inq_varid(ncid1, "electrons", &dataID1);
        err = nc_inq_varid(ncid2, "electrons", &dataID2);
    }
    catch( file::NC_Error)
    {
        try{
            err = nc_inq_varid(ncid1, "T", &dataID1);
            err = nc_inq_varid(ncid2, "T", &dataID2);
        }
        catch( file::NC_Error)
        {
            std::cerr <<"Neither electrons nor T found!\n";
            return -1;
        }
    }
    size_t start[numDims1+1], count[numDims1+1], size=1;
    for( int i=0; i<numDims1; i++) {
        start[numDims1-i] = 0;
        count[numDims1-i] = length1[i];
        size*=length1[i];
    }
    start[0] = 0, count[0] = 1;
    thrust::host_vector<double> input1( size), input2(input1);
    for( size_t i=0; i<length1[numDims1]; i++)
    {
        start[0] = i;
        err = nc_get_vara_double( ncid1, dataID1, start, count, input1.data());
        err = nc_get_vara_double( ncid2, dataID2, start, count, input2.data());
        dg::blas1::axpby( 1., input1, -1., input2, input2);
        double norm = dg::blas1::dot( input1, input1);
        double diff = dg::blas1::dot( input2, input2);
        //double norm2 = *thrust::max_element( input2.begin(), input2.end());
        std::cout << "Abs. and rel. difference at timestep \t"<<i<<"\t"<<sqrt(diff)<<"\t"<<sqrt(diff/norm)<<"\n";
    }
    err = nc_close(ncid1);
    err = nc_close(ncid2);

    return 0;
}
// powerful because it handles both cases when there is material and when there's not
void GeometryExporter::createPolylist(short material_index,
					bool has_uvs,
					bool has_color,
					Object *ob,
					std::string& geom_id,
					std::vector<Face>& norind)
{
	Mesh *me = (Mesh*)ob->data;
	MFace *mfaces = me->mface;
	int totfaces = me->totface;

	// <vcount>
	int i;
	int faces_in_polylist = 0;
	std::vector<unsigned long> vcount_list;

	// count faces with this material
	for (i = 0; i < totfaces; i++) {
		MFace *f = &mfaces[i];
		
		if (f->mat_nr == material_index) {
			faces_in_polylist++;
			if (f->v4 == 0) {
				vcount_list.push_back(3);
			}
			else {
				vcount_list.push_back(4);
			}
		}
	}

	// no faces using this material
	if (faces_in_polylist == 0) {
		fprintf(stderr, "%s: no faces use material %d\n", id_name(ob).c_str(), material_index);
		return;
	}
		
	Material *ma = ob->totcol ? give_current_material(ob, material_index + 1) : NULL;
	COLLADASW::Polylist polylist(mSW);
		
	// sets count attribute in <polylist>
	polylist.setCount(faces_in_polylist);
		
	// sets material name
	if (ma) {
		std::ostringstream ostr;
		ostr << translate_id(id_name(ma)) << material_index+1;
		polylist.setMaterial(ostr.str());
	}
			
	COLLADASW::InputList &til = polylist.getInputList();
		
	// creates <input> in <polylist> for vertices 
	COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0);
		
	// creates <input> in <polylist> for normals
	COLLADASW::Input input2(COLLADASW::InputSemantic::NORMAL, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL), 1);
		
	til.push_back(input1);
	til.push_back(input2);
		
	// if mesh has uv coords writes <input> for TEXCOORD
	int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE);

	for (i = 0; i < num_layers; i++) {
		// char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i);
		COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD,
								makeUrl(makeTexcoordSourceId(geom_id, i)),
								2, // offset always 2, this is only until we have optimized UV sets
								i  // set number equals UV map index
								);
		til.push_back(input3);
	}

	if (has_color) {
		COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::COLOR), has_uvs ? 3 : 2);
		til.push_back(input4);
	}
		
	// sets <vcount>
	polylist.setVCountList(vcount_list);
		
	// performs the actual writing
	polylist.prepareToAppendValues();
		
	// <p>
	int texindex = 0;
	for (i = 0; i < totfaces; i++) {
		MFace *f = &mfaces[i];

		if (f->mat_nr == material_index) {

			unsigned int *v = &f->v1;
			unsigned int *n = &norind[i].v1;
			for (int j = 0; j < (f->v4 == 0 ? 3 : 4); j++) {
				polylist.appendValues(v[j]);
				polylist.appendValues(n[j]);

				if (has_uvs)
					polylist.appendValues(texindex + j);

				if (has_color)
					polylist.appendValues(texindex + j);
			}
		}

		texindex += 3;
		if (f->v4 != 0)
			texindex++;
	}
		
	polylist.finish();
}
void ExtractZakC64::execute() {
    int i, j;
    unsigned short signature;
    char fname[256];

    // Two disks...
    Common::Filename inpath1(_inputPaths[0].path);
    Common::Filename inpath2(_inputPaths[1].path);
    Common::Filename &outpath = _outputPath;

    if (outpath.empty())
        // Standard output path
        outpath.setFullPath("out/");

    Common::File input1(inpath1, "rb");
    Common::File input2(inpath2, "rb");

    /* check signature */
    signature = input1.readUint16LE();
    if (signature != 0x0A31)
        error("Signature not found in disk 1!");
    signature = input2.readUint16LE();
    if (signature != 0x0132)
        error("Signature not found in disk 2!");

    outpath.setFullName("00.LFL");
    Common::File output(outpath, "wb");
    output.setXorMode(0xFF);
    print("Creating 00.LFL...");

    /* write signature */
    output.writeUint16LE(signature);

    /* copy object flags */
    for (i = 0; i < 775; i++)
        output.writeByte(input1.readByte());

    /* copy room offsets */
    for (i = 0; i < NUM_ROOMS; i++) {
        room_disks_c64[i] = input1.readByte();
        output.writeByte(room_disks_c64[i]);
    }
    for (i = 0; i < NUM_ROOMS; i++) {
        room_sectors_c64[i] = input1.readByte();
        output.writeByte(room_sectors_c64[i]);
        room_tracks_c64[i] = input1.readByte();
        output.writeByte(room_tracks_c64[i]);
    }

    /* copy costume offsets */
    for (i = 0; i < 38; i++)
        output.writeByte(input1.readByte());
    for (i = 0; i < 38; i++)
        output.writeUint16LE(input1.readUint16LE());

    /* copy script offsets */
    for (i = 0; i < 155; i++)
        output.writeByte(input1.readByte());
    for (i = 0; i < 155; i++)
        output.writeUint16LE(input1.readUint16LE());

    /* copy sound offsets */
    for (i = 0; i < 127; i++)
        output.writeByte(input1.readByte());
    for (i = 0; i < 127; i++)
        output.writeUint16LE(input1.readUint16LE());

    output.close();

    for (i = 0; i < NUM_ROOMS; i++) {
        Common::File *input;

        if (room_disks_c64[i] == '1')
            input = &input1;
        else if (room_disks_c64[i] == '2')
            input = &input2;
        else
            continue;

        sprintf(fname, "%02i.LFL", i);
        outpath.setFullName(fname);
        output.open(outpath, "wb");

        print("Creating %s...", fname);
        input->seek((SectorOffset[room_tracks_c64[i]] + room_sectors_c64[i]) * 256, SEEK_SET);

        for (j = 0; j < ResourcesPerFile[i]; j++) {
            unsigned short len;

            do {
                len = input->readUint16LE();
                output.writeUint16LE(len);
            } while (len == 0xffff);

            for (len -= 2; len > 0; len--) {
                output.writeByte(input->readByte());
            }
        }

        input->rewind();
    }

    print("All done!");
}
void ExtractMMApple::execute() {
	int i, j;
	unsigned short signature;
	char fname[256];

	Common::Filename inpath1(_inputPaths[0].path);
	Common::Filename inpath2(_inputPaths[1].path);
	Common::Filename &outpath = _outputPath;

	if (outpath.empty())
		// Standard output path
		outpath.setFullPath("out/");

	Common::File input1(inpath1, "rb");
	Common::File input2(inpath2, "rb");

	input1.seek(142080, SEEK_SET);
	input2.seek(143104, SEEK_SET);

	/* check signature */
	signature = input1.readUint16LE();
	if (signature != 0x0A31)
		error("Signature not found in disk 1!");

	signature = input2.readUint16LE();
	if (signature != 0x0032)
		error("Signature not found in disk 2!");

	outpath.setFullName("00.LFL");
	Common::File output(outpath, "wb");
	// All output should be xored
	output.setXorMode(0xFF);
	print("Creating 00.LFL...\n");

	/* write signature */
	output.writeUint16LE(signature);

	/* copy object flags */
	for (i = 0; i < 256; i++)
		output.writeByte(input1.readByte());

	/* copy room offsets */
	for (i = 0; i < NUM_ROOMS; i++) {
		room_disks_apple[i] = input1.readByte();
		output.writeByte(room_disks_apple[i]);
	}
	for (i = 0; i < NUM_ROOMS; i++) {
		room_sectors_apple[i] = input1.readByte();
		output.writeByte(room_sectors_apple[i]);
		room_tracks_apple[i] = input1.readByte();
		output.writeByte(room_tracks_apple[i]);
	}

	/* copy costume offsets */
	for (i = 0; i < 25; i++)
		output.writeByte(input1.readByte());
	for (i = 0; i < 25; i++)
		output.writeUint16LE(input1.readUint16LE());

	/* copy script offsets */
	for (i = 0; i < 160; i++)
		output.writeByte(input1.readByte());
	for (i = 0; i < 160; i++)
		output.writeUint16LE(input1.readUint16LE());

	/* copy sound offsets */
	for (i = 0; i < 70; i++)
		output.writeByte(input1.readByte());
	for (i = 0; i < 70; i++)
		output.writeUint16LE(input1.readUint16LE());

	/* NOTE: Extra 92 bytes of unknown data */

	for (i = 0; i < NUM_ROOMS; i++) {
		Common::File *input;

		if (room_disks_apple[i] == '1')
			input = &input1;
		else if (room_disks_apple[i] == '2')
			input = &input2;
		else
			continue;

		sprintf(fname, "%02i.LFL", i);
		outpath.setFullName(fname);
		output.open(outpath, "wb");

		print("Creating %s...\n", fname);
		input->seek((SectorOffset[room_tracks_apple[i]] + room_sectors_apple[i]) * 256, SEEK_SET);

		for (j = 0; j < ResourcesPerFile[i]; j++) {
			unsigned short len = input->readUint16LE();
			output.writeUint16LE(len);

			for (len -= 2; len > 0; len--)
				output.writeByte(input->readByte());
		}
		input->rewind();
	}
	print("All done!");
}
Intervall parseTermOfIntervals(string input){
    string::iterator it;
    int brackets = 0;
    int closedBrackets = 0;
    if(input=="")
        return 0;
    for(it=input.end();it>=input.begin();it--){
        if(*it=='(')
            brackets++;
        if(*it==')')
            brackets--;
        if(*it=='[')
            closedBrackets++;
        if(*it==']')
            closedBrackets--;
        if(*it=='|' && brackets==0 && closedBrackets==0){
            if(it==input.begin()){
                //Bin‰rem Operator fehlt Operand
                errorWindow("Operand missing!");
                return Intervall(NAN);
            }
            if(it+1==input.end()){
                //Bin‰rem Operator fehlt Operand
                errorWindow("Operand missing!");
                return Intervall(NAN);
            }
            string input1(input.begin(),it);
            string input2(it+1,input.end());
            Intervall result = parseTermOfIntervals(input1)||parseTermOfIntervals(input2);
            if(result.getInf()!=result.getInf()){
                errorWindow("Vereinigung disjunkter Intervalle!");
            }
            return result;
        }
    }
    for(it=input.end();it>=input.begin();it--){
        if(*it=='(')
            brackets++;
        if(*it==')')
            brackets--;
        if(*it=='[')
            closedBrackets++;
        if(*it==']')
            closedBrackets--;
        if(*it=='&' && brackets==0 && closedBrackets==0){
            if(it==input.begin()){
                //Bin‰rem Operator fehlt Operand
                errorWindow("Operand missing!");
                return Intervall(NAN);
            }
            if(it+1==input.end()){
                //Bin‰rem Operator fehlt Operand
                errorWindow("Operand missing!");
                return Intervall(NAN);
            }
            string input1(input.begin(),it);
            string input2(it+1,input.end());
            Intervall result = parseTermOfIntervals(input1)&&parseTermOfIntervals(input2);
            if(result.getInf()!=result.getInf()){
                errorWindow("Schnitt disjunkter Intervalle!");
            }
            return result;
        }
    }
    for(it=input.end();it>=input.begin();it--){
        if(*it=='(')
            brackets++;
        if(*it==')')
            brackets--;
        if(*it=='[')
            closedBrackets++;
        if(*it==']')
            closedBrackets--;
        if(*it=='+' && brackets==0 && closedBrackets==0 && *(it-1)!='/' && *(it-1)!='*' && *(it-1)!='-' && *(it-1)!='+'){
            if(it==input.begin()){
                string input2(it+1,input.end());
                return parseTermOfIntervals(input2);
            }
            if(it+1==input.end()){
                //Bin‰rem Operator fehlt Operand//
                errorWindow("Operand missing!");
                return Intervall(NAN);
            }
            string input1(input.begin(),it);
            string input2(it+1,input.end());
            return parseTermOfIntervals(input1)+parseTermOfIntervals(input2);
        }
        if(*it=='-' && brackets==0 && closedBrackets==0 && *(it-1)!='/' && *(it-1)!='*' && *(it-1)!='-' && *(it-1)!='+'){
            if(it==input.begin()){
                string input2(it+1,input.end());
                return Intervall(0)-parseTermOfIntervals(input2);
            }
            if(it+1==input.end()){
                //Bin‰rem Operator fehlt Operand//
                errorWindow("Operand missing!");
                return Intervall(NAN);
            }
            string input1(input.begin(),it);
            string input2(it+1,input.end());
            return parseTermOfIntervals(input1)-parseTermOfIntervals(input2);
        }
    }
    it=input.begin();
    if(*it=='('){
        brackets++;
        while(brackets>0){
            it++;
            if(*it=='(')
                brackets++;
            if(*it==')')
                brackets--;
        }
        it++;
        if(it==input.end()){
            string input1(input.begin()+1,input.end()-1);
            return parseTermOfIntervals(input1);
        }
        if(*it=='*'){
            string input1(input.begin()+1,it-1);
            if(it+1==input.end()){
                //Bin‰rem Operator fehlt Operand//
                errorWindow("Operand missing!");
                return Intervall(NAN);
            }
            string input2(it+1,input.end());
            return parseTermOfIntervals(input1)*parseTermOfIntervals(input2);
        }
        if(*it=='/'){
            string input1(input.begin()+1,it-1);
            if(it+1==input.end()){
                //Bin‰rem Operator fehlt Operand//
                errorWindow("Operand missing!");
                return Intervall(NAN);
            }
            string input2(it+1,input.end());
            Intervall result2 = parseTermOfIntervals(input2);
            if(result2.getInf()<=0 && result2.getSup()>=0){
                //Teilen durch 0!
                errorWindow("Division by zero!");
                return Intervall(NAN);
            }
            return parseTermOfIntervals(input1)/result2;
        }
    }
    if(*it=='*' || *it=='/'){
        //Bin‰rem Operator fehlt Operand//
        errorWindow("Operand missing!");
        return Intervall(NAN);
    }
    closedBrackets = 0;
    if(*it=='['){
        for(;it<input.end();it++){
            if(*it=='[')
                closedBrackets++;
            if(*it==']')
                closedBrackets--;
            if(*it=='*' && closedBrackets==0){
                string input1(input.begin(),it);
                string input2(it+1,input.end());
                return parseIntervals(input1)*parseTermOfIntervals(input2);
            }
            if(*it=='/' && closedBrackets==0){
                string input1(input.begin(),it);
                string input2(it+1,input.end());
                Intervall result2 = parseTermOfIntervals(input2);
                if(result2.getInf()<=0 && result2.getSup()>=0){
                    //Teilen durch 0!
                    errorWindow("Division by zero!");
                    return Intervall(NAN);
                }
                return parseIntervals(input1)/result2;
            }
        }
        return parseIntervals(input);
    }
    size_t found1 = input.find_first_of("*");
    if(found1!=string::npos){
        string input1 = input.substr(0,found1);
        string input2 = input.substr(found1+1);
        return parseNumbers(input1)*parseTermOfIntervals(input2);
    }
    size_t found2 = input.find_first_of("/");
    if(found2!=string::npos){
        string input1 = input.substr(0,found2);
        string input2 = input.substr(found2+1);
        Intervall result2 = parseTermOfIntervals(input2);
        if(result2.getInf()<=0 && result2.getSup()>=0){
            //Teilen durch 0!
            errorWindow("Division by zero!");
            return Intervall(NAN);
        }
        return parseNumbers(input1)/result2;
    }
    if(found1==string::npos && found2==string::npos){
        return parseNumbers(input);
    }

    errorWindow("42: "+input);
    return Intervall(NAN);
}
double parseTermOfNumbers(string input){
    string::iterator it;
    int brackets = 0;
    if(input=="")
        return 0;
    for(it=input.end();it>=input.begin();it--){
        if(*it=='(')
            brackets++;
        if(*it==')')
            brackets--;
        if(*it=='+' && brackets==0 && *(it-1)!='/' && *(it-1)!='*' && *(it-1)!='-' && *(it-1)!='+' && *(it-1)!='|' && *(it-1)!='&'){
            if(it==input.begin()){
                string input2(it+1,input.end());
                return parseTermOfNumbers(input2);
            }
            if(it+1==input.end()){
                //Bin‰rem Operator fehlt Operand//
                errorWindow("Operand missing!");
                return double(NAN);
            }
            string input1(input.begin(),it);
            string input2(it+1,input.end());
            return parseTermOfNumbers(input1)+parseTermOfNumbers(input2);
        }
        if(*it=='-' && brackets==0 && *(it-1)!='/' && *(it-1)!='*' && *(it-1)!='-' && *(it-1)!='+' && *(it-1)!='|' && *(it-1)!='&'){
            if(it==input.begin()){
                string input2(it+1,input.end());
                return -parseTermOfNumbers(input2);
            }
            if(it+1==input.end()){
                //Bin‰rem Operator fehlt Operand//
                errorWindow("Operand missing!");
                return double(NAN);
            }
            string input1(input.begin(),it);
            string input2(it+1,input.end());
            return parseTermOfNumbers(input1)-parseTermOfNumbers(input2);
        }
    }
    it=input.begin();
    if(*it=='('){
        brackets++;
        while(brackets>0){
            it++;
            if(*it=='(')
                brackets++;
            if(*it==')')
                brackets--;
        }
        it++;
        if(it==input.end()){
            string input1(input.begin()+1,input.end()-1);
            return parseTermOfNumbers(input1);
        }
        if(*it=='*'){
            string input1(input.begin()+1,it-1);
            if(it+1==input.end()){
                //Bin‰rem Operator fehlt Operand//
                errorWindow("Operand missing!");
                return double(NAN);
            }
            string input2(it+1,input.end());
            return parseTermOfNumbers(input1)*parseTermOfNumbers(input2);
        }
        if(*it=='/'){
            string input1(input.begin()+1,it-1);
            if(it+1==input.end()){
                //Bin‰rem Operator fehlt Operand//
                errorWindow("Operand missing!");
                return double(NAN);
            }
            string input2(it+1,input.end());
            double result2 = parseTermOfNumbers(input2);
            if(result2==0){
                //Teilen durch 0!
                errorWindow("Division by zero!");
                return double(NAN);
            }
            return parseTermOfNumbers(input1)/result2;
        }
    }
    if(*it=='*' || *it=='/'){
        //Bin‰rem Operator fehlt Operand//
        errorWindow("Operand missing!");
        return double(NAN);
    }
    size_t found1 = input.find_first_of("*");
    if(found1!=string::npos){
        string input1 = input.substr(0,found1);
        string input2 = input.substr(found1+1);
        return parseNumbers(input1)*parseTermOfNumbers(input2);
    }
    size_t found2 = input.find_first_of("/");
    if(found2!=string::npos){
        string input1 = input.substr(0,found2);
        string input2 = input.substr(found2+1);
        double result2 = parseTermOfNumbers(input2);
        if(result2==0){
            //Teilen durch 0!
            errorWindow("Division by zero!");
            return double(NAN);
        }
        return parseNumbers(input1)/result2;
    }
    if(found1==string::npos && found2==string::npos){
        return parseNumbers(input);
    }
    errorWindow("42!");
    return double(NAN);
}
Beispiel #27
0
int main( int argc, char* argv[])
{

    if( argc != 3)
    {
        std::cerr << "Usage: "<<argv[0]<<" [input.nc] [output.nc]\n";
        return -1;
    }
    std::cout << argv[1]<< " -> "<<argv[2]<<std::endl;   
    //----------------
    const unsigned Nhist = 50; 
    const unsigned nhist = 1;
    const unsigned Ninput =100;
    const double Nsigma =4.;
    std::vector<double> input1(Ninput,0.);    
    std::vector<double> input2(Ninput,0.);    

    thrust::random::minstd_rand generator;
    thrust::random::normal_distribution<double> d1;
    thrust::random::normal_distribution<double> d2;
    std::vector<double> rand1(Ninput,0.);    
    std::vector<double> rand2(Ninput,0.);    
    for (unsigned i=0;i<rand1.size();i++)  {  rand1[i] = d1(generator); }
    for (unsigned i=0;i<rand2.size();i++)  {  rand2[i] = d2(generator); }

    for (unsigned i=0;i<input1.size();i++)  {
        double t = (double)(i/(input1.size()-1));
        double omega1 =2.*M_PI* 20.;
        input1[i] = (rand1[i]*0.1*cos( omega1*t)+1.); 
    }
    for (unsigned i=0;i<input2.size();i++)  {
        double t = (double)(i/(input2.size()-1));
        //double omega1 = 2.*M_PI*20.;
        double omega2= 2.*M_PI*30.;
        //double phase = 0.5*M_PI;
//         input2[i] =input1[i];  //perfectly correlated
//         input2[i] = (-rand1[i]*0.1*cos(omega1*t)+1.);//perfectly anticorrelated
//         input2[i] = (rand2[i]*0.001*cos(omega2*t)+3.);//perfectly uncorrelated
        input2[i] = (rand2[i]*0.001*cos(omega2*t)+3.);//uncorrelated
    } 

    //normalize grid and compute sigma
    NormalizeToFluc(input1);
    NormalizeToFluc(input2);
    dg::Grid1d  g1d1(-Nsigma,Nsigma, nhist, Nhist,dg::DIR);
    dg::Grid1d  g1d2(-Nsigma,Nsigma, nhist, Nhist,dg::DIR); 
    dg::Grid2d  g2d( -Nsigma,Nsigma,-Nsigma,Nsigma, nhist, Nhist,Nhist,dg::DIR,dg::DIR); 
    dg::Histogram<dg::HVec> hist1(g1d1,input1);  
    dg::Histogram<dg::HVec> hist2(g1d2,input2);    
    dg::Histogram2D<dg::HVec> hist12(g2d,input1,input2);    

 
    dg::HVec PA1 = dg::evaluate(hist1,g1d1);
    dg::HVec A1 = dg::evaluate(dg::cooX1d,g1d1);
    dg::HVec PA2= dg::evaluate(hist2,g1d2);
    dg::HVec A2 = dg::evaluate(dg::cooX1d,g1d2);
    dg::HVec PA1A2= dg::evaluate(hist12,g2d);
    
    //-----------------NC output start
    int dataIDs1[2],dataIDs2[2],dataIDs12[1];
    int dim_ids1[1],dim_ids2[1],dim_ids12[2];
    int ncid;
    file::NC_Error_Handle err; 
    err = nc_create(argv[2],NC_NETCDF4|NC_CLOBBER, &ncid); 
    //plot 1
    err = file::define_dimension( ncid,"A1_", &dim_ids1[0],  g1d1);
    err = nc_def_var( ncid, "P(A1)",   NC_DOUBLE, 1, &dim_ids1[0], &dataIDs1[0]);
    err = nc_def_var( ncid, "A1",    NC_DOUBLE, 1, &dim_ids1[0], &dataIDs1[1]);
    err = nc_enddef( ncid);
    err = nc_put_var_double( ncid, dataIDs1[0], PA1.data() );
    err = nc_put_var_double( ncid, dataIDs1[1], A1.data() );
    err = nc_redef(ncid);
    //plot 2
    err = file::define_dimension( ncid,"A2_", &dim_ids2[0],  g1d2);
    err = nc_def_var( ncid, "P(A2)",   NC_DOUBLE, 1, &dim_ids2[0], &dataIDs2[0]);
    err = nc_def_var( ncid, "A2",    NC_DOUBLE, 1, &dim_ids2[0], &dataIDs2[1]);
    err = nc_enddef( ncid);
    err = nc_put_var_double( ncid, dataIDs2[0], PA2.data() );
    err = nc_put_var_double( ncid, dataIDs2[1], A2.data() );
    err = nc_redef(ncid);
    //plot12
//     dim_ids12[0]=dim_ids1[0];
//     dim_ids12[1]=dim_ids2[0];
    dim_ids12[0]=dataIDs1[0];
    dim_ids12[1]=dataIDs2[0];
    err = file::define_dimensions( ncid, &dim_ids12[0],  g2d);
    err = nc_def_var( ncid, "P(A1,A2)",   NC_DOUBLE, 2, &dim_ids12[0], &dataIDs12[0]);
    err = nc_enddef( ncid);
    err = nc_put_var_double( ncid, dataIDs12[0], PA1A2.data() );
    err = nc_redef(ncid);
    nc_close( ncid);

    return 0;
}
Beispiel #28
0
int main(int argc, char *argv[]) {
    try {
        utility::thread_number_range threads(get_default_num_threads);
        utility::parse_cli_arguments(argc, argv,
                                     utility::cli_argument_pack()
                                     //"-h" option for for displaying help is present implicitly
                                     .positional_arg(threads,"#threads","  number of threads to use; a range of the "
                                                     "form low[:high]\n              where low and optional high are "
                                                     "non-negative integers,\n              or 'auto' for the TBB "
                                                     "default")
                                     .arg(verbose,"verbose","   print diagnostic output to screen")
                                     .arg(silent,"silent","    limits output to timing info; overrides verbose")
        );

        if (silent) verbose = false;  // make silent override verbose

        tick_count start = tick_count::now();
        for(int p = threads.first; p <= threads.last; ++p ) {
            task_scheduler_init init(p);
            if (!silent)  cout << "graph test running on " << p << " threads.\n";
            
            graph g;

            { // test buffer: 0, 1
                buffer b(g);
                toggle input(g);
                led output(g, "OUTPUT", false); // false means we will explicitly call display to see LED
                
                make_edge(input.get_out(), b.get_in(0));
                make_edge(b.get_out(), output.get_in());
                
                if (!silent) printf("Testing buffer...\n");
                input.activate(); // 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input.flip(); // 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
            }

            { // test not_gate: 0, 1
                not_gate n(g);
                toggle input(g);
                led output(g, "OUTPUT", false);
                
                make_edge(input.get_out(), n.get_in(0));
                make_edge(n.get_out(), output.get_in());
                
                if (!silent) printf("Testing not_gate...\n");
                input.activate(); // 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input.flip(); // 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
            }

            { // test two-input and_gate: 00, 01, 10, 11
                and_gate<two_input> a(g);
                toggle input0(g);
                toggle input1(g);
                led output(g, "OUTPUT", false);
                
                make_edge(input0.get_out(), a.get_in(0));
                make_edge(input1.get_out(), a.get_in(1));
                make_edge(a.get_out(), output.get_in());
                
                if (!silent) printf("Testing and_gate...\n");
                input1.activate();  input0.activate();  // 0 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input0.flip();  // 0 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input1.flip(); input0.flip();  // 1 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input0.flip();  // 1 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
            }

            { // test three-input or_gate: 000, 001, 010, 100, 011, 101, 110, 111
                or_gate<three_input> o(g);
                toggle input0(g);
                toggle input1(g);
                toggle input2(g);
                led output(g, "OUTPUT", false);
                
                make_edge(input0.get_out(), o.get_in(0));
                make_edge(input1.get_out(), o.get_in(1));
                make_edge(input2.get_out(), o.get_in(2));
                make_edge(o.get_out(), output.get_in());
                
                if (!silent) printf("Testing or_gate...\n");
                input2.activate();  input1.activate();  input0.activate();  // 0 0 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input0.flip();  // 0 0 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input1.flip(); input0.flip();  // 0 1 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input2.flip();  input1.flip();  // 1 0 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input2.flip();  input1.flip();  input0.flip();  // 0 1 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input2.flip();  input1.flip();  // 1 0 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input1.flip();  input0.flip();  // 1 1 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input0.flip();  // 1 1 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
            }

            { // test two-input xor_gate: 00, 01, 10, 11
                xor_gate<two_input> x(g);
                toggle input0(g);
                toggle input1(g);
                led output(g, "OUTPUT", false);
                
                make_edge(input0.get_out(), x.get_in(0));
                make_edge(input1.get_out(), x.get_in(1));
                make_edge(x.get_out(), output.get_in());
                
                if (!silent) printf("Testing xor_gate...\n");
                input1.activate();  input0.activate();  // 0 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input0.flip();  // 0 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input1.flip();  input0.flip();  // 1 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input0.flip();  // 1 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
            }


            { // test two-input nor_gate: 00, 01, 10, 11
                nor_gate<two_input> n(g);
                toggle input0(g);
                toggle input1(g);
                led output(g, "OUTPUT", false);
                
                make_edge(input0.get_out(), n.get_in(0));
                make_edge(input1.get_out(), n.get_in(1));
                make_edge(n.get_out(), output.get_in());
                
                if (!silent) printf("Testing nor_gate...\n");
                input1.activate();  input0.activate();  // 0 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input0.flip();  // 0 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input1.flip();  input0.flip();  // 1 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input0.flip();  // 1 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
            }

            { // test steady_signal and digit
                steady_signal input0(g, high);
                steady_signal input1(g, low);
                and_gate<two_input> a(g);
                or_gate<two_input> o(g);
                xor_gate<two_input> x(g);
                nor_gate<two_input> n(g);
                digit output(g, "OUTPUT", false);
                
                make_edge(input0.get_out(), a.get_in(0));
                make_edge(input1.get_out(), a.get_in(1));
                make_edge(a.get_out(), output.get_in(0));

                make_edge(input0.get_out(), o.get_in(0));
                make_edge(input1.get_out(), o.get_in(1));
                make_edge(o.get_out(), output.get_in(1));

                make_edge(input0.get_out(), x.get_in(0));
                make_edge(input1.get_out(), x.get_in(1));
                make_edge(x.get_out(), output.get_in(2));

                make_edge(input0.get_out(), n.get_in(0));
                make_edge(input1.get_out(), n.get_in(1));
                make_edge(n.get_out(), output.get_in(3));
                
                if (!silent) printf("Testing steady_signal...\n");
                input0.activate();  // 1
                input1.activate();  // 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == 6);
            }

            { // test push_button
                push_button p(g);
                buffer b(g);
                led output(g, "OUTPUT", !silent); // true means print all LED state changes

                make_edge(p.get_out(), b.get_in(0));
                make_edge(b.get_out(), output.get_in());

                if (!silent) printf("Testing push_button...\n");
                p.press();
                p.release();
                p.press();
                p.release();
                g.wait_for_all();
            }

            { // test one_bit_adder
                one_bit_adder my_adder(g);
                toggle A(g);
                toggle B(g);
                toggle CarryIN(g);
                led Sum(g, "SUM");
                led CarryOUT(g, "CarryOUT");
                
                make_edge(A.get_out(), my_adder.get_A());
                make_edge(B.get_out(), my_adder.get_B());
                make_edge(CarryIN.get_out(), my_adder.get_CI());
                make_edge(my_adder.get_out(), Sum.get_in());
                make_edge(my_adder.get_CO(), CarryOUT.get_in());
                
                A.activate();
                B.activate();
                CarryIN.activate();
                
                if (!silent) printf("A on\n");
                A.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == high) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("A off\n");
                A.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("B on\n");
                B.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == high) && (CarryOUT.get_value() == low));
                if (!silent) printf("B off\n");
                B.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("CarryIN on\n");
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == high) && (CarryOUT.get_value() == low));
                if (!silent) printf("CarryIN off\n");
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("A&B on\n");
                A.flip();
                B.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == high));
                if (!silent) printf("A&B off\n");
                A.flip();
                B.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("A&CarryIN on\n");
                A.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == high));
                if (!silent) printf("A&CarryIN off\n");
                A.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("B&CarryIN on\n");
                B.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == high));
                if (!silent) printf("B&CarryIN off\n");
                B.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("A&B&CarryIN on\n");
                A.flip();
                B.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == high) && (CarryOUT.get_value() == high));
                if (!silent) printf("A&B&CarryIN off\n");
                A.flip();
                B.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));
            }

            { // test four_bit_adder
                four_bit_adder four_adder(g);
                std::vector<toggle> A(4, toggle(g));
                std::vector<toggle> B(4, toggle(g));
                toggle CarryIN(g);
                digit Sum(g, "SUM");
                led CarryOUT(g, "CarryOUT");
                
                for (int i=0; i<4; ++i) {
                    make_edge(A[i].get_out(), four_adder.get_A(i));
                    make_edge(B[i].get_out(), four_adder.get_B(i));
                    make_edge(four_adder.get_out(i), Sum.get_in(i));
                }
                make_edge(CarryIN.get_out(), four_adder.get_CI());
                make_edge(four_adder.get_CO(), CarryOUT.get_in());
                
                // Activate all switches at low state
                for (int i=0; i<4; ++i) {
                    A[i].activate();
                    B[i].activate();
                }
                CarryIN.activate();
                
                if (!silent) printf("1+0\n");
                A[0].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("0+1\n");
                A[0].flip();
                B[0].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("3+4\n");
                A[0].flip();
                A[1].flip();
                B[0].flip();
                B[2].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 7) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("6+1\n");
                A[0].flip();
                A[2].flip();
                B[0].flip();
                B[2].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 7) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("0+0+carry\n");
                A[1].flip();
                A[2].flip();
                B[0].flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low));
                
                if (!silent) printf("15+15+carry\n");
                A[0].flip();
                A[1].flip();
                A[2].flip();
                A[3].flip();
                B[0].flip();
                B[1].flip();
                B[2].flip();
                B[3].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 0xf) && (CarryOUT.get_value() == high));
                
                if (!silent) printf("8+8\n");
                A[0].flip();
                A[1].flip();
                A[2].flip();
                B[0].flip();
                B[1].flip();
                B[2].flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 0) && (CarryOUT.get_value() == high));
                
                if (!silent) printf("0+0\n");
                A[3].flip();
                B[3].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 0) && (CarryOUT.get_value() == low));
            }

            { // test D_latch
                D_latch my_d_latch(g);
                toggle D(g);
                pulse E(g, 500, 4); // clock changes every 500ms; stops after 4 changes
                led Q(g, " Q", verbose); // if true, LEDs print at every state change
                led notQ(g, "~Q", verbose);
                
                make_edge(D.get_out(), my_d_latch.get_D());
                make_edge(E.get_out(), my_d_latch.get_E());
                make_edge(my_d_latch.get_Q(), Q.get_in());
                make_edge(my_d_latch.get_notQ(), notQ.get_in());
                
                D.activate();
                
                if (!silent) printf("Toggling D\n");
                E.activate();
                D.flip();
                g.wait_for_all();
                if (!silent && !verbose) { Q.display(); notQ.display(); }
                assert((Q.get_value() == high) && (notQ.get_value() == low));
                E.reset();
                
                if (!silent) printf("Toggling D\n");
                E.activate();
                D.flip();
                g.wait_for_all();
                if (!silent && !verbose) { Q.display(); notQ.display(); }
                assert((Q.get_value() == low) && (notQ.get_value() == high));
                E.reset();
                
                if (!silent) printf("Toggling D\n");
                E.activate();
                D.flip();
                g.wait_for_all();
                if (!silent && !verbose) { Q.display(); notQ.display(); }
                assert((Q.get_value() == high) && (notQ.get_value() == low));
                E.reset();
                
                if (!silent) printf("Toggling D\n");
                E.activate();
                D.flip();
                g.wait_for_all();
                if (!silent && !verbose) { Q.display(); notQ.display(); }
                assert((Q.get_value() == low) && (notQ.get_value() == high));
                E.reset();
                
                if (!silent) printf("Toggling D\n");
                E.activate();
                D.flip();
                g.wait_for_all();
                if (!silent && !verbose) { Q.display(); notQ.display(); }
                assert((Q.get_value() == high) && (notQ.get_value() == low));
            }
        }
        utility::report_elapsed_time((tbb::tick_count::now() - start).seconds());
        return 0;
    } catch(std::exception& e) {
        cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n";
        return 1;
    }
}
Beispiel #29
0
int main(int argc, char *argv[]) {
#if __TBB_FLOW_GRAPH_CPP11_FEATURES
    try {
        utility::thread_number_range threads(get_default_num_threads);
        utility::parse_cli_arguments(argc, argv,
                                     utility::cli_argument_pack()
                                     //"-h" option for displaying help is present implicitly
                                     .positional_arg(threads,"#threads",utility::thread_number_range_desc)
                                     .arg(verbose,"verbose","   print diagnostic output to screen")
                                     .arg(silent,"silent","    limits output to timing info; overrides verbose")
                                    );

        if (silent) verbose = false;  // make silent override verbose

        tick_count start = tick_count::now();
        for(int p = threads.first; p <= threads.last; p = threads.step(p)) {
            task_scheduler_init init(p);
            if (!silent)  cout << "graph test running on " << p << " threads.\n";

            graph g;

            {   // test buffer: 0, 1
                buffer b(g);
                toggle input(g);
                led output(g, "OUTPUT", false); // false means we will explicitly call display to see LED

                make_edge(input.get_out(), input_port<0>(b));
                make_edge(output_port<0>(b), output.get_in());

                if (!silent) printf("Testing buffer...\n");
                input.activate(); // 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input.flip(); // 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
            }

            {   // test not_gate: 0, 1
                not_gate n(g);
                toggle input(g);
                led output(g, "OUTPUT", false);

                make_edge(input.get_out(), input_port<0>(n));
                make_edge(output_port<0>(n), output.get_in());

                if (!silent) printf("Testing not_gate...\n");
                input.activate(); // 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input.flip(); // 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
            }

            {   // test two-input and_gate: 00, 01, 10, 11
                and_gate<2> a(g);
                toggle input0(g);
                toggle input1(g);
                led output(g, "OUTPUT", false);

                make_edge(input0.get_out(), input_port<0>(a));
                make_edge(input1.get_out(), input_port<1>(a));
                make_edge(output_port<0>(a), output.get_in());

                if (!silent) printf("Testing and_gate...\n");
                input1.activate();
                input0.activate();  // 0 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input0.flip();  // 0 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input1.flip();
                input0.flip();  // 1 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input0.flip();  // 1 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
            }

            {   // test three-input or_gate: 000, 001, 010, 100, 011, 101, 110, 111
                or_gate<3> o(g);
                toggle input0(g);
                toggle input1(g);
                toggle input2(g);
                led output(g, "OUTPUT", false);

                make_edge(input0.get_out(), input_port<0>(o));
                make_edge(input1.get_out(), input_port<1>(o));
                make_edge(input2.get_out(), input_port<2>(o));
                make_edge(output_port<0>(o), output.get_in());

                if (!silent) printf("Testing or_gate...\n");
                input2.activate();
                input1.activate();
                input0.activate();  // 0 0 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input0.flip();  // 0 0 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input1.flip();
                input0.flip();  // 0 1 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input2.flip();
                input1.flip();  // 1 0 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input2.flip();
                input1.flip();
                input0.flip();  // 0 1 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input2.flip();
                input1.flip();  // 1 0 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input1.flip();
                input0.flip();  // 1 1 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input0.flip();  // 1 1 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
            }

            {   // test two-input xor_gate: 00, 01, 10, 11
                xor_gate<2> x(g);
                toggle input0(g);
                toggle input1(g);
                led output(g, "OUTPUT", false);

                make_edge(input0.get_out(), input_port<0>(x));
                make_edge(input1.get_out(), input_port<1>(x));
                make_edge(output_port<0>(x), output.get_in());

                if (!silent) printf("Testing xor_gate...\n");
                input1.activate();
                input0.activate();  // 0 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input0.flip();  // 0 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input1.flip();
                input0.flip();  // 1 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input0.flip();  // 1 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
            }


            {   // test two-input nor_gate: 00, 01, 10, 11
                nor_gate<2> n(g);
                toggle input0(g);
                toggle input1(g);
                led output(g, "OUTPUT", false);

                make_edge(input0.get_out(), input_port<0>(n));
                make_edge(input1.get_out(), input_port<1>(n));
                make_edge(output_port<0>(n), output.get_in());

                if (!silent) printf("Testing nor_gate...\n");
                input1.activate();
                input0.activate();  // 0 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == high);
                input0.flip();  // 0 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input1.flip();
                input0.flip();  // 1 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
                input0.flip();  // 1 1
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == low);
            }

            {   // test steady_signal and digit
                steady_signal input0(g, high);
                steady_signal input1(g, low);
                and_gate<2> a(g);
                or_gate<2> o(g);
                xor_gate<2> x(g);
                nor_gate<2> n(g);
                digit output(g, "OUTPUT", false);

                make_edge(input0.get_out(), input_port<0>(a));
                make_edge(input1.get_out(), input_port<1>(a));
                make_edge(output_port<0>(a), input_port<0>(output));

                make_edge(input0.get_out(), input_port<0>(o));
                make_edge(input1.get_out(), input_port<1>(o));
                make_edge(output_port<0>(o), input_port<1>(output));

                make_edge(input0.get_out(), input_port<0>(x));
                make_edge(input1.get_out(), input_port<1>(x));
                make_edge(output_port<0>(x), input_port<2>(output));

                make_edge(input0.get_out(), input_port<0>(n));
                make_edge(input1.get_out(), input_port<1>(n));
                make_edge(output_port<0>(n), input_port<3>(output));

                if (!silent) printf("Testing steady_signal...\n");
                input0.activate();  // 1
                input1.activate();  // 0
                g.wait_for_all();
                if (!silent) output.display();
                assert(output.get_value() == 6);
            }

            {   // test push_button
                push_button p(g);
                buffer b(g);
                led output(g, "OUTPUT", !silent); // true means print all LED state changes

                make_edge(p.get_out(), input_port<0>(b));
                make_edge(output_port<0>(b), output.get_in());

                if (!silent) printf("Testing push_button...\n");
                p.press();
                p.release();
                p.press();
                p.release();
                g.wait_for_all();
            }

            {   // test one_bit_adder
                one_bit_adder my_adder(g);
                toggle A(g);
                toggle B(g);
                toggle CarryIN(g);
                led Sum(g, "SUM");
                led CarryOUT(g, "CarryOUT");

                make_edge(A.get_out(), input_port<P::A0>(my_adder));
                make_edge(B.get_out(), input_port<P::B0>(my_adder));
                make_edge(CarryIN.get_out(), input_port<P::CI>(my_adder));
                make_edge(output_port<P::S0>(my_adder), Sum.get_in());
                make_edge(output_port<1>(my_adder), CarryOUT.get_in());

                A.activate();
                B.activate();
                CarryIN.activate();

                if (!silent) printf("A on\n");
                A.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == high) && (CarryOUT.get_value() == low));

                if (!silent) printf("A off\n");
                A.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));

                if (!silent) printf("B on\n");
                B.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == high) && (CarryOUT.get_value() == low));
                if (!silent) printf("B off\n");
                B.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));

                if (!silent) printf("CarryIN on\n");
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == high) && (CarryOUT.get_value() == low));
                if (!silent) printf("CarryIN off\n");
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));

                if (!silent) printf("A&B on\n");
                A.flip();
                B.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == high));
                if (!silent) printf("A&B off\n");
                A.flip();
                B.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));

                if (!silent) printf("A&CarryIN on\n");
                A.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == high));
                if (!silent) printf("A&CarryIN off\n");
                A.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));

                if (!silent) printf("B&CarryIN on\n");
                B.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == high));
                if (!silent) printf("B&CarryIN off\n");
                B.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));

                if (!silent) printf("A&B&CarryIN on\n");
                A.flip();
                B.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == high) && (CarryOUT.get_value() == high));
                if (!silent) printf("A&B&CarryIN off\n");
                A.flip();
                B.flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == low) && (CarryOUT.get_value() == low));
            }

#if USE_TWO_BIT_FULL_ADDER
            {   // test two_bit_adder
                if (!silent) printf("testing two_bit adder\n");
                two_bit_adder two_adder(g);
                std::vector<toggle> A(2, toggle(g));
                std::vector<toggle> B(2, toggle(g));
                toggle CarryIN(g);
                digit Sum(g, "SUM");
                led CarryOUT(g, "CarryOUT");

                make_edge(A[0].get_out(), input_port<P::A0>(two_adder));
                make_edge(B[0].get_out(), input_port<P::B0>(two_adder));
                make_edge(output_port<P::S0>(two_adder), input_port<0>(Sum));

                make_edge(A[1].get_out(), input_port<P::A1>(two_adder));
                make_edge(B[1].get_out(), input_port<P::B1>(two_adder));
                make_edge(output_port<P::S1>(two_adder), input_port<1>(Sum));

                make_edge(CarryIN.get_out(), input_port<P::CI>(two_adder));
                make_edge(output_port<P::CO>(two_adder), CarryOUT.get_in());

                // Activate all switches at low state
                for (int i=0; i<2; ++i) {
                    A[i].activate();
                    B[i].activate();
                }
                CarryIN.activate();

                if (!silent) printf("1+0\n");
                A[0].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low));

                if (!silent) printf("0+1\n");
                A[0].flip();
                B[0].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low));
            }
#else
            {   // test four_bit_adder
                four_bit_adder four_adder(g);
                std::vector<toggle> A(4, toggle(g));
                std::vector<toggle> B(4, toggle(g));
                toggle CarryIN(g);
                digit Sum(g, "SUM");
                led CarryOUT(g, "CarryOUT");

                make_edge(A[0].get_out(), input_port<P::A0>(four_adder));
                make_edge(B[0].get_out(), input_port<P::B0>(four_adder));
                make_edge(output_port<P::S0>(four_adder), input_port<0>(Sum));

                make_edge(A[1].get_out(), input_port<P::A1>(four_adder));
                make_edge(B[1].get_out(), input_port<P::B1>(four_adder));
                make_edge(output_port<P::S1>(four_adder), input_port<1>(Sum));

                make_edge(A[2].get_out(), input_port<P::A2>(four_adder));
                make_edge(B[2].get_out(), input_port<P::B2>(four_adder));
                make_edge(output_port<P::S2>(four_adder), input_port<2>(Sum));

                make_edge(A[3].get_out(), input_port<P::A3>(four_adder));
                make_edge(B[3].get_out(), input_port<P::B3>(four_adder));
                make_edge(output_port<P::S3>(four_adder), input_port<3>(Sum));

                make_edge(CarryIN.get_out(), input_port<P::CI>(four_adder));
                make_edge(output_port<P::CO>(four_adder), CarryOUT.get_in());

                // Activate all switches at low state
                for (int i=0; i<4; ++i) {
                    A[i].activate();
                    B[i].activate();
                }
                CarryIN.activate();

                if (!silent) printf("1+0\n");
                A[0].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low));

                if (!silent) printf("0+1\n");
                A[0].flip();
                B[0].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low));

                if (!silent) printf("3+4\n");
                A[0].flip();
                A[1].flip();
                B[0].flip();
                B[2].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 7) && (CarryOUT.get_value() == low));

                if (!silent) printf("6+1\n");
                A[0].flip();
                A[2].flip();
                B[0].flip();
                B[2].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 7) && (CarryOUT.get_value() == low));

                if (!silent) printf("0+0+carry\n");
                A[1].flip();
                A[2].flip();
                B[0].flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 1) && (CarryOUT.get_value() == low));

                if (!silent) printf("15+15+carry\n");
                A[0].flip();
                A[1].flip();
                A[2].flip();
                A[3].flip();
                B[0].flip();
                B[1].flip();
                B[2].flip();
                B[3].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 0xf) && (CarryOUT.get_value() == high));

                if (!silent) printf("8+8\n");
                A[0].flip();
                A[1].flip();
                A[2].flip();
                B[0].flip();
                B[1].flip();
                B[2].flip();
                CarryIN.flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 0) && (CarryOUT.get_value() == high));

                if (!silent) printf("0+0\n");
                A[3].flip();
                B[3].flip();
                g.wait_for_all();
                if (!silent) Sum.display();
                if (!silent) CarryOUT.display();
                assert((Sum.get_value() == 0) && (CarryOUT.get_value() == low));
            }
#endif

            {   // test D_latch
                D_latch my_d_latch(g);
                toggle D(g);
                pulse E(g, 500, 4); // clock changes every 500ms; stops after 4 changes
                led Q(g, " Q", verbose); // if true, LEDs print at every state change
                led notQ(g, "~Q", verbose);

                make_edge(D.get_out(), input_port<0>(my_d_latch));
                make_edge(E.get_out(), input_port<1>(my_d_latch));
                make_edge(output_port<0>(my_d_latch), Q.get_in());
                make_edge(output_port<1>(my_d_latch), notQ.get_in());

                D.activate();

                if (!silent) printf("Toggling D\n");
                E.activate();
                D.flip();
                g.wait_for_all();
                if (!silent && !verbose) {
                    Q.display();
                    notQ.display();
                }
                assert((Q.get_value() == high) && (notQ.get_value() == low));
                E.reset();

                if (!silent) printf("Toggling D\n");
                E.activate();
                D.flip();
                g.wait_for_all();
                if (!silent && !verbose) {
                    Q.display();
                    notQ.display();
                }
                assert((Q.get_value() == low) && (notQ.get_value() == high));
                E.reset();

                if (!silent) printf("Toggling D\n");
                E.activate();
                D.flip();
                g.wait_for_all();
                if (!silent && !verbose) {
                    Q.display();
                    notQ.display();
                }
                assert((Q.get_value() == high) && (notQ.get_value() == low));
                E.reset();

                if (!silent) printf("Toggling D\n");
                E.activate();
                D.flip();
                g.wait_for_all();
                if (!silent && !verbose) {
                    Q.display();
                    notQ.display();
                }
                assert((Q.get_value() == low) && (notQ.get_value() == high));
                E.reset();

                if (!silent) printf("Toggling D\n");
                E.activate();
                D.flip();
                g.wait_for_all();
                if (!silent && !verbose) {
                    Q.display();
                    notQ.display();
                }
                assert((Q.get_value() == high) && (notQ.get_value() == low));
            }
        }
        utility::report_elapsed_time((tbb::tick_count::now() - start).seconds());
        return 0;
    } catch(std::exception& e) {
        cerr<<"error occurred. error text is :\"" <<e.what()<<"\"\n";
        return 1;
    }
#else
    utility::report_skipped();
    return 0;
#endif // __TBB_FLOW_GRAPH_CPP11_FEATURES
}
void NtupleDiff(const char * tag, const char * file1, const char * file2, const char * treepath1="l1UpgradeEmuTree/L1UpgradeTree", const char * treepath2="l1UpgradeEmuTree/L1UpgradeTree"){
  cout << "INFO: comparing contents of tree " << treepath1 << " in file " << file1 << "\n";
  cout << "INFO: comparing contents of tree " << treepath2 << " in file " << file2 << "\n";

  TFile input1(file1);
  TTree * tree1  = (TTree*) input1.Get(treepath1);
  if (! tree1) {
    cout << "ERROR: could not open tree 1.\n";
    input1.ls();
    return;
  }

  TFile input2(file2);
  TTree * tree2  = (TTree*) input2.Get(treepath2);
  if (! tree2) {
    cout << "ERROR: could not open tree 2.\n";
    input2.ls();
    return;
  }

  tree1->Print();
  tree2->Print();

  cout << "Very Central Jets:\n";
  bitwise_compare(tag, tree1, tree2, "jetEt", "(jetEt > 10.0) && (abs(jetEta) < 1.5)", 20.0, 0.0, 200.0);
  bitwise_compare(tag, tree1, tree2, "jetEta", "(jetEt > 10.0) && (abs(jetEta) < 1.5)", 20.0, -5.0, 5.0);
  bitwise_compare(tag, tree1, tree2, "jetPhi", "(jetEt > 10.0) && (abs(jetEta) < 1.5)", 20.0, -6.2, 6.2);

  cout << "All Jets:\n";
  bitwise_compare(tag, tree1, tree2, "jetEt", "(jetEt > 10.0)", 20.0, 0.0, 200.0);
  bitwise_compare(tag, tree1, tree2, "jetEta", "(jetEt > 10.0)", 20.0, -5.0, 5.0);
  bitwise_compare(tag, tree1, tree2, "jetPhi", "(jetEt > 10.0)", 20.0, -6.2, 6.2);

  bitwise_compare(tag, tree1, tree2, "tauEt", "tauEt > 10.0", 20.0, 0.0, 200.0);
  bitwise_compare(tag, tree1, tree2, "tauEta", "tauEt > 10.0", 20.0, -5.0, 5.0);
  bitwise_compare(tag, tree1, tree2, "tauPhi", "tauEt > 10.0", 20.0, -6.2, 6.2);

  bitwise_compare(tag, tree1, tree2, "egEt", "egEt > 10.0", 20.0, 0.0, 200.0);
  bitwise_compare(tag, tree1, tree2, "egEta", "egEt > 10.0", 20.0, -5.0, 5.0);
  bitwise_compare(tag, tree1, tree2, "egPhi", "egEt > 10.0", 20.0, -6.2, 6.2);

  bitwise_compare(tag, tree1, tree2, "muonEt", "muonEt > 10.0", 20.0, 0.0, 200.0);
  bitwise_compare(tag, tree1, tree2, "muonEta", "muonEt > 10.0", 20.0, -5.0, 5.0);
  bitwise_compare(tag, tree1, tree2, "muonPhi", "muonEt > 10.0", 20.0, -6.2, 6.2);

  bitwise_compare(tag, tree1, tree2, "sumEt[0]", "", 20.0, 0.0, 500.0);
  bitwise_compare(tag, tree1, tree2, "sumEt[1]", "", 20.0, 0.0, 500.0);
  bitwise_compare(tag, tree1, tree2, "sumEt[2]", "", 20.0, 0.0, 500.0);
  bitwise_compare(tag, tree1, tree2, "sumEt[3]", "", 20.0, 0.0, 500.0);
  

  //TH1F * jetEt = new TH1F("jetEt","", 20, 0.0, 200.0);
  //tree->Draw("jetEt>>jetEt","jetEt > 10.0");
  //cout << "jet count:  " << jetEt->GetEntries() << "\n";

  //TH1F * egEt = new TH1F("egEt","", 20, 0.0, 200.0);
  //tree->Draw("egEt>>egEt","egEt > 10.0");
  //cout << "eg count:  " << egEt->GetEntries() << "\n";

  //TH1F * tauEt = new TH1F("tauEt","", 20, 0.0, 200.0);
  //tree->Draw("tauEt>>tauEt","tauEt > 10.0");
  //cout << "tau count:  " << tauEt->GetEntries() << "\n";

  //TH1F * muonEt = new TH1F("muonEt","", 20, 0.0, 200.0);
  //tree->Draw("muonEt>>muonEt","muonEt > 1.0");
  //cout << "muon count:  " << muonEt->GetEntries() << "\n";  
}