本文整理汇总了C++中TFile::IsZombie方法的典型用法代码示例。如果您正苦于以下问题:C++ TFile::IsZombie方法的具体用法?C++ TFile::IsZombie怎么用?C++ TFile::IsZombie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TFile
的用法示例。
在下文中一共展示了TFile::IsZombie方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hsimpleReader
void hsimpleReader() {
// Create a histogram for the values we read.
TH1F *myHist = new TH1F("h1","ntuple",100,-4,4);
// Open the file containing the tree.
TFile *myFile = TFile::Open("$ROOTSYS/tutorials/hsimple.root");
if (!myFile || myFile->IsZombie()) {
gROOT->ProcessLine(".x $ROOTSYS/tutorials/hsimple.C");
myFile = TFile::Open("$ROOTSYS/tutorials/hsimple.root");
if (!myFile || myFile->IsZombie()) {
return;
}
}
// Create a TTreeReader for the tree, for instance by passing the
// TTree's name and the TDirectory / TFile it is in.
TTreeReader myReader("ntuple", myFile);
// The branch "px" contains floats; access them as myPx.
TTreeReaderValue<Float_t> myPx(myReader, "px");
// The branch "py" contains floats, too; access those as myPy.
TTreeReaderValue<Float_t> myPy(myReader, "py");
// Loop over all entries of the TTree or TChain.
while (myReader.Next()) {
// Just access the data as if myPx and myPy were iterators (note the '*'
// in front of them):
myHist->Fill(*myPx + *myPy);
}
myHist->Draw();
}
示例2: combineHistos
void combineHistos(std::string type) {
bool _dt = (type == "DATA");
bool _mc = !_dt;
TDirectory *curdir = gDirectory;
// Input file: normalized pT spectra
TFile *fin =
new TFile(Form("outputs/output-%s-2a.root", type.c_str()), "READ");
assert(fin && !fin->IsZombie());
// Top-level directory
_top = gDirectory;
// Output file: combined spectra
TFile *fout =
new TFile(Form("outputs/output-%s-2b.root", type.c_str()), "RECREATE");
assert(fout && !fout->IsZombie());
std::cout << "Calling combineHistos(" << type << ");" << std::endl;
std::cout << "Input file " << fin->GetName() << std::endl;
std::cout << "Output file " << fout->GetName() << std::endl;
std::cout << "Starting recursions. These may take a few seconds" << std::endl;
// Store pT ranges to a nice map
for (int itrg = 0; itrg != _jp_ntrigger; ++itrg) {
std::string name = _jp_triggers[itrg];
double lower = _jp_trigranges[itrg][0];
double upper = _jp_trigranges[itrg][1];
_ptranges[name] = pair<double, double>(lower, upper);
}
// Loop over all the directories recursively
recurseFile(fin, fout, "hpt");
recurseFile(fin, fout, "hpt_pre");
if (_dt)
recurseFile(fin, fout, "hlumi");
if (_mc)
recurseFile(fin, fout, "hpt_g0tw");
curdir->cd();
std::cout << std::endl << "Output stored in " << fout->GetName() << std::endl;
// Close files
fout->Close();
fout->Delete();
std::cout << "Output file closed" << std::endl;
fin->Close();
fin->Delete();
std::cout << "Input file closed" << std::endl;
}
开发者ID:cms-opendata-validation,项目名称:2011-jet-inclusivecrosssection-analysis,代码行数:58,代码来源:combineHistos.C
示例3: normalizeHistos
void normalizeHistos(string type) {
assert(type==_jp_type);
_nh_mc = (type=="MC" || type=="HW");
_nh_dt = (type=="DATA");
assert((_nh_mc || _nh_dt) && !(_nh_mc && _nh_dt));
TFile *fin = new TFile(Form("output-%s-1.root",type.c_str()),"READ");
assert(fin && !fin->IsZombie());
TFile *fout = new TFile(Form("output-%s-2a.root",type.c_str()),"RECREATE");
assert(fout && !fout->IsZombie());
if (_lumiscale!=1 && !_nh_mc)
cout << "Attention! : Scaling luminosity to the new estimate"
<< " by multiplying with " << _lumiscale << endl;
if (_jp_usetriglumi) {
cout << "Reading trigger luminosity from settings.h" << endl;
for (int i = 0; i != _jp_ntrigger; ++i) {
double lumi = _jp_triglumi[i]/1e6; // /ub to /pb
cout << Form(" *%s: %1.3f /pb", _jp_triggers[i].c_str(),lumi) << endl;
triglumi[_jp_triggers[i]] = lumi;
}
}
cout << "Calling normalizeHistos("<<type<<");" << endl;
cout << "Input file " << fin->GetName() << endl;
cout << "Output file " << fout->GetName() << endl;
cout << "Starting recursive loop. This may take a minute" << endl << flush;
// Loop over all the directories recursively
recurseFile(fin, fout);
cout << endl;
cout << "Recursive loop done." << endl;
cout << "Writing output to " << fout->GetName() << endl;
cout << "This may again take a minute" << endl << flush;
fout->Write();
cout << "Output written in " << fout->GetName() << endl;
fout->Close();
cout << "Output file closed" << endl;
fout->Delete();
cout << "Output file pointer deleted" << endl << flush;
fin->Close();
fin->Delete();
} // normalizeHistos
示例4: ProcessRun
void KVFAZIAReconDataAnalyser::ProcessRun()
{
// Perform treatment of a given run
// Before processing each run, after opening the associated file, user's InitRun() method is called.
// After each run, user's EndRun() is called.
// For each event of each run, user's Analysis() method is called.
//
// For further customisation, the pre/post-methods are called just before and just after
// each of these methods (preInitRun(), postAnalysis(), etc. etc.)
TString fullPathToRunfile = gDataSet->GetFullPathToRunfile(fDataType.Data(), fRunNumber);
TFile* f = (TFile*)gDataSet->OpenRunfile(fDataType.Data(), fRunNumber);
if (!(f && !f->IsZombie())) {
Error("ProcessRun", "file %s does not exist or is made zombie", fullPathToRunfile.Data());
return;
}
theTree = (TTree*)f->Get("ReconstructedEvents");
TFile* ffriend = 0;
if (fLinkRawData) {
fullPathToRunfile = gDataSet->GetFullPathToRunfile("raw", fRunNumber);
ffriend = (TFile*)gDataSet->OpenRunfile("raw", fRunNumber);
if (!(ffriend && !ffriend->IsZombie())) {
Warning("ProcessRun", "file %s does not exist or is made zombie\n Reading of raw data is not possible", fullPathToRunfile.Data());
} else {
theTree->AddFriend("FAZIA", ffriend);
}
}
TString option("");
// Add any user-defined options
if (GetUserClassOptions() != "") {
if (option != "")
option += ",";
option += GetUserClassOptions();
}
Info("SubmitTask", "Beginning TTree::Process... Option=%s", option.Data());
if (nbEventToRead) {
theTree->Process(GetUserClass(), option.Data(), nbEventToRead);
} else {
theTree->Process(GetUserClass(), option.Data());
}
if (ffriend && ffriend->IsOpen())
ffriend->Close();
f->Close();
}
示例5: appendRootFile
void appendRootFile()
{
TFile* pRootFile = new TFile("myfile.root", "UPDATE");
if (pRootFile != NULL) {
TDirectory* pTestDir = (TDirectory*)pRootFile->Get("TestDir");
if (pTestDir != NULL) {
pTestDir->cd();
MyROOTObject* pMyObj = NULL;
std::string name = "testobj";
pMyObj = (MyROOTObject*)pTestDir->Get(name.c_str());
if (pMyObj != NULL) {
std::cout << *pMyObj << std::endl;
delete pMyObj;
}
name = "newobj";
MyROOTObject* pNewObj = NULL;
pNewObj = new MyROOTObject(42, 5.9e2, name);
if (pNewObj != NULL) {
std::cout << *pMyObj << std::endl;
pNewObj->Write(pNewObj->GetName());
delete pNewObj;
}
}
if (pRootFile->IsOpen() && !pRootFile->IsZombie()) {
pRootFile->Close();
delete pRootFile;
}
}
}
示例6: TDCacheFile
TFile *openRootFile(const std::string& rootfn, const std::string& option="")
{
TFile *rootfile = NULL;
// Now check to see if this file has already been opened...
map<string,TFile*>::const_iterator it = glmap_id2rootfile.find(rootfn);
if( it != glmap_id2rootfile.end() ) {
rootfile = it->second;
if (!rootfile->IsOpen())
rootfile->Open(rootfn.c_str(),option.c_str());
else
rootfile->cd();
} else {
if (strstr(rootfn.c_str(),"dcache") ||
strstr(rootfn.c_str(),"dcap") ) {
rootfile = new TDCacheFile(rootfn.c_str(),option.c_str());
} else
rootfile = new TFile(rootfn.c_str(),option.c_str());
if( rootfile->IsZombie() ) {
cerr << "File failed to open, " << rootfn << endl;
rootfile = NULL;
} else {
glmap_id2rootfile.insert(pair<string,TFile*>(rootfn,rootfile));
}
}
return rootfile;
}
示例7: overwriteRootFile
void overwriteRootFile()
{
TFile* pRootFile = new TFile("myfile.root", "UPDATE");
if (pRootFile != NULL) {
TDirectory* pTestDir = (TDirectory*)pRootFile->Get("TestDir");
if (pTestDir != NULL) {
pTestDir->cd();
pTestDir->Delete("testobj;*");
std::string name = "testobj";
MyROOTObject* pNewObj = NULL;
int ival = rand() % 100 + 1;
double dval = (double)(rand() % 1000 + 1)/1000.0;
pNewObj = new MyROOTObject(ival, dval, name);
if (pNewObj != NULL) {
std::cout << *pNewObj << std::endl;
pNewObj->Write(pNewObj->GetName(), TObject::kOverwrite);
delete pNewObj;
}
}
if (pRootFile->IsOpen() && !pRootFile->IsZombie()) {
pRootFile->Close();
delete pRootFile;
}
}
}
示例8: singlePointLimit
double singlePointLimit(std::string filename, float tanb, unsigned int LIMIT_TYPE, unsigned int verbosity=0)
{
/*
Get the observed, expected and +/-1 ans +/-2 sigma band from limit trees, which are the
output of combine
*/
TString fullpath; fullpath = TString::Format(filename.c_str(), tanb); TFile* file = new TFile(fullpath);
if(file->IsZombie()){ if( verbosity>0 ){ std::cout << "> File not found: " << fullpath << std::endl; } return -999.; }
TTree* tree = (TTree*) file->Get("limit");
if(!tree){ if( verbosity>0 ){ std::cout << "> Tree not found in file: " << fullpath << std::endl; } return -999.; }
int nevent = tree->GetEntries();
if( nevent<=0 ){ if( verbosity>0 ){ std::cout << "> Tree is empty" << std::endl; } return -999.; }
float type; double value;
tree->SetBranchAddress("quantileExpected", &type );
tree->SetBranchAddress("limit" , &value);
float target = LimitTypes[LIMIT_TYPE]; double limit = -999;
for(int idx=0; idx<nevent; ++idx){
tree->GetEvent(idx);
if( fabs(type-target)<0.001 ){
// allow for some tolerance for determination of type
if( verbosity>1 ){ std::cout << "tanb: " << tanb << " limit (" << limitType(LIMIT_TYPE) << ") = " << value/tanb << " Undivided limit = " << value << std::endl; }
limit = value/tanb;
}
}
file->Close();
return limit;
}
示例9: createRootFile
int createRootFile()
{
TFile* pRootFile = new TFile("myfile.root", "RECREATE");
if (pRootFile == NULL) {
std::cout << "Error creating ROOT file" << std::endl;
return 1;
}
TDirectory* pTestDir = pRootFile->mkdir("TestDir");
if (pTestDir == NULL) {
std::cout << "Error creating directory in ROOT file" << std::endl;
delete pRootFile;
return 1;
}
std::string name = "testobj";
MyROOTObject* pMyObj = new MyROOTObject(17, 1.2e3, name);
std::cout << *pMyObj << std::endl;
pTestDir->cd();
pMyObj->Write(pMyObj->GetName());
if (pMyObj != NULL) {
delete pMyObj;
}
if (pRootFile != NULL) {
if (pRootFile->IsOpen() && !pRootFile->IsZombie()) {
pRootFile->Close();
delete pRootFile;
}
}
}
示例10: macro
void macro()
{
cout << "Example macro for testing the ROOTobject library from CINT"
<< endl;
TFile* pRootFile = new TFile("myfile.root", "READ");
if (pRootFile != NULL) {
TDirectory* pTestDir = (TDirectory*)pRootFile->Get("TestDir");
if (pTestDir != NULL) {
pTestDir->cd();
MyROOTObject* pMyObj = NULL;
std::string name = "testobj";
pMyObj = (MyROOTObject*)pTestDir->Get(name.c_str());
if (pMyObj != NULL) {
std::cout << *pMyObj << std::endl;
}
}
if (pRootFile->IsOpen() && !pRootFile->IsZombie()) {
pRootFile->Close();
delete pRootFile;
}
}
}
示例11: mjjshapes
void mjjshapes()
{
SigData_t m_sigdata;
std::map<TString,TGraph *> m_backgrounds;
getItAll(m_sigdata,m_backgrounds);
makeGaussianSignals(m_sigdata);
std::map<TString,std::vector<TH1D *> >::iterator it;
for (it = m_sigdata.begin();
it != m_sigdata.end();
it++) {
TString sigmodel = it->first;
TString outfname = "mjj-histo-shapes-"+sigmodel+".root";
TFile *allHistFile = new TFile(outfname.Data(), "RECREATE");
if (allHistFile->IsZombie()) {
cerr << "Couldn't open output file " << outfname << endl;
exit(-1);
}
writeSignalHistosForModel (it->second,sigmodel,allHistFile);
writeDataBackgroundHistosForModel (m_backgrounds,
it->second, // for channel binning
allHistFile);
allHistFile->Close();
delete allHistFile;
}
}
示例12: 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;
}
示例13: runtime_error
/// Open new data file
bool DDG4EventHandler::Open(const std::string&, const std::string& name) {
if ( m_file.first ) m_file.first->Close();
m_hasFile = false;
m_hasEvent = false;
TFile* f = TFile::Open(name.c_str());
if ( f && !f->IsZombie() ) {
m_file.first = f;
TTree* t = (TTree*)f->Get("EVENT");
if ( t ) {
TObjArray* br = t->GetListOfBranches();
m_file.second = t;
m_entry = -1;
m_branches.clear();
for(Int_t i=0; i<br->GetSize(); ++i) {
TBranch* b = (TBranch*)br->At(i);
if ( !b ) continue;
m_branches[b->GetName()] = make_pair(b,(void*)0);
printout(INFO,"DDG4EventHandler::open","+++ Branch %s has %ld entries.",b->GetName(),b->GetEntries());
}
for(Int_t i=0; i<br->GetSize(); ++i) {
TBranch* b = (TBranch*)br->At(i);
if ( !b ) continue;
b->SetAddress(&m_branches[b->GetName()].second);
}
m_hasFile = true;
return true;
}
throw runtime_error("+++ Failed to access tree EVENT in ROOT file:"+name);
}
throw runtime_error("+++ Failed to open ROOT file:"+name);
}
示例14: read_tree
Float_t read_tree(const char *filename = "data.root", Double_t bytes = 10000000)
{
printf("Reading events from a root tree \n");
TFile *filein = new TFile(filename,"READ");
if ( filein->IsZombie() ) {
printf("Cannot open file \n");
return 0.0;
}
Int_t nbgamma; Int_t e[1000]; // up to 1000 energies ..should be ok
TTree *treein;
treein = (TTree *)filein->Get("TEST");
if ( treein == NULL ) return 0;
else {
treein->SetBranchAddress("mult",&nbgamma);
treein->SetBranchAddress("e",&e);
}
// write events and compute the needed time
TStopwatch watch;
watch.Start();
treein->Draw("e","","goff");
watch.Stop();
cout << " --> Reading rate " << bytes / (1024*1024*watch.RealTime()) << " MB/s"<< endl ;
filein->Close(); delete filein; return bytes / (1024*1024*watch.RealTime()) ;
}
示例15: testSimpleFile
int testSimpleFile(const char *filename, Long64_t entries, Int_t compSetting, Long64_t fileSize, UInt_t tolerance = 0)
{
fprintf(stdout,"Checking %s\n",filename);
TFile *file = TFile::Open(filename);
if (file == nullptr || file->IsZombie()) {
Error("testSimpleFile", "Could not open %s.",filename);
return 1;
}
//file->ls();
if (file->GetCompressionSettings() != compSetting) {
Error("testSimpleFile","Compression level of %s should have been %d but is %d\n",file->GetName(), 206, file->GetCompressionSettings() );
return 3;
}
if (abs(file->GetSize()-fileSize) > tolerance) {
Error("testSimpleFile","Disk size of %s should have been %lld but is %lld (tolerance %u bytes)\n",file->GetName(), fileSize, file->GetSize(), tolerance);
return 4;
}
TTree *ntuple;
file->GetObject("ntuple",ntuple);
if (ntuple == 0) {
Error("testSimpleFile", "Could not retrieve ntuple from %s.",file->GetName());
return 2;
}
if (ntuple->GetEntries() != entries) {
Error("testSimpleFile","Number of entries in ntuple in %s should have been %lld but is %lld\n",file->GetName(), entries, ntuple->GetEntries());
return 4;
}
delete file;
return 0;
}