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


C++ TLeaf::GetTypeName方法代码示例

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


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

示例1: dump_required_lvl2

void dump_required_lvl2(TTree *tree, TLeaf &leaf, CodedOutputStream &o, CodedOutputStream &o2) {
    const int DL = 1; // definition level multiplier
    const int RL = 4; // repetition level multiplier

    std::cout << "Dump vector vector: " << leaf.GetName() << " " << leaf.GetTypeName() << std::endl;
    auto * branch = leaf.GetBranch();

    std::vector<std::vector<T> > * data = NULL;
    tree->SetBranchAddress(leaf.GetBranch()->GetName(), &data);
    int entries = tree->GetEntries();
    for (int i = 0; i < entries; i++) { 
        branch->GetEntry(i);
        if (data->size() == 0) {
            write_out_32(o2, DL*0 + RL*0);
        }
        for (int j = 0; j < data->size(); j++) {
            if (data->at(j).size() == 0) {
                int dl = 1;
                int rl = (j > 0 ? 1 : 0);
                write_out_32(o2, dl*DL + rl*RL);
            }
            for (int k = 0; k < data->at(j).size(); k++) {
                int dl = 2;
                int rl = (k > 0 ? 2 : (j > 0 ? 1 : 0));
                write_out_32(o2, dl*DL + rl*RL);
                write_out_type(o, data->at(j).at(k));
            }
        }
    }
}
开发者ID:pwaller,项目名称:drillbit,代码行数:30,代码来源:root2stripes.cpp

示例2:

// This piece of code is borrowed from Argo written by Nathaniel Tagg
std::vector<std::string> DataFetcher::FindLeavesOfType(std::string pattern) {
  /// Look in the tree and try to find a leaf element that matches 'pattern'.
  /// Return the full name of that leaf.
  std::vector<std::string> leaf_names;

  // Strip whitespace from pattern.
  pattern.erase(std::remove_if(pattern.begin(), pattern.end(), ::isspace),
      pattern.end());

  TObjArray * list = tree_->GetListOfLeaves();
  for (int i = 0; i < list->GetEntriesFast(); ++i) {
    TObject * o = list->At(i);
    TLeaf * leaf = (TLeaf *) o;
    std::string name = leaf->GetTypeName();
    // Strip whitespace from pattern.
    name.erase(std::remove_if(name.begin(), name.end(), ::isspace),
        name.end());
    size_t found = name.find(pattern);
    if (found != std::string::npos) {
      // Return this match.
      leaf_names.push_back(leaf->GetName());
    }
  }
  return leaf_names;
}
开发者ID:lar1nd,项目名称:lar1evd,代码行数:26,代码来源:DataFetcher.cpp

示例3: SetBranchAddressToHolder

void GAInputTreeData::SetBranchAddressToHolder(string branch_name){
    if(!fTTree->GetBranch(branch_name.c_str())){
        cout << "[GAInputTreeData-E]: branch " << branch_name << 
                " is not found";
        throw 1;
    }
    fBranchName.push_back(branch_name);
    TLeaf *leaf = fTTree->GetBranch(branch_name.c_str())
        ->GetLeaf(branch_name.c_str());
    Int_t n_data = leaf->GetNdata();
    string type_name = leaf->GetTypeName();
    fEventDataHolderManager->AddDetector(type_name,branch_name, n_data);
}
开发者ID:YJabberwocKy,项目名称:testganaroot,代码行数:13,代码来源:GAInputTreeData.cpp

示例4: SetAllBranches

void GAInputTreeData::SetAllBranches(){
    TObjArray* ArrayOfBranches = fTTree->GetListOfBranches();
    Int_t n_branch = ArrayOfBranches->GetEntries();
    cout << "[GAInputTreeData-M]:Loading " << n_branch << " branches from "
        << fTTree->GetName() << endl;
    for(int i_branch=0; i_branch<n_branch; i_branch++){
        TBranch* Branch = (TBranch*)ArrayOfBranches->At(i_branch);
        string branch_name = Branch->GetName();
        TLeaf *leaf = (TLeaf*)Branch->GetListOfLeaves()->At(0);//(branch_name.c_str());
        Int_t n_data = leaf->GetNdata();
        string type_name = leaf->GetTypeName();
        fBranchName.push_back(branch_name);
        fEventDataHolderManager->AddDetector(type_name, branch_name, n_data);
        cout << "[GAInputTreeData-M]:Loading branch " << branch_name
            << " (" << type_name << "[" << n_data << "])" << endl;
    }
}
开发者ID:YJabberwocKy,项目名称:testganaroot,代码行数:17,代码来源:GAInputTreeData.cpp

