本文整理汇总了C++中TBranch::GetClassName方法的典型用法代码示例。如果您正苦于以下问题:C++ TBranch::GetClassName方法的具体用法?C++ TBranch::GetClassName怎么用?C++ TBranch::GetClassName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TBranch
的用法示例。
在下文中一共展示了TBranch::GetClassName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
/// Load the specified event
Int_t DDG4EventHandler::ReadEvent(Long64_t event_number) {
m_data.clear();
m_hasEvent = false;
if ( hasFile() ) {
if ( event_number >= m_file.second->GetEntries() ) {
event_number = m_file.second->GetEntries()-1;
printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Cannot read across End-of-file! Reading last event:%d.",event_number);
}
else if ( event_number < 0 ) {
event_number = 0;
printout(ERROR,"DDG4EventHandler","+++ nextEvent: Cannot read across Start-of-file! Reading first event:%d.",event_number);
}
Int_t nbytes = m_file.second->GetEntry(event_number);
if ( nbytes >= 0 ) {
printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Read %d bytes of event data for entry:%d",nbytes,event_number);
for(Branches::const_iterator i=m_branches.begin(); i != m_branches.end(); ++i) {
TBranch* b = (*i).second.first;
std::vector<void*>* ptr_data = *(std::vector<void*>**)b->GetAddress();
m_data[b->GetClassName()].push_back(make_pair(b->GetName(),ptr_data->size()));
}
m_hasEvent = true;
return nbytes;
}
printout(ERROR,"DDG4EventHandler","+++ ReadEvent: Cannot read event data for entry:%d",event_number);
throw runtime_error("+++ EventHandler::readEvent: Failed to read event");
}
throw runtime_error("+++ EventHandler::readEvent: No file open!");
}
示例2: dumpDDG4
int dumpDDG4(const char* fname, int event_num) {
TFile* data = TFile::Open(fname);
if ( !data || data->IsZombie() ) {
printf("+ File seems to not exist. Exiting\n");
usage();
return -1;
}
TTree* tree = (TTree*)data->Get("EVENT");
for(int event=0, num=tree->GetEntries(); event<num; ++event) {
TObjArray* arr = tree->GetListOfBranches();
if ( event_num>= 0 ) event = event_num;
for(int j=0, nj=arr->GetEntries(); j<nj; ++j) {
TBranch* b = (TBranch*)arr->At(j);
typedef vector<void*> _E;
_E* e = 0;
b->SetAddress(&e);
int nbytes = b->GetEvent(event);
if ( nbytes > 0 ) {
if ( e->empty() ) {
continue;
}
string br_name = b->GetName();
string cl_name = b->GetClassName();
if ( cl_name.find("dd4hep::sim::Geant4Tracker::Hit") != string::npos ) {
typedef vector<Geant4Tracker::Hit*> _H;
printHits(br_name,(_H*)e);
}
else if ( cl_name.find("dd4hep::sim::Geant4Calorimeter::Hit") != string::npos ) {
typedef vector<Geant4Calorimeter::Hit*> _H;
printHits(br_name,(_H*)e);
}
else if ( cl_name.find("dd4hep::sim::Geant4Particle") != string::npos ) {
typedef vector<Geant4Particle*> _H;
::printf("%s\n+ Particle Dump of event %8d [%8d bytes] +\n%s\n",
line,event,nbytes,line);
printParticles(br_name,(_H*)e);
}
}
}
if ( event_num >= 0 ) break;
}
delete data;
return 0;
}
示例3: makeHeaderFile
//-------------------------------------------------------------------------------------------------
void makeHeaderFile(TFile *f, const string& treeName, bool paranoid, const string& Classname, const string& nameSpace, const string& objName) {
headerf << "// -*- C++ -*-" << endl;
headerf << "#ifndef " << Classname << "_H" << endl;
headerf << "#define " << Classname << "_H" << endl;
headerf << "#include \"Math/LorentzVector.h\"" << endl;
headerf << "#include \"Math/Point3D.h\"" << endl;
headerf << "#include \"TMath.h\"" << endl;
headerf << "#include \"TBranch.h\"" << endl;
headerf << "#include \"TTree.h\"" << endl;
headerf << "#include \"TH1F.h\"" << endl;
headerf << "#include \"TFile.h\"" << endl;
headerf << "#include \"TBits.h\"" << endl;
headerf << "#include <vector>" << endl;
headerf << "#include <unistd.h>" << endl;
headerf << "typedef ROOT::Math::LorentzVector<ROOT::Math::PxPyPzE4D<float> > LorentzVector;" << endl << endl;
if (paranoid)
headerf << "#define PARANOIA" << endl << endl;
headerf << "using namespace std; " << endl;
headerf << "class " << Classname << " {" << endl;
headerf << "private: " << endl;
headerf << "protected: " << endl;
headerf << "\tunsigned int index;" << endl;
// TTree *ev = (TTree*)f->Get("Events");
TList* list_of_keys = f->GetListOfKeys();
std::string tree_name = "";
if (treeName.empty()) {
unsigned int ntrees = 0;
for (unsigned int idx = 0; idx < (unsigned int)list_of_keys->GetSize(); idx++) {
const char* obj_name = list_of_keys->At(idx)->GetName();
TObject* obj = f->Get(obj_name);
if (obj->InheritsFrom("TTree")) {
++ntrees;
tree_name = obj_name;
}
}
if (ntrees == 0) {
std::cout << "Did not find a tree. Exiting." << std::endl;
return;
}
if (ntrees > 1) {
std::cout << "Found more than one tree. Please specify a tree to use." << std::endl;
return;
}
}
else
tree_name = treeName;
TTree *ev = (TTree*)f->Get(tree_name.c_str());
TSeqCollection *fullarray = ev->GetListOfAliases();
bool have_aliases = true;
if (!fullarray) {
have_aliases = false;
fullarray = ev->GetListOfBranches();
}
// if (have_aliases && fullarray->GetSize() != ev->GetListOfBranches()->GetSize()) {
// std::cout << "Tree has " << fullarray->GetSize() << " aliases and " << ev->GetListOfBranches()->GetSize() << " branches. Exiting." << std::endl;
// return;
// }
TList *aliasarray = new TList();
for(Int_t i = 0; i < fullarray->GetEntries(); ++i) {
TString aliasname(fullarray->At(i)->GetName());
// TBranch *branch = ev->GetBranch(ev->GetAlias(aliasname.Data()));
TBranch *branch = 0;
if (have_aliases)
branch = ev->GetBranch(ev->GetAlias(aliasname.Data()));
else
branch = (TBranch*)fullarray->At(i);
TString branchname(branch->GetName());
TString branchtitle(branch->GetTitle());
TString branchclass(branch->GetClassName());
if(!branchname.BeginsWith("int") &&
!branchname.BeginsWith("uint") &&
!branchname.BeginsWith("bool") &&
!branchname.BeginsWith("float") &&
!branchname.BeginsWith("double") &&
!branchtitle.EndsWith("/F") &&
!branchtitle.EndsWith("/I") &&
!branchtitle.EndsWith("/i") &&
!branchtitle.EndsWith("/O") &&
!branchtitle.BeginsWith("TString") &&
!branchtitle.BeginsWith("TBits") &&
!branchclass.Contains("LorentzVector") &&
!branchclass.Contains("int") &&
!branchclass.Contains("uint") &&
!branchclass.Contains("bool") &&
!branchclass.Contains("float") &&
!branchclass.Contains("double") &&
!branchclass.Contains("TString"))
continue;
// if (branchclass.Contains("TString"))
//.........这里部分代码省略.........
示例4: qaitsAddMetadata
//.........这里部分代码省略.........
regCategory[2]=TPRegexp("pt[0-9]+"); // pt bin
for (Int_t ibr=0; ibr<branches->GetEntriesFast(); ibr++){
TBranch * branch = (TBranch*)branches->At(ibr);
TString matchClass=""; // class match
TString brClass="";
TString brAxisTitle="";
TString brTitle="";
TString brLegend="";
//
TString brNameCase(branches->At(ibr)->GetName());
brNameCase.ToLower();
//
// define met
brClass="ITS";
brAxisTitle="";
// stat
for (Int_t ivar=0; ivar<11; ivar++) if (brNameCase.Contains( regStat[ivar])) {
brClass+=" "+statClass[ivar];
brTitle+=statTitle[ivar];
}
// kine variables
for (Int_t ivar=0; ivar<7; ivar++) if (brNameCase.Contains( regKineVariables[ivar])) {
brClass+=" "+kineVariableClass[ivar];
brAxisTitle+=" "+kineVariableAxisTitle[ivar];
brTitle+=" "+kineVariableTitle[ivar];
brLegend+=" "+kineVariableLegend[ivar];
}
// QA variables
for (Int_t ivar=0; ivar<5; ivar++) if (brNameCase.Contains( regQAVariable[ivar])) {
if ( qaVariableClass[ivar].Contains("$")==kFALSE){
brClass+=" "+ qaVariableClass[ivar];
brLegend+=" "+ qaVariableLegend[ivar];
brTitle+=" "+ qaVariableTitle[ivar];
}else{
TObjArray *amatch=regQAVariable[ivar].MatchS(brNameCase);
if (amatch){
TString match=amatch->At(0)->GetName();
brClass+=" "+match;
brLegend+=" "+match;
brTitle+=" "+match;
}
}
}
// category
for (Int_t ivar=0; ivar<3; ivar++) if (brNameCase.Contains(regCategory[ivar])) {
if (categoryClass[ivar].Contains("$")==kFALSE){
brClass+=" "+categoryClass[ivar];
brLegend+=" "+categoryLegend[ivar];
brTitle+=" "+categoryTitle[ivar];
}else{
TObjArray *amatch=regCategory[ivar].MatchS(brNameCase);
if (amatch){
TString match=amatch->At(0)->GetName();
brClass+=" "+match;
brLegend+=" "+match;
brTitle+=" "+match;
}
}
}
if (branch!=NULL && branch->GetClassName()!=NULL && strlen(branch->GetClassName())>0){
brClass+=" Class:";
brClass+=branch->GetClassName();
}
//
TStatToolkit::AddMetadata(tree,TString::Format("%s.Description",branches->At(ibr)->GetName()).Data(),
TString::Format("ITS standard QA variables. Class %s", brClass.Data()).Data());
TStatToolkit::AddMetadata(tree,TString::Format("%s.class",branches->At(ibr)->GetName()).Data(),brClass.Data());
TStatToolkit::AddMetadata(tree,TString::Format("%s.AxisTitle",branches->At(ibr)->GetName()).Data(),brAxisTitle.Data());
TStatToolkit::AddMetadata(tree,TString::Format("%s.Title",branches->At(ibr)->GetName()).Data(),brTitle.Data());
TStatToolkit::AddMetadata(tree,TString::Format("%s.Legend",branches->At(ibr)->GetName()).Data(),brLegend.Data());
if (verbose&4) printf("Class %s: \t%s\n", branches->At(ibr)->GetName(),brClass.Data());
if (verbose&8) printf("Axis title %s: \t%s\n", branches->At(ibr)->GetName(),brAxisTitle.Data());
if (verbose&16) printf("Title %s: \t%s\n", branches->At(ibr)->GetName(),brTitle.Data());
if (verbose&32) printf("Legend %s: \t%s\n", branches->At(ibr)->GetName(),brLegend.Data());
}
// Fill Based and custom metadata
//
// Index
TStatToolkit::AddMetadata(tree,"run.class","Base Index");
TStatToolkit::AddMetadata(tree,"run.Title","run");
TStatToolkit::AddMetadata(tree,"run.AxisTitle","run");
//
TList * mlist = (TList*)(tree->GetUserInfo()->FindObject("metaTable"));
mlist->Sort();
if ((verbose&1)>0){
mlist->Print();
}
if ((verbose&2)>0){
AliTreePlayer::selectMetadata(tree, "[class==\"\"]",0)->Print();
}
::Info("qaitsAddMetadata","End");
}
示例5: generateCodeFromStreamers
std::string generateCodeFromStreamers(std::string url, std::string treeLocation, std::vector<std::string> &classNames, std::string &errorMessage) {
TFile *tfile = TFile::Open(url.c_str());
if (tfile == nullptr || !tfile->IsOpen()) {
errorMessage = std::string("File not found: ") + url;
return std::string();
}
if (tfile->IsZombie()) {
errorMessage = std::string("Not a ROOT file: ") + url;
return std::string();
}
TTreeReader reader(treeLocation.c_str(), tfile);
if (reader.IsZombie()) {
errorMessage = std::string("Not a TTree: ") + treeLocation.c_str() + std::string(" in file: ") + url;
return std::string();
}
TTree *ttree = reader.GetTree();
std::set<std::string> includes;
std::vector<ClassStructure> classes;
TIter listOfBranches = ttree->GetListOfBranches();
for (TBranch *tbranch = (TBranch*)listOfBranches.Next(); tbranch != nullptr; tbranch = (TBranch*)listOfBranches.Next()) {
TClass *tclass = TClass::GetClass(tbranch->GetClassName());
if (tclass != nullptr && tbranch->GetListOfBranches()->GetEntries() > 0)
classesFromBranch(tbranch, tclass, classes, 0, includes);
}
for (int i = 0; i < classes.size(); i++)
classNames.push_back(classes[i].fullName);
tfile->Close();
std::string out;
for (std::set<std::string>::iterator iter = includes.begin(); iter != includes.end(); ++iter)
out += *iter + "\n";
out += "\n";
for (std::vector<ClassStructure>::iterator iter = classes.begin(); iter != classes.end(); ++iter) {
int i = 0;
for (; i < iter->splitName.size() - 1; i++)
out += std::string(i * 2, ' ') + "namespace " + iter->splitName[i] + " {\n";
out += std::string(i * 2, ' ') + "class " + iter->splitName.back() + ";\n";
i--;
for (; i >= 0; i--)
out += std::string(i * 2, ' ') + "}\n";
}
out += "\n";
for (std::vector<ClassStructure>::iterator iter = classes.begin(); iter != classes.end(); ++iter) {
int i = 0;
for (; i < iter->splitName.size() - 1; i++)
out += std::string(i * 2, ' ') + "namespace " + iter->splitName[i] + " {\n";
out += iter->cpp(i * 2) + "\n";
i--;
for (; i >= 0; i--)
out += std::string(i * 2, ' ') + "}\n";
}
for (std::vector<ClassStructure>::iterator iter = classes.begin(); iter != classes.end(); ++iter) {
int i = 0;
for (; i < iter->splitName.size() - 1; i++)
out += std::string(i * 2, ' ') + "namespace " + iter->splitName[i] + " {\n";
out += std::string(i * 2, ' ') + "ClassImp(" + iter->splitName.back() + ")\n";
i--;
for (; i >= 0; i--)
out += std::string(i * 2, ' ') + "}\n";
}
return out;
}