示例#1
0
class GenericLineHierarchy:
    def __init__(self, devices):
        self.devices = devices
        self.reader = LHBuilderUtils()
        self.y_prec_parser = XMLParser(self.devices.accelerator_zone,
                                       self.devices.rigidity)

    def generate_linkrules(self):

        # print ('LinkRules:')
        # print ('device is under study')
        for device in self.devices.alldevices:
            # print ('device is in alldevices')

            ##print (self.devices._devicelinkrulemap)
            if device in self.devices.devicelinkrulemap:
                linkrule = self.devices.devicelinkrulemap.get(device)

                self.lh_builder.lh.add_linkrule_for_device(device, linkrule)
                # print (device , linkrule)
                # print ('device ', device, 'is in devicelinkrulemap')

            else:
                print('device ', device, ' not in devicelinkrulemap')

    def build(self):

        ## Standard beam and logical devices
        self.beam_device = self.devices.accelerator_zone + '_BEAM'
        self.timeparam_device = self.devices.accelerator_zone + '_TIMEPARAM'
        # self.rf_device = self.devices.accelerator_zone + '_RF'

        self.lh_builder.lh.define_device(self.beam_device,
                                         'BEAM',
                                         self.devices.accelerator_zone,
                                         description=self.beam_device +
                                         ' Transfer Line Beam')
        self.lh_builder.lh.define_device(self.timeparam_device,
                                         'TIMEPARAM',
                                         self.devices.accelerator_zone,
                                         description=self.timeparam_device +
                                         ' Transfer Line Beam')
        # self.lh_builder.lh.define_device(self.rf_device,        'RF',      self.devices.accelerator_zone, description= self.beam_device + ' Transfer Line Beam')

        ## Beam parameters
        self.a_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/A',
            'SCALAR_A',
            self.beam_device,
            belongs_to_function_bproc=True)
        self.aoq_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/AOQ',
            'SCALAR_AOQ',
            self.beam_device,
            is_trimable=False,
            belongs_to_function_bproc=True)
        self.brho_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/BRHO',
            'BRHO',
            self.beam_device,
            is_trimable=True)
        self.chopped_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/CHOPPED_BEAM', 'SCALAR_ACTIVE',
            self.beam_device)  # boolean
        self.e_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/E', 'SCALAR_E', self.beam_device, y_prec=8)
        self.element_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/ELEMENT',
            'SCALAR_ELEMENT',
            self.beam_device,
            belongs_to_function_bproc=True)
        self.erho_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/ERHO',
            'ERHO',
            self.beam_device,
            is_trimable=True)
        self.isotope_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/ISOTOPE',
            'SCALAR_ISOTOPE',
            self.beam_device,
            belongs_to_function_bproc=True)
        self.q_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/Q',
            'SCALAR_Q',
            self.beam_device,
            belongs_to_function_bproc=True)

        self.lh_builder.lh.add_parameter_to_system(self.a_parameter, 'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.aoq_parameter, 'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.brho_parameter, 'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.chopped_parameter,
                                                   'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.e_parameter, 'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.element_parameter,
                                                   'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.erho_parameter, 'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.isotope_parameter,
                                                   'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.q_parameter, 'BEAM')

        if not self.yrle_bp:
            self.lh_builder.lh.add_parameter_to_system(self.e_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(self.e_parameter,
                                                       'generation')

        if self.yrle_bp:
            self.epercharge_parameter = self.lh_builder.lh.define_physics_parameter(
                self.beam_device + '/E_PER_CHARGE', 'SCALAR_E_PER_CHARGE',
                self.beam_device)
            self.source_hv_parameter = self.lh_builder.lh.define_physics_parameter(
                self.beam_device + '/ION_SOURCE_HIGH_VOLTAGE',
                'SCALAR_U',
                self.beam_device,
                y_prec=8)

            self.lh_builder.lh.add_parameter_to_system(
                self.epercharge_parameter, 'BEAM')
            self.lh_builder.lh.add_parameter_to_system(
                self.source_hv_parameter, 'BEAM')
            self.lh_builder.lh.add_parameter_to_system(
                self.source_hv_parameter, '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(
                self.source_hv_parameter, 'generation')

        if not (self.yrme_bp):
            self.lh_builder.lh.add_parameter_to_system(self.element_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(self.element_parameter,
                                                       'generation')

            self.lh_builder.lh.add_parameter_to_system(self.isotope_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(self.isotope_parameter,
                                                       'generation')

            self.lh_builder.lh.add_parameter_to_system(self.q_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(self.q_parameter,
                                                       'generation')

            self.lh_builder.lh.add_parameter_to_system(self.chopped_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(self.chopped_parameter,
                                                       'generation')

        ## Timing parameters
        if self.standalone_acczone:
            self.t_master_parameter = self.lh_builder.lh.define_physics_parameter(
                self.timeparam_device + '/TIMING_MASTER',
                'SCALAR_TIMING_MASTER',
                self.timeparam_device,
                belongs_to_function_bproc=True)
            self.t_sequence_parameter = self.lh_builder.lh.define_physics_parameter(
                self.timeparam_device + '/T_SEQUENCE_KEY',
                'SCALAR_TIMING_SEQUENCE_KEY',
                self.timeparam_device,
                belongs_to_function_bproc=True)
            self.t_process_parameter = self.lh_builder.lh.define_physics_parameter(
                self.timeparam_device + '/T_PROCESS_KEY',
                'SCALAR_TIMING_PROCESS_KEY',
                self.timeparam_device,
                belongs_to_function_bproc=True)
            self.t_pulse_parameter = self.lh_builder.lh.define_physics_parameter(
                self.timeparam_device + '/T_PULSE',
                'SCALAR_TIMING_BEAM_PULSE_LENGTH',
                self.timeparam_device,
                belongs_to_function_bproc=True)

            # self.lh_builder.lh.add_parameter_to_system(self.t_pulse_parameter, '-TOPLEVEL')
            # self.lh_builder.lh.add_parameter_to_system(self.t_pulse_parameter, 'generation')

            self.lh_builder.lh.add_parameter_to_system(self.t_master_parameter,
                                                       'TIMEPARAM')
            self.lh_builder.lh.add_parameter_to_system(self.t_pulse_parameter,
                                                       'TIMEPARAM')

            self.lh_builder.lh.add_parameter_to_system(
                self.t_sequence_parameter, 'TIMEPARAM')
            self.lh_builder.lh.add_parameter_to_system(
                self.t_sequence_parameter, '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(
                self.t_sequence_parameter, 'generation')

            self.lh_builder.lh.add_parameter_to_system(
                self.t_process_parameter, 'TIMEPARAM')
            self.lh_builder.lh.add_parameter_to_system(
                self.t_process_parameter, '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(
                self.t_process_parameter, 'generation')

            if self.yrle_bp:
                self.t_bi_delay_parameter = self.lh_builder.lh.define_physics_parameter(
                    self.timeparam_device + '/T_BI_DELAY',
                    'SCALAR_TIMING_BI_DELAY',
                    self.timeparam_device,
                    belongs_to_function_bproc=True,
                    y_prec=8)
                self.t_bi_window_parameter = self.lh_builder.lh.define_physics_parameter(
                    self.timeparam_device + '/T_BI_WINDOW',
                    'SCALAR_TIMING_BI_WINDOW',
                    self.timeparam_device,
                    belongs_to_function_bproc=True,
                    y_prec=8)

                self.lh_builder.lh.add_parameter_to_system(
                    self.t_bi_delay_parameter, 'TIMEPARAM')
                self.lh_builder.lh.add_parameter_to_system(
                    self.t_bi_delay_parameter, '-TOPLEVEL')
                self.lh_builder.lh.add_parameter_to_system(
                    self.t_bi_delay_parameter, 'generation')

                self.lh_builder.lh.add_parameter_to_system(
                    self.t_bi_window_parameter, 'TIMEPARAM')
                self.lh_builder.lh.add_parameter_to_system(
                    self.t_bi_window_parameter, '-TOPLEVEL')
                self.lh_builder.lh.add_parameter_to_system(
                    self.t_bi_window_parameter, 'generation')

            if self.yrme_bp:
                self.t_rf_pulse_parameter = self.lh_builder.lh.define_physics_parameter(
                    self.timeparam_device + '/T_RF_PAUSE',
                    'SCALAR_TIMING_RF_PAUSE_PULSE_LENGTH',
                    self.timeparam_device,
                    belongs_to_function_bproc=True,
                    y_prec=8)
                self.lh_builder.lh.add_parameter_to_system(
                    self.t_rf_pulse_parameter, 'TIMEPARAM')

        ## Cavities
        for device in self.devices.cavities:
            urf_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/URF', 'SCALAR_URF', device, y_prec=8)
            prf_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/PHASE_OFFSET',
                'SCALAR_PHASE_OFFSET',
                device,
                y_prec=1)
            act_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/ACT_ON_BEAM', 'SCALAR_ACTIVE', device, y_prec=1)
            tpause_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/T_PAUSE_PULSE_LENGTH',
                'SCALAR_THIGH',
                device,
                y_prec=8)
            upause_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/U_PAUSE_PULSE_AMPL', 'U', device, y_prec=8)
            utohardware_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/U_TO_HARDWARE', 'SCALAR_U', device, y_prec=8)

            system = self.devices.devicesystemmap.get(device)
            print(device, system)

            self.lh_builder.lh.add_parameter_to_system(urf_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(utohardware_parameter,
                                                       system)
            self.lh_builder.lh.add_parameter_to_system(prf_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(prf_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(prf_parameter,
                                                       'generation')
            self.lh_builder.lh.add_parameter_to_system(act_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(act_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(act_parameter,
                                                       'generation')

            self.lh_builder.lh.add_parameter_to_system(tpause_parameter,
                                                       system)
            self.lh_builder.lh.add_parameter_to_system(tpause_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(tpause_parameter,
                                                       'generation')
            self.lh_builder.lh.add_parameter_to_system(upause_parameter,
                                                       system)
            self.lh_builder.lh.add_parameter_to_system(upause_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(upause_parameter,
                                                       'generation')

        ## Magnet groups according to multipole
        for device in self.devices.main_dipoles:

            y_prec_KL = 6
            kl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K0L', device, y_prec=y_prec_KL)
            y_prec_BL = 6
            bl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'B0L', device, y_prec=y_prec_BL)
            y_prec_I = 6
            i_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/I', 'I', device, y_prec=y_prec_I)

            system = self.devices.devicesystemmap.get(device)
            print(device, system)

            self.lh_builder.lh.add_parameter_to_system(kl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       'generation')
            self.lh_builder.lh.add_parameter_to_system(bl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(i_parameter, system)

        for device in self.devices.horizontal_correctors + self.devices.vertical_correctors:

            y_prec_KL = 6
            kl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K0L', device, y_prec=y_prec_KL)
            y_prec_BL = 6
            bl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'B0L', device, y_prec=y_prec_BL)
            y_prec_I = 6
            i_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/I', 'I', device, y_prec=y_prec_I)

            system = self.devices.devicesystemmap.get(device)
            print(device, system)

            self.lh_builder.lh.add_parameter_to_system(kl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       'generation')
            self.lh_builder.lh.add_parameter_to_system(bl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(i_parameter, system)

        for device in self.devices.main_quadrupoles:

            y_prec_KL = 6
            kl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K1L', device, y_prec=y_prec_KL)
            y_prec_BL = 6
            bl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'B1L', device, y_prec=y_prec_BL)
            y_prec_I = 6
            i_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/I', 'I', device, y_prec=y_prec_I)

            system = self.devices.devicesystemmap.get(device)
            print(device, system)

            self.lh_builder.lh.add_parameter_to_system(kl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       'generation')
            self.lh_builder.lh.add_parameter_to_system(bl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(i_parameter, system)

        for device in self.devices.septa:

            y_prec_KL = 6
            kl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K0L', device, y_prec=y_prec_KL)
            usep_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/USEP', 'USEP', device, y_prec=y_prec_KL)

            system = self.devices.devicesystemmap.get(device)
            print(device, system)

            self.lh_builder.lh.add_parameter_to_system(kl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       'generation')
            self.lh_builder.lh.add_parameter_to_system(usep_parameter, system)

        ## Beam diagnostics
#        for device in self.devices.cavities:
        for device in self.devices.faraday_cups:

            q_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/Q', 'SCALAR_Q', device)  # integer
            t_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/TIME_OF_FLIGHT', 'SCALAR_TIME_OF_FLIGHT',
                device)  # double
            chopped_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/CHOPPED_BEAM', 'SCALAR_ACTIVE', device,
                y_prec=1)  # boolean
            semiauto_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/SEMI_AUTOMATIC_GAIN_RANGE',
                'SCALAR_ACTIVE',
                device,
                y_prec=1)  # boolean
            gain_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/GAIN', 'SCALAR_TAU_NLP', device, y_prec=3)  # double

            system = self.devices.devicesystemmap.get(device)
            print(device, system)

            self.lh_builder.lh.add_parameter_to_system(q_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(t_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(chopped_parameter,
                                                       system)

            self.lh_builder.lh.add_parameter_to_system(semiauto_parameter,
                                                       system)
            self.lh_builder.lh.add_parameter_to_system(semiauto_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(semiauto_parameter,
                                                       'generation')

            self.lh_builder.lh.add_parameter_to_system(gain_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(gain_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(gain_parameter,
                                                       'generation')

        ### Creation of relations

        ## Beam Parameters
        self.lh_builder.create_child_node(
            self.a_parameter, [self.isotope_parameter, self.element_parameter])
        self.lh_builder.create_child_node(self.aoq_parameter,
                                          [self.a_parameter, self.q_parameter])
        self.lh_builder.create_child_node(
            self.brho_parameter, [self.e_parameter, self.aoq_parameter])
        self.lh_builder.create_child_node(
            self.erho_parameter, [self.brho_parameter, self.aoq_parameter])
        if self.yrle_bp:
            self.lh_builder.create_child_node(self.epercharge_parameter,
                                              [self.source_hv_parameter])
            self.lh_builder.create_child_node(self.e_parameter, [
                self.epercharge_parameter, self.isotope_parameter,
                self.q_parameter
            ])

        ## Timeparam Parameters
        if self.standalone_acczone:
            self.lh_builder.create_child_node(self.t_master_parameter,
                                              [self.t_pulse_parameter])
            self.lh_builder.create_child_node(self.t_master_parameter,
                                              [self.t_sequence_parameter])
            self.lh_builder.create_child_node(self.t_master_parameter,
                                              [self.t_process_parameter])

            if self.yrme_bp:
                self.lh_builder.create_child_node(self.t_master_parameter,
                                                  [self.t_rf_pulse_parameter])

            if self.yrle_bp:
                self.lh_builder.create_child_node(self.t_master_parameter,
                                                  [self.t_bi_delay_parameter])
                self.lh_builder.create_child_node(self.t_master_parameter,
                                                  [self.t_bi_window_parameter])

        ## Magnets
        for device in self.devices.main_dipoles + self.devices.horizontal_correctors + self.devices.vertical_correctors + self.devices.main_quadrupoles:
            kl_parameter = self.reader.find_unique_string(
                device + '/K[0-1]?L$', self.lh_builder.lh.get_parameters())
            bl_parameter = self.reader.find_unique_string(
                device + '/B[0-1]?L$', self.lh_builder.lh.get_parameters())
            i_parameter = self.reader.find_unique_string(
                device + '/I$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(
                bl_parameter, [self.brho_parameter, kl_parameter])
            self.lh_builder.create_child_node(i_parameter, bl_parameter)

        for device in self.devices.septa:
            kl_parameter = self.reader.find_unique_string(
                device + '/KL', self.lh_builder.lh.get_parameters())
            usep_parameter = self.reader.find_unique_string(
                device + '/USEP', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(
                usep_parameter, [self.erho_parameter, kl_parameter])

        ## Cavities
        for device in self.devices.cavities:
            urf_parameter = self.reader.find_unique_string(
                device + '/URF$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(
                urf_parameter, [self.q_parameter, self.isotope_parameter])
            prf_parameter = self.reader.find_unique_string(
                device + '/PHASE_OFFSET$', self.lh_builder.lh.get_parameters())
            act_parameter = self.reader.find_unique_string(
                device + '/ACT_ON_BEAM$', self.lh_builder.lh.get_parameters())
            tpause_parameter = self.reader.find_unique_string(
                device + '/T_PAUSE_PULSE_LENGTH$',
                self.lh_builder.lh.get_parameters())
            upause_parameter = self.reader.find_unique_string(
                device + '/U_PAUSE_PULSE_AMPL$',
                self.lh_builder.lh.get_parameters())
            utohardware_parameter = self.reader.find_unique_string(
                device + '/U_TO_HARDWARE$',
                self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(
                utohardware_parameter,
                [act_parameter, urf_parameter, upause_parameter])

        ## Beam diagnostics
#        for device in self.devices.cavities:
        for device in self.devices.faraday_cups:
            q_parameter = self.reader.find_unique_string(
                device + '/Q$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(q_parameter, [self.q_parameter])
            t_parameter = self.reader.find_unique_string(
                device + '/TIME_OF_FLIGHT$',
                self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(
                t_parameter, [self.e_parameter, self.a_parameter])
            chopped_parameter = self.reader.find_unique_string(
                device + '/CHOPPED_BEAM$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(chopped_parameter,
                                              [self.chopped_parameter])
            semiauto_parameter = self.reader.find_unique_string(
                device + '/SEMI_AUTOMATIC_GAIN_RANGE$',
                self.lh_builder.lh.get_parameters())
            gain_parameter = self.reader.find_unique_string(
                device + '/GAIN$', self.lh_builder.lh.get_parameters())
示例#2
0
class GenericParameters:
    def __init__(self, lh_builder, csv_filename):
        self.lh_builder = lh_builder
        self.reader = LHBuilderUtils()
        self.all_devices = self.reader._read_devices(csv_filename)

    def setmaindipole(self, main_dipoles):
        self.main_dipoles = main_dipoles

    def sethorizontal_correctors(self, horizontal_correctors):
        self.horizontal_correctors = horizontal_correctors

    def setvertical_correctors(self, vertical_correctors):
        self.vertical_correctors = vertical_correctors

    def setmain_quadrupoles(self, main_quadrupoles):
        self.main_quadrupoles = main_quadrupoles

    def setextraction_quadrupoles(self, extraction_quadrupoles):
        self.extraction_quadrupoles = extraction_quadrupoles

    def setcorrection_quadrupoles(self, correction_quadrupoles):
        self.correction_quadrupoles = correction_quadrupoles

    def setmain_sextupoles(self, main_sextupoles):
        self.main_sextupoles = main_sextupoles

    def setchromaticity_sextupoles(self, chromaticity_sextupoles):
        self.chromaticity_sextupoles = chromaticity_sextupoles

    def setresonance_sextupoles(self, resonance_sextupoles):
        self.resonance_sextupoles = resonance_sextupoles

    def setcorrection_sextupoles(self, correction_sextupoles):
        self.correction_sextupoles = correction_sextupoles

    def setcorrection_octupoles(self, correction_octupoles):
        self.correction_octupoles = correction_octupoles

    def setcavities(self, cavities):
        self.cavities = cavities

    def setkicker(self, kicker):
        self.kicker = kicker

    def getdevices(self):
        return self.all_devices

    def build(self, particle_transfer):

        all_correctors = self.horizontal_correctors + self.vertical_correctors

        ## Standard beam and logical devices
        beam_device = self.reader.find_unique_string(
            particle_transfer.replace('_RING', 'BEAM'), self.all_devices)
        optics_device = self.reader.find_unique_string(
            particle_transfer.replace('_RING', 'OPTICS'), self.all_devices)
        orbit_device = self.reader.find_unique_string(
            particle_transfer.replace('_RING', 'ORBIT'), self.all_devices)
        rf_device = self.reader.find_unique_string(
            particle_transfer.replace('_RING', 'RF'), self.all_devices)
        timeparam_device = self.reader.find_unique_string(
            particle_transfer.replace('_RING', 'TIMEPARAM'), self.all_devices)
        kicker_device = self.reader.find_unique_string(
            particle_transfer.replace('_RING', 'KICKER'), self.all_devices)
        #bumper_device = reader.find_unique_string(particle_transfer.replace('_RING','BUMPER'), self.all_devices)

        ## Beam parameters
        a_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/A',
            'SCALAR_A',
            beam_device,
            belongs_to_function_bproc=False)
        alphac_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/ALPHAC', 'ALPHAC', beam_device, is_trimable=False)
        aoq_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/AOQ',
            'SCALAR_AOQ',
            beam_device,
            is_trimable=False,
            belongs_to_function_bproc=False)
        brho_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/BRHO', 'BRHO', beam_device, is_trimable=False)
        brhodot_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/BRHODOT',
            'BRHODOT',
            beam_device,
            is_trimable=False)
        brho_start_end_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/BRHO_START_END',
            'SCALAR_BRHO',
            beam_device,
            is_trimable=False)
        bucketfill_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/BUCKETFILL', 'SCALAR_BUCKETFILL', beam_device)
        bunchfactor_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/BUNCHFACTOR', 'BUNCHFACTOR', beam_device)
        bunchpattern_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/BUNCHPATTERN', 'SCALAR_BUNCHPATTERN', beam_device)
        ch_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/CH', 'CHROMATICITY', beam_device)
        cv_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/CV', 'CHROMATICITY', beam_device)
        deltar_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/DELTAR', 'DELTAR', beam_device)
        e_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/E', 'SCALAR_E', beam_device)
        element_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/ELEMENT',
            'SCALAR_ELEMENT',
            beam_device,
            belongs_to_function_bproc=False)
        erho_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/ERHO', 'ERHO', beam_device, is_trimable=False)
        eta_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/ETA', 'ETA', beam_device, is_trimable=False)
        frev_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/FREV', 'FREV', beam_device, is_trimable=False)
        gamma_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/GAMMA', 'GAMMA', beam_device, is_trimable=False)
        geofact_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/GEOFACT', 'GEOFACT', beam_device)
        h_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/H', 'SCALAR_H', beam_device)
        inj_emih_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/INJ_EMIH',
            'SCALAR_INJ_EMIH',
            beam_device,
            belongs_to_function_bproc=False)
        inj_emil_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/INJ_EMIL',
            'SCALAR_INJ_EMIL',
            beam_device,
            belongs_to_function_bproc=False)
        inj_emiv_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/INJ_EMIV',
            'SCALAR_INJ_EMIV',
            beam_device,
            belongs_to_function_bproc=False)
        isotope_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/ISOTOPE',
            'SCALAR_ISOTOPE',
            beam_device,
            belongs_to_function_bproc=False)
        kl_ampl_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/KL_AMPL', 'SCALAR_KL_AMPL', beam_device)
        kl_harm_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/KL_HARM', 'SCALAR_KL_HARM', beam_device)
        kl_offset_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/KL_OFFSET', 'SCALAR_KL_OFFSET', beam_device)
        kl_phase_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/KL_PHASE', 'SCALAR_KL_PHASE', beam_device)
        maxrh_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/MAXRH', 'MAXRH', beam_device, is_trimable=False)
        maxrv_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/MAXRV', 'MAXRV', beam_device, is_trimable=False)
        nparticles_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/NPARTICLES',
            'SCALAR_NPARTICLES',
            beam_device,
            belongs_to_function_bproc=False)
        nperbunch_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/NPERBUNCH',
            'SCALAR_NPERBUNCH',
            beam_device,
            is_trimable=False)
        phis_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/PHIS', 'PHIS', beam_device, is_trimable=False)
        q_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/Q',
            'SCALAR_Q',
            beam_device,
            belongs_to_function_bproc=False)
        qh_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/QH', 'TUNE', beam_device)
        qv_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/QV', 'TUNE', beam_device)
        tbunch_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/TBUNCH',
            'SCALAR_TBUNCH',
            beam_device,
            is_trimable=False)
        trev_parameter = self.lh_builder.lh.define_physics_parameter(
            beam_device + '/TREV', 'TREV', beam_device, is_trimable=False)

        ## RF parameters
        abkt_parameter = self.lh_builder.lh.define_physics_parameter(
            rf_device + '/ABKT', 'ABKT', rf_device)
        dualh_parameter = self.lh_builder.lh.define_physics_parameter(
            rf_device + '/DUALH', 'SCALAR_DUALH', rf_device)
        dualhip_parameter = self.lh_builder.lh.define_physics_parameter(
            rf_device + '/DUALHIP', 'DUALHIP', rf_device)
        frfring_parameter = self.lh_builder.lh.define_physics_parameter(
            rf_device + '/FRFRING', 'FRFRING', rf_device, is_trimable=False)
        rf_mode_parameter = self.lh_builder.lh.define_physics_parameter(
            rf_device + '/MODE', 'SCALAR_CAVITY_MODE', rf_device)
        prfring_parameter = self.lh_builder.lh.define_physics_parameter(
            rf_device + '/PRFRING', 'PRFRING', rf_device, is_trimable=False)
        urfring_parameter = self.lh_builder.lh.define_physics_parameter(
            rf_device + '/URFRING', 'URFRING', rf_device, is_trimable=False)
        urfsc_parameter = self.lh_builder.lh.define_physics_parameter(
            rf_device + '/URFSC', 'URFSC', rf_device, is_trimable=False)

        for device in self.cavities:
            self.lh_builder.lh.define_physics_parameter(
                device + '/URF', 'URF', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/FRF', 'FRF', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/PRF', 'PRF', device)

        ## Optics parameters
        #ext_sigma_parameter = self.lh_builder.lh.define_physics_parameter(optics_device + '/EXT_SIGMA', 'SCALAR_EXT_SIGMA', optics_device)
        opticsip_parameter = self.lh_builder.lh.define_physics_parameter(
            optics_device + '/OPTICSIP', 'OPTICSIP', optics_device)
        #sigma_parameter = self.lh_builder.lh.define_physics_parameter(optics_device + '/SIGMA', 'SIGMA', optics_device)
        #tau_parameter = self.lh_builder.lh.define_physics_parameter(optics_device + '/TAU', 'TAU', optics_device)
        #tau_endpoint_parameter = self.lh_builder.lh.define_physics_parameter(optics_device + '/TAU_ENDPOINT', 'SCALAR_TAU_ENDPOINT', optics_device)
        #tau_nlp_parameter = self.lh_builder.lh.define_physics_parameter(optics_device + '/TAU_NLP', 'SCALAR_TAU_NLP', optics_device)
        tau_start_end_parameter = self.lh_builder.lh.define_physics_parameter(
            optics_device + '/TAU_START_END', 'SCALAR_TAU', optics_device)

        ## Timeparam parameters
        bdot_parameter = self.lh_builder.lh.define_physics_parameter(
            timeparam_device + '/BDOT', 'SCALAR_BDOT', timeparam_device)
        bp_length_parameter = self.lh_builder.lh.define_physics_parameter(
            timeparam_device + '/BP_LENGTH',
            'SCALAR_BP_LENGTH',
            timeparam_device,
            is_trimable=False)
        incorpip_parameter = self.lh_builder.lh.define_physics_parameter(
            timeparam_device + '/INCORPIP',
            'INCORPIP',
            timeparam_device,
            is_trimable=False)
        tgrid_parameter = self.lh_builder.lh.define_physics_parameter(
            timeparam_device + '/TGRID', 'SCALAR_TGRID', timeparam_device)
        tround_parameter = self.lh_builder.lh.define_physics_parameter(
            timeparam_device + '/TROUND', 'SCALAR_TROUND', timeparam_device)
        t_bp_length_parameter = self.lh_builder.lh.define_physics_parameter(
            timeparam_device + '/T_BP_LENGTH', 'SCALAR_T_BP_LENGTH',
            timeparam_device)
        t_wait_parameter = self.lh_builder.lh.define_physics_parameter(
            timeparam_device + '/T_WAIT', 'SCALAR_T_WAIT', timeparam_device)

        ## Kicker parameters
        #kicker_knob_parameter = self.lh_builder.lh.define_physics_parameter(kicker_device + '/KNOB', 'SCALAR_KICKER_KNOB', kicker_device)
        kicker_mode_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/MODE', 'SCALAR_KICKER_MODE', kicker_device)
        nbunch1_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/NBUNCH1', 'SCALAR_NBUNCH1', kicker_device)
        start_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/START', 'SCALAR_KICKER_START', kicker_device)
        thigh1_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/THIGH1', 'SCALAR_KICKER_THIGH1', kicker_device)
        thigh2_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/THIGH2', 'SCALAR_KICKER_THIGH2', kicker_device)
        toffset1_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/TOFFSET1', 'SCALAR_KICKER_TOFFSET1',
            kicker_device)
        toffset2_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/TOFFSET2', 'SCALAR_KICKER_TOFFSET2',
            kicker_device)

        ## Magnet groups according to multipole
        all_dipoles = self.main_dipoles + self.horizontal_correctors + self.vertical_correctors
        all_quadrupoles = self.main_quadrupoles + self.extraction_quadrupoles + self.correction_quadrupoles
        all_sextupoles = self.main_sextupoles + self.correction_sextupoles
        all_octupoles = self.correction_octupoles

        all_magnets = all_dipoles + all_quadrupoles + all_sextupoles + all_octupoles
        main_magnets = self.main_dipoles + self.main_quadrupoles

        kicker = self.kicker

        for device in all_dipoles:
            self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K0L', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'B0L', device)

        for device in all_quadrupoles:
            self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K1L', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'B1L', device)

        for device in all_sextupoles:
            #self.lh_builder.lh.define_physics_parameter(device + '/KLDELTA', 'DELTA_K2L', device) ## KLDELTA soll nicht fuer S02KM5SS und S08KM5SS angelegt werden, hier muss noch eine extra gruppe / hierarchie erstellt werden
            self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K2L', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'B2L', device)

        for device in all_octupoles:
            self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K3L', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'B3L', device)

        for device in kicker:
            self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'SCALAR_K0L', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'SCALAR_B0L', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/UKICK', 'SCALAR_UKICK', device)
            #if device == 'S05MK2E': # Skip these parameters for the seconds kicker in SIS18
            #continue
            #self.lh_builder.lh.define_hardware_parameter(device, 'TIMDELRF', 'time')
            #self.lh_builder.lh.define_hardware_parameter(device, 'TIMDELTG', 'time')
            #self.lh_builder.lh.define_hardware_parameter(device, 'TIMFTRF', 'time')
            #self.lh_builder.lh.define_hardware_parameter(device, 'TIMFTTG', 'time')
            #self.lh_builder.lh.define_hardware_parameter(device, 'VOLTRFS', 'voltages')
            #self.lh_builder.lh.define_hardware_parameter(device, 'VOLTRIS', 'voltages')
            #self.lh_builder.lh.define_hardware_parameter(device, 'VOLTTGS', 'voltages')

        for device in all_magnets:
            self.lh_builder.lh.define_physics_parameter(
                device + '/I', 'I', device)
            #self.lh_builder.lh.define_hardware_parameter(device, 'RAMPVALS', 'data')

        for device in main_magnets:
            self.lh_builder.lh.define_physics_parameter(
                device + '/IDOT', 'IDOT', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/UEDDY', 'UEDDY', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/U', 'U', device)

        ### Creation of relations

        ## Beam Parameters
        self.lh_builder.create_child_node(
            a_parameter, [isotope_parameter, element_parameter])
        self.lh_builder.create_child_node(alphac_parameter, opticsip_parameter)
        self.lh_builder.create_child_node(aoq_parameter,
                                          [a_parameter, q_parameter])
        self.lh_builder.create_child_node(brho_parameter, bp_length_parameter)
        self.lh_builder.create_child_node(brhodot_parameter,
                                          bp_length_parameter)
        self.lh_builder.create_child_node(brho_start_end_parameter,
                                          [e_parameter, aoq_parameter])
        self.lh_builder.create_child_node(bunchfactor_parameter,
                                          phis_parameter)
        self.lh_builder.create_child_node(ch_parameter, opticsip_parameter)
        self.lh_builder.create_child_node(cv_parameter, opticsip_parameter)
        self.lh_builder.create_child_node(deltar_parameter,
                                          bp_length_parameter)
        self.lh_builder.create_child_node(erho_parameter,
                                          [brho_parameter, aoq_parameter])
        self.lh_builder.create_child_node(eta_parameter,
                                          [gamma_parameter, alphac_parameter])
        self.lh_builder.create_child_node(frev_parameter, gamma_parameter)
        self.lh_builder.create_child_node(gamma_parameter,
                                          [brho_parameter, aoq_parameter])
        self.lh_builder.create_child_node(geofact_parameter, [
            brho_start_end_parameter, brho_parameter, inj_emiv_parameter,
            inj_emih_parameter
        ])
        self.lh_builder.create_child_node(maxrh_parameter, [
            inj_emih_parameter, brho_parameter, opticsip_parameter,
            brho_start_end_parameter
        ])
        self.lh_builder.create_child_node(maxrv_parameter, [
            inj_emiv_parameter, brho_parameter, opticsip_parameter,
            brho_start_end_parameter
        ])
        self.lh_builder.create_child_node(
            nperbunch_parameter,
            [nparticles_parameter, h_parameter, bunchpattern_parameter])
        self.lh_builder.create_child_node(phis_parameter, [
            aoq_parameter, h_parameter, eta_parameter, abkt_parameter,
            brhodot_parameter, gamma_parameter, inj_emil_parameter,
            dualhip_parameter, geofact_parameter, e_parameter,
            nperbunch_parameter, q_parameter
        ])
        self.lh_builder.create_child_node(qh_parameter, opticsip_parameter)
        self.lh_builder.create_child_node(qv_parameter, opticsip_parameter)
        self.lh_builder.create_child_node(tbunch_parameter,
                                          [h_parameter, trev_parameter])
        self.lh_builder.create_child_node(trev_parameter, frev_parameter)

        ## RF Parameters
        self.lh_builder.create_child_node(abkt_parameter, [
            bp_length_parameter, bucketfill_parameter, inj_emil_parameter,
            tgrid_parameter
        ])
        self.lh_builder.create_child_node(
            dualhip_parameter, [dualh_parameter, bp_length_parameter])
        self.lh_builder.create_child_node(frfring_parameter,
                                          [frev_parameter, h_parameter])
        self.lh_builder.create_child_node(prfring_parameter, phis_parameter)
        self.lh_builder.create_child_node(urfring_parameter, phis_parameter)
        self.lh_builder.create_child_node(urfsc_parameter, phis_parameter)

        ## Optics Parameters
        #self.lh_builder.create_child_node(opticsip_parameter, [ sigma_parameter, tau_parameter, incorpip_parameter ])
        #self.lh_builder.create_child_node(sigma_parameter, [ brho_start_end_parameter, ext_sigma_parameter, bp_length_parameter, t_wait_parameter, tround_parameter, tgrid_parameter, tau_endpoint_parameter ])
        #self.lh_builder.create_child_node(tau_parameter, [ tau_nlp_parameter, tau_start_end_parameter, bp_length_parameter, t_wait_parameter, brho_start_end_parameter, tround_parameter, tgrid_parameter, tau_endpoint_parameter ])

        ## Timeparam Parameters
        #self.lh_builder.create_child_node(bp_length_parameter, [ t_bp_length_parameter, t_wait_parameter, ext_sigma_parameter, tau_start_end_parameter, tround_parameter,  bdot_parameter, brho_start_end_parameter, tgrid_parameter ])
        #self.lh_builder.create_child_node(incorpip_parameter, bp_length_parameter )

        ## Kicker Parameters
        self.lh_builder.create_child_node(
            thigh1_parameter,
            [nbunch1_parameter, tbunch_parameter, h_parameter])
        self.lh_builder.create_child_node(
            thigh2_parameter,
            [tbunch_parameter, h_parameter, nbunch1_parameter])
        self.lh_builder.create_child_node(
            toffset2_parameter, [toffset1_parameter, thigh1_parameter])

        ## Magnets
        for device in all_magnets:
            bl_parameter = self.reader.find_unique_string(
                device + '/B[0-3]?L$', self.lh_builder.lh.get_parameters())
            kl_parameter = self.reader.find_unique_string(
                device + '/K[0-3]?L$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(
                bl_parameter,
                [brho_parameter, kl_parameter, incorpip_parameter])

        for device in all_dipoles:
            bl_parameter = self.reader.find_unique_string(
                device + '/B[0-3]?L$', self.lh_builder.lh.get_parameters())
            i_parameter = self.reader.find_unique_string(
                device + '/I$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(i_parameter, bl_parameter)

        for device in self.main_dipoles:
            kl_parameter = self.reader.find_unique_string(
                device + '/K0?L$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(kl_parameter, opticsip_parameter)

        for device in self.main_quadrupoles:
            kl_parameter = self.reader.find_unique_string(
                device + '/K1?L$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(
                kl_parameter, [qh_parameter, qv_parameter, opticsip_parameter])

        for device in self.main_sextupoles:
            #kldelta_parameter = self.reader.find_unique_string(device + '/KLDELTA$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(kldelta_parameter, [ incorpip_parameter, kl_harm_parameter, kl_phase_parameter, kl_ampl_parameter, kl_offset_parameter ])

            kl_parameter = self.reader.find_unique_string(
                device + '/K2?L$', self.lh_builder.lh.get_parameters())

            if (device in self.resonance_sextupoles):
                self.lh_builder.create_child_node(kl_parameter,
                                                  opticsip_parameter)
            else:
                self.lh_builder.create_child_node(
                    kl_parameter,
                    [ch_parameter, cv_parameter, opticsip_parameter])
                #self.lh_builder.create_child_node(kl_parameter, [ ch_parameter, cv_parameter, opticsip_parameter, kldelta_parameter ])

            bl_parameter = self.reader.find_unique_string(
                device + '/B[0-3]?L$', self.lh_builder.lh.get_parameters())
            i_parameter = self.reader.find_unique_string(
                device + '/I$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(i_parameter, bl_parameter)

            #rampvals_parameter = self.reader.find_unique_string(device + '/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_parameter, i_parameter )

        for device in (self.correction_quadrupoles +
                       self.extraction_quadrupoles):
            kl_parameter = self.reader.find_unique_string(
                device + '/K2?L$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(kl_parameter, opticsip_parameter)

            bl_parameter = self.reader.find_unique_string(
                device + '/B[1]?L$', self.lh_builder.lh.get_parameters())
            i_parameter = self.reader.find_unique_string(
                device + '/I$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(i_parameter, bl_parameter)

            #rampvals_parameter = self.reader.find_unique_string(device + '/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_parameter, i_parameter)

        for device in self.chromaticity_sextupoles:
            kl_parameter = self.reader.find_unique_string(
                device + '/K2?L$', self.lh_builder.lh.get_parameters())
            if (device in self.resonance_sextupoles):
                self.lh_builder.create_child_node(kl_parameter,
                                                  opticsip_parameter)
            else:
                self.lh_builder.create_child_node(
                    kl_parameter,
                    [ch_parameter, cv_parameter, opticsip_parameter])

        for device in main_magnets:
            bl_parameter = self.reader.find_unique_string(
                device + '/B[0-3]?L$', self.lh_builder.lh.get_parameters())
            i_parameter = self.reader.find_unique_string(
                device + '/I$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(i_parameter, bl_parameter)

            idot_parameter = self.reader.find_unique_string(
                device + '/IDOT$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(idot_parameter, i_parameter)

            ueddy_parameter = self.reader.find_unique_string(
                device + '/UEDDY$', self.lh_builder.lh.get_parameters())
            u_parameter = self.reader.find_unique_string(
                device + '/U$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(ueddy_parameter, idot_parameter)
            self.lh_builder.create_child_node(
                u_parameter, [ueddy_parameter, i_parameter, idot_parameter])

            #rampvals_parameter = self.reader.find_unique_string(device + '/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_parameter, [ u_parameter, i_parameter ])

        for device in all_correctors:
            kl_parameter = self.reader.find_unique_string(
                device + '/K[0-3]?L$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(kl_parameter, opticsip_parameter)

        for device in self.correction_sextupoles:
            kl_parameter = self.reader.find_unique_string(
                device + '/K[0-3]?L$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(kl_parameter, opticsip_parameter)

            bl_parameter = self.reader.find_unique_string(
                device + '/B[0-3]?L$', self.lh_builder.lh.get_parameters())
            i_parameter = self.reader.find_unique_string(
                device + '/I$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(i_parameter, bl_parameter)

            #rampvals_parameter = self.reader.find_unique_string(device + '/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_parameter, i_parameter)

        for device in self.resonance_sextupoles:
            i_parameter = self.reader.find_unique_string(
                device + '/I$', self.lh_builder.lh.get_parameters())
            #rampvals_parameter = self.reader.find_unique_string(device + '/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_parameter, i_parameter)

        for device in self.correction_octupoles:
            kl_parameter = self.reader.find_unique_string(
                device + '/K0?L$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(kl_parameter, opticsip_parameter)

            bl_parameter = self.reader.find_unique_string(
                device + '/B[0-3]?L$', self.lh_builder.lh.get_parameters())
            i_parameter = self.reader.find_unique_string(
                device + '/I$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(i_parameter, bl_parameter)

        ## Cavities
        for device in self.cavities:
            urf_parameter = self.reader.find_unique_string(
                device + '/URF$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(urf_parameter, [
                h_parameter, incorpip_parameter, urfring_parameter,
                rf_mode_parameter
            ])

            frf_parameter = self.reader.find_unique_string(
                device + '/FRF$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(frf_parameter, [
                h_parameter, incorpip_parameter, frfring_parameter,
                rf_mode_parameter
            ])

            prf_parameter = self.reader.find_unique_string(
                device + '/PRF$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(prf_parameter, [
                h_parameter, incorpip_parameter, prfring_parameter,
                rf_mode_parameter
            ])

        return self.lh_builder
class SpecialSIS100Parameters:
    def __init__(self, lh_builder, csv_filename):
        self.lh_builder = lh_builder
        self.reader = LHBuilderUtils()
        self.all_devices = self.reader._read_devices(csv_filename)

    def setkicker(self, kicker):
        self.kicker = kicker

    def setq_kicker(self, q_kicker):
        self.q_kicker = q_kicker

    def build(self, particle_transfer):

        beam_device = self.reader.find_unique_string(
            particle_transfer.replace('_RING', 'BEAM'), self.all_devices)
        optics_device = self.reader.find_unique_string(
            particle_transfer.replace('_RING', 'OPTICS'), self.all_devices)
        timeparam_device = self.reader.find_unique_string(
            particle_transfer.replace('_RING', 'TIMEPARAM'), self.all_devices)
        kicker_device = self.reader.find_unique_string(
            particle_transfer.replace('_RING', 'KICKER'), self.all_devices)

        incorpip_parameter = self.reader.find_unique_string(
            timeparam_device + '/INCORPIP$',
            self.lh_builder.lh.get_parameters())

        opticsip_parameter = self.reader.find_unique_string(
            optics_device + '/OPTICSIP$', self.lh_builder.lh.get_parameters())
        tau_start_end_parameter = self.reader.find_unique_string(
            optics_device + '/TAU_START_END$',
            self.lh_builder.lh.get_parameters())
        brho_start_end_parameter = self.reader.find_unique_string(
            beam_device + '/BRHO_START_END$',
            self.lh_builder.lh.get_parameters())
        brho_parameter = self.reader.find_unique_string(
            beam_device + '/BRHO$', self.lh_builder.lh.get_parameters())

        t_wait_parameter = self.reader.find_unique_string(
            timeparam_device + '/T_WAIT$', self.lh_builder.lh.get_parameters())
        tgrid_parameter = self.reader.find_unique_string(
            timeparam_device + '/TGRID$', self.lh_builder.lh.get_parameters())
        tround_parameter = self.reader.find_unique_string(
            timeparam_device + '/TROUND$', self.lh_builder.lh.get_parameters())
        t_bp_length_parameter = self.reader.find_unique_string(
            timeparam_device + '/T_BP_LENGTH$',
            self.lh_builder.lh.get_parameters())
        bp_length_parameter = self.reader.find_unique_string(
            timeparam_device + '/BP_LENGTH$',
            self.lh_builder.lh.get_parameters())
        bdot_parameter = self.reader.find_unique_string(
            timeparam_device + '/BDOT$', self.lh_builder.lh.get_parameters())

        gamma_parameter = self.reader.find_unique_string(
            beam_device + '/GAMMA$', self.lh_builder.lh.get_parameters())

        ## Kicker parameters
        kicker_inj_kick_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/INJ_KICK', 'SCALAR_INJ_KICK', kicker_device)
        kicker_ext_kick_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/EXT_KICK', 'SCALAR_EXT_KICK', kicker_device)
        kicker_qh_kick_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/QH_KICK', 'SCALAR_Q_KICK', kicker_device)
        kicker_qv_kick_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/QV_KICK', 'SCALAR_Q_KICK', kicker_device)

        ## Optics parameters

        #SIS100
        self.lh_builder.create_child_node(opticsip_parameter, [
            tau_start_end_parameter, incorpip_parameter, tgrid_parameter,
            tround_parameter, t_wait_parameter, gamma_parameter
        ])

        ## Timeparam Parameters
        ##SIS100
        self.lh_builder.create_child_node(bp_length_parameter, [
            t_bp_length_parameter, t_wait_parameter, tau_start_end_parameter,
            tround_parameter, bdot_parameter, brho_start_end_parameter,
            tgrid_parameter
        ])
        self.lh_builder.create_child_node(incorpip_parameter,
                                          bp_length_parameter)

        ## Kicker
        for device in self.kicker:
            kl_parameter = self.reader.find_unique_string(
                device + '/KL$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(
                kl_parameter, [kicker_ext_kick_parameter, opticsip_parameter])

            bl_parameter = self.reader.find_unique_string(
                device + '/BL$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(bl_parameter,
                                              [kl_parameter, brho_parameter])

            ukick_parameter = self.reader.find_unique_string(
                device + '/UKICK$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(ukick_parameter, bl_parameter)

        ## Q_Kicker
        for device in self.q_kicker:
            kl_parameter = self.reader.find_unique_string(
                device + '/KL$', self.lh_builder.lh.get_parameters())

            number = int(device[6:7])
            if (number == 1):
                self.lh_builder.create_child_node(
                    kl_parameter,
                    [opticsip_parameter, kicker_qh_kick_parameter])
            elif (number == 2):
                self.lh_builder.create_child_node(
                    kl_parameter,
                    [opticsip_parameter, kicker_qv_kick_parameter])

            bl_parameter = self.reader.find_unique_string(
                device + '/BL$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(bl_parameter,
                                              [kl_parameter, brho_parameter])

            ukick_parameter = self.reader.find_unique_string(
                device + '/UKICK$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(ukick_parameter, bl_parameter)

        return self.lh_builder
class GenericTransferlineHierarchy:
    def __init__(self, devices):
        self.devices = devices
        self.reader = LHBuilderUtils()
        self.y_prec_parser = XMLParser(self.devices.accelerator_zone,
                                       self.devices.rigidity)

    def generate_linkrules(self):

        print('LinkRules:')
        for device in self.devices.alldevices:

            ##print (self.devices._devicelinkrulemap)
            if device in self.devices.devicelinkrulemap:
                linkrule = self.devices.devicelinkrulemap.get(device)

                self.lh_builder.lh.add_linkrule_for_device(device, linkrule)
                print(device, linkrule)

    def build(self):

        ## Standard beam and logical devices
        self.beam_device = self.devices.accelerator_zone + '_BEAM'
        self.lh_builder.lh.define_device(self.beam_device,
                                         'BEAM',
                                         self.devices.accelerator_zone,
                                         description=self.beam_device +
                                         ' Transfer Line Beam')

        ## Beam parameters
        self.a_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/A', 'SCALAR_A', self.beam_device)
        self.aoq_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/AOQ',
            'SCALAR_AOQ',
            self.beam_device,
            is_trimable=False)
        self.brho_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/BRHO',
            'BRHO',
            self.beam_device,
            is_trimable=False)
        self.e_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/E', 'SCALAR_E', self.beam_device)
        self.element_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/ELEMENT', 'SCALAR_ELEMENT', self.beam_device)
        self.erho_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/ERHO',
            'ERHO',
            self.beam_device,
            is_trimable=False)
        self.isotope_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/ISOTOPE', 'SCALAR_ISOTOPE', self.beam_device)
        self.q_parameter = self.lh_builder.lh.define_physics_parameter(
            self.beam_device + '/Q', 'SCALAR_Q', self.beam_device)

        self.lh_builder.lh.add_parameter_to_system(self.a_parameter, 'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.aoq_parameter, 'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.brho_parameter, 'BEAM')

        self.lh_builder.lh.add_parameter_to_system(self.e_parameter, 'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.e_parameter,
                                                   '-TOPLEVEL')
        ## remove energy parameter for transfer lines from system 'generation'.
        ## parameter is set by makerule from preceding ring or transfer line
        ## self.lh_builder.lh.add_parameter_to_system(self.e_parameter, 'generation')

        self.lh_builder.lh.add_parameter_to_system(self.element_parameter,
                                                   'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.element_parameter,
                                                   '-TOPLEVEL')
        self.lh_builder.lh.add_parameter_to_system(self.element_parameter,
                                                   'generation')

        self.lh_builder.lh.add_parameter_to_system(self.erho_parameter, 'BEAM')

        self.lh_builder.lh.add_parameter_to_system(self.isotope_parameter,
                                                   'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.isotope_parameter,
                                                   '-TOPLEVEL')
        self.lh_builder.lh.add_parameter_to_system(self.isotope_parameter,
                                                   'generation')

        self.lh_builder.lh.add_parameter_to_system(self.q_parameter, 'BEAM')
        self.lh_builder.lh.add_parameter_to_system(self.q_parameter,
                                                   '-TOPLEVEL')
        self.lh_builder.lh.add_parameter_to_system(self.q_parameter,
                                                   'generation')

        ## Magnet groups according to multipole
        for device in self.devices.main_dipoles:
            y_prec_KL = self.y_prec_parser.findYPrec(device, 'KL', 5.0e-5)
            kl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K0L', device, y_prec=y_prec_KL)
            y_prec_BL = self.y_prec_parser.findYPrec(device, 'BL', 5.0e-5)
            bl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'B0L', device, y_prec=y_prec_BL)

            system = self.devices.devicesystemmap.get(device)
            print(device, system)

            self.lh_builder.lh.add_parameter_to_system(kl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       'generation')
            self.lh_builder.lh.add_parameter_to_system(bl_parameter, system)

        for device in self.devices.horizontal_correctors + self.devices.vertical_correctors:
            y_prec_KL = self.y_prec_parser.findYPrec(device, 'KL', 1.0e-3)
            kl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K0L', device, y_prec=y_prec_KL)
            y_prec_BL = self.y_prec_parser.findYPrec(device, 'BL', 1.0e-4)
            bl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'B0L', device, y_prec=y_prec_BL)

            system = self.devices.devicesystemmap.get(device)
            print(device, system)

            self.lh_builder.lh.add_parameter_to_system(kl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       'generation')
            self.lh_builder.lh.add_parameter_to_system(bl_parameter, system)

        for device in self.devices.main_quadrupoles:
            y_prec_KL = self.y_prec_parser.findYPrec(device, 'KL', 5.0e-5)
            y_prec_BL = self.y_prec_parser.findYPrec(device, 'BL', 5.0e-5)

            kl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K1L', device, y_prec=y_prec_KL)
            bl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'B1L', device, y_prec=y_prec_BL)

            system = self.devices.devicesystemmap.get(device)
            print(device, system)

            self.lh_builder.lh.add_parameter_to_system(kl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       'generation')
            self.lh_builder.lh.add_parameter_to_system(bl_parameter, system)

        for device in self.devices.main_sextupoles:
            y_prec_KL = self.y_prec_parser.findYPrec(device, 'KL', 5.0e-5)
            y_prec_BL = self.y_prec_parser.findYPrec(device, 'BL', 5.0e-5)

            kl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K2L', device, y_prec=y_prec_KL)
            bl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/BL', 'B2L', device, y_prec=y_prec_BL)

            system = self.devices.devicesystemmap.get(device)
            print(device, system)

            self.lh_builder.lh.add_parameter_to_system(kl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       'generation')
            self.lh_builder.lh.add_parameter_to_system(bl_parameter, system)

        for device in self.devices.septum:
            y_prec_KL = self.y_prec_parser.findYPrec(device, 'KL', 5.0e-5)

            kl_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K0L', device, y_prec=y_prec_KL)
            usep_parameter = self.lh_builder.lh.define_physics_parameter(
                device + '/USEP', 'USEP', device)

            system = self.devices.devicesystemmap.get(device)
            print(device, system)

            self.lh_builder.lh.add_parameter_to_system(kl_parameter, system)
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       '-TOPLEVEL')
            self.lh_builder.lh.add_parameter_to_system(kl_parameter,
                                                       'generation')
            self.lh_builder.lh.add_parameter_to_system(usep_parameter, system)

        ### Creation of relations

        ## Beam Parameters
        self.lh_builder.create_child_node(
            self.a_parameter, [self.isotope_parameter, self.element_parameter])
        self.lh_builder.create_child_node(self.aoq_parameter,
                                          [self.a_parameter, self.q_parameter])
        self.lh_builder.create_child_node(
            self.brho_parameter, [self.e_parameter, self.aoq_parameter])
        self.lh_builder.create_child_node(
            self.erho_parameter, [self.brho_parameter, self.aoq_parameter])

        ## Magnets
        for device in self.devices.main_dipoles + self.devices.horizontal_correctors + self.devices.vertical_correctors + self.devices.main_quadrupoles + self.devices.main_sextupoles:
            bl_parameter = self.reader.find_unique_string(
                device + '/B[0-3]?L$', self.lh_builder.lh.get_parameters())
            kl_parameter = self.reader.find_unique_string(
                device + '/K[0-3]?L$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(
                bl_parameter, [self.brho_parameter, kl_parameter])

        for device in self.devices.septum:
            usep_parameter = self.reader.find_unique_string(
                device + '/USEP', self.lh_builder.lh.get_parameters())
            kl_parameter = self.reader.find_unique_string(
                device + '/K[0-3]?L$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(
                usep_parameter, [self.erho_parameter, kl_parameter])
class SpecialSIS18Parameters:

    def __init__(self, lh_builder, csv_filename):
        self.lh_builder = lh_builder
        self.reader = LHBuilderUtils()
        self.all_devices = self.reader._read_devices(csv_filename)

    def sethardware_fs_system(self, hardware_fs_system):
        self.hardware_fs_system = hardware_fs_system

    def sethardware_rf_system(self, hardware_rf_system):
        self.hardware_rf_system = hardware_rf_system

    def settgx_system(self, tgx_system):
        self.tgx_system = tgx_system

    def settiming_device(self, timing_device):
        self.timing_device = timing_device

    def setmaindipole(self, main_dipoles):
        self.main_dipoles = main_dipoles

    def sethorizontal_correctors(self, horizontal_correctors):
        self.horizontal_correctors = horizontal_correctors
    def setvertical_correctors(self, vertical_correctors):
        self.vertical_correctors = vertical_correctors
   
    def setmain_sextupoles(self, main_sextupoles):
        self.main_sextupoles = main_sextupoles

    def sethorizontal_correction_coils(self, horizontal_correction_coils):
        self.horizontal_correction_coils = horizontal_correction_coils

    def setextraction_bump_correction_coils(self, extraction_bump_correction_coils):
        self.extraction_bump_correction_coils = extraction_bump_correction_coils

    def setextra_correction_coils(self, extra_correction_coils):
        self.extra_correction_coils = extra_correction_coils

    def sethorizontal_orbit_correction_coils(self, horizontal_orbit_correction_coils):
        self.horizontal_orbit_correction_coils = horizontal_orbit_correction_coils

    def setsis18_cavities_ampl(self, sis18_cavities_ampl):
        self.sis18_cavities_ampl = sis18_cavities_ampl

    def setsis18_cavities_freq(self, sis18_cavities_freq):
        self.sis18_cavities_freq = sis18_cavities_freq

    def setsis18_cavities_phase(self, sis18_cavities_phase):
        self.sis18_cavities_phase = sis18_cavities_phase

    def setsis18_bypass(self, sis18_bypass):
        self.sis18_bypass = sis18_bypass

    def setsis18_ko_exiter(self, sis18_ko_exiter):
        self.sis18_ko_exiter = sis18_ko_exiter

    def setkicker(self, kicker):
        self.kicker = kicker

    def setbumper(self, bumper):
        self.bumper = bumper

    def build(self, particle_transfer):

        beam_device = self.reader.find_unique_string(particle_transfer.replace('_RING','BEAM'), self.all_devices)
        optics_device = self.reader.find_unique_string(particle_transfer.replace('_RING','OPTICS'), self.all_devices)
        orbit_device = self.reader.find_unique_string(particle_transfer.replace('_RING','ORBIT'), self.all_devices)
        bumper_device = self.reader.find_unique_string(particle_transfer.replace('_RING','BUMPER'), self.all_devices)
        kicker_device = self.reader.find_unique_string(particle_transfer.replace('_RING','KICKER'), self.all_devices)

        ## Beam parameters
        dp_over_p_parameter = self.lh_builder.lh.define_physics_parameter(beam_device + '/DP_OVER_P', 'SCALAR_DP_OVER_P', beam_device, belongs_to_function_bproc=False)

        for device in self.main_sextupoles:
            self.lh_builder.lh.define_physics_parameter(device + '/KLDELTA', 'DELTA_K2L', device) ## KLDELTA soll nicht fuer S02KM5SS und S08KM5SS 

        ## Optics parameters
        ext_sigma_parameter = self.lh_builder.lh.define_physics_parameter(optics_device + '/EXT_SIGMA', 'SCALAR_EXT_SIGMA', optics_device, belongs_to_function_bproc=False)
        sigma_parameter = self.lh_builder.lh.define_physics_parameter(optics_device + '/SIGMA', 'SIGMA', optics_device)
        tau_parameter = self.lh_builder.lh.define_physics_parameter(optics_device + '/TAU', 'TAU', optics_device)
        tau_endpoint_parameter = self.lh_builder.lh.define_physics_parameter(optics_device + '/TAU_ENDPOINT', 'SCALAR_TAU_ENDPOINT', optics_device)
        tau_nlp_parameter = self.lh_builder.lh.define_physics_parameter(optics_device + '/TAU_NLP', 'SCALAR_TAU_NLP', optics_device)


        ## Kicker parameters
        for device in self.kicker:
            self.lh_builder.lh.define_physics_parameter(device + '/KL', 'SCALAR_K0L', device)
            self.lh_builder.lh.define_physics_parameter(device + '/BL', 'SCALAR_B0L', device)
            self.lh_builder.lh.define_physics_parameter(device + '/UKICK', 'SCALAR_UKICK', device)
            if device == 'S05MK2E': # Skip these parameters for the seconds kicker in SIS18
                continue
            #self.lh_builder.lh.define_hardware_parameter(device, 'TIMDELRF', 'time')
            #self.lh_builder.lh.define_hardware_parameter(device, 'TIMDELTG', 'time')
            #self.lh_builder.lh.define_hardware_parameter(device, 'TIMFTRF', 'time')
            #self.lh_builder.lh.define_hardware_parameter(device, 'TIMFTTG', 'time')
            #self.lh_builder.lh.define_hardware_parameter(device, 'VOLTRFS', 'voltages')
            #self.lh_builder.lh.define_hardware_parameter(device, 'VOLTRIS', 'voltages')
            #self.lh_builder.lh.define_hardware_parameter(device, 'VOLTTGS', 'voltages')


        ## Kicker parameters
        kicker_knob_parameter = self.lh_builder.lh.define_physics_parameter(kicker_device + '/KNOB', 'SCALAR_KICKER_KNOB', kicker_device)
        kicker_mode_parameter = self.lh_builder.lh.define_physics_parameter(kicker_device + '/MODE', 'SCALAR_KICKER_MODE', kicker_device)
        nbunch1_parameter = self.lh_builder.lh.define_physics_parameter(kicker_device + '/NBUNCH1', 'SCALAR_NBUNCH1', kicker_device)
        start_parameter = self.lh_builder.lh.define_physics_parameter(kicker_device + '/START', 'SCALAR_KICKER_START', kicker_device)
        thigh1_parameter = self.lh_builder.lh.define_physics_parameter(kicker_device + '/THIGH1', 'SCALAR_KICKER_THIGH1', kicker_device)
        thigh2_parameter = self.lh_builder.lh.define_physics_parameter(kicker_device + '/THIGH2', 'SCALAR_KICKER_THIGH2', kicker_device)
        toffset1_parameter = self.lh_builder.lh.define_physics_parameter(kicker_device + '/TOFFSET1', 'SCALAR_KICKER_TOFFSET1', kicker_device)
        toffset2_parameter = self.lh_builder.lh.define_physics_parameter(kicker_device + '/TOFFSET2', 'SCALAR_KICKER_TOFFSET2', kicker_device)


        ## Bumper parameters
        curvature_parameter = self.lh_builder.lh.define_physics_parameter(bumper_device + '/CURVATURE', 'SCALAR_BUMPER_CURVATURE', bumper_device)
        bumper_knob_parameter = self.lh_builder.lh.define_physics_parameter(bumper_device + '/KNOB', 'SCALAR_BUMPER_KNOB', bumper_device)
        tfall_parameter = self.lh_builder.lh.define_physics_parameter(bumper_device + '/TFALL', 'SCALAR_TFALL', bumper_device)


        for device in self.bumper:
            self.lh_builder.lh.define_physics_parameter(device + '/KL', 'SCALAR_K0L', device)
            self.lh_builder.lh.define_physics_parameter(device + '/BL', 'SCALAR_B0L', device)
            self.lh_builder.lh.define_physics_parameter(device + '/I', 'SCALAR_I', device)
            #self.lh_builder.lh.define_hardware_parameter(device, 'CURRENTS', 'currents')
            #self.lh_builder.lh.define_hardware_parameter(device, 'FTIMES', 'ftimes')
            #self.lh_builder.lh.define_hardware_parameter(device, 'PARA', 'reference_parameters')
        

        ## Hardware rf system parameters
        #for parameter in self.hardware_fs_system:
        #    hardware_fs_rampvals_parameter =  self.lh_builder.lh.define_hardware_parameter(self.hardware_fs_system, 'RAMPVALS', 'data')

        #mhbpar_damp1_parameter = self.lh_builder.lh.define_hardware_parameter(self.hardware_rf_system, 'MHBPAR', 'DAmp1')
        #mhbpar_damp2_parameter = self.lh_builder.lh.define_hardware_parameter(self.hardware_rf_system, 'MHBPAR', 'DAmp2')
        #mhbpar_delay_parameter = self.lh_builder.lh.define_hardware_parameter(self.hardware_rf_system, 'MHBPAR', 'Delay')
        #mhbpar_harm1_parameter = self.lh_builder.lh.define_hardware_parameter(self.hardware_rf_system, 'MHBPAR', 'Harm1')
        #mhbpar_harm2_parameter = self.lh_builder.lh.define_hardware_parameter(self.hardware_rf_system, 'MHBPAR', 'Harm2')
        #syncmode_hfssync_parameter = self.lh_builder.lh.define_hardware_parameter(self.hardware_rf_system, 'SYNCMODE', 'hfssync')
        #workmode_workmode_parameter = self.lh_builder.lh.define_hardware_parameter(self.hardware_rf_system, 'WORKMODE', 'workmode')

        #delay_trgdelay_parameter =  self.lh_builder.lh.define_hardware_parameter(self.tgx_system, 'DELAY', 'trgdelay')
        #harmonic_harmonic_parameter = self.lh_builder.lh.define_hardware_parameter(self.tgx_system, 'HARMONIC', 'harmonic')
        #mode_kickmode_parameter = self.lh_builder.lh.define_hardware_parameter(self.tgx_system, 'MODE', 'kickmode')
        #rftrig_rftrig_parameter = self.lh_builder.lh.define_hardware_parameter(self.tgx_system, 'RFTRIG', 'rftrig')

        #chansequ_chancount_parameter = self.lh_builder.lh.define_hardware_parameter(self.timing_device, 'CHANSEQU', 'chanCount')
        #chansequ_chansequ_parameter = self.lh_builder.lh.define_hardware_parameter(self.timing_device, 'CHANSEQU', 'chanSequ')
        #evtarray_chanarray_parameter = self.lh_builder.lh.define_hardware_parameter(self.timing_device, 'EVTARRAY', 'chanArray')
        timeout_unilac_parameter = self.lh_builder.lh.define_physics_parameter(self.timing_device + '/TIMEOUT_UNILAC', 'SCALAR_TIMEOUT_UNILAC', self.timing_device, belongs_to_function_bproc=False)
        tmeasure_parameter = self.lh_builder.lh.define_physics_parameter(self.timing_device + '/TMEASURE', 'SCALAR_TMEASURE', self.timing_device)
        toffset_unilac_parameter = self.lh_builder.lh.define_physics_parameter(self.timing_device + '/TOFFSET_UNILAC', 'SCALAR_TOFFSET_UNILAC', self.timing_device, belongs_to_function_bproc=False)


        for device in self.sis18_cavities_ampl:
            self.lh_builder.lh.define_physics_parameter(device + '/URF', 'URF', device)
            #self.lh_builder.lh.define_hardware_parameter(device, 'RAMPVALS', 'data')
            #self.lh_builder.lh.define_hardware_parameter(device, 'BROTAMPL', 'highValue')


        for device in self.sis18_cavities_freq:
            self.lh_builder.lh.define_physics_parameter(device + '/FRF', 'FRF', device)
            #self.lh_builder.lh.define_hardware_parameter(device, 'RAMPVALS', 'data')

        for device in self.sis18_cavities_phase:
            self.lh_builder.lh.define_physics_parameter(device + '/PRF', 'PRF', device)
            #self.lh_builder.lh.define_hardware_parameter(device, 'RAMPVALS', 'data')


        ## Orbit parameters
        coh01_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH01', 'ORBITBUMP', orbit_device)
        coh02_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH02', 'ORBITBUMP', orbit_device)
        coh03_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH03', 'ORBITBUMP', orbit_device)
        coh04_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH04', 'ORBITBUMP', orbit_device)
        coh05_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH05', 'ORBITBUMP', orbit_device)
        coh06_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH06', 'ORBITBUMP', orbit_device)
        coh07_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH07', 'ORBITBUMP', orbit_device)
        coh08_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH08', 'ORBITBUMP', orbit_device)
        coh09_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH09', 'ORBITBUMP', orbit_device)
        coh10_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH10', 'ORBITBUMP', orbit_device)
        coh11_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH11', 'ORBITBUMP', orbit_device)
        coh12_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COH12', 'ORBITBUMP', orbit_device)
        cov01_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV01', 'ORBITBUMP', orbit_device)
        cov02_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV02', 'ORBITBUMP', orbit_device)
        cov03_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV03', 'ORBITBUMP', orbit_device)
        cov04_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV04', 'ORBITBUMP', orbit_device)
        cov05_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV05', 'ORBITBUMP', orbit_device)
        cov06_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV06', 'ORBITBUMP', orbit_device)
        cov07_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV07', 'ORBITBUMP', orbit_device)
        cov08_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV08', 'ORBITBUMP', orbit_device)
        cov09_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV09', 'ORBITBUMP', orbit_device)
        cov10_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV10', 'ORBITBUMP', orbit_device)
        cov11_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV11', 'ORBITBUMP', orbit_device)
        cov12_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/COV12', 'ORBITBUMP', orbit_device)
        extesep_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/EXTESEP', 'FLATBUMP', orbit_device)
        extmsep_parameter = self.lh_builder.lh.define_physics_parameter(orbit_device + '/EXTMSEP', 'FLATBUMP', orbit_device)

        coh_list = [coh01_parameter, coh02_parameter, coh03_parameter, coh04_parameter, coh05_parameter, coh06_parameter, coh07_parameter, coh08_parameter, coh09_parameter, coh10_parameter, coh11_parameter, coh12_parameter]

        cov_list = [cov01_parameter, cov02_parameter, cov03_parameter, cov04_parameter, cov05_parameter, cov06_parameter, cov07_parameter, cov08_parameter, cov09_parameter, cov10_parameter, cov11_parameter, cov12_parameter]

        ## Correction coils
        for device in self.extraction_bump_correction_coils:
            self.lh_builder.lh.define_physics_parameter(device + '/KL', 'FLAT_K0L', device)

        for device in self.horizontal_orbit_correction_coils:
            self.lh_builder.lh.define_physics_parameter(device + '/KL', 'K0L', device)

        for device in self.horizontal_correction_coils:
            self.lh_builder.lh.define_physics_parameter(device + '/BLCORR', 'CORR_B0L', device)   
            self.lh_builder.lh.define_physics_parameter(device + '/ICORR', 'ICORR', device)
            #self.lh_builder.lh.define_hardware_parameter(device, 'RAMPVALS', 'data')

        for device in self.extra_correction_coils:
            self.lh_builder.lh.define_physics_parameter(device + '/ICORRDOT', 'ICORRDOT', device)
            self.lh_builder.lh.define_physics_parameter(device + '/UCORR', 'UCORR', device)

        ## SIS18 Bypass
        for device in self.sis18_bypass:
            self.lh_builder.lh.define_physics_parameter(device + '/KLBYP', 'SCALAR_KLBYP', device)
            self.lh_builder.lh.define_physics_parameter(device + '/BLBYP', 'SCALAR_BLBYP', device)
            self.lh_builder.lh.define_physics_parameter(device + '/IBYP', 'IBYP', device)
            #self.lh_builder.lh.define_hardware_parameter(device, 'RAMPVALS', 'data')

        ## SIS18 KO
        for device in self.sis18_ko_exiter:
            self.lh_builder.lh.define_physics_parameter(device + '/DQH', 'SCALAR_DQHKO', device)
            self.lh_builder.lh.define_physics_parameter(device + '/QHFR', 'SCALAR_QHFRKO', device)
            self.lh_builder.lh.define_physics_parameter(device + '/START_TAU', 'SCALAR_START_TAUKO', device)
            self.lh_builder.lh.define_physics_parameter(device + '/END_TAU', 'SCALAR_END_TAUKO', device)
            self.lh_builder.lh.define_physics_parameter(device + '/START_AMPL', 'SCALAR_START_AMPLKO', device)
            self.lh_builder.lh.define_physics_parameter(device + '/END_AMPL', 'SCALAR_END_AMPLKO', device)
            self.lh_builder.lh.define_physics_parameter(device + '/UPP', 'UPPKO', device) 
            self.lh_builder.lh.define_physics_parameter(device + '/UCTRL', 'UCTRLKO', device)
            #self.lh_builder.lh.define_hardware_parameter(device, 'RAMPVALS', 'data')

        ### Creation of relations

        incorpip_parameter = self.reader.find_unique_string('SIS18TIMEPARAM/INCORPIP$', self.lh_builder.lh.get_parameters())

        opticsip_parameter = self.reader.find_unique_string('SIS18OPTICS/OPTICSIP$', self.lh_builder.lh.get_parameters())
        tau_start_end_parameter = self.reader.find_unique_string('SIS18OPTICS/TAU_START_END$', self.lh_builder.lh.get_parameters())
        brho_start_end_parameter = self.reader.find_unique_string('SIS18BEAM/BRHO_START_END$', self.lh_builder.lh.get_parameters())

        t_wait_parameter = self.reader.find_unique_string('SIS18TIMEPARAM/T_WAIT$', self.lh_builder.lh.get_parameters())
        tgrid_parameter = self.reader.find_unique_string('SIS18TIMEPARAM/TGRID$', self.lh_builder.lh.get_parameters())
        tround_parameter = self.reader.find_unique_string('SIS18TIMEPARAM/TROUND$', self.lh_builder.lh.get_parameters())
        t_bp_length_parameter = self.reader.find_unique_string('SIS18TIMEPARAM/T_BP_LENGTH$', self.lh_builder.lh.get_parameters())
        bp_length_parameter = self.reader.find_unique_string('SIS18TIMEPARAM/BP_LENGTH$', self.lh_builder.lh.get_parameters())
        bdot_parameter = self.reader.find_unique_string('SIS18TIMEPARAM/BDOT$', self.lh_builder.lh.get_parameters())
        frev_parameter = self.reader.find_unique_string('SIS18BEAM/FREV$', self.lh_builder.lh.get_parameters())

        h_parameter = self.reader.find_unique_string('SIS18BEAM/H$', self.lh_builder.lh.get_parameters())

        urfring_parameter = self.reader.find_unique_string('SIS18RF/URFRING$', self.lh_builder.lh.get_parameters())
        frfring_parameter = self.reader.find_unique_string('SIS18RF/FRFRING$', self.lh_builder.lh.get_parameters())
        prfring_parameter = self.reader.find_unique_string('SIS18RF/PRFRING$', self.lh_builder.lh.get_parameters())
        rf_mode_parameter = self.reader.find_unique_string('SIS18RF/MODE$', self.lh_builder.lh.get_parameters())

        brho_parameter = self.reader.find_unique_string('SIS18BEAM/BRHO$', self.lh_builder.lh.get_parameters())
        erho_parameter = self.reader.find_unique_string('SIS18BEAM/ERHO$', self.lh_builder.lh.get_parameters())

        tbunch_parameter = self.reader.find_unique_string('SIS18BEAM/TBUNCH$', self.lh_builder.lh.get_parameters())

        ch_parameter = self.reader.find_unique_string('SIS18BEAM/CH$', self.lh_builder.lh.get_parameters())
        cv_parameter = self.reader.find_unique_string('SIS18BEAM/CV$', self.lh_builder.lh.get_parameters())

        kl_ampl_parameter = self.reader.find_unique_string('SIS18BEAM/KL_AMPL$', self.lh_builder.lh.get_parameters())
        kl_harm_parameter = self.reader.find_unique_string('SIS18BEAM/KL_HARM$', self.lh_builder.lh.get_parameters())
        kl_offset_parameter = self.reader.find_unique_string('SIS18BEAM/KL_OFFSET$', self.lh_builder.lh.get_parameters())
        kl_phase_parameter = self.reader.find_unique_string('SIS18BEAM/KL_PHASE$', self.lh_builder.lh.get_parameters())

        ## Beam parameters
        inj_emil_parameter = self.reader.find_unique_string('SIS18BEAM/INJ_EMIL$', self.lh_builder.lh.get_parameters())
        e_parameter = self.reader.find_unique_string('SIS18BEAM/E$', self.lh_builder.lh.get_parameters())
        self.lh_builder.create_child_node(inj_emil_parameter, [ dp_over_p_parameter, e_parameter, h_parameter ])

        ## Optics Parameters
        self.lh_builder.create_child_node(opticsip_parameter, [ sigma_parameter, tau_parameter, incorpip_parameter ])
        self.lh_builder.create_child_node(sigma_parameter, [ brho_start_end_parameter, ext_sigma_parameter, bp_length_parameter, t_wait_parameter, tround_parameter, tgrid_parameter, tau_endpoint_parameter ])
        self.lh_builder.create_child_node(tau_parameter, [ tau_nlp_parameter, tau_start_end_parameter, bp_length_parameter, t_wait_parameter, brho_start_end_parameter, tround_parameter, tgrid_parameter, tau_endpoint_parameter ])

        ## Timeparam Parameters
        self.lh_builder.create_child_node(bp_length_parameter, [ t_bp_length_parameter, t_wait_parameter, ext_sigma_parameter, tau_start_end_parameter, tround_parameter,  bdot_parameter, brho_start_end_parameter, tgrid_parameter ])
        self.lh_builder.create_child_node(incorpip_parameter, bp_length_parameter )


        ## Hardware rf system parameters
        #self.lh_builder.create_child_node(hardware_fs_rampvals_parameter, frev_parameter)

        #self.lh_builder.create_child_node(mhbpar_damp1_parameter, h_parameter )
        #self.lh_builder.create_child_node(mhbpar_damp2_parameter, h_parameter )
        #self.lh_builder.create_child_node(mhbpar_delay_parameter, h_parameter )
        #self.lh_builder.create_child_node(mhbpar_harm1_parameter, h_parameter )
        #self.lh_builder.create_child_node(mhbpar_harm2_parameter, h_parameter )
        #self.lh_builder.create_child_node(syncmode_hfssync_parameter, h_parameter )
        #self.lh_builder.create_child_node(workmode_workmode_parameter, h_parameter )

        #self.lh_builder.create_child_node(delay_trgdelay_parameter, [ tbunch_parameter, h_parameter, start_parameter ])
        #self.lh_builder.create_child_node(harmonic_harmonic_parameter, h_parameter )
        #self.lh_builder.create_child_node(mode_kickmode_parameter, [ kicker_mode_parameter, nbunch1_parameter, h_parameter ])
        #self.lh_builder.create_child_node(rftrig_rftrig_parameter, h_parameter )

        #self.lh_builder.create_child_node(chansequ_chancount_parameter, [timeout_unilac_parameter, tmeasure_parameter, toffset_unilac_parameter, bp_length_parameter,    kicker_mode_parameter ])
        #self.lh_builder.create_child_node(chansequ_chansequ_parameter, [timeout_unilac_parameter, tmeasure_parameter, toffset_unilac_parameter, bp_length_parameter,   kicker_mode_parameter ])
        #self.lh_builder.create_child_node(evtarray_chanarray_parameter, [timeout_unilac_parameter, tmeasure_parameter, toffset_unilac_parameter, bp_length_parameter, kicker_mode_parameter ])

        ## Main sextupoles:
        for device in self.main_sextupoles:
            kldelta_parameter = self.reader.find_unique_string(device + '/KLDELTA$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(kldelta_parameter, [ incorpip_parameter, kl_harm_parameter, kl_phase_parameter, kl_ampl_parameter, kl_offset_parameter ])

            kl_parameter = self.reader.find_unique_string(device + '/K2?L$', self.lh_builder.lh.get_parameters())    
            self.lh_builder.create_child_node(kl_parameter, [ ch_parameter, cv_parameter, opticsip_parameter, kldelta_parameter ]) 

        ## Horizontal_orbit_correction_coils
        self.horizontal_orbit_correction_coils.sort()
        for device in self.horizontal_orbit_correction_coils:
            kl_parameter = self.reader.find_unique_string(device + '/K[0-3]?L$', self.lh_builder.lh.get_parameters())
            sector = int(device[1:3])
            index = sector - 1
            if (sector == 5) :
                self.lh_builder.create_child_node(kl_parameter, [ extesep_parameter, opticsip_parameter, coh_list[index], coh_list[index - 1], coh_list[index - 2] ])
            elif (sector == 7) :
                self.lh_builder.create_child_node(kl_parameter, [ extmsep_parameter, opticsip_parameter, coh_list[index], coh_list[index - 1], coh_list[index - 2] ])
            else:
                self.lh_builder.create_child_node(kl_parameter, [ opticsip_parameter, coh_list[index], coh_list[index - 1], coh_list[index - 2] ])

        ## Extraction_bump_correction_coils
        for device in self.extraction_bump_correction_coils:
            kl_parameter = self.reader.find_unique_string(device + '/K[0-3]?L$', self.lh_builder.lh.get_parameters())
            sector = int(device[1:3])
            if ((sector == 10) | (sector == 11) | (sector == 12)) :
                self.lh_builder.create_child_node(kl_parameter, opticsip_parameter)
            elif ((sector == 4) | (sector == 5)) :
                self.lh_builder.create_child_node(kl_parameter, [ opticsip_parameter, extesep_parameter ])
            else:
                self.lh_builder.create_child_node(kl_parameter, [ opticsip_parameter, extmsep_parameter ])


        ## Orbit Parameters
        self.lh_builder.create_child_node(coh01_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(coh02_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(coh03_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(coh04_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(coh05_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(coh06_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(coh07_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(coh08_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(coh09_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(coh10_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(coh11_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(coh12_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov01_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov02_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov03_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov04_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov05_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov06_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov07_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov08_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov09_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov10_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov11_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(cov12_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(extesep_parameter, incorpip_parameter )
        self.lh_builder.create_child_node(extmsep_parameter, incorpip_parameter )


        for device in self.sis18_cavities_ampl:
            urf_parameter = self.reader.find_unique_string(device[:-1] + 'A/URF$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(urf_parameter, [ h_parameter, incorpip_parameter, urfring_parameter, rf_mode_parameter ])
            #rampvals_a_parameter = self.reader.find_unique_string(device[:-1] + 'A/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_a_parameter, urf_parameter )

            frf_parameter = self.reader.find_unique_string(device[:-1] + 'FS/FRF$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(frf_parameter, [ h_parameter, incorpip_parameter, frfring_parameter, rf_mode_parameter ])
            #rampvals_fs_parameter = self.reader.find_unique_string(device[:-1] + 'FS/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_fs_parameter, frf_parameter )

            prf_parameter = self.reader.find_unique_string(device[:-1] + 'P/PRF$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(prf_parameter, [ h_parameter, incorpip_parameter, prfring_parameter, rf_mode_parameter ])
            #rampvals_p_parameter = self.reader.find_unique_string(device[:-1] + 'P/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_p_parameter, prf_parameter )

            #brotampl_parameter = self.reader.find_unique_string(device[:-1] + 'A/BROTAMPL#highValue$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(brotampl_parameter, urf_parameter )

        ## Magnets

        for device in self.vertical_correctors:
            kl_parameter = self.reader.find_unique_string(device + '/K[0-3]?L$', self.lh_builder.lh.get_parameters())
            sector = int(device[1:3])
            index = sector - 1
            self.lh_builder.create_child_node(kl_parameter, [ opticsip_parameter, cov_list[index], cov_list[index - 1], cov_list[index + 1 - len(cov_list)] ])

            i_parameter = self.reader.find_unique_string(device + '/I$', self.lh_builder.lh.get_parameters())
            #rampvals_parameter = self.reader.find_unique_string(device + '/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_parameter, i_parameter)

        for device in self.horizontal_correction_coils:
            kl_parameter = self.reader.find_unique_string(device + '/K[0-3]?L$', self.lh_builder.lh.get_parameters())
            blcorr_parameter = self.reader.find_unique_string(device + '/B[0-3]?LCORR$', self.lh_builder.lh.get_parameters())
            icorr_parameter = self.reader.find_unique_string(device + '/ICORR$', self.lh_builder.lh.get_parameters())
            if device in self.extraction_bump_correction_coils:
                self.lh_builder.create_child_node(blcorr_parameter, [ brho_parameter, kl_parameter ])
            else:
                self.lh_builder.create_child_node(blcorr_parameter, [ brho_parameter, kl_parameter, incorpip_parameter ])

            for dipol_device in self.main_dipoles:
                i_parameter = self.reader.find_unique_string(dipol_device + '/I$', self.lh_builder.lh.get_parameters())
                bl_parameter = self.reader.find_unique_string(dipol_device + '/B[0-3]?L$', self.lh_builder.lh.get_parameters())
                self.lh_builder.create_child_node(icorr_parameter, [ i_parameter, blcorr_parameter, bl_parameter ])

        for device in self.extra_correction_coils:
            icorr_parameter = self.reader.find_unique_string(device + '/ICORR$', self.lh_builder.lh.get_parameters())
            icorrdot_parameter = self.reader.find_unique_string(device + '/ICORRDOT$', self.lh_builder.lh.get_parameters())
            ucorr_parameter = self.reader.find_unique_string(device + '/UCORR$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(icorrdot_parameter, icorr_parameter )

            #rampvals_parameter = self.reader.find_unique_string(device + '/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_parameter, [ icorr_parameter, ucorr_parameter ])
    
            for dipol_device in self.main_dipoles:
                i_parameter = self.reader.find_unique_string(dipol_device + '/I$', self.lh_builder.lh.get_parameters())
                idot_parameter = self.reader.find_unique_string(dipol_device + '/IDOT$', self.lh_builder.lh.get_parameters())
                self.lh_builder.create_child_node(ucorr_parameter, [ icorr_parameter, icorrdot_parameter, i_parameter, idot_parameter ])

        for device in list(set(self.horizontal_correction_coils) - set(self.extra_correction_coils)):
            icorr_parameter = self.reader.find_unique_string(device + '/ICORR$', self.lh_builder.lh.get_parameters())
            #rampvals_parameter = self.reader.find_unique_string(device + '/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_parameter, icorr_parameter)

        ## Kicker
        kicker_ukick_parameters = []
        for device in self.kicker:
            ukick_parameter = self.reader.find_unique_string(device + '/UKICK$', self.lh_builder.lh.get_parameters())
            kicker_ukick_parameters.append(ukick_parameter)



        self.kicker.sort()
        for device in self.kicker:
            kl_parameter = self.reader.find_unique_string(device + '/KL$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(kl_parameter, [ kicker_knob_parameter , opticsip_parameter ])

            bl_parameter = self.reader.find_unique_string(device + '/BL$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(bl_parameter, [ kl_parameter , brho_parameter ])

            ukick_parameter = self.reader.find_unique_string(device + '/UKICK$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(ukick_parameter, bl_parameter )

            #if (device == self.kicker[0]):
                #timdelrf_time_parameter = self.reader.find_unique_string(device + '/TIMDELRF#time$', self.lh_builder.lh.get_parameters())
                #self.lh_builder.create_child_node(timdelrf_time_parameter, toffset1_parameter)
        
                #timdeltg_time_parameter = self.reader.find_unique_string(device + '/TIMDELTG#time$', self.lh_builder.lh.get_parameters())
                #self.lh_builder.create_child_node(timdeltg_time_parameter, toffset2_parameter)
        
                #timftrf_time_parameter = self.reader.find_unique_string(device + '/TIMFTRF#time$', self.lh_builder.lh.get_parameters())
                #self.lh_builder.create_child_node(timftrf_time_parameter, [ toffset1_parameter, thigh1_parameter ])
        
                #timfttg_time_parameter = self.reader.find_unique_string(device + '/TIMFTTG#time$', self.lh_builder.lh.get_parameters())
                #self.lh_builder.create_child_node(timfttg_time_parameter, [ toffset2_parameter, thigh2_parameter ])
        
                #voltrfs_voltages_parameter = self.reader.find_unique_string(device + '/VOLTRFS#voltages$', self.lh_builder.lh.get_parameters())
                #self.lh_builder.create_child_node(voltrfs_voltages_parameter, kicker_ukick_parameters)
        
                #voltris_voltages_parameter = self.reader.find_unique_string(device + '/VOLTRIS#voltages$', self.lh_builder.lh.get_parameters())
                #self.lh_builder.create_child_node(voltris_voltages_parameter, kicker_ukick_parameters)
        
                #volttgs_voltages_parameter = self.reader.find_unique_string(device + '/VOLTTGS#voltages$', self.lh_builder.lh.get_parameters())
                #self.lh_builder.create_child_node(volttgs_voltages_parameter, kicker_ukick_parameters)


        ## Bumper
        for device in self.bumper:
            kl_parameter = self.reader.find_unique_string(device + '/KL$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(kl_parameter, [ opticsip_parameter, bumper_knob_parameter ])

            bl_parameter = self.reader.find_unique_string(device + '/BL$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(bl_parameter, [ brho_parameter, kl_parameter ])

            i_parameter = self.reader.find_unique_string(device + '/I$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(i_parameter, bl_parameter )

            #currents_currents_parameter = self.reader.find_unique_string(device + '/CURRENTS#currents$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(currents_currents_parameter, i_parameter )

            #ftimes_ftimes_parameter = self.reader.find_unique_string(device + '/FTIMES#ftimes$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(ftimes_ftimes_parameter, tfall_parameter )

            #para_reference_parameter = self.reader.find_unique_string(device + '/PARA#reference_parameters$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(para_reference_parameter, curvature_parameter )


        ## SIS18 Bypass
        for device in self.sis18_bypass:
            kl_parameter = self.reader.find_unique_string(device + '/KLBYP$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(kl_parameter, opticsip_parameter )

            bl_parameter = self.reader.find_unique_string(device + '/BLBYP$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(bl_parameter, [ kl_parameter , brho_parameter ])

            ibyp_parameter = self.reader.find_unique_string(device + '/IBYP$', self.lh_builder.lh.get_parameters())
            for dipol_device in self.main_dipoles:
                i_parameter = self.reader.find_unique_string(dipol_device + '/I$', self.lh_builder.lh.get_parameters())
                self.lh_builder.create_child_node(ibyp_parameter, [ bl_parameter , incorpip_parameter , i_parameter ])

            #rampvals_parameter = self.reader.find_unique_string(device + '/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_parameter, i_parameter )

        ## SIS18 KO
        for device in self.sis18_ko_exiter:
            start_tau_parameter = self.reader.find_unique_string(device + '/START_TAU$', self.lh_builder.lh.get_parameters())
            end_tau_parameter = self.reader.find_unique_string(device + '/END_TAU$', self.lh_builder.lh.get_parameters())
            start_ampl_parameter = self.reader.find_unique_string(device + '/START_AMPL$', self.lh_builder.lh.get_parameters())
            end_ampl_parameter = self.reader.find_unique_string(device + '/END_AMPL$', self.lh_builder.lh.get_parameters())
            upp_parameter = self.reader.find_unique_string(device + '/UPP$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(upp_parameter, [ start_tau_parameter, end_tau_parameter, start_ampl_parameter, end_ampl_parameter, erho_parameter, tgrid_parameter, bp_length_parameter ])

            uctrl_parameter = self.reader.find_unique_string(device + '/UCTRL$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(uctrl_parameter, [ upp_parameter, incorpip_parameter ])

            dqh_parameter = self.reader.find_unique_string(device + '/DQH$', self.lh_builder.lh.get_parameters())
            qhfr_parameter = self.reader.find_unique_string(device + '/QHFR$', self.lh_builder.lh.get_parameters())
            #rampvals_parameter = self.reader.find_unique_string(device + '/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_parameter, [ h_parameter, frev_parameter, dqh_parameter, uctrl_parameter, qhfr_parameter ])



        return self.lh_builder
示例#6
0
class SpecialESRParameters:
    def __init__(self, lh_builder, csv_filename):
        self.lh_builder = lh_builder
        self.reader = LHBuilderUtils()
        self.all_devices = self.reader._read_devices(csv_filename)

    def setmaindipole(self, main_dipoles):
        self.main_dipoles = main_dipoles

    def sethorizontal_correction_coils(self, horizontal_correction_coils):
        self.horizontal_correction_coils = horizontal_correction_coils

    def setesr_cavities_ampl(self, esr_cavities_ampl):
        self.esr_cavities_ampl = esr_cavities_ampl

    def setesr_cavities_freq(self, esr_cavities_freq):
        self.esr_cavities_freq = esr_cavities_freq

    def setpolefacewindings(self, polefacewindings):
        self.polefacewindings = polefacewindings

    def build(self, particle_transfer):

        kicker_device = self.reader.find_unique_string(
            particle_transfer.replace('_RING', 'KICKER'), self.all_devices)

        for device in self.horizontal_correction_coils:
            self.lh_builder.lh.define_physics_parameter(
                device + '/KL', 'K0L', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/BLCORR', 'CORR_B0L', device)
            self.lh_builder.lh.define_physics_parameter(
                device + '/ICORR', 'ICORR', device)
            #self.lh_builder.lh.define_hardware_parameter(device, 'RAMPVALS', 'data')

        for device in self.esr_cavities_ampl:
            self.lh_builder.lh.define_physics_parameter(
                device + '/URF', 'URF', device)
            #self.lh_builder.lh.define_hardware_parameter(device, 'RAMPVALS', 'data')
            #self.lh_builder.lh.define_hardware_parameter(device, 'BROTAMPL', 'highValue')

        for device in self.esr_cavities_freq:
            self.lh_builder.lh.define_physics_parameter(
                device + '/FRF', 'FRF', device)
            #self.lh_builder.lh.define_hardware_parameter(device, 'RAMPVALS', 'data')

        for device in self.polefacewindings:
            self.lh_builder.lh.define_physics_parameter(
                device + '/IPFW', 'IPFW', device)

        ## Kicker parameters
        kicker_knob_parameter = self.lh_builder.lh.define_physics_parameter(
            kicker_device + '/KNOB', 'SCALAR_KICKER_KNOB', kicker_device)

        ## relations

        incorpip_parameter = self.reader.find_unique_string(
            'ESRTIMEPARAM/INCORPIP$', self.lh_builder.lh.get_parameters())
        brho_parameter = self.reader.find_unique_string(
            'ESRBEAM/BRHO$', self.lh_builder.lh.get_parameters())
        brho_start_end_parameter = self.reader.find_unique_string(
            'ESRBEAM/BRHO_START_END$', self.lh_builder.lh.get_parameters())

        h_parameter = self.reader.find_unique_string(
            'ESRBEAM/H$', self.lh_builder.lh.get_parameters())

        opticsip_parameter = self.reader.find_unique_string(
            'ESROPTICS/OPTICSIP$', self.lh_builder.lh.get_parameters())
        tau_start_end_parameter = self.reader.find_unique_string(
            'ESROPTICS/TAU_START_END$', self.lh_builder.lh.get_parameters())

        t_wait_parameter = self.reader.find_unique_string(
            'ESRTIMEPARAM/T_WAIT$', self.lh_builder.lh.get_parameters())
        tgrid_parameter = self.reader.find_unique_string(
            'ESRTIMEPARAM/TGRID$', self.lh_builder.lh.get_parameters())
        tround_parameter = self.reader.find_unique_string(
            'ESRTIMEPARAM/TROUND$', self.lh_builder.lh.get_parameters())
        t_bp_length_parameter = self.reader.find_unique_string(
            'ESRTIMEPARAM/T_BP_LENGTH$', self.lh_builder.lh.get_parameters())
        bp_length_parameter = self.reader.find_unique_string(
            'ESRTIMEPARAM/BP_LENGTH$', self.lh_builder.lh.get_parameters())
        bdot_parameter = self.reader.find_unique_string(
            'ESRTIMEPARAM/BDOT$', self.lh_builder.lh.get_parameters())

        urfring_parameter = self.reader.find_unique_string(
            'ESRRF/URFRING$', self.lh_builder.lh.get_parameters())
        frfring_parameter = self.reader.find_unique_string(
            'ESRRF/FRFRING$', self.lh_builder.lh.get_parameters())
        rf_mode_parameter = self.reader.find_unique_string(
            'ESRRF/MODE$', self.lh_builder.lh.get_parameters())

        ## Optics Parameters
        self.lh_builder.create_child_node(
            opticsip_parameter,
            [bp_length_parameter, tau_start_end_parameter, incorpip_parameter])

        ## Timeparam Parameters
        self.lh_builder.create_child_node(bp_length_parameter, [
            t_bp_length_parameter, t_wait_parameter, tau_start_end_parameter,
            tround_parameter, bdot_parameter, brho_start_end_parameter,
            tgrid_parameter
        ])
        self.lh_builder.create_child_node(incorpip_parameter,
                                          bp_length_parameter)

        ## Magnets
        for device in self.horizontal_correction_coils:
            kl_parameter = self.reader.find_unique_string(
                device + '/K[0-3]?L$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(kl_parameter, opticsip_parameter)
            blcorr_parameter = self.reader.find_unique_string(
                device + '/B[0-3]?LCORR$', self.lh_builder.lh.get_parameters())
            icorr_parameter = self.reader.find_unique_string(
                device + '/ICORR$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(
                blcorr_parameter,
                [brho_parameter, kl_parameter, incorpip_parameter])

            for dipol_device in self.main_dipoles:
                i_parameter = self.reader.find_unique_string(
                    dipol_device + '/I$', self.lh_builder.lh.get_parameters())
                bl_parameter = self.reader.find_unique_string(
                    dipol_device + '/B[0-3]?L$',
                    self.lh_builder.lh.get_parameters())
                self.lh_builder.create_child_node(
                    icorr_parameter,
                    [i_parameter, blcorr_parameter, bl_parameter])

        for device in self.polefacewindings:
            ipfw_parameter = self.reader.find_unique_string(
                device + '/IPFW$', self.lh_builder.lh.get_parameters())

            for dipol_device in self.main_dipoles:
                bl_parameter = self.reader.find_unique_string(
                    dipol_device + '/B[0-3]?L$',
                    self.lh_builder.lh.get_parameters())
                self.lh_builder.create_child_node(
                    ipfw_parameter, [bl_parameter, incorpip_parameter])

        for device in self.esr_cavities_ampl:
            urf_parameter = self.reader.find_unique_string(
                device[:-1] + 'A/URF$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(urf_parameter, [
                h_parameter, incorpip_parameter, urfring_parameter,
                rf_mode_parameter
            ])
            #rampvals_a_parameter = self.reader.find_unique_string(device[:-1] + 'A/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_a_parameter, urf_parameter )

            frf_parameter = self.reader.find_unique_string(
                device[:-1] + 'FS/FRF$', self.lh_builder.lh.get_parameters())
            self.lh_builder.create_child_node(frf_parameter, [
                h_parameter, incorpip_parameter, frfring_parameter,
                rf_mode_parameter
            ])
            #rampvals_fs_parameter = self.reader.find_unique_string(device[:-1] + 'FS/RAMPVALS#data$', self.lh_builder.lh.get_parameters())
            #self.lh_builder.create_child_node(rampvals_fs_parameter, frf_parameter )

        return self.lh_builder