示例5: ProcessFilePar

//std::mutex mtx;
void ProcessFilePar(TString fileIn, TString fileOut, TString treename,  vector<TString> friends, vector<TString> branches, vector<TString> newbranches, unsigned jobid = 0, unsigned NPAR = 1)
{
  //mtx.lock(); //for threads
  TFile *fin = new TFile(fileIn);
  TTree *tjet = (TTree*)fin->Get(treename);
  //mtx.unlock();

  vector<TTree *> friendTrees;
  vector<bool> sameFileFriend;
  for (auto f:friends) {
    auto fr = tokenize(f,":");
    if (fr.size()==1) {tjet->AddFriend(fr[0]); sameFileFriend.push_back(true);}
    else if (fr.size()==2) {tjet->AddFriend(fr[1],fr[0]); sameFileFriend.push_back(false);}

    TTree *tfriend = (TTree*)fin->Get(f);
    friendTrees.push_back(tfriend);
  }

  AddBranchesByCounter(tjet, branches);
  for (unsigned i=0;i<friendTrees.size();i++) AddBranchesByCounter(friendTrees[i],branches);

  //sort branches into categories
  for (auto bName:branches) {
    TBranch *b=tjet->GetBranch(bName);
    if (b==0) cout <<"Branch "<<bName<<" doesn't exist!"<<endl;

    //parse in case there is a tree name in the branch
    auto branchtoken = tokenize(bName,".");
    auto leafname = branchtoken[branchtoken.size()-1];

    TObjArray *bl = b->GetListOfLeaves();
    if (bl->GetEntries()>1)
      cout <<" Branch "<<b->GetTitle()<<" has more than 1 leave. Taking first..."<<endl;
    if (bl->GetEntries()==0) {
      cout <<" Branch "<<b->GetTitle()<<" has no leaves! Skipping..."<<endl;
      continue;
    }

    TLeaf * l = (TLeaf *)(*bl)[0];
    //what's the type?
    TString type = l->GetTypeName();
    if (VERBOSE) cout<<l->GetTitle()<<endl;

    //array?
    bool array = l->GetLeafCount()!=0;
    TString counter;
    if (array) counter = l->GetLeafCount()->GetBranch()->GetName();

    if (type=="Float_t")
      {  if (array) {brVFloat.push_back(bName); brVFloatCounter.push_back(counter); }else brFloat.push_back(bName);}
    else if (type=="Int_t")
      {  if (array) {brVInt.push_back(bName); brVIntCounter.push_back(counter); }else brInt.push_back(bName);}
    else cout << "Unsupported branch type "<<type<<" for branch "<<bName<<". Skipping..."<<endl;
  }


  //treat counters as ints only
  AppendToListUniquely(brVIntCounter, brInt);
  AppendToListUniquely(brVFloatCounter, brInt);

  //too keep track of old branches, which cannot be read (todo: just check it...)
  int noldbrInt = brInt.size(), noldbrFloat = brFloat.size(), noldbrVInt = brVInt.size(), noldbrVIntCounter = brVIntCounter.size(), noldbrVFloat = brVFloat.size(), noldbrVFloatCounter = brVFloatCounter.size();
  //add new branches
  ParseNewBranches(newbranches, brInt, brFloat, brVInt, brVIntCounter, brVFloat, brVFloatCounter);

  //print for debugging
  if (VERBOSE) {
    cout<<"int       : "; for (auto s:brInt) cout <<s<<", "; cout<<endl;
    cout<<"float     : "; for (auto s:brFloat) cout <<s<<", "; cout<<endl;
    cout<<"Vint      : "; for (auto s:brVInt) cout <<s<<", "; cout<<endl;
    cout<<"Vfloat    : "; for (auto s:brVFloat) cout <<s<<", "; cout<<endl;
    cout<<"Vintcnt   : "; for (auto s:brVIntCounter) cout <<s<<", "; cout<<endl;
    cout<<"Vfloatcnt : "; for (auto s:brVFloatCounter) cout <<s<<", "; cout<<endl;
  }

  tjet->SetBranchStatus("*",1);
  for (auto b:brVFloat) if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,0);
  for (auto b:brFloat)  if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,0);
  for (auto b:brVInt)   if (tjet->GetBranch(b)!=0) tjet->SetBranchStatus(b,0);
  for (auto b:brInt)    if (tjet->GetBranch(b)!=0) {unsigned f=0; tjet->SetBranchStatus(b,0,&f); if (VERBOSE) cout<<"turning off "<<b<<", found = "<<f<<endl;}


  TFile *fout = new TFile(fileOut,"recreate");
  TTree *tjetout;


  //in case of one-to-many event - do not copy branches automatically!
  if (useOneToOne) tjetout = tjet->CloneTree(0);
  else tjetout = new TTree(tjet->GetName(),tjet->GetTitle());


  //think about memory tree
  // tjetout->SetDirectory(0);
  tjetout->SetName(tjet->GetName());
  //TTree *tjetout = new TTree("t","t");

  //to see what is copied...
  //tjetout->Print();

