sdb_run_record = cur.fetchone() # ensure run exists in RCDB run = db.create_run(run_number) if not sdb_run_record or not sdb_run_record["num_events"]: # no such run in SeanDB print "skipped run {}".format(run_number) continue total += 1 # cycle through condition types for cnd_name, cnd_type in columns_to_import.iteritems(): if cnd_type == ConditionType.FLOAT_FIELD: value = float(sdb_run_record[cnd_name]) if sdb_run_record[cnd_name] else 0.0 elif cnd_type == ConditionType.INT_FIELD: value = int(sdb_run_record[cnd_name]) if sdb_run_record[cnd_name] else 0 else: value = sdb_run_record[cnd_name] db.add_condition(run_number, cnd_name, value, replace=True) # event number event_count = int(sdb_run_record["num_events"]) db.add_condition(run_number, "seandb_event_count", event_count, replace=True) db.add_condition(run_number, DefaultConditions.EVENT_COUNT, event_count, replace=True) print "done run {}".format(run_number) print ("Total {} runs converted".format(total))
def main(): # DB Connection #------------------------------------------ update_parts = ["coda"] update_reason = "update" # Connection if "RCDB_CONNECTION" in os.environ: con_string = os.environ["RCDB_CONNECTION"] else: print ("ERROR! RCDB_CONNECTION is not set and is not given as a script parameter (-c)") sys.exit(2) # Open DB connection db = ConfigurationProvider(con_string) # Create update context update_context = rcdb.UpdateContext(db, update_reason) #------------------------------------------ # Read the list """ format: Run, #Config, Date/Time, RunType, Beam Mode, Beam Current, Beam Energy, Target, Log entries (HALOG, HAPLOG), Run analyzed?, Comment, Raster X/Y, Helicity, IHWP setting SAM 1 HVSAM 2 HVSAM 3 HVSAM 4 HVSAM 5 HVSAM 6 HVSAM 7 HVSAM 8 HV """ run_list = sys.argv[1] with open('%s' % run_list, 'rb') as f: for line in f: values = [] # ignore the first line if "Run #" in line: continue for item in line.split('\t'): if item != '\t': values.append(item) run_type = values[3] comment = values[10] if '-' in values[0]: # Loop over the range run1=int(values[0].split('-')[0]) run2=int(values[0].split('-')[1]) for run in range(run1, run2+1): print run try: post_update.update(str(run), update_parts, update_context) db.add_condition(db.get_run(run), DefaultConditions.USER_COMMENT, comment) if "junk" in run_type.lower(): db.add_condition(db.get_run(run), DefaultConditions.RUN_TYPE, "Junk", replace=True) except Exception as ex: print str(ex) else: if not values[0].isdigit(): continue else: try: run=values[0] print run post_update.update(run, update_parts, update_context) db.add_condition(db.get_run(run), DefaultConditions.USER_COMMENT, comment) if "junk" in run_type.lower(): db.add_condition(db.get_run(run), DefaultConditions.RUN_TYPE, "Junk", replace=True) except Exception as ex: print str(ex)
total += 1 # cycle through condition types for cnd_name, cnd_type in columns_to_import.iteritems(): if cnd_type == ConditionType.FLOAT_FIELD: value = float(sdb_run_record[cnd_name] ) if sdb_run_record[cnd_name] else 0.0 elif cnd_type == ConditionType.INT_FIELD: value = int(sdb_run_record[cnd_name] ) if sdb_run_record[cnd_name] else 0 else: value = sdb_run_record[cnd_name] db.add_condition(run_number, cnd_name, value, replace=True) # event number event_count = int(sdb_run_record["num_events"]) db.add_condition(run_number, "seandb_event_count", event_count, replace=True) db.add_condition(run_number, DefaultConditions.EVENT_COUNT, event_count, replace=True) print "done run {}".format(run_number) print("Total {} runs converted".format(total))