Skip to content

Commit

Permalink
Changes is_newformat_file to is_oldformat_file
Browse files Browse the repository at this point in the history
Checking for the extents table to identify
an old format MC file was deemed more stable.
Function and use changed accordingly
  • Loading branch information
andLaing committed Mar 17, 2020
1 parent eae304f commit 74ff84b
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions invisible_cities/io/mcinfo_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from typing import List
from typing import Optional
from typing import Tuple
from typing import Union


Expand Down Expand Up @@ -154,9 +155,9 @@ def __call__(self, mctables: (tb.Table, tb.Table, tb.Table, tb.Table),
self.generator_table.flush()


def is_newformat_file(file_name : str) -> bool:
def is_oldformat_file(file_name : str) -> bool:
with tb.open_file(file_name) as h5in:
return hasattr(h5in.root, 'MC/sns_positions')
return hasattr(h5in.root, 'MC/extents')


def load_mchits_df(file_name : str) -> pd.DataFrame:
Expand All @@ -165,11 +166,11 @@ def load_mchits_df(file_name : str) -> pd.DataFrame:
file_name : str
The name of the file to be read
"""
if is_newformat_file(file_name):
return load_mchits_dfnew(file_name)
else:
if is_oldformat_file(file_name):
## Is this a pre-Feb 2020 file?
return load_mchits_dfold(file_name)
else:
return load_mchits_dfnew(file_name)


def load_mchits_dfold(file_name : str) -> pd.DataFrame:
Expand Down Expand Up @@ -232,10 +233,10 @@ def load_mcparticles_df(file_name: str) -> pd.DataFrame:
file_name : str
The name of the file to be read
"""
if is_newformat_file(file_name):
return load_mcparticles_dfnew(file_name)
else:
if is_oldformat_file(file_name):
return load_mcparticles_dfold(file_name)
else:
return load_mcparticles_dfnew(file_name)


def load_mcparticles_dfold(file_name: str) -> pd.DataFrame:
Expand Down Expand Up @@ -307,10 +308,10 @@ def get_sensor_binning(file_name : str) -> pd.DataFrame:
input file and extracts the binning used
for both types of sensitive detector.
"""
if is_newformat_file(file_name):
return sensor_binning_new(file_name)
else:
if is_oldformat_file(file_name):
return sensor_binning_old(file_name)
else:
return sensor_binning_new(file_name)


def sensor_binning_old(file_name : str) -> pd.DataFrame:
Expand Down Expand Up @@ -372,13 +373,13 @@ def load_mcsensor_response_df(file_name : str ,
Sensor name of the data to be returned
Default: return for every sensor
"""
if is_newformat_file(file_name):
return read_mcsensors_dfnew(file_name, sns_name)
else:
if is_oldformat_file(file_name):
assert(db_file), "Database name required for this file"
assert( run_no), "Run number required for database access"
return read_mcsensors_dfold(file_name, db_file ,
run_no , sns_name)
else:
return read_mcsensors_dfnew(file_name, sns_name)


def read_mcsensors_dfnew(file_name : str,
Expand Down

0 comments on commit 74ff84b

Please sign in to comment.