本文整理汇总了C++中TBranch::GetListOfLeaves方法的典型用法代码示例。如果您正苦于以下问题:C++ TBranch::GetListOfLeaves方法的具体用法?C++ TBranch::GetListOfLeaves怎么用?C++ TBranch::GetListOfLeaves使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBranch
的用法示例。
在下文中一共展示了TBranch::GetListOfLeaves方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getlist
void getlist(ostream& out, TBranch* branch, int depth=0)
{
TObjArray* array = branch->GetListOfBranches();
if ( ! array ) return;
if ( depth > 10 ) return;
string name;
int nitems = array->GetEntries();
for (int i = 0; i < nitems; i++)
{
TBranch* b = (TBranch*)((*array)[i]);
if ( ! b ) continue;
string branchname(b->GetName());
out << SPACE.substr(0,4*depth) << branchname << endl;
TObjArray* a = b->GetListOfLeaves();
if ( a )
{
int n = a->GetEntries();
{
for (int j = 0; j < n; j++)
{
TLeaf* leaf = (TLeaf*)((*a)[j]);
int count = 0;
int ndata = 0;
TLeaf* leafc = leaf->GetLeafCounter(count);
if ( ! leafc)
ndata = leaf->GetLen();
else
ndata = leafc->GetMaximum();
string leafname(leaf->GetName());
out << SPACE.substr(0,4*(depth+1))
<< ndata << " " << leafname << endl;
}
}
// else if ( n == 1 )
// {
// TBranch* bc = (TBranch*)((*a)[j]);
// string leafname(bc->GetName());
// if ( leafname != branchname )
// out << SPACE.substr(0,4*(depth+1)) << leafname << endl;
// }
}
getlist(out, b, depth+1);
}
}
示例2: 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;
}
}
示例3: verifyBranch
template <class HolderClass> bool verifyBranch(const char *testname, TTree *chain, const char *bname, int type = 0) {
static HolderClass *gHolder = new HolderClass;
HolderClass **add = 0;
HolderClass *holder = 0;
TBranch *branch = chain->GetBranch(bname);
if (branch==0) {
TestError("treeReading",Form("Missing branch: %s",bname));
return false;
}
if (branch->InheritsFrom("TBranchObject")) {
TLeafObject *tbo = dynamic_cast<TLeafObject*>(branch->GetListOfLeaves()->At(0));
holder = (HolderClass*)(tbo->GetObject());
if (holder==0) {
TestError("treeReading",Form("BranchObject %s with holder == 0!",bname));
return false;
}
} else {
add = (HolderClass**)branch->GetAddress();
if (add==0) {
TestError("treeReading",Form("Branch %s with add == 0!",bname));
return false;
}
void **p;
switch (type) {
case 0: holder = *add; break;
case 1: p = (void**) &(gHolder->fScalarPtr); *p = ((TBranchElement*)branch)->GetObject(); break;
case 2: p = (void**) &(gHolder->fObjectPtr); *p = ((TBranchElement*)branch)->GetObject(); break;
case 3: p = (void**) &(gHolder->fNestedPtr); *p = ((TBranchElement*)branch)->GetObject(); break;
}
}
int splitlevel = branch->GetSplitLevel();
switch (type) {
case 0: return holder->Verify(chain->GetTree()->GetReadEntry(),Form("%s %s",testname,bname),splitlevel);
case 1: return gHolder->VerifyScalarPtr(chain->GetTree()->GetReadEntry(),Form("%s %s",testname,bname),splitlevel);
case 2: return gHolder->VerifyObjectPtr(chain->GetTree()->GetReadEntry(),Form("%s %s",testname,bname),splitlevel);
case 3: return gHolder->VerifyNestedPtr(chain->GetTree()->GetReadEntry(),Form("%s %s",testname,bname),splitlevel);
default:
TestError("treeReading",Form("Unknown type %d in verifyBranch",type));
return false;
}
}
示例4: main
int main(int argc, char** argv){
// RETRIEVING LIST OF FILENAMES TO CHECK
if (argc != 3) {
cout << "Usage: ./TopTreeContentDump --inputfiles file1;file2;fileN\n\n" << endl;
exit(0);
} else if (argc == 3 && !strstr(argv[1],"--inputfiles")) {
cout << "Usage: ./TopTreeContentDump --inputfiles file1;file2;fileN\n\n" << endl;
exit(0);
}
vector<string> fileNames;
Tokenize(argv[2], fileNames, ";");
// CHECKING THE FILECONTENT FOR FILE 0 AND COUNT EVENTS FOR ALL FILES
unsigned int nEvents = 0;
for (int fileID=0; fileID < fileNames.size(); fileID++) {
//cout << fileNames.at(fileID) << endl;
TFile* f = TFile::Open(fileNames.at(fileID).c_str());
TTree* runTree = (TTree*) f->Get("runTree");
TTree* eventTree = (TTree*) f->Get("eventTree");
TBranch* run_br = (TBranch *) runTree->GetBranch("runInfos");
TRootRun* runInfos = 0;
run_br->SetAddress(&runInfos);
TBranch* event_br = (TBranch *) eventTree->GetBranch("Event");
TRootEvent* event = 0;
event_br->SetAddress(&event);
nEvents += eventTree->GetEntriesFast();
if (fileID == 0) {
cout << "* Dumping the event content of the TopTree" << endl;
for (int i=1; i<eventTree->GetListOfBranches()->GetEntriesFast(); i++) {
TBranch * branch = (TBranch *)eventTree->GetListOfBranches()->At(i);
TObject* obj = branch->GetListOfLeaves()->At(0);
std::string ObjName = obj->GetName();
string::size_type position = ObjName.find_last_of("_");
std::string className = "";
if (strstr(ObjName.c_str(),"CaloJet"))
className="TopTree::TRootCaloJet";
else if (strstr(ObjName.c_str(),"PFJet"))
className="TopTree::TRootPFJet";
else if (strstr(ObjName.c_str(),"JPTJet"))
className="TopTree::TRootJPTJet";
else if (strstr(ObjName.c_str(),"GenJet"))
className="TopTree::TRootGenJet";
else if (strstr(ObjName.c_str(),"MCParticles"))
className="TopTree::TRootMCParticle";
else if (strstr(ObjName.c_str(),"NPGenEvent"))
className="TopTree::TRootNPGenEvent";
else if (strstr(ObjName.c_str(),"GenEvent"))
className="TopTree::TRootGenEvent";
else if (strstr(ObjName.c_str(),"Muon"))
className="TopTree::TRootMuon";
else if (strstr(ObjName.c_str(),"Electron"))
className="TopTree::TRootElectron";
else if (strstr(ObjName.c_str(),"TCMET"))
className="TopTree::TRootMET";
else if (strstr(ObjName.c_str(),"CaloMET"))
className="TopTree::TRootCaloMET";
else if (strstr(ObjName.c_str(),"PFMET"))
className="TopTree::TRootPFMET";
else if (strstr(ObjName.c_str(),"MET"))
className="TopTree::TRootMET";
else if (strstr(ObjName.c_str(), "TrackMET"))
className="TopTree::TRootTrackMET";
else if (strstr(ObjName.c_str(),"MHT"))
className="TopTree::TRootMHT";
else if (strstr(ObjName.c_str(),"PrimaryVertex"))
className="TopTree::TRootVertex";
cout << "- " << className << setw(5) << " -> " << "\"" << ObjName.substr(0,position) << "\"" << endl;
}
//.........这里部分代码省略.........
示例5: 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;
//.........这里部分代码省略.........