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


C++ TFile::GetNkeys方法代码示例

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


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

示例1: assert

void
dumpToPDF(string inName, string fitName){
  TFile *fin = TFile::Open(inName.c_str(), "read"); assert(fin);


  string outName = inName;
  outName.replace(outName.find(".root"), 5, ".pdf");

  //fitName = "HLT_10LS_delivered_vs_rate_Run190949-191090.root";
  TFile *fFit = TFile::Open(fitName.c_str(), "read"); assert(fFit);

  TCanvas c1;
  c1.Print(Form("%s[", outName.c_str()), "pdf"); //Open .pdf

  //get list of keys
  int nplots = fin->GetNkeys(); 
  int nfits = fFit->GetNkeys(); 
  printf("nplots: %i, nfits: %i\n", nplots, nfits);
  if(nplots != nfits){
    cout<<" PDF output will be wrong since different number of triggers in fit and current run"<<endl;
    abort();
  }
  TList* plots = fin->GetListOfKeys();  
  TList* fits  = fFit->GetListOfKeys();
  for(int i=0; i<nplots; ++i){
    TKey* plot = (TKey*) plots->At(i);
    TKey* fit = (TKey*) fits->At(i);//assume they're in the same order for now

    if(!fin->GetKey(plot->GetName())){
      cout<<"Didn't find "<<plot<<". Removing."<<endl;
      abort();
    }
    if(!fFit->GetKey(fit->GetName())){
      cout<<"Didn't find "<<fit<<". Removing."<<endl;
      abort();
    }
    TCanvas* c = new TCanvas();
    c->Divide(1,2);

    TCanvas* cPlot = (TCanvas*) fin->Get(plot->GetName());
    c->cd(1);
    cPlot->DrawClonePad();

    TCanvas* cFit  = (TCanvas*) fFit->Get(fit->GetName());
    c->cd(2);
    cFit->DrawClonePad();

    string bookmarkName = "Title: ";
    bookmarkName += plot->GetName();

    c->Print(outName.c_str(), bookmarkName.c_str());
  }

  c1.Print(Form("%s]", outName.c_str()), "pdf"); //Close .pdf

}
开发者ID:drankincms,项目名称:RateMon,代码行数:56,代码来源:dumpToPDF.C

示例2: getTree

int reader_wrapper::getTree(TString infile, TString treename, TString outfile) {
  m_infile = TFile::Open(infile,"update");
  if (nullptr == m_infile || m_infile->IsZombie() || m_infile->GetNkeys() <= 0) {
    std::cerr << "File " << infile << " could not be opened properly." << std::endl;
    return 1;
  }

  m_intree = dynamic_cast<TTree*>(m_infile->Get(treename.Data()));
  if (nullptr == m_intree) {
    std::cerr << "Tree " << treename << " could not be opened properly." << std::endl;
    return 2;
  }
  m_outfile = TFile::Open(outfile,"create");
  if (nullptr == m_outfile || m_outfile->IsZombie()) {
    std::cerr << "File " << outfile << " could not be opened properly." << std::endl;
    return 3;
  }
  return 0;
}
开发者ID:petitcactusorange,项目名称:BAE,代码行数:19,代码来源:main.cpp

示例3: plotr

void plotr(int top){
  if (setup("vm","","pol__")==kFALSE) return;

  c = new TCanvas("R", "R");
  ct = new TCanvas("ct","ct");
  c->AddExec("tnail","tnail()");

  int itop = top-1;
  TFile* fy = _fyexp[itop];

  int nq2wbins = fy->GetNkeys();
  int nrows = 4;
  int ncols = nq2wbins/nrows;
  c->Divide(nrows, ncols);
  TIter nextkey(fy->GetListOfKeys());
  TKey *key;
  int iq2wbin = 0;
  while (key = (TKey*)nextkey()) {
    TString Q2Wdirname = key->GetName();
    if(Q2Wdirname.EqualTo("hYW_Dir") || Q2Wdirname.EqualTo("hYW"))continue;
    cout << "Q2Wdirname = " << Q2Wdirname << endl;
    TString hname_pos = TString::Format("%s/hPhi_POS/Varset1/theta/hRvVar",Q2Wdirname.Data());
    TString hname_neg = TString::Format("%s/hPhi_NEG/Varset1/theta/hRvVar",Q2Wdirname.Data());
    cout << "hname_pos = " << hname_pos << endl;
    cout << "hname_neg = " << hname_neg << endl;
    TH1D* hpos = (TH1D*)fy->Get(hname_pos);
    TH1D* hneg = (TH1D*)fy->Get(hname_neg);
    if (hpos==NULL || hneg==NULL) cout << "histogram not found" << endl;

    //cosmetics and display
    hpos->SetLineColor(kRed);
    hneg->SetLineColor(kBlue);
    c->cd(iq2wbin+1);
    hpos->Draw();
    hneg->Draw("sames");
    iq2wbin+=1;
  }
  c->Update();
}
开发者ID:arjun-trivedi,项目名称:ana2pi,代码行数:39,代码来源:xsec-tools.092513.pretwoscales.C

