Skip to content

Commit

Permalink
working on more examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmlongLANL committed Apr 17, 2024
1 parent c885035 commit 535e724
Show file tree
Hide file tree
Showing 5 changed files with 278 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import os, sys
from multiprocessing import Pool
import threading
from multiprocessing import Value, Lock
from pyHERMES import empir


def main(dest, max_concurrent_jobs=5, verbose_level=0):
# Check to see if the destination directory exists
if not os.path.exists(dest):
print(f"Destination directory does not exist: {dest}")
sys.exit(1)

else:
print(f"Unpacking tpx3 files in directory: {dest}")

# Create an instance of the empirConfig class
config_empir = empir.empirConfig(dest)

# Check to if sub directories in the destination directory exists
config_empir.check_or_create_sub_dirs()

# Shared counters and locks for processed files
photon_file_counter = Value('i', 0)
photon_file_counter_lock = Lock()

# Create a pool of workers to process the photon files
# using a with() statement will close the pool when the work is done
with Pool(max_concurrent_jobs) as pool:

# Check to see if the destination directory exists
if not os.path.exists(dest):
print(f"Destination directory does not exist: {dest}")
print(f"Skipping directory: {dest}")
sys.exit(1)

else:
# Create an instance of the empirConfig class
config_empir = empir.empirConfig(dest)

# Check to if sub directories in the destination directory exists
config_empir.check_or_create_sub_dirs()

# Check for existing .photon files
existing_photon_files = empir.check_for_files(config_empir.event_file_dir, '.event', verbose_level)

# Set the parameters for pixel_to_photon conversion
config_empir.set_event_to_image_params( size_x=512, size_y=512, nPhotons_min=2, nPhotons_max=9999, time_extTrigger=True, time_res_s=10E-6, time_limit=2400, psd_min=1E-7, psd_max=100)

empir.process_existing_event_files(config=config_empir, process_pool=pool, file_counter=photon_file_counter, lock=photon_file_counter_lock,file_input_option="folder")


if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python script.py <dest> <verbose_level>,")
print("\t<dest> is the destination directory for the raw tpx3 files")
print("\t<verbose_level> is the level of verbosity for messaging during the execution process")
sys.exit(1)
elif len(sys.argv) < 3:
dest = sys.argv[1]
verbose_level = 0
else:
dest = sys.argv[1]
verbose_level = int(sys.argv[2])

main(dest, max_concurrent_jobs=5, verbose_level=verbose_level)
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import os, sys
from multiprocessing import Pool
import threading
from multiprocessing import Value, Lock
from pyHERMES import empir


def main(run_folder, max_concurrent_jobs=5, verbose_level=0):
sub_dirs = [f.path for f in os.scandir(run_folder) if f.is_dir()]
tpx3_file_counter = Value('i', 0)
tpx3_file_counter_lock = Lock()
photon_file_counter = Value('i', 0)
photon_file_counter_lock = Lock()

# Create a pool of workers to process the tpx3 files
# Create a pool of workers to process the photon files
# using a with() statement will close the pool when the work is done
with Pool(max_concurrent_jobs) as pool:

Expand All @@ -37,13 +36,14 @@ def main(run_folder, max_concurrent_jobs=5, verbose_level=0):
# Check to if sub directories in the destination directory exists
config_empir.check_or_create_sub_dirs()

# Check for existing .tpx3 files
existing_tpx3_files = empir.check_for_files(config_empir.tpx3_file_dir, '.tpx3', verbose_level)
# Check for existing .photon files
existing_photon_files = empir.check_for_files(config_empir.list_file_dir, '.empirphot', verbose_level)

# Set the parameters for pixel_to_photon conversion
config_empir.set_pixel_to_photon_params(d_space=5,d_time=5E-8,min_number=2,use_tdc1=True)
config_empir.set_photon_to_event_params(d_space=2,d_time=15E-6,max_duration=100E-6)

empir.process_existing_tpx3_files(config_empir, pool, tpx3_file_counter, tpx3_file_counter_lock)
empir.process_existing_photon_files(config_empir, pool, photon_file_counter, photon_file_counter_lock)




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,34 @@ def main(dest, max_concurrent_jobs=5, verbose_level=0):
# Check to if sub directories in the destination directory exists
config_empir.check_or_create_sub_dirs()

# Set the global pool for concurrent jobs
global_pool = Pool(max_concurrent_jobs)

# Shared counters and locks for processed files
tpx3_file_counter = Value('i', 0)
tpx3_file_counter_lock = Lock()

# Check for existing .tpx3 files
existing_tpx3_files = empir.check_for_files(config_empir.tpx3_file_dir, '.tpx3', verbose_level)

# Set the parameters for pixel_to_photon conversion
config_empir.set_pixel_to_photon_params(d_space=5,d_time=5E-8,min_number=2,use_tdc1=True)
photon_file_counter = Value('i', 0)
photon_file_counter_lock = Lock()


# Thread for exporting tpx3 files
if existing_tpx3_files:
process_existing_thread = threading.Thread(target=empir.process_existing_tpx3_files, args=(config_empir, global_pool, tpx3_file_counter, tpx3_file_counter_lock))
process_existing_thread.start()
# Create a pool of workers to process the photon files
# using a with() statement will close the pool when the work is done
with Pool(max_concurrent_jobs) as pool:

# Check to see if the destination directory exists
if not os.path.exists(dest):
print(f"Destination directory does not exist: {dest}")
print(f"Skipping directory: {dest}")
sys.exit(1)

else:
# Create an instance of the empirConfig class
config_empir = empir.empirConfig(dest)

# Check to if sub directories in the destination directory exists
config_empir.check_or_create_sub_dirs()

# Check for existing .photon files
existing_photon_files = empir.check_for_files(config_empir.list_file_dir, '.empirphot', verbose_level)

# Set the parameters for pixel_to_photon conversion
config_empir.set_photon_to_event_params(d_space=2,d_time=15E-6,max_duration=100E-6)

empir.process_existing_photon_files(config_empir, pool, photon_file_counter, photon_file_counter_lock)


if __name__ == "__main__":
Expand All @@ -51,6 +61,6 @@ def main(dest, max_concurrent_jobs=5, verbose_level=0):
verbose_level = 0
else:
dest = sys.argv[1]
verbose_level = sys.argv[2]
verbose_level = int(sys.argv[2])

main(dest, max_concurrent_jobs=5, verbose_level=verbose_level)
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os, sys
from multiprocessing import Pool
import threading
from multiprocessing import Value, Lock
from pyHERMES import empir

Expand Down
Loading

0 comments on commit 535e724

Please sign in to comment.