db.create_condition_type("seandb_event_count", ConditionType.INT_FIELD, "Event count by Sean db") total = 0 run_min = 742 run_max = 2472 for run_number in range(run_min, run_max): # read sean db run cur = con.cursor() cur.execute( "SELECT * FROM run_info WHERE run_num={}".format(run_number)) 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:
for cnd_name, cnd_type in columns_to_import.iteritems(): db.create_condition_type(cnd_name, cnd_type, "") db.create_condition_type("seandb_event_count", ConditionType.INT_FIELD, "Event count by Sean db") total = 0 run_min = 742 run_max = 2472 for run_number in range(run_min, run_max): # read sean db run cur = con.cursor() cur.execute("SELECT * FROM run_info WHERE run_num={}".format(run_number)) 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:
# connect to sqlite source database con = sqlite3.connect(args.in_sqlite_file) con.row_factory = sqlite3.Row cur = con.cursor() cur.execute("select run_number, started from run_configurations ORDER BY run_number LIMIT 1") for row in cur: print row["run_number"], row["started"] # connect to target DB db = ConfigurationProvider(args.out_con_string) rcdb.model.Base.metadata.create_all(db.engine) # create database db.create_run(0) db.create_run(1) print("Database schema created") # select files from old DB cur = con.cursor() cur.execute("select path, sha256, content from files " #"where content LIKE '%<run-end>%' " "ORDER BY id DESC ") # LIMIT 100 OFFSET 2") run_count = 0 for row in cur: path = row["path"] content = row["content"] # add data to database