コード例 #1
0
def fill_the_matrix_of_events(matrix_of_events, tail_files, tail, start_time):

    chunk_size = 282
    tail_files_counter = 0
    for tail_file in tail_files:
        print("Tail file  {}  amplitudes collecting...".format(tail_file))
        tail_file = tools.make_BSM_file_temp(tail_file) + '.wfp'
        try:
            with open(tail_file, 'rb') as tail_file:
                chunk = tail_file.read(chunk_size)
                chunk_counter = 0
                while chunk:
                    try:
                        head_array = tools.unpacked_from_bytes('hhii', chunk[:12])
                        num_event_1 = head_array[2]
                        maroc_number = tools.unpacked_from_bytes('h', chunk[20:22])[0]
                        time_array = tools.unpacked_from_bytes('hhhh', chunk[12:20])
                        ns = (time_array[0] & 0x7f)*10
                        mks = (time_array[0] & 0xff80) >> 7
                        mks |= (time_array[1] & 1) << 9
                        mls = (time_array[1] & 0x7fe) >> 11
                        s = (time_array[1] & 0xf800) >> 11
                        s |= (time_array[2] & 1) << 5
                        m = (time_array[2] & 0x7e) >> 1
                        h = (time_array[2] & 0xf80) >> 7
                        time_string = "{}:{}:{}.{}.{}.{}".format(h, m, s, mls, mks, ns)
                        result_array = tools.unpacked_from_bytes('fBB'*32, chunk[24:-4])
                        result_string_ampls = '\t'.join([str(x) for x in result_array])
                        matrix_of_events[num_event_1][maroc_number] =\
                            "{}\t{}\t{}".format(
                                maroc_number,
                                time_string,
                                result_string_ampls)
                    except Exception:
                        print("{} Chunk number {} in file {} is seems to be corrupted!".format(
                            "WFP FILE CHUNK CORRUPTION ERROR!",
                            chunk_counter,
                            tail_file))
                    chunk_counter += 1
                    chunk = tail_file.read(chunk_size)

            tail_files_counter += 1
            tools.syprogressbar(
                tail_files_counter,
                len(tail_files),
                u'\u24BB',
                "tail files {} amplitudes collecting".format(tail),
                start_time)
        except Exception:
            print("{} File {} is seems to be not existed!".format(
                    "WFP FILE EXISTING ERROR!",
                    tail_file))
    return matrix_of_events
コード例 #2
0
def to_process_single_file(file_to_process):
    """Conducts one input file through all sequence of needed operations.

    Firstly checks is needed pedestal files exist. If no:
    - calculates pedestals,
    - calculates pedestals sigmas,
    - make ignore file, which contains information is channel make noise
    (concluded from the sigmas).
    If needed pedestal files exists, skips it and calculates amplitudes
    for all events in this files and lightweight header file. By the way,
    header file is not further used anywhere. It is rather a tribute to
    tradition. What the data processing without header files?!

    The details of functions see in their own docstrings."""

    with open(".mess.txt", "a") as mess_file:
        if (tools.is_exist(tools.make_PED_file_temp(file_to_process) + ".fpd") or
                tools.is_exist(tools.make_PED_file_temp(file_to_process) + ".sgm") or
                tools.is_exist(tools.make_PED_file_temp(file_to_process) + ".ig")) is False:
            make_pedestals(file_to_process)
#           .fpd - fine pedestals
            print("Cleaning for pedestals")
            mess_file.write("Made temporary file:  {}.fpd\n".format(
                tools.make_PED_file_temp(file_to_process)))
            print("Made temporary file:  {}.fpd".format(
                tools.make_PED_file_temp(file_to_process)))
#           .sgm - sigmas of pedestals
            print("Calculating pedestals sigmas...")
            mess_file.write("Made temporary file:  {}.sgm\n".format(
                tools.make_PED_file_temp(file_to_process)))
            print("Made temporary file:  {}.sgm".format(
                tools.make_PED_file_temp(file_to_process)))
#           .ig ignore status from sigma
#           (PED_sigma < PED_average + 3*sigma_sigma)
            print("Compiling file with channels to be ignored...")
            mess_file.write("Made temporary file:  {}.ig\n".format(
                tools.make_PED_file_temp(file_to_process)))
            print("Made temporary file:  {}.ig".format(
                tools.make_PED_file_temp(file_to_process)))
        else: print("Pedestal file exists.")
        if (tools.is_exist(tools.make_BSM_file_temp(file_to_process) + ".wfp") or
                tools.is_exist(tools.make_BSM_file_temp(file_to_process) + ".hdr")) is False:
            make_clean_amplitudes_and_headers(file_to_process)
#           .hdr - file with only events number #1, event number #2,
#           time of event and maroc number
            print("Creating of the header...")
            mess_file.write("Made temporary file:  {}.hdr\n".format(
                tools.make_BSM_file_temp(file_to_process)))
            print("Made temporary file:  {}.hdr".format(
                tools.make_BSM_file_temp(file_to_process)))
#           .wfp - amplitudes minus fine pedestals
            print("Cleaning for pedestals...")
            mess_file.write("Made temporary file:  {}.wfp\n".format(
                tools.make_BSM_file_temp(file_to_process)))
            print("Made temporary file:  {}.wfp".format(
                tools.make_BSM_file_temp(file_to_process)))
        else: print("Cleaned files exists.")
