ATLAS Offline Software
Classes | Functions
AtlTriggerDBCopy Namespace Reference

Classes

class  DBConnection
 
class  OracleExporter
 
class  SQLiteInserter
 

Functions

def parseCmdline ()
 
def main ()
 

Function Documentation

◆ main()

def AtlTriggerDBCopy.main ( )

Definition at line 274 of file AtlTriggerDBCopy.py.

274 def 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 

◆ parseCmdline()

def AtlTriggerDBCopy.parseCmdline ( )

Definition at line 11 of file AtlTriggerDBCopy.py.

11 def 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)
AtlTriggerDBCopy.parseCmdline
def parseCmdline()
Definition: AtlTriggerDBCopy.py:11
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
AtlTriggerDBCopy.main
def main()
Definition: AtlTriggerDBCopy.py:274
CaloGetLC_CL_W_OOC_Config.DBConnection
DBConnection
Definition: CaloGetLC_CL_W_OOC_Config.py:65
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70