ATLAS Offline Software
Loading...
Searching...
No Matches
AtlTriggerDBCopy Namespace Reference

Classes

class  DBConnection
class  OracleExporter
class  SQLiteInserter

Functions

 parseCmdline ()
 main ()

Function Documentation

◆ main()

AtlTriggerDBCopy.main ( )

Definition at line 274 of file AtlTriggerDBCopy.py.

274def main():
275 args = parseCmdline()
276 if args is None:
277 return 1
278
279 # instantiate the sqlite inserter with the sqlite db filename
280 sqliteInserter = SQLiteInserter(args.createfile)
281
282 # connect to oracle and do the work
283 with DBConnection(args.dbalias) as oraConn:
284 oraExp = OracleExporter(oraConn)
285
286 # extract the schema into a temporary file and create it on the sqlite side
287 tempTableCreationFileName = "tmpCreateTablesSQLite.sql"
288 oraExp.extractSchema(tempTableCreationFileName)
289 sqliteInserter.createSchema(tempTableCreationFileName)
290
291 # collect some info about the size, to not run completely blind
292 entries = {}
293 tablesToCreate = oraExp.getTables(exceptTables = oraExp.ignoreTablesCreate)
294 tablesToFill = oraExp.getTables(exceptTables = oraExp.ignoreTablesFill)
295 print("Tables to create: %i" % len(tablesToCreate))
296 print("Tables to fill: %i" % len(tablesToFill))
297
298
299 for tableName in tablesToCreate:
300 entries[tableName] = oraExp.tableSize(tableName)
301 doNotCopy = tableName not in tablesToFill
302 print(" table %s has %i entries %s" % (tableName, entries[tableName], ("(will not copy)" if doNotCopy else "") ) )
303 totalEntries = sum(entries.values())
304 print("\nTotal number of entries: %i" %totalEntries)
305
306 # copy the data one table at the time
307 print("Start copying data")
308 copiedEntries = 0
309 for tableName in tablesToFill:
310 print("Copying table %s" % tableName, end = '', flush=True)
311 oraExp.copyTable(tableName, sqliteInserter, entries[tableName])
312 copiedEntries += entries[tableName]
313 print(" => done %i / %i (%f%%)" % (copiedEntries, totalEntries, 100 * copiedEntries/totalEntries))
314
315 sqliteInserter.connection.close()
316
317
void print(char *figname, TCanvas *c1)
int main()
Definition hello.cxx:18

◆ parseCmdline()

AtlTriggerDBCopy.parseCmdline ( )

Definition at line 11 of file AtlTriggerDBCopy.py.

11def parseCmdline():
12 import argparse
13 parser = argparse.ArgumentParser(prog = "AtlTriggerDBCopy.py", description="Example: %(prog)s -d TRIGGERDBMC -c triggerDBMC_Run2.db")
14 parser.add_argument("-d", "--dbalias", dest="dbalias", help="TriggerDB connection alias for the source DB")
15 parser.add_argument("-c", "--create", dest="createfile", help="create sqlite db file")
16 parser.add_argument("-v", help="increase output verbosity", action="count", default=0)
17 args = parser.parse_args()
18 if not args.dbalias:
19 print("No source Trigger DB specified")
20 parser.print_help()
21 return None
22 if not args.createfile:
23 print("No sqlite target file specified")
24 parser.print_help(parser)
25 return None
26 return args
27
28# class to handle the oracle db connection
29# it uses the CORAL authentication method implemented in the TrigConfIO.TriggerConfigAccessBase (ConfigDBLoader)