本文整理汇总了C++中TFile::ls方法的典型用法代码示例。如果您正苦于以下问题:C++ TFile::ls方法的具体用法?C++ TFile::ls怎么用?C++ TFile::ls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TFile
的用法示例。
在下文中一共展示了TFile::ls方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execCreateAndMerge
void execCreateAndMerge() {
//--------------------------------------------------------------------------
for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) {
TFile* outputFile = TFile::Open(Form("a_file_%d.root",ifile),"RECREATE");
TNamed* namedObj = new TNamed(Form("namedObj%d",ifile),Form("namedObj%d",ifile));
namedObj->Write();
outputFile->Close();
}
cout << "4 a files created" << endl;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) {
TFile* outputFile = TFile::Open(Form("b_file_%d.root",ifile),"RECREATE");
TNamed* namedObj = new TNamed("namedObj","namedObj");
namedObj->Write();
outputFile->Close();
}
cout << "4 b files created" << endl;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
TFileMerger* aMerger = new TFileMerger(kFALSE);
for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) {
TFile* inFile = TFile::Open(Form("a_file_%d.root",ifile));
aMerger->AddFile(inFile);
}
aMerger->OutputFile("a_file.root");
aMerger->Merge();
cout << "4 a files merged" << endl;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
TFileMerger* bMerger = new TFileMerger(kFALSE);
for ( Int_t ifile = 0 ; ifile < 4 ; ifile++ ) {
TFile* inFile = TFile::Open(Form("b_file_%d.root",ifile));
bMerger->AddFile(inFile);
}
bMerger->OutputFile("b_file.root");
bMerger->Merge();
cout << "4 b files merged" << endl;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
TFile* inAFile = TFile::Open("a_file.root");
cout << "******* MERGED A FILE ******** 4 objects with different names" << endl;
inAFile->ls();
cout << "******************************" << endl;
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
TFile* inBFile = TFile::Open("b_file.root");
cout << "******* MERGED B FILE ******** 4 objects with the same names" << endl;
inBFile->ls();
cout << "******************************" << endl;
//--------------------------------------------------------------------------
}
示例2: GetGraph
TGraph2DErrors* GetGraph(std::string fname)
{
TGraph2DErrors* gr = 0;
std::string fGrName = "mygraph";
TFile *f = new TFile(fname.data());
if (!f->IsOpen())
{
std::cerr << "Failed to open " << fname << std::endl;
return gr;
}
f->ls();
std::cout << "Enter name of graph : ";
if (std::cin.peek()=='\n') std::cin.get();
std::getline(std::cin, fGrName);
f->GetObject(fGrName.data(), gr);
if (gr!=NULL)
{
TGraph2DErrors* tgr = (TGraph2DErrors*) gr->Clone("mygraph_0");
gr=tgr;
gr->SetDirectory(0);
}
return gr;
}
示例3: makeSVfitMEM_xSectionPlot
void makeSVfitMEM_xSectionPlot()
{
gROOT->SetBatch(true);
std::string inputFilePath = "/afs/cern.ch/user/v/veelken/scratch0/SVfitMEM_with_vamp/CMSSW_7_4_6/src/TauAnalysis/SVfitMEM/data/";
std::string inputFileName = "svFitMEM_xSection_and_AccCorr_13TeV_fitted.root";
std::string inputFileName_full = Form("%s%s", inputFilePath.data(), inputFileName.data());
TFile* inputFile = new TFile(inputFileName_full.data());
if ( !inputFile ) {
std::cerr << "Failed to open input file = '" << inputFileName_full << "' !!" << std::endl;
assert(0);
}
std::string graphName = "graph_Xsection_woAcc_13TeV_hadhad_vamp_fitted";
TGraph* graph = dynamic_cast<TGraph*>(inputFile->Get(graphName.data()));
if ( !graph ) {
std::cerr << "Failed to load graph = '" << graphName << "' from file = '" << inputFileName.data() << "' !!" << std::endl;
inputFile->ls();
assert(0);
}
std::string outputFileName = "./makeSVfitMEM_xSectionPlot.pdf";
showGraph(800, 650,
graph,
false, 50., 5000., "m_{H} [GeV]", 1.30,
true, 1.e-4, 1.e+2, "#sigma(gg #rightarrow H) [pb]", 1.35,
outputFileName);
delete inputFile;
}
示例4: OpenDataThisFile
//_______________________________________
int OpenDataThisFile(TString fname ) {
int success = 0 ;
// open the ROOT file to process
TString path ="./data1/moukaddam/SpiceTestSep2014/Calibration/Files/";
TString inFileName = fname+".root";
TFile *inFile = new TFile(path + inFileName);
if ( !inFile->IsOpen() ) { //try present directory
cout << "File doesn't exist in the directory : " << path << endl ;
cout << "Trying the present working directory : ./" << endl ;
path ="./";
inFile = new TFile(path + inFileName);
}
if ( inFile->IsOpen() ) {
success = 1 ;
cout << "Opening the root file and grabing the histograms from " << inFile->GetName() << endl ;
inFile->ls();
}
else {
cout << "File is not found.. EXIT!"<< endl;
exit(-1);
}
gFolderHistos = (TFolder*)(inFile->FindObjectAny("histos"));
return success ;
}
示例5: testMergedFile
int testMergedFile(const char *filename, Int_t compSetting, Long64_t fileSize)
{
TFile *file = TFile::Open(filename);
if (file == nullptr || file->IsZombie()) {
Error("testSimpleFile", "Could not open %s.",filename);
return 1;
}
file->ls();
file->cd("hist");
gDirectory->ls();
gDirectory->Get("Gaus")->Print();
file->cd("named");
gDirectory->ls();
file->Get("MyList")->Print();
if (file->GetCompressionSettings() != compSetting) {
Error("execTestMultiMerge","Compression level of %s should have been %d but is %d\n",file->GetName(), 206, file->GetCompressionSettings() );
return 3;
}
if (file->GetSize() != fileSize) {
Error("execTestMultiMerge","Disk size of %s should have been %lld but is %lld\n",file->GetName(), fileSize, file->GetSize() );
return 4;
}
delete file;
return 0;
}
示例6: BuildUniformField
//__________________________________________________________________________
Bool_t BuildUniformField(const TGeoHMatrix& matrix)
{
// Create a Uniform Magnetic field and write it to file
cout << "Building Uniform Mag Field" << endl;
MagFieldArray* magFieldArray = new MagFieldArray();
// -- Define solenoid field - uniform magnetic field
// Define shape of field
TGeoShape* fieldShape = new Tube("SolenoidFieldShape",hvCellRMin, hvCellRMax, hvCellHalfZ);
// Define transformation that locates field in geometry
TGeoMatrix* fieldPosition = new TGeoHMatrix(matrix);
// Define field vector in Coordinate system of Field
TVector3 fieldStrength(solenoidBx, solenoidBy, solenoidBz);
cout << "Local Coordinates - ";
cout << "Bx: " << fieldStrength[0] << "\t By: " << fieldStrength[1];
cout << "\t Bz: " << fieldStrength[2] << endl;
// Define field object
MagField* uniformField = new UniformMagField("SolenoidField", fieldStrength, fieldShape, fieldPosition);
// Add field to magfield manager
magFieldArray->AddField(uniformField);
// -- Write magfieldmanager to geometry file
const char *magFileName = "$(UCN_GEOM)/fields.root";
TFile *f = TFile::Open(magFileName,"recreate");
if (!f || f->IsZombie()) {
Error("Export","Cannot open file: %s", magFileName);
return kFALSE;
}
magFieldArray->Write(magFieldArray->GetName());
f->ls();
f->Close();
if (magFieldArray) delete magFieldArray;
magFieldArray = 0;
return kTRUE;
}
示例7: evtime
void evtime() {
vector<int> runs;
vector<int> marks;
vector<int> mcols;
runs.push_back(13893);
marks.push_back(2);
mcols.push_back(2);
runs.push_back(14009);
marks.push_back(24);
mcols.push_back(4);
runs.push_back(14085);
marks.push_back(25);
mcols.push_back(3);
runs.push_back(14234);
marks.push_back(5);
mcols.push_back(3);
runs.push_back(14434);
marks.push_back(28);
mcols.push_back(3);
string pre = "run";
string suf = "evt.root";
double tmax = 160;
double emax = 180;
new TCanvas;
TH1* ph = new TH2F("hevtime", "Event vs. time; Time [sec]; Event",
tmax, 0, tmax, emax, 0, emax);
ph->SetStats(0);
ph->Draw("axis");
TLegend* pleg = new TLegend(0.65,0.15,0.85,0.37);
pleg->SetBorderSize(0);
for ( unsigned int isam=0; isam<runs.size(); ++isam ) {
int run = runs[isam];
int icol = dsindex(run);
int col = colormap(icol);
ostringstream ssrun;
ssrun << run;
string srun = ssrun.str();
ostringstream sst0;
sst0 << t0map(run);
string fname = pre + srun + suf;
TFile* pfile = TFile::Open(fname.c_str(), "READ");
TTree* ptree = dynamic_cast<TTree*>(pfile->Get("DXDisplay/EventTree"));
ptree->SetMarkerStyle(marks[isam]);
ptree->SetMarkerColor(col);
cout << run << " " << col << " " << sst0.str() << endl;
if ( ptree == 0 ) {
cout << "Tree not found" << endl;
pfile->ls();
return;
}
string sarg = "event:tlo-";
sarg += sst0.str();
sarg += ">>hevtime";
ptree->Draw(sarg.c_str(), "", "same");
pleg->AddEntry(ptree, srun.c_str(), "p");
}
pleg->Draw();
}
示例8: MergeSimpleHistogramFile
//________________________________________________________________________________
void MergeSimpleHistogramFile( const Char_t *TargetName=0, const Char_t *inputFilesPattern=0)
{
// This is the deprecated version. To be dleted after debugging
if (TargetName && TargetName[0] && inputFilesPattern && inputFilesPattern[0] ) {
TStopwatch time;
Int_t fileCounter = 0;
Int_t histogramCounter = 0;
// Create the output file
TFile *outFile = TFile::Open(TargetName,"RECREATE");
TDirIter listOfFiles(inputFilesPattern);
const char *fileName = 0;
while ( (fileName = listOfFiles.NextFile() ) ) {
printf(".");
fileCounter++;
TFileIter file(fileName);
TObject *obj = 0;
while ( (obj = *file) ) {
if ( obj->IsA()->InheritsFrom( "TH1" ) ) {
// descendant of TH1 -> merge it
// printf("Merging histogram: %s\n",obj->GetName() );
// std::cout << "Merging histogram " << obj->GetName() << std::endl;
TH1 *h1 = (TH1*)obj;
TH1 *dstHistogram = 0;
// Check whether we found the new histogram
if ( (dstHistogram = (TH1 *)outFile->FindObject(h1->GetName()))) {
// Accumulate the histogram
dstHistogram->Add(h1);
delete h1; // Optional, to reduce the memory consumption
printf("+");
} else {
// First time - move the histogram
h1->SetDirectory(outFile);
printf(" The new Histogram found: %s \n", h1->GetName() );
histogramCounter++;
}
} else {
// printf("Skipping object: %s\n",obj->GetName() );
}
++file;
}
}
printf("\n Finishing . . . \n");
outFile->ls();
outFile->Write();
outFile->Close();
delete outFile;
printf(" Total files merged: %d \n", fileCounter);
printf(" Total histograms merged: %d \n", histogramCounter);
time.Print("Merge");
} else {
printf("\nUsage: root MergeHistogramFile.C(\"DestinationFileName\",\"InputFilesPattern\",kTRUE)\n");
printf("------ where InputFilesPattern ::= <regexp_pattern_for_the_input_files>|@indirect_file_list\n");
printf(" indirect_file_list ::= a text file with the list of the files\n");
printf(" indirect_file_list can be create by the shell command:\n");
printf(" ls -1 --color=never *.root>indirect_file_list \n\n");
}
}
示例9: fit1
void fit1() {
//Simple fitting example (1-d histogram with an interpreted function)
//To see the output of this macro, click begin_html <a href="gif/fit1.gif">here</a>. end_html
//Author: Rene Brun
TCanvas *c1 = new TCanvas("c1_fit1","The Fit Canvas",200,10,700,500);
c1->SetGridx();
c1->SetGridy();
c1->GetFrame()->SetFillColor(21);
c1->GetFrame()->SetBorderMode(-1);
c1->GetFrame()->SetBorderSize(5);
gBenchmark->Start("fit1");
//
// We connect the ROOT file generated in a previous tutorial
// (see begin_html <a href="fillrandom.C.html">Filling histograms with random numbers from a function</a>) end_html
//
TString dir = gSystem->UnixPathName(gInterpreter->GetCurrentMacroName());
dir.ReplaceAll("fit1.C","");
dir.ReplaceAll("/./","/");
TFile *fill = TFile::Open("fillrandom.root");
if (!fill) {
gROOT->ProcessLine(Form(".x %s../hist/fillrandom.C",dir.Data()));
fill = TFile::Open("fillrandom.root");
if (!fill) return;
}
//
// The function "ls()" lists the directory contents of this file
//
fill->ls();
//
// Get object "sqroot" from the file. Undefined objects are searched
// for using gROOT->FindObject("xxx"), e.g.:
// TF1 *sqroot = (TF1*) gROOT.FindObject("sqroot")
//
sqroot->Print();
//
// Now fit histogram h1f with the function sqroot
//
h1f->SetFillColor(45);
h1f->Fit("sqroot");
// We now annotate the picture by creating a PaveText object
// and displaying the list of commands in this macro
//
fitlabel = new TPaveText(0.6,0.3,0.9,0.80,"NDC");
fitlabel->SetTextAlign(12);
fitlabel->SetFillColor(42);
fitlabel->ReadFile(Form("%sfit1_C.C",dir.Data()));
fitlabel->Draw();
c1->Update();
gBenchmark->Show("fit1");
}
示例10: runmergeWithDir
void runmergeWithDir()
#endif
{
TChain *tph;
tph = new TChain("CBNT/t3333");
tph->AddFile("file1.root");
tph->AddFile("file2.root");
tph->Merge("merged.root");
TFile *fil = new TFile("merged.root");
fil->ls();
}
示例11: xrootdTestVanderbilt
void xrootdTestVanderbilt(const int iOption=0) {
TDatime *dateTime = new TDatime;
int iDate = dateTime->GetDate();
int iTime = dateTime->GetTime();
cout << " Begin Vanderbilt access testing " << iDate << " at " << iTime << endl;
if(iOption == 0 || iOption == 1) {
TFile *f = TFile::Open("root://cmsxrootd.fnal.gov//store/test/xrootd/T2_US_Vanderbilt//store/mc/SAM/GenericTTbar/GEN-SIM-RECO/CMSSW_5_3_1_START53_V5-v1/0013/CE4D66EB-5AAE-E111-96D6-003048D37524.root");
if(f) {
cout << "\n cmsxrootd.fnal.gov successful access to Vanderbilt" << endl;
f->ls();
f->Close();
}
else {
cout << "\n cmsxrootd.fnal.gov unsuccessful access to Vanderbilt" << endl;
}
dateTime->Set(); // set to system date/time
iDate = dateTime->GetDate();
iTime = dateTime->GetTime();
cout << " Completed Vanderbilt access test from FNAL on " << iDate << " at " << iTime << endl;
} // check on iOption = 0 or iOption = 1
if(iOption == 0 || iOption == 2) {
TFile *g = TFile::Open("root://cms-xrd-global.cern.ch//store/test/xrootd/T2_US_Vanderbilt//store/mc/SAM/GenericTTbar/GEN-SIM-RECO/CMSSW_5_3_1_START53_V5-v1/0013/CE4D66EB-5AAE-E111-96D6-003048D37524.root");
if(g) {
cout << "\n cms-xrd-global.cern.ch successful access to Vanderbilt" << endl;
g->ls();
g->Close();
}
else {
cout << "\n cms-xrd-global.cern.ch unsuccessful access to Vanderbilt" << endl;
}
dateTime->Set(); // set to system date/time
iDate = dateTime->GetDate();
iTime = dateTime->GetTime();
cout << " Completed Vanderbilt access test from CERN on " << iDate << " at " << iTime << endl;
} // check on iOption = 0 or iOption = 2
dateTime->Set(); // set to system date/time
cout << "\n Completed Vanderbilt access testing " << iDate << " at " << iTime << endl;
return;
}
示例12: execTestMultiMerge
int execTestMultiMerge()
{
TFile *file = TFile::Open("mfile1-4.root");
file->ls();
file->cd("hist");
gDirectory->ls();
gDirectory->Get("Gaus")->Print();
file->cd("named");
gDirectory->ls();
file->Get("MyList")->Print();
return 0;
}
示例13: TFile
TFile *createRootFile(TString fileName,TString STlepCut,TString HTCut,TH1D *hIn,TString histoName) {
TH1::SetDefaultSumw2();
TFile *fout = new TFile(fileName,"UPDATE");
fout->mkdir("ANplots"+STlepCut+"_NOLPsecondD"+HTCut);
fout->ls();
fout->cd("ANplots"+STlepCut+"_NOLPsecondD"+HTCut);
fout->pwd();
TH1D *hOut = (TH1D*)hIn->Clone(histoName); hOut->SetName(histoName);
hOut->Write(histoName);
fout->Close();
return fout;
}
示例14: BuildFieldMap
//__________________________________________________________________________
Bool_t BuildFieldMap(const TGeoHMatrix& matrix)
{
// Create a Uniform Magnetic field and write it to file
string filename = "runs/polarisation/guide_tube/C8=9 A +SQUIDs Coil =26_4 mA +D1=2 A + 6WS TC guide tube -100 z +80 cm.txt";
// Define shape of field
TGeoShape* magFieldShape = new Box("FieldShape",0.031, 0.031, 3.0);
// Define transformation that locates field in geometry
TGeoMatrix* magFieldPosition = new TGeoHMatrix(matrix);
magFieldPosition->Print();
MagFieldMap* field = new MagFieldMap("Field", magFieldShape, magFieldPosition);
if (field->BuildMap(filename) == kFALSE) {
Error("BuildFieldMap","Cannot open file: %s", filename);
return kFALSE;
}
// Add field to magfield manager
MagFieldArray* magFieldArray = new MagFieldArray();
magFieldArray->AddField(field);
/* // Elec Field
// Define shape of field
TGeoShape* elecFieldShape = new Tube("SolenoidFieldShape",hvCellRMin, hvCellRMax, hvCellHalfZ);
// Define transformation that locates field in geometry
TGeoMatrix* elecFieldPosition = new TGeoHMatrix(matrix);
TVector3 elecFieldStrength(hvCellEx, hvCellEy, hvCellEz);
ElecField* elecField = new UniformElecField("ElectricField", elecFieldStrength, elecFieldShape, elecFieldPosition);
// Add field to electric field manager
ElecFieldArray* elecFieldArray = new ElecFieldArray();
elecFieldArray->AddField(elecField);
*/
// -- Write magfieldmanager to geometry file
const char *magFileName = "geom/fields.root";
TFile *f = TFile::Open(magFileName,"recreate");
if (!f || f->IsZombie()) {
Error("BuildFieldMap","Cannot open file: %s", magFileName);
return kFALSE;
}
magFieldArray->Write(magFieldArray->GetName());
// elecFieldArray->Write(elecFieldArray->GetName());
f->ls();
f->Close();
delete magFieldArray;
// delete elecFieldArray;
magFieldArray = 0;
// elecFieldArray = 0;
return kTRUE;
}
示例15: TFile
mkplots(){
gStyle->SetOptStat(1);
TFile * f = new TFile("plots.root");
f->ls();
TH1F * hpn = (TH1F *) f->Get("hpn");
TH1F * hpt = (TH1F *) f->Get("hpt");
TH1F * hpp = (TH1F *) f->Get("hpp");
TH1F * hde = (TH1F *) f->Get("hde");
TH1F * hdp = (TH1F *) f->Get("hdp");
TH1F * hdt = (TH1F *) f->Get("hdt");
TCanvas * c1 = new TCanvas;
hpn->SetXTitle("pull shower log(N)");
hpn->Draw("ep");
c1->SaveAs("plots/pn.png");
TCanvas * c2 = new TCanvas;
hpt->SetXTitle("pull shower eta)");
hpt->Draw("ep");
c2->SaveAs("plots/pt.png");
TCanvas * c3 = new TCanvas;
hpp->SetXTitle("pull shower phi");
hpp->Draw("ep");
c3->SaveAs("plots/pp.png");
TCanvas * c4 = new TCanvas;
hde->SetXTitle("shower E fractional difference");
hde->Draw("ep");
c4->SaveAs("plots/dn.png");
TCanvas * c5 = new TCanvas;
hdt->SetXTitle("shower theta fractional difference");
hdt->Draw("ep");
c5->SaveAs("plots/dt.png");
TCanvas * c6 = new TCanvas;
hdp->SetXTitle("shower phi fractional difference");
hdp->Draw("ep");
c6->SaveAs("plots/dp.png");
}