Aren’t you missing the leading slash when you define dir?
Try this:
dir = "/eos/home/tcarnaha/UL_2018/ ROOT.TFile(dir+"fits_data/muon/generalTracks/Z/Run2018_UL/AltBkg/NUM_LooseID_DEN_genTracks/NUM_LooseID_DEN_genTracks_abseta_1_pt_2.root")
Hey @ferhue , thank you for the loop reference. And, I did originally have the forward slash in my code; sorry for the typo in rewriting it in this forum. Still doesn’t work to output an actual png file. Here’s what I’ve got so far:
c = ROOT.TCanvas('','',200,10,700,500) \
dir1 = '/eos/user/t/tcarnaha/spark_tnp/' \
file_name = (dir1 +inFile.strip(".")[1:])
#print('Loading file: ', file_name) \
myfile = ROOT.TFile.Open(file_name, "READ") \
root_dir = myfile.GetDirectory(file_name+"_Canv") #may cause problems
#List of Keys() \
root_keys = myfile.GetListOfKeys() \
c.cd() \
for key in root_keys: \
if key.ClassName() == "TCanvas":
key.SaveAs('folder/' + mytitle() + '.png')
print("Saving: " + mytitle() + ".png")
where “mytitle()” is just a name-tagging function. I’m just wondering why my SaveAs is not saving a png now. It seems like the last if block is not returning anything at all (no print statements either).
SysError in <TFile::ReadBuffer>: error reading from file ./UL_2018/fits_data/muon/generalTracks/Z/Run2018_UL/massRangeDown/NUM_TightID_DEN_genTracks/NUM_TightID_DEN_genTracks_abseta_3_pt_7.root (Input/output error)
Error in <TFile::Init>: ./UL_2018/fits_data/muon/generalTracks/Z/Run2018_UL/massRangeDown/NUM_TightID_DEN_genTracks/NUM_TightID_DEN_genTracks_abseta_3_pt_7.root failed to read the file type data.
Ah, just with this one! When I go to the actual file and look around, I get:
SysError in <TFile::ReadBuffer>: error reading from file ./UL_2018/fits_data/muon/generalTracks/Z/Run2018_UL/massRangeDown/NUM_TightID_DEN_genTracks/NUM_TightID_DEN_genTracks_abseta_3_pt_7.root (Remote I/O error)
Error in <TFile::Init>: ./UL_2018/fits_data/muon/generalTracks/Z/Run2018_UL/massRangeDown/NUM_TightID_DEN_genTracks/NUM_TightID_DEN_genTracks_abseta_3_pt_7.root failed to read the file type data.
(TFile *) nullptr
@ferhue Thank you so much for that! Is there a way I can go around those null pointers (not include them when trying to get TCanvases from ~200 other files that are good)?
Hmm…@ferhue, it’s still giving me a similar error:
SysError in <TFile::ReadBuffer>: error reading from file ./UL_2018/fits_data/muon/generalTracks/Z/Run2018_UL/massRangeDown/NUM_TightID_DEN_genTracks/NUM_TightID_DEN_genTracks_abseta_3_pt_7.root (Remote I/O error)
Error in <TFile::Init>: ./UL_2018/fits_data/muon/generalTracks/Z/Run2018_UL/massRangeDown/NUM_TightID_DEN_genTracks/NUM_TightID_DEN_genTracks_abseta_3_pt_7.root failed to read the file type data.
No worries, @ferhue; thanks so much for all of your time invested. I’m sure I’ll beat my head against something fundamental eventually. Something is going wrong when it attempts to retrieve the TFiles I think.
Maybe just to anyone as a more general question: is there a general, fundamental way to retrieve a Canvas from an already-existent root file, and save it as a .pdf or .png? (See drawing–from directory spark_tnp/UL_2018/…/<file.root>, retrieving the Canvas, saving it in a picture.png file–the whole procedure should be saved in the scripts/ directory)? Because from what I’m doing, it is not coming to fruition.