示例4: initROOT

void MainWindow::initROOT() {
  // resultFile = new TFile(resultFileLineEdit->text().toStdString().c_str(), "RECREATE");

  QString inputFileList = this->inputFileListLineEdit->text();
  QFile file(inputFileList);
  if (!file.open(QFile::ReadOnly | QFile::Text)) {
    std::cout << "Can not open file for reading: " << qPrintable(file.errorString()) << std::endl;
  }

  chain = new TChain("AMPT");
  QTextStream in(&file);
  while (!in.atEnd()) {
    QString eachRootFile = in.readLine();
    TFile *testRootFile = new TFile(eachRootFile.toStdString().c_str());
    if (!testRootFile || !testRootFile->IsOpen() || !testRootFile->GetNkeys()) {
      std::cout << "The root file is bad :" << qPrintable(eachRootFile) << std::endl;
    } else {
      chain->Add(eachRootFile.toStdString().c_str());
    }
    delete testRootFile;
  }
  file.close();
}
开发者ID:Jinxiaohai,项目名称:QT,代码行数:23,代码来源:mainwindow.cpp

示例5: doEvents

// ------------------ Here is the actual method -----------------------------------------
void doEvents(const Char_t *fileList, const Char_t *outputname)
{
  Int_t nEvents = 1000;
  Int_t nfiles = 100;

  //
  // First load some shared libraries we need
  //
  if (gClassTable->GetID("TTable") < 0) {
    gSystem->Load("libStar");
    gSystem->Load("libPhysics");
  }  
  gROOT->LoadMacro("$STAR/StRoot/StMuDSTMaker/COMMON/macros/loadSharedLibraries.C");
  loadSharedLibraries();
  gSystem->Load("StarMagField");
  gSystem->Load("StMagF");
  gSystem->Load("StTpcDb");
//  gSystem->Load("StDbUtilities");
  gSystem->Load("StDaqLib");
  gSystem->Load("StDbBroker");
  gSystem->Load("StDetectorDbMaker");
  gSystem->Load("StDbUtilities");
  gSystem->Load("St_db_Maker");

  gSystem->Load("StEvent");
  gSystem->Load("StEventMaker");
  gSystem->Load("StarMagField");
  gSystem->Load("StTofUtil");   
 
  gSystem->Load("StVpdAnalysisMaker");
    //
    // Handling depends on whether file is a ROOT file or XDF file
    //
    chain  = new StChain("StChain");


    delete setFiles; setFiles =0;
    if (fileList) {     //Normal case
      setFiles= new StFile();
    } else        {     //
      return;
    }
    ifstream* inputStream = new ifstream;
    inputStream->open(fileList);
    if (!(inputStream)) {
      cout << "can not open list file" << endl;
      return;
    }
    cout<<"Open file list: --- "<<fileList<<endl;

    char line[512];
    for (;inputStream->good();) {
      inputStream->getline(line,512);
      if  ( inputStream->good() ) {
	//cout<<" root file "<<line<<endl;
	TFile *ftmp = new TFile(line);
	 //----------
         if (!(ftmp->IsOpen())) {
           cout<<line<<" open failed ! not chained"<<endl;
           continue;   
         }
         if (ftmp->IsZombie()) {
           cout<<"sth. very wrong with "<<line<<", not chained "<<endl;
           continue;   
         }
         if (ftmp->TestBit(1024)) { 
           cout<<"revocer procedure applied to "<<line<<endl;
           continue;   
         } 
	 //--------------------------           
         if( ftmp && ftmp->IsOpen() && ftmp->GetNkeys()) {
	    cout << "add file " << line << endl;
	    setFiles->AddFile(line);
	 } else {
	     cout << " cannot open file " << line << endl;
    	 }
    	 delete ftmp;
       }
    }


   StMuDstMaker* muDstMaker = new StMuDstMaker(0,0,"",fileList,"MuDst.root",nfiles);
   muDstMaker->SetStatus("*",0);
   muDstMaker->SetStatus("MuEvent",1);
   muDstMaker->SetStatus("TofRawData",1);

   cout<<endl<<"============  Data Base ========="<<endl;
   dbMk = new St_db_Maker("db","MySQL:StarDb","$STAR/StarDb","StarDb");

   StVpdAnalysisMaker *vpdAna = new StVpdAnalysisMaker();
   vpdAna->SetDebug();

    //
    // Initialize chain
    //
    Int_t iInit = chain->Init();
    if (iInit) chain->Fatal(iInit,"on init");
    chain->PrintInfo();
    
//.........这里部分代码省略.........
开发者ID:star-bnl,项目名称:star-tof,代码行数:101,代码来源:doEvents.C

示例6: main


//.........这里部分代码省略.........
		TSelectionClass* selectionClass = new TSelectionClass(settings);
		selectionClass->SetResults(currentResults);
		selectionClass->MakeSelection(RunParameters[i].getEvents());
		delete selectionClass;

		if(RunParameters[i].doSelectionAnalysis()){
			sys->cd(currentDir.c_str());
			TAnalysisOfSelection *analysisSelection=new TAnalysisOfSelection(settings);
			analysisSelection->doAnalysis(RunParameters[i].getEvents());
			delete analysisSelection;
		}

		if (DO_ALIGNMENT){
			sys->cd(currentDir.c_str());
			TAlignment *alignment = new TAlignment(settings);
			//			alignment->setSettings(settings);
			//alignment->PrintEvents(1511,1501);
			alignment->Align(RunParameters[i].getEvents());
			delete alignment;
		}

		if(DO_ALIGNMENTANALYSIS){
			sys->cd(currentDir.c_str());
			TAnalysisOfAlignment *anaAlignment;
			anaAlignment=new TAnalysisOfAlignment(settings);
			anaAlignment->doAnalysis(RunParameters[i].getEvents());
			delete anaAlignment;
		}

		if (DO_TRANSPARENT_ANALYSIS) {
			TTransparentAnalysis *transpAna;
			transpAna = new TTransparentAnalysis(settings);
			transpAna->setResults(currentResults);
			transpAna->analyze(RunParameters[i].getEvents(),RunParameters.at(i).getStartEvent());
			delete transpAna;
		}

		if (settings && settings->doTransparentAlignmnet()){
			sys->cd(currentDir.c_str());
			TAlignment *alignment = new TAlignment(settings,TSettings::transparentMode);
			alignment->createTransparentEventVectors(RunParameters[i].getEvents());
			//			alignment->setSettings(settings);
			//alignment->PrintEvents(1511,1501);
			alignment->Align(RunParameters[i].getEvents(),0,TAlignment::diaAlignment);
			delete alignment;

			TTransparentAnalysis *transpAna;
			transpAna = new TTransparentAnalysis(settings,TSettings::transparentMode);
			transpAna->setResults(currentResults);
			transpAna->analyze(RunParameters[i].getEvents(),RunParameters.at(i).getStartEvent());
			delete transpAna;
		}
		cout<<"PRINT RESULTS"<<endl;
		currentResults->Print();
		cout<<"SAVE RESULTS"<<endl;
//		currentResults->saveResults(settings->getResultsRootFilePath());
		TFile* file = new TFile (settings->getResultsRootFilePath().c_str(),"RECREATE");
		file->Print();
		file->ls();
		file->SetName("fileName");
		file->cd();
		cout<<"KEYS: "<<file->GetNkeys()<<endl;
		file->GetListOfKeys()->Print();
		cout<<"Write"<<endl;

		currentResults->Write("test");
		cout<<"CLOSE FILE"<<endl;
		file->Close();
//		if (currentResults){
//			cout<<"DELETE RESULTS"<<endl;
//			delete currentResults;
//			cout<<"#"<<endl;;
//		}
		cout<<"saved results..."<<endl;


		runWatch.Stop();
		cout<<"needed Time for Run "<<RunParameters[i].getRunNumber()<<":"<<endl;
		runWatch.Print();
   
        cout<<"needed Time for Run "<<RunParameters[i].getRunNumber()<<":\n\t"<<flush;
        runWatch.Print();
        if (settings!=NULL){
            cout<<"delete Settings..."<<endl;
            delete settings;
            cout<<"DONE_SETTINGS"<<endl;
                                                           
        }
        cout<<"DONE with Analysis of Run "<< RunParameters[i].getRunNumber();
        cout<<": "<<i+1<<"/"<<RunParameters.size()<<endl;
   }
   cout<<"DONE with Analysis of all "<<RunParameters.size()<<" Runs from RunList.ini"<<endl;
   cout<<"total time for all analysis:\n\t"<<flush;

	cout<<"time for all analysis:"<<endl;
	comulativeWatch.Print();
	cout<<"DONE_ALL"<<endl;

	return 0;
}
开发者ID:diamondIPP,项目名称:StripTelescopeAnalysis,代码行数:101,代码来源:diamondAnalysis.cpp

