def hit_io_builtin_formatted_test(hit): test_pass_all = True for key in Hit.file_types(): test_pass = True filehandle = open('out_test', 'w') if not filehandle: return 'warning - could not open file out_test' try: hit.write_builtin_formatted(key, filehandle) if key.find('maus') > -1: test_pass = False except IOError: if key.find('maus') == -1 and key.find('muon1_csv') == -1: test_pass = False filehandle.close() os.remove('out_test') if test_pass == False: print('Failed on builtin format', key) test_pass_all = False if test_pass_all: return 'pass' return 'fail'
import sys print('========= XBOA example 1 =========') print("In this example, I will do some basic file i/o and data manipulation") #input data #by default this is installed at file_location filename = sys.prefix+'/share/xboa/data/for009.dat' filetype = "icool_for009" #some other options are "maus_root_virtual_hit", (requires libMausCpp.so in python path), "icool_for003", "g4blTrackFile", ... #try to load an input file #this will load the for009 file, and make a list of "bunches", one for each region #a list is a python version of an array print("Data can be loaded using new_list_from_read_builtin(filetype, filename) for builtin types") print('List of builtin types:') print(Hit.file_types()) print('For non-builtin types, you would use new_from_read_user(format_list, format_units_dict, filehandle, number_of_skip_lines)') print('I\'ll try to load some example data that came with your installation...') try: bunch_list = Bunch.new_list_from_read_builtin(filetype, filename) except IOError: 'Oh dear, I couldn\'t load the example data - I wonder if it was installed in the default place ('+filename+')?\nTry inputting a new location:' filename = input() bunch_list = Bunch.new_list_from_read_builtin(filetype, filename) print("Loaded") print('\n====== HIT ======') print('A hit is the intersection of a particle trajectory with a detector or output plane') my_hit = bunch_list[0][10] print('Normally you would access hit data using my_hit[get_variable], for example') print('my_hit[\'x\']: ',my_hit['x'])