def setup_constraint(name,style):
    gauss_constraint=user.gauss_constraints.get().get(name)
    contour_constraint=user.contour_constraints.get().get(name)
    mneu_mg_m12g_m3g_X2_lookup=user.mneu_mg_m12g_m3g_X2_lookups.get().get(name)
    if gauss_constraint is not None:
        gauss_constraint=add_array_ids(gauss_constraint,style)
        tools.add_gauss_constraints({name:gauss_constraint})
    elif contour_constraint is not None:
        contours=tools.populate_contours(user.contours.get())
        tools.add_contours(contours)
        contour_constraint=add_array_ids(contour_constraint,style)
        tools.add_contour_constraints({name:contour_constraint})
    elif mneu_mg_m12g_m3g_X2_lookup is not None:
        mneu_mg_m12g_m3g_X2_lookup=add_array_ids(mneu_mg_m12g_m3g_X2_lookup,style)
        lookups={name:mneu_mg_m12g_m3g_X2_lookup}
        lookups=tools.populate_mneu_mg_m12g_m3g_X2_lookups(lookups)
        tools.add_mneu_mg_m12g_m3g_X2_lookups(lookups)
    else:
        print('{} not found in gauss or contour constraints.\Exiting'.format(name))
        exit()
if __name__ == '__main__':
    #get arguments
    args=parse_args()
    input_name=args.db_in
    output_name=args.db_out
    max_chi2=args.max_chi2
    chi2_function_name=args.reference
    # create mcpp_observable_ids in new database
    create_mcpp_observable_ids(input_name,output_name)
    # get array ids
    array_ids_dict, style=get_array_ids_and_style(input_name)
    # populate vars_lookups, vars_functions, and gauss_constraints with array ids
    gauss_constraints=tools.populate_with_array_ids((user.gauss_constraints.get()),style,array_ids_dict)
    contour_constraints=tools.populate_with_array_ids((user.contour_constraints.get()),style,array_ids_dict)
    # populate contours and add to managers
    contours=tools.populate_contours(user.contours.get())
    tools.add_contours(contours)
    # now add values to the managers
    tools.add_gauss_constraints(gauss_constraints)
    tools.add_contour_constraints(contour_constraints)
    # look for chi2 calculators
    if args.reference in user.constraints_sets.constraints.keys():
        tools.add_chi2_calculator(args.reference,user.constraints_sets.get(args.reference))
    # make selection query
    sql_where=''
    if args.sql_where is not None:
        sql_where='where ' + args.sql_where
    select_query='select rowid, * from points {};'.format(sql_where)
    #finally make the plots
    cw.sqlite_reduce_db(input_name,output_name,select_query,chi2_function_name,max_chi2)