示例#1
0
int main()
{
    {
        typedef std::unique_ptr<A> APtr;
        APtr s(new A);
        A* p = s.get();
        APtr s2 = std::move(s);
        assert(s2.get() == p);
        assert(s.get() == 0);
        assert(A::count == 1);
    }
    assert(A::count == 0);
    {
        typedef Deleter<A> MoveDel;
        typedef std::unique_ptr<A, MoveDel> APtr;
        MoveDel d(5);
        APtr s(new A, std::move(d));
        assert(d.state() == 0);
        assert(s.get_deleter().state() == 5);
        A* p = s.get();
        APtr s2 = std::move(s);
        assert(s2.get() == p);
        assert(s.get() == 0);
        assert(A::count == 1);
        assert(s2.get_deleter().state() == 5);
        assert(s.get_deleter().state() == 0);
    }
    assert(A::count == 0);
    {
        typedef NCDeleter<A> NonCopyDel;
        typedef std::unique_ptr<A, NonCopyDel&> APtr;

        NonCopyDel d;
        APtr s(new A, d);
        A* p = s.get();
        APtr s2 = std::move(s);
        assert(s2.get() == p);
        assert(s.get() == 0);
        assert(A::count == 1);
        d.set_state(6);
        assert(s2.get_deleter().state() == d.state());
        assert(s.get_deleter().state() ==  d.state());
    }
    assert(A::count == 0);
    {
       sink1(source1());
       assert(A::count == 0);
       sink2(source2());
       assert(A::count == 0);
       sink3(source3());
       assert(A::count == 0);
    }
    assert(A::count == 0);
}
示例#2
0
static void crtheap2(const int size, int *a)
{ 
	fprintf(stderr,"crtheap2\n");
	if (size<2) return; 

	int n=size/2;
	while (--n>-1) {
		fprintf(stderr,"n = %d\n",n);
		sink2(size,a,n);
	}

	return;
}
示例#3
0
static void sink2(const int size, int *a, const int n)
{
	//fprintf(stderr,"sink2\n");
	int *pt = a+n;
	int *c1 = a+2*n+1;
	int *c2 = a+2*n+2;
	if (2*n+1>=size)
		return;
	else if (2*n+2==size) {
		if (*c1>*pt) {
			swp(pt,c1);
			sink2(size,a,2*n+1); 
		}
	} else {
		if (*c1>*pt && *c1>*c2) {
			swp(pt,c1);
			sink2(size,a,2*n+1);
		} else if (*c2>*pt && *c2>*c1) {
			swp(pt,c2);
			sink2(size,a,2*n+2);
		}
	}
}
void init_logging()
{
    boost::shared_ptr< logging::core > core = logging::core::get();

    // The simplest way, the backend is default-constructed
    boost::shared_ptr< sink_t > sink1(new sink_t());
    core->add_sink(sink1);

    // One can construct backend separately and pass it to the frontend
    boost::shared_ptr< my_backend > backend(new my_backend());
    boost::shared_ptr< sink_t > sink2(new sink_t(backend));
    core->add_sink(sink2);

    // You can manage filtering through the sink interface
    sink1->set_filter(expr::attr< severity_level >("Severity") >= warning);
    sink2->set_filter(expr::attr< std::string >("Channel") == "net");
}
示例#5
0
void heapsort2(int size, int *a)
{
	fprintf(stderr,"heapsort2\n");

	if (!size) return;

	swp_count=0;

	crtheap2(size,a); 

	do {
		fprintf(stderr,"pop\n");
		swp(a,a+size-1);
		sink2(size-1,a,0);
	}
	while (--size>0);

	fprintf(stderr,"swp_count=%d\n",swp_count);

	return;
}
void test()
{
   //Single unique_ptr
   reset_counters(); 
   sink1(source1());
   sink2(source2());
   sink3(source3());
   BOOST_TEST(A::count == 0);
   //Unbounded array unique_ptr
   reset_counters();
   sink1_unbounded_array(source1_unbounded_array());
   sink2_unbounded_array(source2_unbounded_array());
   sink3_unbounded_array(source3_unbounded_array());
   BOOST_TEST(A::count == 0);
   //Bbounded array unique_ptr
   reset_counters();
   sink1_bounded_array(source1_bounded_array());
   sink2_bounded_array(source2_bounded_array());
   sink3_bounded_array(source3_bounded_array());
   BOOST_TEST(A::count == 0);
}
int main()
{
    // std::cout << " ------ test 1, direct init from rvalue ------- " << std::endl;
// #if defined(__GNUC__) && 0 // GCC having trouble parsing the extra parens
    // X z2((0, X() ));
// #else
    X z2((X()));
// #endif 

    // std::cout << " ------ test 2, copy init from rvalue ------- " << std::endl;
    X z4 = X();

    // std::cout << " ------ test 3, copy init from lvalue ------- " << std::endl;
    X z5 = z4;

    // std::cout << " ------ test 4, direct init from lvalue ------- " << std::endl;
    X z6(z4);

    // std::cout << " ------ test 5, construct const ------- " << std::endl;
    X const z7;

    // std::cout << " ------ test 6, copy init from lvalue ------- " << std::endl;
    X z8 = z7;

    // std::cout << " ------ test 7, direct init from lvalue ------- " << std::endl;
    X z9(z7);

    // std::cout << " ------ test 8, pass rvalue by-value ------- " << std::endl;
    sink(source());

    // std::cout << " ------ test 9, pass const rvalue by-value ------- " << std::endl;
    sink(csource());

    // std::cout << " ------ test 10, pass rvalue by overloaded reference ------- " << std::endl;
    // This one fails in Comeau's strict mode due to 8.5.3/5.  GCC 3.3.1 passes it.
    sink2(source());

    // std::cout << " ------ test 11, pass const rvalue by overloaded reference ------- " << std::endl;
    sink2(csource());

#if 0    // These two correctly fail to compile, just as desired
    std::cout << " ------ test 12, pass rvalue by non-const reference ------- " << std::endl;
    sink3(source());

    std::cout << " ------ test 13, pass const rvalue by non-const reference ------- " << std::endl;
    sink3(csource());
#endif 

    // std::cout << " ------ test 14, pass lvalue by-value ------- " << std::endl;
    sink(z5);

    // std::cout << " ------ test 15, pass const lvalue by-value ------- " << std::endl;
    sink(z7);

    // std::cout << " ------ test 16, pass lvalue by-reference ------- " << std::endl;
    sink2(z4);

    // std::cout << " ------ test 17, pass const lvalue by const reference ------- " << std::endl;
    sink2(z7);

    // std::cout << " ------ test 18, pass const lvalue by-reference ------- " << std::endl;
#if 0   // correctly fails to compile, just as desired
    sink3(z7);
#endif 

    // std::cout << " ------ test 19, pass rvalue by value to template param ------- " << std::endl;
    tsink(source());

    // std::cout << " ------ test 20, direct initialize a const A with an A ------- " << std::endl;
    typedef X const XC;
    sink2(XC(X()));

    // std::cout << " ------ test 21, assign from lvalue ------- " << std::endl;
    z4 = z5;

    // std::cout << " ------ test 22, assign from rvalue ------- " << std::endl;
    z4 = source();
}
示例#8
0
void Field::put(Sink & sink1) const {
  Sink sink2(sink1.outputFunction("List",2L));
  sink1 << numerator().asInt() << denominator().asInt();
};
示例#9
0
/*
 * @file sim-hlt-tpc.C
 * @brief HLT Conformal mapping tracker embedded into AliRoot simulation.
 *
 * Example macro to run the HLT Conformal mapping tracker embedded into
 * AliRoot simulation. The reconstruction is done from the TPC digits.
 *
 * Usage: aliroot -b -q sim-hlt-tpc.C | tee sim-hlt-tpc.log
 *
 * The chain to be run is defined within the macro. The input data is
 * read from the TPC.Digits.
 *
 * The following options can be specified comma separated in a string:
 * <pre>
 *   aliroot -b -q sim-hlt-tpc.C'("options")'
 *       CA      use the cellular automaton  tracker and track merger
 *       CM      use the conformal mapping tracker and track merger
 *       SORTED  use CF pre-sorting and corresponding sequential CF
 *               algorithm, by default the algorithm capable of reading
 *               unsorted data is used
 *       RAW     write raw data for all detectors
 *       RAWHLT  write raw data only for HLT
 *       MC      propagate the MC information
 * </pre>
 *
 * The macro asumes the data to be already simulated. If it should run
 * within the initial simulation, comment the corresponding functions
 * below (SetRunGeneration etc.)
 *
 * @author [email protected]
 * @ingroup alihlt_tpc
 */