コード例 #3
0
def dict_of_num_min_max_in_tail(tail, files_list, day):
    """Find minimum and maximum event number from one tail from one day.

    Takes one tail from one day in format '001', '002' etc. Then searches
    for all the corresponding tail files (22 in general case). Runs through
    each of them, reads their event numbers.
    Finally returns list with two values: minimum event number for all this
    files and the maximum one."""

    print("Evevt numbers range in tail {} are finding out...".format(tail))
    chunk_size = 282
    num_max, num_min = 0, 0
    for file in files_list:
        file = tools.check_and_cut_the_tail(file)
        day_of_this_file = file[:-18]
        if day_of_this_file == day:
            tail_of_this_file = file[-3:]
            if tail_of_this_file == tail:
                file = tools.make_BSM_file_temp(file) + '.wfp'
                with open(file, 'rb') as wfp_file:
                    try:
                        chunk = wfp_file.read(chunk_size)
                        num_ev_bytes = chunk[4:8]
                        num_ev = tools.unpacked_from_bytes(
                            'I', num_ev_bytes)[0]
                        if num_ev < num_min:
                            num_min = num_ev
                    except Exception:
                        print("{} Chunk number {} in file {} is seems to be corrupted!\n".format(
                            "WFP FILE CORRUPTION ERROR!",
                            'ZERO',
                            file))
                    while chunk:
                        next_chunk = wfp_file.read(chunk_size)
                        if next_chunk: chunk = next_chunk
                        else: break
                    try:
                        num_ev_bytes = chunk[4:8]
                        num_ev = tools.unpacked_from_bytes(
                            'I', num_ev_bytes)[0]
                        if num_ev > num_max:
                            num_max = num_ev
                    except Exception:
                        print("{} Chunk number {} in file {} is seems to be corrupted!\n".format(
                            "WFP FILE CORRUPTION ERROR!",
                            'LAST',
                            file))  
    return [num_min, num_max]
コード例 #4
0
def make_clean_amplitudes_and_headers(file_to_process):

    chunk_size = 156
    codes_beginning_byte = 24
    codes_ending_byte = 152
    number_1_beginning_byte = 4
    maroc_number_byte = 20

    with open(tools.make_PED_file_temp(file_to_process) + ".fpd", "rb") as ped_fin:
        peds = ped_fin.read()
        try:
            peds_array = tools.unpacked_from_bytes('<64f', peds)
        except Exception:
            print("{} File {} is seems to be corrupted!\n".format(
                "FPD-file CORRUPTION ERROR!",
                tools.make_PED_file_temp(file_to_process) + ".fpd"))

    with open(tools.make_PED_file_temp(file_to_process) + ".ig", "rb") as ig_fin:
        ig_bytes = ig_fin.read()
        try:
            ig_array = tools.unpacked_from_bytes('<64B', ig_bytes)
        except Exception:
            print("{} File {} is seems to be corrupted!\n".format(
                "IG-file CORRUPTION ERROR!",
                tools.make_PED_file_temp(file_to_process) + ".ig"))

    with open(file_to_process, "rb") as codes_fin:
        with open(tools.make_BSM_file_temp(file_to_process) + ".wfp", "wb") as cleaned_file:
            with open(tools.make_BSM_file_temp(file_to_process) + ".hdr", "wb") as header_file:

                chunk_counter = 0
                chunk = codes_fin.read(chunk_size)
                while chunk:
                    try:
                        cleaned_amplitudes = [0]*96
                        codes_array = tools.unpacked_from_bytes(
                            '<64h', chunk[codes_beginning_byte:codes_ending_byte])
                        for i in range(0, len(cleaned_amplitudes), 3):
                            if codes_array[2*i//3] <= 1800:
                                cleaned_amplitudes[i] =\
                                codes_array[2*i//3]/4 - peds_array[2*i//3]
                            else:
                                cleaned_amplitudes[i] =\
                                codes_array[2*i//3 + 1]/4 - peds_array[2*i//3 + 1]
                            cleaned_amplitudes[i+1] =\
                            int(bin(codes_array[2*i//3 + 1])[-1])
#                           ig_status = 0 if BOTH channels IS ignored
#                           1 if LOW IS NOT ignored, HIGH IS ignored
#                           2 if HIGH IS NOT ignored, LOW IS ignored
#                           3 if BOTH IS NOT ignored
                            cleaned_amplitudes[i+2] =\
                            ig_array[2*i//3] + ig_array[2*i//3 + 1]
                        cleaned_amplitudes_pack = tools.packed_bytes(
                            'fBB'*32,
                            cleaned_amplitudes)
                        # chunk_size in wfp_file will be 282 bytes
                        cleaned_file.write(chunk[:codes_beginning_byte])
                        cleaned_file.write(cleaned_amplitudes_pack)
                        cleaned_file.write(chunk[codes_ending_byte:])
                        # chunk_size in header will be 17 bytes
                        header_file.write(
                            chunk[number_1_beginning_byte:maroc_number_byte +1])
                    except Exception:
                        print("{} Chunk number {} in file {} is seems to be corrupted!\n".format(
                            "RAW CHUNK CORRUPTION ERROR!",
                            chunk_counter,
                            file_to_process))
                    chunk_counter += 1
                    chunk = codes_fin.read(chunk_size)