// open_hbook.C // // David Adams // June 2003 // // ROOT macro to convert an HBOOK file to ROOT format and then // open the resulting ROOT file. // // open_hbook(filename) converts and returns reference to the root file. // If another file is open, it is closed. // open_hbook("close") closes the current file // open_hbook() returns a reference to the last file opened. //********************************************************************** // Open a named HBOOK file. // // const TFile& open_hbook(string hbname, bool verbose =true) { static TFile badfile; static TFile* pfile = &badfile; // If no name is given, then return the last file opened. if ( hbname == "" ) { return *pfile; } // Delete the last file. if ( pfile != &badfile ) { if ( pfile->IsOpen() ) { pfile->Close(); gSystem->Unlink(pfile->GetName()); } } // Exit if close is set. if ( hbname == "close" ) return *pfile; // Convert to ROOT format. string rname = "hbook.root"; string com = "ln -sf " + hbname + " res.hbk; h2root res.hbk " + rname; if ( ! verbose ) { com += " >/dev/null 2>&1"; } int stat = gSystem->Exec(com.c_str()); if ( stat != 0 ) { cout << "Conversion failed" << endl; return 0; } // Open the file. pfile = new TFile(rname.c_str()); if ( pfile == 0 ) pfile = &badfile; return *pfile; } //********************************************************************** // Extract the HBOOK file from a DIAL result and open the file. const TFile& open_hbook(const dset::Dataset& res, bool verbose=true) { // Cast to HbookDataset. const dset::HbookDataset* pres = dynamic_cast(&res); if ( pres == 0 ) { cout << "Dataset is not of type HbookDataset" << endl; return open_hbook("close", verbose); } // Extract the file name. string fname = pres->logical_file().get_readonly(); if ( fname == "" ) { cout << "Unable to extract file name from result" << endl; cout << *pres << endl; return open_hbook("close"); } // Open the file. return open_hbook(fname, verbose); } //********************************************************************** // Extract the HBOOK file from a DIAL result and open the file. // Returns 0 if job is inactive. int open_hbook(bool verbose =true) { if ( ! jid.is_valid() ) { cout << "Job ID jid is not valid" << endl; return 1; } const dial::Job job3 = msch.job(jid); // Acquire mutex so that result is comnsistent with job description. job3.lock_mutex(); if ( job3.is_valid() ) { cout << job3 << endl; if ( job3.has_result() ) { open_hbook(job3.result(), verbose); } else { cout << "Job " << jid.to_string() << " does not have a result" << endl; } } else { cout << "Job " << jid.to_string() << " is not valid" << endl; } job3.unlock_mutex(); if ( job3.is_inactive() ) return 0; return 2; } //**********************************************************************