当前位置: 首页>>代码示例>>C++>>正文


C++ TTree::ResetBranchAddresses方法代码示例

本文整理汇总了C++中TTree::ResetBranchAddresses方法的典型用法代码示例。如果您正苦于以下问题:C++ TTree::ResetBranchAddresses方法的具体用法?C++ TTree::ResetBranchAddresses怎么用?C++ TTree::ResetBranchAddresses使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TTree的用法示例。


在下文中一共展示了TTree::ResetBranchAddresses方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: execCheckErrors

void execCheckErrors(bool what = 0)
{
  TTree *tree = 0;
  TFile *file = 0;
  if (what == 0) {
    tree = new TTree("ntuple","");
    float px = 0;
    tree->Branch("px",&px);
    TString str;
    tree->Branch("str",&str);
    tree->Fill();
    tree->ResetBranchAddresses(); 
  } else if (what == 1) {
    file = new TFile("hsimple.root");
    tree = (TTree*)file->Get("ntuple");
  } else {
    tree = new TChain("ntuple", "ntuple");
    ((TChain*)tree)->Add("hsimple.root");
  }
  // tree->SetBranchStatus("*", 1);
  // tree->SetBranchStatus("px", 1);
  // std::cout << "fTreeNumber = " << tree->GetTreeNumber() << std::endl;
  tree->LoadTree(0); // REQUIRED
  // std::cout << "fTreeNumber = " << tree->GetTreeNumber() << std::endl;
  
  TBranch *p = ((TBranch *)-1);
  Int_t r;
  
  Float_t px, fake_px;
  Float_t *pxp = new Float_t();
  Float_t *fake_pxp = new Float_t();
  
  Int_t ix;
  Int_t *ixp = new Int_t();
  
  TString s;
  TString *sp = new TString();
  
  TObjString os;
  TObjString *osp = new TObjString();
  
  // Float_t ... (should be fine)
  std::cout << std::endl << "ALL should be FINE ... " << std::endl;
  p = ((TBranch *)-1);
  r = tree->SetBranchAddress("px", &px, &p);
  std::cout << "Float_t ... " << r << std::endl;
  if (p==((TBranch*)-1)) {
     std::cout << "p unchanged\n";
  } else if (p==0) {
     std::cout << "p set to zero\n";
  } else {
     std::cout << "p set to the branch address\n";
  }
  r = tree->SetBranchAddress("px", &px);
  std::cout << "Float_t ... "  << r << std::endl;
  r = tree->SetBranchAddress("px", pxp);
  std::cout << "Float_t ... "  << r << std::endl;
  r = tree->SetBranchAddress("px", &pxp);
  std::cout << "Float_t ... "  << r << std::endl;
  
  // Int_t ...  (should fail)
  std::cout << std::endl << "ALL should FAIL ... " << std::endl;
  p = ((TBranch *)-1);
  r = tree->SetBranchAddress("px", &ix, &p);
  std::cout << "Int_t ...  "  << r << std::endl;
  if (p==((TBranch*)-1)) {
     std::cout << "p unchanged\n";
  } else if (p==0) {
     std::cout << "p set to zero\n";
  } else {
     std::cout << "p set to the branch address\n";
  }
  r = tree->SetBranchAddress("px", &ix);
  std::cout << "Int_t ...  "  << r << std::endl;
  r = tree->SetBranchAddress("px", ixp);
  std::cout << "Int_t ...  "  << r << std::endl;
  r = tree->SetBranchAddress("px", &ixp);
  std::cout << "Int_t ...  "  << r << std::endl;
  
  // TString ... (should fail)
  std::cout << std::endl << "ALL should FAIL ... " << std::endl;
  p = ((TBranch *)-1);
  r = tree->SetBranchAddress("px", &s, &p);
  std::cout << "TString ... "  << r << std::endl;
  if (p==((TBranch *)-1)) {
     std::cout << "p unchanged\n";
  } else if (p==0) {
     std::cout << "p set to zero\n";
  } else {
     std::cout << "p set to the branch address\n";
  }
  r = tree->SetBranchAddress("px", sp);
  std::cout << "TString ... "  << r << std::endl;
  r = tree->SetBranchAddress("px", &sp);
  std::cout << "TString ... "  << r << std::endl;
  
  // TObjString ... (should fail)
  std::cout << std::endl << "ALL should FAIL ... " << std::endl;
  p = ((TBranch *)-1);
  r = tree->SetBranchAddress("px", &os, &p);
//.........这里部分代码省略.........
开发者ID:asmagina1995,项目名称:roottest,代码行数:101,代码来源:execCheckErrors.C

示例2: hadd

void hadd(std::string& targetName, std::vector<std::string>& sources)
{
    using namespace std;
    TFile* target = 0;
    if(isForce) target = TFile::Open(targetName.c_str(), "RECREATE");
    else        target = TFile::Open(targetName.c_str(),   "CREATE");
    if(!target)
    {
        printf("target file already exists! (use -f to force recreation)\n");
        exit(0);
    }

    map<pair<string, string>, TObject*> outputMap;
    vector<pair<string, TObject*> > outputVec;

    for(vector<string>::const_iterator iF = sources.begin(); iF != sources.end(); ++iF)
    {
        if(verbosity >= 2) 
        {
            printf("Processing source file: %s\n", iF->c_str());
            fflush(stdout);
        }
        TFile * f = new TFile(iF->c_str());
        MergeRootfile(outputMap, outputVec, f, f);
        f->Close();
    }

    target->cd();
    map<string, TDirectory*> paths;
    for(std::vector<std::pair<std::string, TObject*> >::const_iterator iO = outputVec.begin(); iO != outputVec.end(); ++iO)
    {
        if(iO->second == 0)
        {
            if(paths.find(iO->first) == paths.end())
            {
                size_t pos = iO->first.rfind('/');
                if(pos == size_t(-1))
                {
                    target->cd();
                    pos = 0;
                }
                else
                {
                    target->cd(iO->first.substr(0, pos).c_str());
                    pos++;
                }
                paths[iO->first] = gDirectory->mkdir(iO->first.substr(pos).c_str());
            }
        }
        else
        {
            paths[iO->first]->cd();
            if(iO->second->IsA()->InheritsFrom(TH1::Class())) iO->second->Write();
            else
            {
                if(iO->second && ((TTree*)iO->second)->GetTreeIndex()) ((TTree*)iO->second)->GetTreeIndex()->Append(0, kFALSE); // Force the sorting
                TTree* tree = ((TTree*)iO->second)->CloneTree();
                ((TTree*)iO->second)->GetListOfClones()->Remove(tree);
                ((TTree*)iO->second)->ResetBranchAddresses();
                tree->ResetBranchAddresses();
                tree->Write();
            }
        }
    }
    
    if(verbosity >= 3)
    {
        printf("Results written to target file: %s\n", target->GetName());
        fflush(stdout);
    }

    target->Close();
    for(vector<pair<string, TFile*> >::const_iterator iF = tmpFiles.begin(); iF != tmpFiles.end(); ++iF)
    {
        if(iF->second)
        {
            iF->second->Close();
            system(("rm " + iF->first).c_str());
        }

    }
}
开发者ID:pastika,项目名称:jhadd,代码行数:82,代码来源:jhadd.cpp

示例3: Lambda_C_Mass_Fitter


//.........这里部分代码省略.........
	      h_yield_varBins_LambdaCharm.SetBinContent(iBin,binValue);
	      h_yield_varBins_LambdaCharm.GetBinError(iBin,errorValue);
	    }
			
	}
      //		cout << "BIN SIZE OF Lc HISTO =======================>>>>>>>>>>>>>>>>>"<< VectorSize << endl;

      h_yield_varBins_LambdaCharm.Write();
      h_yield_varBins_LambdaCharm.Draw();	
	
    }
  

  else if(particle_choice[0]==1)
    {
    
      outputFile.Close();
  	
      vector<double> xBins2;
  	
      TFile f1("output-histos-LambdaCharm.root"); 
      TTree *vectorBranch = (TTree*) f1.Get("vectorBranch");
      vector<double> *xBinsPointer = 0; 	
      vectorBranch->SetBranchAddress("xBins", &xBinsPointer);
	  
      int num = (int) vectorBranch->GetEntries();
      //	  	cout << "entries==============================================================>"<< num << endl;
    
      for (int i =0; i<=num; i++)
	{
	  vectorBranch->GetEntry(i);
	  xBins2=xBinsPointer[0];
	  //  			cout << "entries======================================================>"<< xBins2 << endl;
	  vectorBranch->ResetBranchAddresses();
	}
  
      f1.Close();
      //  		cout << "======================================================>"<<xBins2<< endl;
   
      // Enter name of the first root file to take the histogram from
      //TH1D* histo1;									// Declare  a new histogram
      //f1.GetObject("vectorBranch", histo1);
	
      TFile outputFile("output-histos-XiCharm.root" ,"update");


      double vectorBranch_array[xBins2.size()];								
      //		cout << "vectorBranch_ARRAY--------->: " <<endl;
      //		cout << "vectorBranch-ARAAAY SIZE >>>>>>>>>>>>>>>>>>>>>>" << xBins2.size() << endl;
	
      for(unsigned int i=0; i <=xBins2.size()-1; ++i)
	{
	  vectorBranch_array[i]=xBins2[i];
	  //			cout << vectorBranch_array[i] << "   "; 
	}
      //			cout<<endl;
      //			cout<<endl;
      //			cout << "XARRAY--------------------------------------------->: " << xBins2 << endl;

	
	
      TH1D h_yield_varBins_XiCharm( "h_yield_varBins_XiCharm", "Yield in variable bins of decay Time, with equal events per bin", xBins2.size()-1, vectorBranch_array );

      for(unsigned int iBin=0; iBin <= xBins2.size()-1; ++iBin)
	{
	  Fitter binFitter(configFiles, &massFitModel, GetVariables::getMass, "", &timeBinSelector);
开发者ID:MannyMoo,项目名称:baryon-lifetimes-run-I,代码行数:67,代码来源:Lambda_C_Mass_Fitter.C

示例4: MergeRootfile

void MergeRootfile(std::map<std::pair<std::string, std::string>, TObject*>& outputMap, std::vector<std::pair<std::string, TObject*> >& outputVec, TDirectory *target, TFile *source)
{
    using namespace std;
    string path(target->GetPath());
    path = path.substr(path.find(":") + 1);

    source->cd(path.c_str());
    TDirectory *current_sourcedir = gDirectory;
    //gain time, do not add the objects in the list in memory
    Bool_t status = TH1::AddDirectoryStatus();
    TH1::AddDirectory(kFALSE);

    // loop over all keys in this directory
    TIter nextkey( current_sourcedir->GetListOfKeys() );
    TKey *key, *oldkey = 0;
    while(key = (TKey*)nextkey())
    {
        //keep only the highest cycle number for each key
        if (oldkey && !strcmp(oldkey->GetName(), key->GetName())) continue;
        oldkey = key;

        // read object from source file
        source->cd(path.c_str());
        TObject *obj = key->ReadObj();

        if(obj->IsA()->InheritsFrom(TH1::Class()))
        {
            if(verbosity >= 4) 
            {
                printf("| Found TH1: %s\n", obj->GetName());
                fflush(stdout);
            }
            string path(target->GetPath());
            pair<string, string> okey(path.substr(path.find(':') + 2), obj->GetName());
            //cout << okey.first << "\t" << okey.second << endl;
            if(outputMap.find(okey) == outputMap.end())
            {
                outputVec.push_back(make_pair(path.substr(path.find(':') + 2), obj));
                outputMap[okey] = obj;
            }
            else
            {
                ((TH1*)outputMap[okey])->Add((TH1*)obj);
                ((TH1*)obj)->Delete();
            }
        }
        else if(obj->IsA()->InheritsFrom(TTree::Class()))
        {
            string path(target->GetPath());
            if(verbosity >= 4) 
            {
                printf("| Found Tree: %s\n", obj->GetName());
                fflush(stdout);
            }
            pair<string, string> okey(path.substr(path.find(':') + 2), obj->GetName());
            if(outputMap.find(okey) == outputMap.end())
            {
                string fname(okey.first);
                fname = fname + "_" + obj->GetName() + "tmpfile";
                for(size_t pos; (pos = fname.find('/')) != size_t(-1); ) fname[pos] = '_';
                tmpFiles.push_back(make_pair(fname, new TFile(fname.c_str(), "RECREATE")));
                TTree* tree = ((TTree*)obj)->CloneTree();
                ((TTree*)obj)->GetListOfClones()->Remove(tree);
                ((TTree*)obj)->ResetBranchAddresses();
                tree->ResetBranchAddresses();
                outputVec.push_back(make_pair(path.substr(path.find(':') + 2), (TObject*)tree));
                outputMap[okey] = (TObject*)tree;
            }
            else 
            {
                TTree* tm = (TTree*)outputMap[okey];
                TTree* ts = (TTree*)obj;
                tm->CopyAddresses(ts);
                for(int i = 0; i < ts->GetEntries(); i++)
                {
                    ts->GetEntry(i);
                    tm->Fill();
                }
                ts->ResetBranchAddresses();
                if (tm->GetTreeIndex()) tm->GetTreeIndex()->Append(ts->GetTreeIndex(), kTRUE); 
                ((TTree*)obj)->Delete();
            }
        }
        else if(obj->IsA()->InheritsFrom(TDirectory::Class()))
        {
            if(verbosity >= 3) 
            {
                printf("Hadding Directory: %s\n", ((TDirectory*)obj)->GetPath());
                fflush(stdout);
            }
            string path(((TDirectory*)obj)->GetPath());
            pair<string, string> okey(path.substr(path.find(':') + 2), " -------- ");
            if(outputMap.find(okey) == outputMap.end())
            {
                outputVec.push_back(make_pair(path.substr(path.find(':') + 2), (TDirectory*)0));
                outputMap[okey] = 0;
            }
            MergeRootfile(outputMap, outputVec, (TDirectory*)obj, source);
        }
        else
//.........这里部分代码省略.........
开发者ID:pastika,项目名称:jhadd,代码行数:101,代码来源:jhadd.cpp

示例5: read

void read(char *filename, char *friend_name)
{

   TFile *f = TFile::Open(filename, "update");
   // TFile *frnd_f = TFile::Open(friend_name, "recreate");

   if (!f) { return; }

   TTree *t; f->GetObject("RPVMCInfoTree",t);
   // TTree *frnd_t = new TTree("RPVMCFriend","Track matching tree");

   // jetroimatched
   std::vector<int> *jrmV = 0;
   TBranch *jrmB = 0;
   t->SetBranchAddress("jetroimatched", &jrmV, &jrmB);
   
   // track2roi_index
   std::vector<int> *track2roiV = 0;
   TBranch *track2roiB = 0;
   t->SetBranchAddress("tracktoroi_index", &track2roiV, &track2roiB);
   
   // track_d0 (just to see the length of it)
   std::vector<float> *track_d0V = 0;
   TBranch *track_d0B = 0;
   t->SetBranchAddress("track_d0", &track_d0V, &track_d0B);
   
   // track_matched - new branch
   std::vector<int> *track_matchedV = 0;
   TBranch *track_matchedB = t->Branch("track_matched", &track_matchedV);

   for (Int_t i = 0; i < 1; i++) {
      Long64_t event = t->LoadTree(i);

      jrmB->GetEntry(event);
      track2roiB->GetEntry(event);
      track_d0B->GetEntry(event);

      UInt_t roi_ind;
      for (roi_ind = 0; roi_ind < jrmV->size() - 1; ++roi_ind) {
         int tracksInRoi = track2roiV->at(roi_ind + 1) - track2roiV->at(roi_ind);
         printf("%d\n", tracksInRoi);
         for (int track_ind = 0; track_ind < tracksInRoi; track_ind++) {
            track_matchedV->push_back(jrmV->at(roi_ind));
         }
      }

      // handle last roi seperately
      for (int track_ind = 0; track_ind < track_d0V->size() - track2roiV->at(roi_ind); track_ind++) {
         track_matchedV->push_back(jrmV->at(roi_ind));
      }

      track_matchedB.Fill();
   }

   // Since we passed the address of a local variable we need
   // to remove it.
   t->Write();
   t->ResetBranchAddresses();
   f->Close();
   // frnd_f->cd();
   // frnd_t->Write();
   // frnd_f->Close();
}
开发者ID:orbegam,项目名称:TriggerDV,代码行数:63,代码来源:track_labeling.c


注:本文中的TTree::ResetBranchAddresses方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。