Within a python framework, I am attempting to store several files within the user's working directory that meet certain criteria; these files are created and destroyed by different users at will, so while the storage code is going through the working directory, I am getting a null-pointer "ReferenceError" error, such as the one below when the file still exists but without its histogram attributes (aka are turned into null-pointers):
Error in <TFile::TFile>: file ./UL_2022_EE/fits_data/muon/generalTracks/Z/Run2022_EE/tagIsoUp/NUM_HighPtID_DEN_TrackerMuons/NUM_HighPtID_DEN_TrackerMuons_abseta_4_pt_5.root does not exist
ReferenceError: attempt to access a null-pointer
(essentially within certain files, nothing is saved that can be accessible to my storage program)
I have attempted many variations of the try-except code, and even an if-then statement that has evolved into something like this:
def catchgeese():
'''
catchgeese() finds the appropriate .png file for the selected fit failure, using pulls or other mathematical parameters, such as the chi2probability distribution, or KS.
catchgeese() is used within the 'for' loop to ensure access to TTree 'tests', or any other `VALIDATION parameters` set
'''
for i in baseDir:
try:
myfile = inFile.replace(".root",".png")
if not os.path.exists(baseDir + '/geese/'): os.makedirs(baseDir + '/geese/')
except ReferenceError:
print("Failed job encountered. Please run `./tnp_fitter.py [...] -j 16 --recover` in order to retrieve all jobs")
continue
target = (baseDir + '/geese/')
goosechase = shutil.copy(myfile, target+mytitle()+".png")
return goosechase
where inFile is just each separate path to the select file, and baseDir is defined as the working directory where this function runs.
I have also tried putting different for loops above the try-except statement due to getting an error that continue is not rightly within the loop if for is not present, but the for loop has given a similar error (ZeroDivisionError: float division by zero), while not correctly iterating through the list. The problem I think is that for i in baseDir doesn't really work because each inFile within the baseDir is a retrieved pathway, not an iterative list (I attempted this from the forum on this question: Use try and except to skip a file). But, because this particular function is only called when certain mathematical criteria are met, within the user's working directory, I'm not sure exactly how to iterate through the list correctly here. I've tried using things like os.path.exists() functions to no avail. Any guidance would be sincerely appreciated!