LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Static Public Attributes | List of all members
lsst.pipe.tasks.ingest.RegisterTask Class Reference
Inheritance diagram for lsst.pipe.tasks.ingest.RegisterTask:

Public Member Functions

def openRegistry
 
def createTable
 
def check
 
def addRow
 
def addVisits
 

Static Public Attributes

 ConfigClass = RegisterConfig
 

Detailed Description

Task that will generate the registry for the Mapper

Definition at line 233 of file ingest.py.

Member Function Documentation

def lsst.pipe.tasks.ingest.RegisterTask.addRow (   self,
  conn,
  info,
  dryrun = False,
  create = False 
)
Add a row to the file table (typically 'raw').

@param conn    Database connection
@param info    File properties to add to database

Definition at line 295 of file ingest.py.

296  def addRow(self, conn, info, dryrun=False, create=False):
297  """Add a row to the file table (typically 'raw').
298 
299  @param conn Database connection
300  @param info File properties to add to database
301  """
302  sql = "INSERT"
303  if self.config.ignore:
304  sql += " OR IGNORE"
305  sql += " INTO %s VALUES (NULL" % self.config.table
306  sql += ", ?" * len(self.config.columns)
307  sql += ")"
308  values = [info[col] for col in self.config.columns]
309  if dryrun:
310  print "Would execute: '%s' with %s" % (sql, ",".join([str(value) for value in values]))
311  else:
312  conn.execute(sql, values)
def lsst.pipe.tasks.ingest.RegisterTask.addVisits (   self,
  conn,
  dryrun = False 
)
Generate the visits table (typically 'raw_visits') from the
file table (typically 'raw').

@param conn    Database connection

Definition at line 313 of file ingest.py.

314  def addVisits(self, conn, dryrun=False):
315  """Generate the visits table (typically 'raw_visits') from the
316  file table (typically 'raw').
317 
318  @param conn Database connection
319  """
320  sql = "INSERT OR IGNORE INTO %s_visit SELECT DISTINCT " % self.config.table
321  sql += ",".join(self.config.visit)
322  sql += " FROM %s" % self.config.table
323  if dryrun:
324  print "Would execute: %s" % sql
325  else:
326  conn.execute(sql)
327 
def lsst.pipe.tasks.ingest.RegisterTask.check (   self,
  conn,
  info 
)
Check for the presence of a row already

Not sure this is required, given the 'ignore' configuration option.

Definition at line 278 of file ingest.py.

279  def check(self, conn, info):
280  """Check for the presence of a row already
281 
282  Not sure this is required, given the 'ignore' configuration option.
283  """
284  if self.config.ignore or len(self.config.unique) == 0:
285  return False # Our entry could already be there, but we don't care
286  cursor = conn.cursor()
287  sql = "SELECT COUNT(*) FROM %s WHERE " % self.config.table
288  sql += " AND ".join(["%s=?" % col for col in self.config.unique])
289  values = [info[col] for col in self.config.unique]
290 
291  cursor.execute(sql, values)
292  if cursor.fetchone()[0] > 0:
293  return True
294  return False
def lsst.pipe.tasks.ingest.RegisterTask.createTable (   self,
  conn 
)
Create the registry tables

One table (typically 'raw') contains information on all files, and the
other (typically 'raw_visit') contains information on all visits.

@param conn    Database connection

Definition at line 255 of file ingest.py.

256  def createTable(self, conn):
257  """Create the registry tables
258 
259  One table (typically 'raw') contains information on all files, and the
260  other (typically 'raw_visit') contains information on all visits.
261 
262  @param conn Database connection
263  """
264  cmd = "create table %s (id integer primary key autoincrement, " % self.config.table
265  cmd += ",".join([("%s %s" % (col, colType)) for col,colType in self.config.columns.items()])
266  if len(self.config.unique) > 0:
267  cmd += ", unique(" + ",".join(self.config.unique) + ")"
268  cmd += ")"
269  conn.execute(cmd)
270 
271  cmd = "create table %s_visit (" % self.config.table
272  cmd += ",".join([("%s %s" % (col, self.config.columns[col])) for col in self.config.visit])
273  cmd += ", unique(" + ",".join(set(self.config.visit).intersection(set(self.config.unique))) + ")"
274  cmd += ")"
275  conn.execute(cmd)
276 
277  conn.commit()
def lsst.pipe.tasks.ingest.RegisterTask.openRegistry (   self,
  butler,
  create = False,
  dryrun = False 
)
Open the registry and return the connection handle.

@param butler  Data butler, from which the registry file is determined
@param create  Clobber any existing registry and create a new one?
@param dryrun  Don't do anything permanent?
@return Database connection

Definition at line 237 of file ingest.py.

238  def openRegistry(self, butler, create=False, dryrun=False):
239  """Open the registry and return the connection handle.
240 
241  @param butler Data butler, from which the registry file is determined
242  @param create Clobber any existing registry and create a new one?
243  @param dryrun Don't do anything permanent?
244  @return Database connection
245  """
246  if dryrun:
247  from contextlib import contextmanager
248  @contextmanager
249  def fakeContext():
250  yield
251  return fakeContext
252  registryName = os.path.join(butler.mapper.root, "registry.sqlite3")
253  context = RegistryContext(registryName, self.createTable, create, self.config.permissions)
254  return context

Member Data Documentation

lsst.pipe.tasks.ingest.RegisterTask.ConfigClass = RegisterConfig
static

Definition at line 235 of file ingest.py.


The documentation for this class was generated from the following file: