本文整理汇总了C++中TKey::IsFolder方法的典型用法代码示例。如果您正苦于以下问题:C++ TKey::IsFolder方法的具体用法?C++ TKey::IsFolder怎么用?C++ TKey::IsFolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TKey
的用法示例。
在下文中一共展示了TKey::IsFolder方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: validateInput
void validateInput(const char* filename, int level=0)
{
TFile* file = new TFile(filename, "update");
TIter nextDirectory(file->GetListOfKeys());
TKey* idir;
while((idir = (TKey*)nextDirectory())){
file->cd();
if( idir->IsFolder() ){
if( level>-1 ){ std::cout << "Found directory: " << idir->GetName() << std::endl; }
file->cd(idir->GetName());
validateFolder(file, idir->GetName(), level);
}
else{
if( level> 0 ){ std::cout << "Found histogram: " << idir->GetName() << std::endl; }
if( level>-1 ){
TH1F* h = (TH1F*)file->Get(idir->GetName());
if(h->Integral() == 0){
std::cout << "----- E R R O R ----- : histogram has 0 integral please fix this: --> " << idir->GetName() << std::endl;
}
}
}
}
file->Close();
return;
}
示例2: next
std::vector<std::string>
signalList(const char* dirName="", const char* pattern="", unsigned int debug=0)
{
std::vector<std::string> histnames;
TIter next(gDirectory->GetListOfKeys());
TKey* iobj;
unsigned int idx=0;
while((iobj = (TKey*)next())){
if(iobj->IsFolder()) continue;
if(debug>2){ std::cout << "[" << ++idx << "] ...Found object: " << iobj->GetName() << " of type: " << iobj->GetClassName() << std::endl; }
std::string fullpath(dirName);
fullpath += fullpath == std::string("") ? "" : "/"; fullpath += iobj->GetName();
// why does \\w*_\\d+ not work to catch them all?!?
if(std::string(pattern).empty()){
std::map<const char*, const char*> dict = httDictionary();
for(std::map<const char*, const char*>::const_iterator name = dict.begin(); name!=dict.end(); ++name){
if(match(iobj->GetName(), (char*)name->first)){
histnames.push_back(fullpath);
}
}
}
else if(!std::string(pattern).empty() && match(iobj->GetName(), (char*)pattern)){
histnames.push_back(fullpath);
}
}
return histnames;
}
示例3: next
void
validateFolder(TFile* file, const char* folder="", int level=-1)
{
TIter next(gDirectory->GetListOfKeys());
TKey* iobj;
unsigned int idx=0;
while((iobj = (TKey*)next())){
if(iobj->IsFolder()) continue;
if(level>1){ std::cout << "[" << ++idx << "] ...Found object: " << iobj->GetName() << " of type: " << iobj->GetClassName() << std::endl; }
std::string fullpath(folder);
fullpath += (fullpath == std::string("")) ? "" : "/"; fullpath += iobj->GetName();
TH1F* h = (TH1F*)file->Get(fullpath.c_str());
if(h->Integral() == 0){
std::cout << "----- E R R O R ----- : histogram has 0 integral please fix this: --> " << fullpath << std::endl;
}
}
return;
}
示例4: next
std::vector<std::string>
signalList(const char* dirName="", const char* pattern="",const char* iExprMatch="", unsigned int debug=0)
{
std::vector<std::string> histnames;
TIter next(gDirectory->GetListOfKeys());
TKey* iobj;
unsigned int idx=0;
while((iobj = (TKey*)next())){
if(iobj->IsFolder()) continue;
if(debug>2){ std::cout << "[" << ++idx << "] ...Found object: " << iobj->GetName() << " of type: " << iobj->GetClassName() << std::endl; }
std::string fullpath(dirName);
fullpath += fullpath == std::string("") ? "" : "/"; fullpath += iobj->GetName();
// why does \\w*_\\d+ not work to catch them all?!?
if(std::string(pattern).empty() && matchSignal(iobj->GetName(),iExprMatch)){
histnames.push_back(fullpath);
}
else if(!std::string(pattern).empty() && match(iobj->GetName(), (char*)pattern)){
histnames.push_back(fullpath);
}
}
return histnames;
}
示例5: rescaleSignal
void rescaleSignal(bool armed, double scale, const char* filename, const char* pattern="", unsigned int debug=0)
{
std::vector<std::string> histnames; histnames.clear();
if( debug>0 ){
std::cout << "file = " << filename << std::endl;
std::cout << "scale = " << scale << std::endl;
std::cout << "armed = " << armed << std::endl;
}
TFile* file = new TFile(filename, "update");
TIter nextDirectory(file->GetListOfKeys());
std::vector<std::string> buffer;
TKey* idir;
while((idir = (TKey*)nextDirectory())){
buffer.clear();
if( idir->IsFolder() ){
file->cd(); // make sure to start in directory head
if( debug>0 ){ std::cout << "Found directory: " << idir->GetName() << std::endl; }
if( file->GetDirectory(idir->GetName()) ){
file->cd(idir->GetName()); // change to sub-directory
buffer = signalList(idir->GetName(), pattern, debug);
}
// append to the vector of histograms to be rescaled
for(std::vector<std::string>::const_iterator elem=buffer.begin(); elem!=buffer.end(); ++elem){
histnames.push_back(*elem);
}
if(debug>1){
std::cout << "added " << buffer.size() << " elements to histnames [" << histnames.size() << "] for directory " << idir->GetName() << std::endl;
}
}
}
// pick up files which are not kept in an extra folder
file->cd(); buffer.clear();
buffer = signalList("", pattern, debug);
// append to the vector of histograms to be rescaled
for(std::vector<std::string>::const_iterator elem=buffer.begin(); elem!=buffer.end(); ++elem){
histnames.push_back(*elem);
}
if(debug>1){
std::cout << "added " << buffer.size() << " elements to histnames [" << histnames.size() << "] for file head" << std::endl;
}
for(std::vector<std::string>::const_iterator hist=histnames.begin(); hist!=histnames.end(); ++hist){
file->cd();
TH1F* h = (TH1F*)file->Get(hist->c_str());
std::string histName;
if(hist->find("/")!=std::string::npos){
histName = hist->substr(hist->find("/")+1);
}
else{
histName = *hist;
}
TH1F* hout = (TH1F*)h->Clone(histName.c_str());
if(debug>1){
std::cout << "...folder : " << hist->substr(0, hist->find("/")).c_str() << std::endl;
std::cout << "...histogram : " << hout->GetName () << " / " << hist->c_str() << std::endl;
std::cout << "...old scale : " << hout->Integral() << std::endl;
}
hout->Scale(scale);
if(match(pattern, "data")){
//make sure to have an integer integral when rescaling data yields
hout->Scale(int(hout->Integral())/hout->Integral());
}
if(debug>1){
std::cout << "...new scale : " << hout->Integral() << std::endl;
}
if(armed){
if(hist->find("/")!=std::string::npos){
file->cd(hist->substr(0, hist->find("/")).c_str());
}
else{
file->cd();
}
std::cout << "writing to file: " << hout->GetName() << std::endl;
hout->Write(hist->substr(hist->find("/")+1).c_str(), TObject::kOverwrite);
}
}
file->Close();
return;
}
示例6: rescale2SM4
void rescale2SM4(bool armed, const char* filename, double ecms=7., double mass=-1)
{
unsigned int debug = 1;
std::vector<std::string> histnames; histnames.clear();
if( debug>0 ){
std::cout << "file = " << filename << std::setw(10);
std::cout << "mass = " << mass << std::setw(10);
std::cout << "armed = " << armed << std::endl;
}
TFile* file = new TFile(filename, "update");
TIter nextDirectory(file->GetListOfKeys());
std::vector<std::string> buffer; TKey* idir;
while((idir = (TKey*)nextDirectory())){
buffer.clear();
if( idir->IsFolder() ){
file->cd(); // make sure to start in directory head
if( debug>1 ){ std::cout << "Found directory: " << idir->GetName() << std::endl; }
if( file->GetDirectory(idir->GetName()) ){
file->cd(idir->GetName()); // change to sub-directory
buffer = signalList(idir->GetName(), "", debug);
}
// append to the vector of histograms to be rescaled
for(std::vector<std::string>::const_iterator elem=buffer.begin(); elem!=buffer.end(); ++elem){
histnames.push_back(*elem);
}
if(debug>1){
std::cout << "added " << buffer.size() << " elements to histnames [" << histnames.size() << "] for directory " << idir->GetName() << std::endl;
}
}
}
// pick up histograms which are not kept in an extra folder
file->cd(); buffer.clear();
buffer = signalList("", "", debug);
// append to the vector of histograms to be rescaled
for(std::vector<std::string>::const_iterator elem=buffer.begin(); elem!=buffer.end(); ++elem){
histnames.push_back(*elem);
}
if(debug>1){
std::cout << "added " << buffer.size() << " elements to histnames [" << histnames.size() << "] for file head" << std::endl;
}
HiggsCSandWidth smx; HiggsCSandWidthSM4 sm4;
for(std::vector<std::string>::const_iterator hist=histnames.begin(); hist!=histnames.end(); ++hist){
int type = 0;
// determine mass from hostogram name
std::string strippedName = (hist->find("/")!=std::string::npos ? hist->substr(hist->find("/")+1) : *hist);
std::string massName;
if(strippedName.find("ggH")!=std::string::npos) {
massName = strippedName.substr(3, 3); type = 1;
}
if(strippedName.find("qqH")!=std::string::npos) {
massName = strippedName.substr(3, 3); type = 2;
}
if(strippedName.find("VH" )!=std::string::npos) {
massName = strippedName.substr(2, 3); type = 3;
}
if( type==0 ) {
std::cout << "not supported process" << std::endl;
continue;
}
else {
file->cd();
float mdx = atof(massName.c_str());
TH1F* h = (TH1F*)file->Get(hist->c_str());
float smxXS = type==1 ? smx.HiggsCS(type, mdx, ecms, true) : 0.; float smxBR = smx.HiggsBR(2, mdx, true);
float sm4XS = type==1 ? sm4.HiggsCS(type, mdx, ecms, true) : 0.; float sm4BR = sm4.HiggsBR(2, mdx, true);
if( debug>1 ){
std::cout << " -- hist = " << std::setw(10) << h->GetName() << std::endl
<< " -- type = " << std::setw(10) << type << std::endl
<< " -- mass = " << std::setw(10) << mdx << std::endl
<< " -- SM = " << std::setw(10) << smxXS*smxBR << " (BR = " << smxBR << ")" << std::endl
<< " -- SM4 = " << std::setw(10) << sm4XS*sm4BR << " (BR = " << sm4BR << ")" << std::endl
<< " -- scale = " << std::setw(10) << (type==1 ? sm4XS*sm4BR/(smxXS*smxBR) : 0) << std::endl
<< std::endl;
}
if( type==1 ){ h->Scale(sm4XS*sm4BR/(smxXS*smxBR)); }
//scaling old style
//if( type==2 ){ h->Scale(sm4BR/smxBR); }
//if( type==3 ){ h->Scale(sm4BR/smxBR); }
// scaling new style
if( type==2 ){ h->Scale(0.); }
if( type==3 ){ h->Scale(0.); }
if(armed){
if(hist->find("/")!=std::string::npos){
file->cd(hist->substr(0, hist->find("/")).c_str());
}
else{
file->cd();
}
h->Write(strippedName.c_str(), TObject::kOverwrite);
}
}
}
file->Close();
return;
}
示例7: changeAxis
void changeAxis(bool armed, TString iExprMatch,float iMin, const char* filename, const char* pattern="", unsigned int debug=0)
{
std::vector<std::string> histnames; histnames.clear();
if( debug>0 ){
std::cout << "file = " << filename << std::endl;
std::cout << "old = " << iExprMatch.Data() << std::endl;
std::cout << "armed = " << armed << std::endl;
}
TFile* file = new TFile(filename, "update");
TIter nextDirectory(file->GetListOfKeys());
std::vector<std::string> buffer;
TKey* idir;
while((idir = (TKey*)nextDirectory())){
buffer.clear();
if( idir->IsFolder() ){
file->cd(); // make sure to start in directory head
if( debug>0 ){ std::cout << "Found directory: " << idir->GetName() << std::endl; }
if( file->GetDirectory(idir->GetName()) ){
file->cd(idir->GetName()); // change to sub-directory
buffer = signalList(idir->GetName(), pattern,iExprMatch.Data(), debug);
}
// append to the vector of histograms to be rescaled
for(std::vector<std::string>::const_iterator elem=buffer.begin(); elem!=buffer.end(); ++elem){
histnames.push_back(*elem);
}
if(debug>1){
std::cout << "added " << buffer.size() << " elements to histnames [" << histnames.size() << "] for directory " << idir->GetName() << std::endl;
}
}
}
// pick up files which are not kept in an extra folder
file->cd(); buffer.clear();
buffer = signalList("", pattern,iExprMatch.Data(), debug);
// append to the vector of histograms to be rescaled
for(std::vector<std::string>::const_iterator elem=buffer.begin(); elem!=buffer.end(); ++elem){
histnames.push_back(*elem);
}
if(debug>1){
std::cout << "added " << buffer.size() << " elements to histnames [" << histnames.size() << "] for file head" << std::endl;
}
for(std::vector<std::string>::const_iterator hist=histnames.begin(); hist!=histnames.end(); ++hist){
file->cd();
TH1F* h = (TH1F*)file->Get(hist->c_str());
std::string histName;
if(hist->find("/")!=std::string::npos){
histName = hist->substr(hist->find("/")+1);
}
else{
histName = *hist;
}
TH1F* hout = (TH1F*)h->Clone(histName.c_str());
if(debug>1){
std::cout << "...folder : " << hist->substr(0, hist->find("/")).c_str() << std::endl;
std::cout << "...histogram : " << hout->GetName () << " / " << hist->c_str() << std::endl;
}
for(int i0 = 0; i0 < hout->GetNbinsX()+1; i0++) if(hout->GetXaxis()->GetBinCenter(i0) < iMin) hout->SetBinContent(i0,0);
if(debug>1){
std::cout << "...new name : " << hout->GetName() << std::endl;
std::cout << "...new title : " << hout->GetTitle() << std::endl;
}
if(armed){
if(hist->find("/")!=std::string::npos){
file->cd(hist->substr(0, hist->find("/")).c_str());
}
else{
file->cd();
}
std::cout << "writing to file: " << hout->GetName() << " -- " << hist->substr(hist->find("/")+1).c_str() << std::endl;
hout->Write(hist->substr(hist->find("/")+1).c_str(), TObject::kOverwrite);
}
}
file->Close();
return;
}
示例8: populate
//=========================================================================
void hTreeBrowser::populate(TDirectory* currentDirectory, QTreeWidgetItem* parentWItem)
{
// STDLINE("populate(TDirectory,QTree)",ACRed);
QTreeWidgetItem * wItem = NULL;
bool create = false ;
//currentDirectory->ls() ;
TKey * keyH = NULL ;
TIter hList(currentDirectory->GetListOfKeys());
while((keyH = (TKey*)hList()))
{
//If you uncomment this line you will get a
//Error in <TBufferFile::ReadClassBuffer>: class: TUUID, attempting to access a wrong version
//Every time it tries to read a TFolder or TDirectory object
//this->getObjectType(keyH->ReadObj());
std::string objPath = std::string(currentDirectory->GetName()) + std::string("-") + std::string(keyH->GetName());
//std::string objectName = keyH->GetName() ;
// STDLINE(keyH->GetName(),ACPurple);
if( existingWItems_.find(objPath) == existingWItems_.end())
{
wItem = new QTreeWidgetItem(parentWItem) ;
existingWItems_[objPath] = wItem ;
create = true ;
}
else
{
wItem = existingWItems_[objPath] ;
create = false ;
}
if( keyH->IsFolder() )
{
if(std::string(keyH->GetClassName()) == "TTree")
{
if( !create ) continue ;
wItem->setText(0, keyH->GetName()) ;
wItem->setText(1, "TTree") ;
wItem->setIcon(0, tTreeIcon_);
}
else if (std::string(keyH->GetClassName()) == "TFolder" )
{
TFolder * aFolder = (TFolder*)(currentDirectory->GetKey(keyH->GetName())->ReadObj()) ; // Get the folder in memory (this is the trick!)
if( create )
{
wItem->setText(0, tr(keyH->GetName())) ;
wItem->setText(1, tr(keyH->GetClassName())) ;
wItem->setIcon(0, folderIcon_);
}
this->populate(aFolder,wItem) ;
}
else
{
currentDirectory->cd(keyH->GetName());
if( create )
{
wItem->setText(0, tr(gDirectory->GetName())) ;
wItem->setText(1, tr(keyH->GetClassName())) ;
wItem->setIcon(0, folderIcon_);
}
this->populate(gDirectory,wItem) ;
}
}
else
{
if( !create ) continue ;
wItem->setText(0, tr(keyH->GetName())) ;
wItem->setText(1, tr(keyH->GetClassName())) ;
std::string className = keyH->GetClassName();
if(className == "TCanvas" )
{
wItem->setIcon(0, canvasIcon_);
}
else if( className.find("TH1") != std::string::npos )
{
wItem->setIcon(0, TH1Icon_);
}
else if( className.find("TH2") != std::string::npos )
{
wItem->setIcon(0, TH2Icon_);
}
else if( className.find("TGraph") != std::string::npos )
{
wItem->setIcon(0, tGraphIcon_);
}
else if( className == "TProfile" )
{
wItem->setIcon(0, tProfileIcon_);
}
else
{
//STDLINE(className + "-" + this->getObjectType(keyH->ReadObj()),ACRed);
wItem->setIcon(0, fileIcon_);
}
}
}
}