本文整理汇总了C++中TDirectory::GetListOfKeys方法的典型用法代码示例。如果您正苦于以下问题:C++ TDirectory::GetListOfKeys方法的具体用法?C++ TDirectory::GetListOfKeys怎么用?C++ TDirectory::GetListOfKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TDirectory
的用法示例。
在下文中一共展示了TDirectory::GetListOfKeys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cmpLRD
void cmpLRD(TFile* f1, TFile* f2, const char* dName, const char* patt = 0, unsigned int logmod=0, unsigned int dOpt=1){
// std::cout<<"cmpLRD In "<< dName<<std::endl;
TDirectory* td = gROOT->GetDirectory(dName);
if (td){
TList* tkl = td->GetListOfKeys();
unsigned int tklSize = tkl->GetEntries();
// std::cout<<"\t size "<<tklSize<<std::endl;
for (unsigned int iK=0; iK< tklSize; ++iK){
// std::cout<<"at "<<iK<<"\t " <<tkl->At(iK)->GetName()<<std::endl;
if (TClass(((TKey*)tkl->At(iK))->GetClassName()).InheritsFrom("TDirectory")){
TDirectory* tdc = (TDirectory*)((TKey*)tkl->At(iK))->ReadObj();
if (tdc ==0) continue;
TString tdcPFull(tdc->GetPath());
TString pRel(tdcPFull.Tokenize(":")->At(1)->GetName());
// std::cout<<tdcPFull.Data()<<std::endl;
//now execute compare
// if(pRel.Index("/SiStrip/")>=0) continue; //this takes a huge time in alcareco and is irrelevant
///DQMData/Run 1/Btag
if (patt==0 || (patt!=0 && pRel.Index(patt)>=0)){
// std::cout<<"Comparing in " <<pRel.Data()<<std::endl;
compareInDir(f1, f2, pRel.Data(),logmod,dOpt);
}
cmpLRD(f1, f2, tdcPFull.Data(), patt,logmod,dOpt);
}
}
}
}
示例2: getKS
/*************************************************************************************
* getKS: Searches through the histograms in the plotter output, adds the MC together
* for each field, and compares the MC with the Data histogram using a KS test
* input: the main() arguments array
* output: writes to stdout the (human-readable) KS statistics of pairs of histograms
*
* Structure-wise: this is fine, can be implemented into class easily.
***********************************/
void getKS(const char* argv[]) {
//open the input TFile
TFile *f = new TFile(argv[2]);
f->cd();
//get the filesystem information from the file
TList *alokDirs = (TList*) f->GetListOfKeys();
//loop through the directories in the input file
for(int idir=0; alokDirs->At(idir-1) != alokDirs->Last(); idir++) {
TDirectory *cDir = (TDirectory*) f->Get(alokDirs->At(idir)->GetName());
TList *alokHistos = (TList*) cDir->GetListOfKeys();
// create the MC histogram and start collecting relevant MC histograms
// from the current directory
TList *aloh = new TList;
// loop through keys (histograms) in current directory
for(int ihisto=0; alokHistos->At(ihisto) != alokHistos->Last(); ihisto++) {
if(TString(alokHistos->At(ihisto)->GetName()).Contains("MC8TeV")) {
TH1F *cHisto = (TH1F*) cDir->Get(alokHistos->At(ihisto)->GetName());
aloh->Add(cHisto);
}
}
//merge the data histograms into one histogram
TH1F *MCHisto = (TH1F*) (aloh->Last())->Clone(TString(cDir->GetName()) + TString("MCHisto"));
aloh->RemoveLast();
MCHisto->Merge(aloh);
cout<<"-------------------- "<<cDir->GetName()<<" -----------------------"<<endl;
//now create the data histogram and run the KS test
TH1F *DataHisto = (TH1F*) cDir->Get(alokHistos->Last()->GetName());
cout<<" ---> KS Test: "<<cDir->GetName()<<" has probability "<<MCHisto->KolmogorovTest(DataHisto, "D")<<"\n"<<endl;
}
}
示例3: GetListOfJobs
UInt_t GetListOfJobs( TFile* file, TList& jobdirs)
{
// get a list of all jobs in all method directories
// based on ideas by Peter and Joerg found in macro deviations.C
TIter next(file->GetListOfKeys());
TKey *key(0);
while ((key = (TKey*)next())) {
if (TString(key->GetName()).BeginsWith("Method_")) {
if (gROOT->GetClass(key->GetClassName())->InheritsFrom("TDirectory")) {
TDirectory* mDir = (TDirectory*)key->ReadObj();
TIter keyIt(mDir->GetListOfKeys());
TKey *jobkey;
while ((jobkey = (TKey*)keyIt())) {
if (!gROOT->GetClass(jobkey->GetClassName())->InheritsFrom("TDirectory")) continue;
TDirectory *jobDir = (TDirectory *)jobkey->ReadObj();
cout << "jobdir name " << jobDir->GetName() << endl;
jobdirs.Add(jobDir);
}
}
}
}
return jobdirs.GetSize();
}
示例4: i
std::vector<TString> histoList( TString currentfile, TString theDir )
{
gROOT ->Reset();
const char* sfilename = currentfile.Data();
delete gROOT->GetListOfFiles()->FindObject(sfilename);
TFile * sfile = new TFile(sfilename);
const char* baseDir=theDir.Data();
sfile->cd(baseDir);
TDirectory * d = gDirectory;
std::vector<TString> theHistList;
TIter i( d->GetListOfKeys() );
TKey *k;
while( (k = (TKey*)i())) {
TClass * c1 = gROOT->GetClass(k->GetClassName());
if ( !c1->InheritsFrom("TH1")) continue;
theHistList.push_back(k->GetName());
}
std::cout << "Histograms considered: " << std::endl;
for (unsigned int index = 0; index < theHistList.size() ; index++ ) {
std::cout << index << " " << theHistList[index] << std::endl;
}
return theHistList;
}
示例5: create_module_info
void create_module_info(TString dir = "/castor/cern.ch/user/r/rougny/vcalH2L_7/GainRun_173484"){
ofstream t;
t.open("module_info.txt");
if(! t.is_open()){
cout << "[create_module_info] Could not open output txt file. Exiting ..." << endl;
exit(1);
}
for(int i=0 ; i<40 ; ++i){
ostringstream f_str("");
f_str << "rfio://" << dir << "/" << i << ".root";
cout << "Opening file : " << f_str.str() << endl;
TFile* f = TFile::Open(f_str.str().c_str() , "READ");
vector<TString> dir_list = makedirlist(f , "Module");
for(int m = 0 ; m < dir_list.size() ; ++m){
TDirectory* dir = f->GetDirectory(dir_list[m]);
int detid = getDetId(((TH1*) dir->Get(((TKey*) dir->GetListOfKeys()->At(0))->GetName()))->GetName());
t << detid << " " << i << " " << dir_list[m].Remove(0,dir_list[m].First('y')+2) << endl;
}
f->Close();
}
t.close();
}
示例6: fill
void fill(TDirectory & out, TObject * o, double w) {
TDirectory * dir;
TH1F * th1f;
TH1D * th1d;
TH2F * th2f;
TH2D * th2d;
if((dir = dynamic_cast<TDirectory*>(o)) != 0) {
const char * name = dir->GetName();
TDirectory * outDir = dynamic_cast<TDirectory*>(out.Get(name));
if(outDir == 0) {
cerr << "can't find directory " << name << " in output file" << endl;
exit(-1);
}
TIter next(dir->GetListOfKeys());
TKey *key;
while( (key = dynamic_cast<TKey*>(next())) ) {
string className(key->GetClassName());
string name(key->GetName());
TObject * obj = dir->Get(name.c_str());
if(obj == 0) {
cerr <<"error: key " << name << " not found in directory " << dir->GetName() << endl;
exit(-1);
}
fill(*outDir, obj, w);
}
} else if((th1f = dynamic_cast<TH1F*>(o)) != 0) {
const char * name = th1f->GetName();
TH1F * outTh1f = dynamic_cast<TH1F*>(out.Get(name));
if(outTh1f == 0) {
cerr <<"error: histogram TH1F" << name << " not found in directory " << out.GetName() << endl;
exit(-1);
}
outTh1f->Add(th1f, w);
} else if((th1d = dynamic_cast<TH1D*>(o)) != 0) {
const char * name = th1d->GetName();
TH1D * outTh1d = dynamic_cast<TH1D*>(out.Get(name));
if(outTh1d == 0) {
cerr <<"error: histogram TH1D" << name << " not found in directory " << out.GetName() << endl;
exit(-1);
}
outTh1d->Add(th1d, w);
} else if((th2f = dynamic_cast<TH2F*>(o)) != 0) {
const char * name = th2f->GetName();
TH2F * outTh2f = dynamic_cast<TH2F*>(out.Get(name));
if(outTh2f == 0) {
cerr <<"error: histogram TH2F" << name << " not found in directory " << out.GetName() << endl;
exit(-1);
}
outTh2f->Add(th2f, w);
} else if((th2d = dynamic_cast<TH2D*>(o)) != 0) {
const char * name = th2d->GetName();
TH2D * outTh2d = dynamic_cast<TH2D*>(out.Get(name));
if(outTh2d == 0) {
cerr <<"error: histogram TH2D" << name << " not found in directory " << out.GetName() << endl;
exit(-1);
}
outTh2d->Add(th2d, w);
}
}
示例7: ReadFromDir
int ReadFromDir(TFile *fout, const TString &dirName, std::vector<std::vector<TH1F*>*> &hVV, std::vector<TString> &names) {
hVV.clear(); names.clear();
fout->cd(dirName);
TDirectory *sourceDir = gDirectory;
TList *subDirList=sourceDir->GetListOfKeys();
int count=subDirList->GetEntries();
std::cout << "there are " << count << " keys\n";
hVV.reserve(count);
TIter subDirs(subDirList);
TKey *key=NULL;
while ( (key = (TKey*)subDirs()) ) {
const TString sDirName=key->GetName();
std::cout << "sDirName=" << sDirName << "\n";
names.push_back( sDirName );
sourceDir->cd( sDirName );
TDirectory *currDir = gDirectory;
TList *histosList=currDir->GetListOfKeys();
TIter histos( histosList );
std::vector<TH1F*> *hV = new std::vector<TH1F*>();
hVV.push_back(hV);
hV->reserve(histosList->GetEntries());
while( (key = (TKey*)histos()) ) {
std::cout << "key->GetName() = " << key->GetName() << "\n";
TObject *obj= key->ReadObj();
if ( obj->IsA()->InheritsFrom( TH1F::Class() ) ) {
TH1F *h=(TH1F*)obj;
h->SetDirectory(0);
hV->push_back(h);
}
else {
delete hV;
}
}
}
return 1;
}
示例8: GetListOfTitles
UInt_t GetListOfTitles( TString & methodName, TList & titles, TDirectory *dir=0 )
{
// get the list of all titles for a given method
// if the input dir is 0, gDirectory is used
// returns a list of keys
UInt_t ni=0;
if (dir==0) dir = gDirectory;
TDirectory* rfdir = (TDirectory*)dir->Get( methodName );
if (rfdir==0) {
cout << "+++ Could not locate directory '" << methodName << endl;
return 0;
}
return GetListOfTitles( rfdir, titles );
TList *keys = rfdir->GetListOfKeys();
if (keys==0) {
cout << "+++ Directory '" << methodName << "' contains no keys" << endl;
return 0;
}
//
TIter rfnext(rfdir->GetListOfKeys());
TKey *rfkey;
titles.Clear();
titles.SetOwner(kFALSE);
while ((rfkey = (TKey*)rfnext())) {
// make sure, that we only look at histograms
TClass *cl = gROOT->GetClass(rfkey->GetClassName());
if (cl->InheritsFrom("TDirectory")) {
titles.Add(rfkey);
ni++;
}
}
cout << "--- Found " << ni << " instance(s) of the method " << methodName << endl;
return ni;
}
示例9: getSummaries
void CalibrationScanAnalysis::getSummaries(FileList::const_iterator file) {
std::cout << "." << std::flush;
std::vector<TH1*> result;
TFile* input = file->second;
TDirectory* directory = input->GetDirectory(HISTOPATH);
TList* histograms = directory->GetListOfKeys();
TIter next(histograms);
TKey* key = NULL;
while ((key = (TKey*)next())) {
if(TClass(key->GetClassName()).InheritsFrom("TH1")) {
TH1* h = (TH1*)key->ReadObj();
result.push_back(h);
}
}
summaries_[file->first] = result;
}
示例10: make
void make(TDirectory & out, TObject * o) {
TDirectory * dir;
TH1F * th1f;
TH1D * th1d;
TH2F * th2f;
TH2D * th2d;
out.cd();
if((dir = dynamic_cast<TDirectory*>(o)) != 0) {
TDirectory * outDir = out.mkdir(dir->GetName(), dir->GetTitle());
TIter next(dir->GetListOfKeys());
TKey *key;
while( (key = dynamic_cast<TKey*>(next())) ) {
string className(key->GetClassName());
string name(key->GetName());
TObject * obj = dir->Get(name.c_str());
if(obj == 0) {
cerr <<"error: key " << name << " not found in directory " << dir->GetName() << endl;
exit(-1);
}
make(*outDir, obj);
}
} else if((th1f = dynamic_cast<TH1F*>(o)) != 0) {
TH1F *h = (TH1F*) th1f->Clone();
h->Reset();
h->Sumw2();
h->SetDirectory(&out);
} else if((th1d = dynamic_cast<TH1D*>(o)) != 0) {
TH1D *h = (TH1D*) th1d->Clone();
h->Reset();
h->Sumw2();
h->SetDirectory(&out);
} else if((th2f = dynamic_cast<TH2F*>(o)) != 0) {
TH2F *h = (TH2F*) th2f->Clone();
h->Reset();
h->Sumw2();
h->SetDirectory(&out);
} else if((th2d = dynamic_cast<TH2D*>(o)) != 0) {
TH2D *h = (TH2D*) th2d->Clone();
h->Reset();
h->Sumw2();
h->SetDirectory(&out);
}
}
示例11: DrawNetworkMovie
void DrawNetworkMovie( TFile* file, const TString& methodType, const TString& methodTitle )
{
TString dirname = methodType + "/" + methodTitle + "/" + "EpochMonitoring";
TDirectory *epochDir = (TDirectory*)file->Get( dirname );
if (!epochDir) {
cout << "Big troubles: could not find directory \"" << dirname << "\"" << endl;
exit(1);
}
epochDir->cd();
// loop over all epoch-wise monitoring histograms
TIter keyIt(epochDir->GetListOfKeys());
TKey *key;
vector<TString> epochList;
Int_t ic = 0;
while ((key = (TKey*)keyIt())) {
if (!gROOT->GetClass(key->GetClassName())->InheritsFrom("TH2F")) continue;
TString name = key->GetName();
if (!name.BeginsWith("epochmonitoring___")) continue;
// extract epoch
TObjArray* tokens = name.Tokenize("_");
TString es = ((TObjString*)tokens->At(2))->GetString();
// check if done already
Bool_t isOld = kFALSE;
for (vector<TString>::const_iterator it = epochList.begin(); it < epochList.end(); it++) {
if (*it == es) isOld = kTRUE;
}
if (isOld) continue;
epochList.push_back( es );
// create bulk file name
TString bulkname = Form( "epochmonitoring___epoch_%s_weights_hist", es.Data() );
// draw the network
if (ic <= 60) draw_network( file, epochDir, bulkname, kTRUE, es );
ic++;
}
}
示例12: merge
void merge(){
if (!TClass::GetDict("NBD")) {
gROOT->ProcessLine(".L /afs/cern.ch/user/q/qixu/CMSSW_6_2_5/src/Centrality/NBD_Glauber_fit/NBD/NBDclass.C++");
}
TFile *f;
f=TFile::Open(Form("G.root"),"ReadOnly");
TFile *fg = new TFile("graph.root","Update");
TDirectory *dir;
TList *def, *tl;
TKey *key;
TString dirname;
for(int sth=0; sth<3; sth++){
if(sth==0) dirname = "std";
else if(sth==1) dirname ="Gri055";
else dirname ="Gri101";
dir = f->GetDirectory(dirname);
def = new TList();
int iGlau=0;
//int iGlau=atoi(getenv("GTH"));
tl = dir->GetListOfKeys();
for(iGlau=0; iGlau<nGlau; iGlau++){
key = ((TKey*) tl->At(iGlau));
NBD* temp = (NBD*)key->ReadObj();
def->Add(temp);
}
NBD *n0 = (NBD*)def->At(0);
n0->calcsys(def);
TString op;
for(int option=0;option<3;option++){
if(option==0) op=Form("%s_Ncoll",dirname.Data());
else if(option==1) op=Form("%s_Npart",dirname.Data());
else op=Form("%s_B",dirname.Data());
TGraphErrors* gr = n0->DrawGraph(option);
gr->Write(op);
}
}
fg->Close();
f->Close();
}
示例13: rescaleBoundaryHists
void rescaleBoundaryHists(std::string infile, int numSamples=-1){
TFile* f = new TFile(infile.c_str(), "UPDATE");
TDirectory* dir = 0;
TIter dir_it(f->GetListOfKeys());
TKey* dir_k;
while ((dir_k = (TKey *)dir_it())) {
if (TString(dir_k->GetClassName()) != "TDirectoryFile") continue;
std::string dir_name = std::string(dir_k->GetTitle());
if(dir_name == "") continue;
dir = (TDirectory*)dir_k->ReadObj();
if(dir == 0) continue;
TIter hist_it(dir->GetListOfKeys(), kIterBackward);
TKey* hist_k;
while ((hist_k = (TKey *)hist_it())) {
std::string hist_name = (hist_k->GetTitle());
if (hist_name.find("_HI") != std::string::npos || hist_name.find("_LOW") != std::string::npos || hist_name.find("h_n_mt2bins") != std::string::npos) {
TH1* h = (TH1*)hist_k->ReadObj();
if(numSamples==-1)
h->Scale(1.0/h->GetEntries());
else
h->Scale(1.0/numSamples);
dir->cd();
h->Write("",TObject::kOverwrite);
}
}
}
delete dir;
gDirectory->GetList()->Delete();
f->Write("",TObject::kOverwrite);
f->Close();
delete f;
}
示例14: printBadEvents
void printBadEvents(string filename){
string run = filename.substr(filename.find("_R000")+10, 1);
int nrun = atoi(run.c_str());
string fname(filename.substr(filename.find_last_of("/")+1) );
cout << "FileName is " << fname.c_str() << endl;
ofstream outfile;
stringstream namefile;
namefile << "BadEvents_" << nrun << ".txt";
outfile.open(namefile.str().c_str());
outfile << "Bad events in file " << fname.c_str() << endl;
TDirectory* topDir;
TFile* file = TFile::Open(filename.c_str());
if (!file->IsOpen()) {
cerr << "Failed to open " << filename << endl;
return;
}
string dir = "DQMData/Run " + run + "/ParticleFlow/Run summary/ElectronValidation/JetPtRes/BadEvents";
topDir = dynamic_cast<TDirectory*>( file->Get(dir.c_str()));
topDir->cd();
if (topDir){
TIter next(topDir->GetListOfKeys());
TKey *key;
while ( (key = dynamic_cast<TKey*>(next())) ) {
string sflag = key->GetName();
string info(sflag.substr(1, sflag.find_first_of(">")-1 ) );
string run(info.substr(0, info.find_first_of("_")) );
string evt = info.substr( info.find_first_of("_")+1, info.find_last_of("_")-2);
string ls(info.substr(info.find_last_of("_")+1,info.find_first_of("_")+1));
string ptres = ( sflag.substr( sflag.find( "f=" ) + 2, 6 ) ).c_str();
cout << "Event info: Run " << run << " LS " << ls << " Evt " << evt << " Jet Pt Res = " << ptres << endl;
outfile << "Event info: Run " << run << " LS " << ls << " Evt " << evt << " Jet Pt Res = " << ptres << endl;
}
}
}
示例15: drawBeamSpotGraphsAll
void drawBeamSpotGraphsAll (TFile* file, const char* fname=0)
{
TDirectory* module = (TDirectory*)_file0->FindObjectAny("beamSpotFitPV");
if ( module==0 ) return;
// unsigned int nrun = module->GetListOfKeys()->GetSize();
// TDirectory* currDir = gDirectory;
// gROOT->cd();
// TH1* hChi2 = new TH1F("runChi2","runChi2",nrun,0.5,nrun+0.5);
// TH1* hConst = new TH1F("runConst","runConst",nrun,0.5,nrun+0.5);
// TH1* hSlope = new TH1F("runSlope","runSlope",nrun,0.5,nrun+0.5);
// currDir->cd();
TIter iter(module->GetListOfKeys());
TKey* key;
// unsigned int irun(0);
// float runSummary[6];
while ( (key=(TKey*)iter()) ) {
std::cout << key->GetName() << std::endl;
drawBeamSpotGraphs(_file0,key->GetName(),fname);
TIter ic(gROOT->GetListOfCanvases());
TCanvas* c;
while ( (c=(TCanvas*)ic()) ) delete c;
// ++irun;
// if ( runSummary[1]>0.1 ) hChi2->SetBinContent(irun,runSummary[0]/runSummary[1]);
// hConst->SetBinContent(irun,runSummary[2]);
// hConst->SetBinError(irun,runSummary[3]);
// hSlope->SetBinContent(irun,runSummary[4]);
// hSlope->SetBinError(irun,runSummary[5]);
// hChi2->GetXaxis()->SetBinLabel(irun,key->GetName());
// hConst->GetXaxis()->SetBinLabel(irun,key->GetName());
// hSlope->GetXaxis()->SetBinLabel(irun,key->GetName());
// if ( irun==3 ) return;
}
}