sim_hlt_tpc(const char* options="CA")
{
  // this is just a tool to switch the logging systems
  AliHLTLogging log;
  //log.SwitchAliLog(0);

  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // scanning the options
  //
  bool bUseCA=true;   // use the CA tracker and merger
  bool bCFSort=false; // CF pre-sorting and sequential CF algorithm
  bool bRawData=false;// raw data for all detectors
  bool bRawHLTData=false; // raw data only for HLT
  bool bPropagateMC=false;
  TString tsOptions=options;
  TObjArray* pTokens=tsOptions.Tokenize(",");
  if (pTokens) {
    for (int n=0; n<pTokens->GetEntries(); n++) {
      TString arg=((TObjString*)pTokens->At(n))->GetString();
      if (arg.CompareTo("ca", TString::kIgnoreCase)==0) {
	bUseCA=true;
      } else if (arg.CompareTo("cm", TString::kIgnoreCase)==0) {
	bUseCA=false;
      } else if (arg.CompareTo("sorted", TString::kIgnoreCase)==0) {
	bCFSort=true;
      } else if (arg.CompareTo("unsorted", TString::kIgnoreCase)==0) {
	bCFSort=false;
      } else if (arg.CompareTo("raw", TString::kIgnoreCase)==0) {
	bRawData=true;
      } else if (arg.CompareTo("rawhlt", TString::kIgnoreCase)==0) {
	bRawHLTData=true;
      } else if (arg.CompareTo("mc", TString::kIgnoreCase)==0) {
	bPropagateMC=true;
      } else {
	cout << "unknown argument: " << arg << endl;
	return 0;
      }
    }
    delete pTokens;
  }
  // summary
  cout << "using " << bUseCA?"CA":"CM" << " tracker" << endl;
  
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // init the HLT system in order to define the analysis chain below
  //
  AliHLTSystem* gHLT=AliHLTPluginBase::GetInstance();

  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // define the analysis chain
  //

  // load TPCParam from OCDB
  const char* cdbEntry="TPC/Calib/Parameters";
  AliCDBManager* pMan=AliCDBManager::Instance();
  AliTPCParam* pTPCParam=NULL;
  if (pMan) {
    if (!pMan->IsDefaultStorageSet()) {
      pMan->SetDefaultStorage("local://$ALICE_ROOT/OCDB");
      pMan->SetRun(0);
    }
    AliCDBEntry *pEntry = pMan->Get(cdbEntry);
    if (pEntry && 
	pEntry->GetObject() &&
	(pTPCParam=dynamic_cast<AliTPCParam*>(pEntry->GetObject()))) {
    } else {
      HLTWarning("can not load AliTPCParam from CDB entry %s", cdbEntry);
    }
  }

  int iMinSlice=0; 
  int iMaxSlice=35;
  int iMinPart=0;
  int iMaxPart=5;
  TString mergerInput;
  TString writerInput;
  TString sinkClusterInput;
  for (int slice=iMinSlice; slice<=iMaxSlice; slice++) {
    TString trackerInput;
    for (int part=iMinPart; part<=iMaxPart; part++) {
      TString arg, publisher, cf;

      // digit publisher components
      arg.Form("-slice %d -partition %d", slice, part);
      publisher.Form("DP_%02d_%d", slice, part);
      AliHLTConfiguration pubconf(publisher.Data(), "TPCDigitPublisher", NULL , arg.Data());

      // cluster finder components
      arg="-timebins ";
      if (pTPCParam) arg+=pTPCParam->GetMaxTBin()+1;
      else arg+=446; // old simulated data
      if (bCFSort) arg+=" -sorted ";
      if (bPropagateMC) arg+=" -do-mc ";
      cf.Form("CF_%02d_%d", slice, part);
      AliHLTConfiguration cfconf(cf.Data(), "TPCClusterFinderUnpacked", publisher.Data(), arg.Data());
      if (trackerInput.Length()>0) trackerInput+=" ";
      trackerInput+=cf;
      if (sinkClusterInput.Length()>0) sinkClusterInput+=" ";
      sinkClusterInput+=cf;
    }

    TString tracker;
    // tracker finder components
    tracker.Form("TR_%02d", slice);
    if (bUseCA) {
      AliHLTConfiguration trackerconf(tracker.Data(), "TPCCATracker", trackerInput.Data(), "");
    } else {
      AliHLTConfiguration trackerconf(tracker.Data(), "TPCSliceTracker", trackerInput.Data(), "-pp-run");
    }

    //add all trackers to writer input. Include if you would like all slice tracks written.
    //if (writerInput.Length()>0) writerInput+=" ";
    //writerInput+=tracker;

    // add all clusterfinders to the writer input
    if (writerInput.Length()>0) writerInput+=" ";
    writerInput+=trackerInput;

    if (mergerInput.Length()>0) mergerInput+=" ";
    mergerInput+=tracker;

  }

  // GlobalMerger component
  if (bUseCA) {
    AliHLTConfiguration mergerconf("globalmerger","TPCCAGlobalMerger",mergerInput.Data(),"");
  } else {
    AliHLTConfiguration mergerconf("globalmerger","TPCGlobalMerger",mergerInput.Data(),"");
  }

  TString converterInput="globalmerger";

  // collector for the MC information to be propagated from CFs to ESDConverter
  if (bPropagateMC){
    AliHLTConfiguration mcinfo("mcinfo", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLMCINFO' 'TPC '");  
    AliHLTConfiguration mcTrackMarker("mcTrackMarker","TPCTrackMCMarker","globalmerger mcinfo","" );
    converterInput+=" mcTrackMarker";
  }

  if (writerInput.Length()>0) writerInput+=" ";
  writerInput+="globalmerger";


  //////////////////////////////////////////////////////////////////////////////////////////
  //
  // output section
  //

  //////////////////////////////////////////////////////////////////////////////////////////
  // sink1: id=sink-writeall write all blocks
  AliHLTConfiguration sink1("sink-writeall", "FileWriter"   , writerInput.Data(), "-specfmt -subdir=event_%d -blcknofmt=_0x%x -idfmt=_0x%08x");


  //////////////////////////////////////////////////////////////////////////////////////////
  // sink2: id=sink-esd-file write ESD using the TPCEsdWriter
  AliHLTConfiguration sink2("sink-esd-file", "TPCEsdWriter"   , converterInput.Data(), "-datafile AliHLTESDs.root");


  //////////////////////////////////////////////////////////////////////////////////////////
  // sink3: id=sink-esd add ESD to HLTOUT using the TPCEsdConverter

  // the esd converter configuration
  AliHLTConfiguration sink3("sink-esd", "TPCEsdConverter"   , converterInput.Data(), "");

  //////////////////////////////////////////////////////////////////////////////////////////
  // sink4: id=sink-clusters add cluster data blocks to HLTOUT
  AliHLTConfiguration sink4("sink-clusters", "BlockFilter"   , sinkClusterInput.Data(), "-datatype 'CLUSTERS' 'TPC '");

  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  //
  // Init and run the HLT simulation
  // All but HLT simulation is switched off
  //
  AliSimulation sim;
 
  // switch of simulation and data generation
  // comment all that stuff to also simulate the events and data
  sim.SetRunGeneration(kFALSE);
  sim.SetMakeDigits("");
  sim.SetMakeSDigits("");
  sim.SetMakeDigitsFromHits("");
  //sim.SetMakeTrigger("");
  sim.SetRunQA(":");

  // the normal simulation sets the specific storage for the GRP entry
  if (gSystem->AccessPathName("GRP/GRP/Data")) {
    cerr << "*********************************************************" << endl;
    cerr << "error: no GRP entry found in the currect directory, simulation might be incomplete. Skip setting specific storage for GRP entry" << endl;
    cerr << "*********************************************************" << endl << endl;
  } else {
    sim.SetSpecificStorage("GRP/GRP/Data",
			   Form("local://%s",gSystem->pwd()));
  }

  TString rawDataSelection="HLT";
  if (bRawData) rawDataSelection="ALL";
  if (bRawHLTData || bRawData) sim.SetWriteRawData(rawDataSelection, "raw.root", kTRUE);

  // set the options for the HLT simulation
  sim.SetRunHLT("libAliHLTUtil.so libAliHLTTPC.so loglevel=0x7c "
		"chains=sink-esd,sink-clusters");
  sim.Run();
}
int main()
{
	Source src(100);
	Pipe pipe1(80);
	Valve valve1(on);

	Tank tank1(60);
	Switch switch1(&tank1,300);
	Switch switch2(&tank1, 50);

	Pipe pipe2(80);
	Sink sink1(30);
	Pipe pipe3(40);
	Valve valve2(on);

	Tank tank2(80);
	Switch switch3(&tank2, 250);
	Switch switch4(&tank2, 50);

	Sink sink2(20);

	while( !kbhit() )
	{
		src>=pipe1;
		pipe1>=valve1;
		valve1>=tank1;
		Tee(tank1,pipe2,pipe3);
		pipe2>=sink1;
		pipe3>=valve2;
		valve2>=tank2;
		tank2>=sink2;

		src.Tick();
		pipe1.Tick();
		valve1.Tick();
		tank1.Tick();
		switch1.Tick();
		switch2.Tick();
		pipe2.Tick();
		sink1.Tick();
		pipe3.Tick();
		valve2.Tick();
		tank2.Tick();
		switch3.Tick();
		switch4.Tick();
		sink2.Tick();
		if(valve1.Status()==on&& switch1.Status()==on)
			valve1.Status()=off;
		if (valve1.Status()==off && switch2.Status()==off)
			valve1.Status()=on;
		if(valve2.Status()==on && switch3.Status()==on)
			valve2.Status()=off;
		if(valve2.Status()==off && switch4.Status()==off)
			valve2.Status()=on;
		cout<<" Src=" <<setw(2)<<src.Flow();
		cout<<" p1="<<setw(2)<<pipe1.Flow();

		if(valve1.Status()==off)
			cout<<" v1=off";
		else
			cout<<" v1=on";

		cout<<" T1="<<setw(3)<<tank1.Contents();
		cout<<" p2="<<setw(2)<<pipe2.Flow();
		cout<<" Sink1= "<<setw(2)<<sink1.Flow();
		cout<<" p3="<<setw(2)<<pipe3.Flow();
		if(valve2.Status()==off)
			cout<<" v2=off";
		else
		cout<<" v2=on";
		cout<<" T2= "<<setw(3)<<tank2.Contents();
		cout<<" sink2= "<<setw(2)<<sink2.Flow();
		cout<<"\n";
	}
		return 0;
}