示例7: plotphi

void plotphi(int top, bool phi=kFALSE){
  if (setup("vm","","pol__")==kFALSE) return;
  gStyle->SetOptFit(1111); //pcev = 1111
  //gStyle->SetTitleW(1.5);

  int itop = top-1;
  TFile* fy = _fyexp[itop];

  int nq2wbins = fy->GetNkeys();
  TIter nextkey(fy->GetListOfKeys());
  TKey *key;
  int iq2wbin = 0;
  while (key = (TKey*)nextkey()) {
    TString Q2Wdirname = key->GetName();
    if(Q2Wdirname.EqualTo("hYW_Dir") || Q2Wdirname.EqualTo("hYW"))continue;
    cout << "Q2Wdirname = " << Q2Wdirname << endl;

    THStack* hs[10];
    TF1 *fphi = new TF1("fphi", "([0] + [1]*cos(x*TMath::DegToRad()) + [2]*cos(2*x*TMath::DegToRad()) + [3]*sin(x*TMath::DegToRad()))",0, 360);
    fphi->SetParameter(0,1);
    fphi->SetParameter(1,10);
    fphi->SetParameter(2,20);
    fphi->SetParameter(3,100);
    fphi->SetParName(0, "A");
    fphi->SetParName(1, "B");
    fphi->SetParName(2, "C");
    fphi->SetParName(3, "hPR");
    for (int i = 0; i < 10; i++)
    {
      TString hname_unp = TString::Format("%s/hPhi/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1);
      TString hname_pos = TString::Format("%s/hPhi_POS/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1);
      TString hname_neg = TString::Format("%s/hPhi_NEG/Varset1/theta/hphi_%02d",Q2Wdirname.Data(),i+1);
      cout << "hname_unp = " << hname_unp << endl;
      cout << "hname_pos = " << hname_pos << endl;
      cout << "hname_neg = " << hname_neg << endl;
      TH1D* hunp = (TH1D*)fy->Get(hname_unp);
      TH1D* hpos = (TH1D*)fy->Get(hname_pos);
      TH1D* hneg = (TH1D*)fy->Get(hname_neg);
      if (hunp==NULL || hpos==NULL || hneg==NULL) cout << "histogram not found" << endl;
      hunp->SetLineColor(kBlack);
      hpos->SetLineColor(kRed);
      hneg->SetLineColor(kBlue);
      hunp->Fit(fphi);
      hpos->Fit(fphi);
      hneg->Fit(fphi);

      //! Modify titles
      TObjArray *tarr;
      char t[100];

      TPaveText *ptunp = new TPaveText(0.0, 0.9, 1.0, 1, "NDC");
      TString tunp = hunp->GetTitle();
      tarr = tunp.Tokenize("|");
      sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName());
      ptunp->AddText(tarr->At(0)->GetName());
      ptunp->AddText(t);
      hunp->SetTitle("");

      TPaveText *ptpos = new TPaveText(0.0, 0.9, 1.0, 1, "NDC");
      TString tpos = hpos->GetTitle();
      tarr = tpos.Tokenize("|");
      sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName());
      ptpos->AddText(tarr->At(0)->GetName());
      ptpos->AddText(t);
      hpos->SetTitle("");

      TPaveText *ptneg = new TPaveText(0.0, 0.9, 1.0, 1, "NDC");
      TString tneg = hneg->GetTitle();
      tarr = tneg.Tokenize("|");
      sprintf(t, "%s:%s:%s", tarr->At(1)->GetName(), tarr->At(2)->GetName(), tarr->At(3)->GetName());
      ptneg->AddText(tarr->At(0)->GetName());
      ptneg->AddText(t);
      hneg->SetTitle("");

      //! Draw histograms
      TCanvas *c = new TCanvas(hpos->GetName(),hpos->GetName(),900, 600);
      c->Divide(3,1);
      c->cd(1);
      hunp->Draw();
      ptunp->Draw();
      c->cd(2);
      hpos->Draw();
      ptpos->Draw();
      c->cd(3);
      hneg->Draw();
      ptneg->Draw();
      TString dir = TString::Format("./polobs/top%d/%s/Varset1/theta", top, Q2Wdirname.Data());
      gSystem->mkdir(dir,1);
      c->SaveAs(TString::Format("%s/%s.png", dir.Data(), c->GetName()));
      c->Close();
      c->Delete();
    }
  }
}
开发者ID:arjun-trivedi,项目名称:ana2pi,代码行数:94,代码来源:xsec-tools.092513.pretwoscales.C


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