//.........这里部分代码省略.........
开发者ID:istaslis,项目名称:pPbmacro,代码行数:101,代码来源:HelperProcess.C

示例6: dump_tree

void dump_tree(TTree *tree, const char *outdir) {
    GzipOutputStream::Options options;
    options.compression_level = 1;

    for(int li = 0; li < tree->GetListOfLeaves()->GetEntries(); li++) {
        TLeaf *l = (TLeaf*) tree->GetListOfLeaves()->At(li);

        if (lstat(outdir, NULL) == -1) {
            mkdir(outdir, 0777);
        }

        // Open data file
        std::string fn = std::string(outdir) + "/" + l->GetName() + ".dit";
        auto fd = open(fn.c_str(), O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
        assert(fd != -1);
        FileOutputStream fstream(fd);
        GzipOutputStream zstream(&fstream, options);


        // Open meta file
        std::string mfn = fn + "m";
        auto mfd = open(mfn.c_str(), O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
        assert(mfd != -1);
        FileOutputStream meta_fstream(mfd);
        GzipOutputStream meta_zstream(&meta_fstream, options);
        { // Coded stream block 
            CodedOutputStream o(&zstream);
            CodedOutputStream o2(&meta_zstream);

            // determine level and type name
            int level = 0;
            std::string tn = l->GetTypeName();
            while (tn.substr(0,6) == "vector") {
                level = level + 1;
                tn = remove_vector(tn);
            }

            if (tn == "double") {
                dump_required<double>(level, tree, *l, o, o2);
            } else if (tn == "float") {
                dump_required<float>(level, tree, *l, o, o2);
            } else if (tn == "int") {
                dump_required<int>(level, tree, *l, o, o2);
            } else if (tn == "short" || tn == "Short_t") {
                dump_required<short>(level, tree, *l, o, o2);
            } else if (tn == "unsigned int") {
                dump_required<unsigned int>(level, tree, *l, o, o2);
            } else if (tn == "unsigned short") {
                dump_required<unsigned short>(level, tree, *l, o, o2);
            } else if (tn == "Float_t") {
                dump_required<Float_t>(level, tree, *l, o, o2);
            } else if (tn == "Bool_t") {
                dump_required<Bool_t>(level, tree, *l, o, o2);
            } else if (tn == "Char_t") {
                dump_required<Char_t>(level, tree, *l, o, o2);
            } else if (tn == "Double_t") {
                dump_required<Double_t>(level, tree, *l, o, o2);
            } else if (tn == "Int_t") {
                dump_required<Int_t>(level, tree, *l, o, o2);
            } else if (tn == "UInt_t") {
                dump_required<UInt_t>(level, tree, *l, o, o2);
            } else if (tn == "string") {
                dump_required<std::string>(level, tree, *l, o, o2);
            } else {
                std::cerr << "Unknown branch type: " << tn << std::endl;
                assert(false);
            }
        }
        meta_zstream.Close();
        zstream.Close();
        meta_fstream.Close();
        fstream.Close();
    }
}
开发者ID:pwaller,项目名称:drillbit,代码行数:74,代码来源:root2stripes.cpp

示例7: Initialize

bool TreeReader::Initialize(vector <string> br, string opt)
{
	if(!init)
	{
	    if( !fChain )
		{
		        cout << endl;
			cout << "No tree to initialize" << endl;
			cout << endl;
			return false;
		}

		TObjArray *fileElements = fChain->GetListOfFiles();
		if( !fileElements || ( fileElements->GetEntries() == 0 ))
		{
		        cout << endl;
			cout << "No file(s) to initialize" << endl;
			cout << endl;
			return false;
		}
	}

	varList.clear();

	TObjArray* branches = fChain->GetListOfBranches();
	int nBranches = branches->GetEntries();

	for (int i = 0; i < nBranches; ++i)
	{
		TBranch* branch = (TBranch*)branches->At(i);
		string brname = branch->GetName();
		TLeaf* leaf = branch->GetLeaf(branch->GetName());

		if ( leaf == 0 )  // leaf name is different from branch name
		{
			TObjArray* leafs = branch->GetListOfLeaves();
			leaf = (TLeaf*)leafs->At(0);
		}

		string curtype = leaf->GetTypeName();
        int id = TypeDB::getType(curtype.c_str());
		int arreysize = 1;
		string title = leaf->GetTitle();
        //cout << curtype << "   " << title << endl;

		// Find out whether we have array by inspecting leaf title
		if ( title.find("[")!=std::string::npos )
		{
			TLeaf * nelem = leaf->GetLeafCounter(arreysize);
			if(arreysize == 1 && nelem != NULL) arreysize = nelem->GetMaximum() + 1; //search for maximum value of the lenght
		}


		if(id >= 0)
		{
			bool addVar = true;
			if(br.size()>0)
			{
				addVar = false;
				for(unsigned b = 0; b < br.size(); b++)
				{
					if(opt == "names" || opt == "except")
					{
						if(br[b] == brname) { addVar = true; break;}
					}
					else if(opt.find("contains")!=string::npos)
					{
						if((string(brname)).find(br[b])!=string::npos) { addVar = true; break;}
					}
					else if(opt.find("except")==string::npos) cout << "Option " << opt << " not found" << endl;
				}

				if(opt.find("except")!=string::npos) addVar = !addVar;
			}

			if(addVar)
			{
				variable * tmpVar = new variable(id,arreysize);

				tmpVar->name = leaf->GetName();
				tmpVar->bname = branch->GetName();
				tmpVar->title = title;

				varList.push_back(tmpVar);
				fChain->SetBranchAddress(tmpVar->bname,tmpVar->value.address);
			}
		}
		else
		{
			cout << curtype << ": type not found" << endl;
			exit(1);
			return false;
		}
	}

	init = true;
	continueSorting = true;
	if(pmode=="v") cout << endl << "Set up " << varList.size() << " / " << nBranches << " branches" << endl;

	return true;
//.........这里部分代码省略.........
开发者ID:Williams224,项目名称:AnalysisTools,代码行数:101,代码来源:ReadTree_comp.cpp

示例8: execute

bool execute(const std::string& skeleton, const std::string& config_file, std::string output_dir/* = ""*/) {

    std::vector<Plot> plots;
    // If an output directory is specified, use it, otherwise use the current directory
    if (output_dir == "")
      output_dir = ".";

    std::map<std::string, std::string> unique_names;

    get_plots(config_file, plots);

    std::cout << "List of requested plots: ";
    for (size_t i = 0; i < plots.size(); i++) {
        std::cout << "'" << plots[i].name << "'";
        if (i != plots.size() - 1)
            std::cout << ", ";
    }
    std::cout << std::endl;

    // Convert plots name to unique name to avoid collision between different runs
    for (Plot& plot: plots) {
        std::string uuid = get_uuid();
        unique_names[uuid] = plot.name;
        plot.name = uuid;
    }

    std::unique_ptr<TChain> t(new TChain("t"));
    t->Add(skeleton.c_str());

    std::vector<Branch> branches;
    std::function<void(TTreeFormula*)> getBranches = [&branches, &getBranches](TTreeFormula* f) {
        if (!f)
            return;

        for (size_t i = 0; i < f->GetNcodes(); i++) {
            TLeaf* leaf = f->GetLeaf(i);
            if (! leaf)
                continue;

            TBranch* p_branch = getTopBranch(leaf->GetBranch());

            Branch branch;
            branch.name = p_branch->GetName();
            if (std::find_if(branches.begin(), branches.end(), [&branch](const Branch& b) {  return b.name == branch.name;  }) == branches.end()) {
                branch.type = p_branch->GetClassName();
                if (branch.type.empty())
                    branch.type = leaf->GetTypeName();

                branches.push_back(branch);
            }

            for (size_t j = 0; j < f->fNdimensions[i]; j++) {
                if (f->fVarIndexes[i][j])
                    getBranches(f->fVarIndexes[i][j]);
            }
        }

        for (size_t i = 0; i < f->fAliases.GetEntriesFast(); i++) {
            getBranches((TTreeFormula*) f->fAliases.UncheckedAt(i));
        }
    };

    std::string hists_declaration;
    std::string text_plots;
    for (auto& p: plots) {
        // Create formulas
        std::shared_ptr<TTreeFormula> selector(new TTreeFormula("selector", p.plot_cut.c_str(), t.get()));

        getBranches(selector.get());

        std::vector<std::string> splitted_variables = split(p.variable, ":");
        for (const std::string& variable: splitted_variables) {
            std::shared_ptr<TTreeFormula> var(new TTreeFormula("var", variable.c_str(), t.get()));
            getBranches(var.get());
        }

        std::string binning = p.binning;
        binning.erase(std::remove_if(binning.begin(), binning.end(), [](char chr) { return chr == '(' || chr == ')'; }), binning.end());

        // If a variable bin size is specified, declare array that will be passed as array to histogram constructor
        if(binning.find("{") != std::string::npos){
          std::string arrayString = buildArrayForVariableBinning(binning, splitted_variables.size(), p.name);
          hists_declaration += arrayString;
        }

        std::string title = p.title + ";" + p.x_axis + ";" + p.y_axis + ";" + p.z_axis;
        std::string histogram_type = getHistogramTypeForDimension(splitted_variables.size());

        hists_declaration += "    std::unique_ptr<" + histogram_type + "> " + p.name + "(new " + histogram_type + "(\"" + p.name + "\", \"" + title + "\", " + binning + ")); " + p.name + "->SetDirectory(nullptr);\n";
 
        std::string variable_string;
        for (size_t i = 0; i < splitted_variables.size(); i++) {
            variable_string += splitted_variables[i];
            if (i != splitted_variables.size() - 1)
                variable_string += ", ";
        }

        ctemplate::TemplateDictionary plot("plot");
        plot.SetValue("CUT", p.plot_cut);
        plot.SetValue("VAR", variable_string);
//.........这里部分代码省略.........
开发者ID:sdevissc,项目名称:CommonTools,代码行数:101,代码来源:createPlotter.cpp

示例9: ensure_dictionaries

// Generate dictionaries required to read `tree`.
void ensure_dictionaries(TTree *tree) {
    for (int li = 0; li < tree->GetListOfLeaves()->GetEntries(); li++) {
        TLeaf *l = (TLeaf*) tree->GetListOfLeaves()->At(li);
        ensure_dictionary(l->GetTypeName());
    }
}
开发者ID:ndawe,项目名称:drillbit,代码行数:7,代码来源:root_dictionaries.cpp


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