LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
Clipboard.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 #
4 # LSST Data Management System
5 # Copyright 2008, 2009, 2010 LSST Corporation.
6 #
7 # This product includes software developed by the
8 # LSST Project (http://www.lsst.org/).
9 #
10 # This program is free software: you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
14 #
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the LSST License Statement and
21 # the GNU General Public License along with this program. If not,
22 # see <http://www.lsstcorp.org/LegalNotices/>.
23 #
24 
25 
26 """
27 Clipboard provides a container for carrying image data from one Stage of
28 the Pipeline to the next. It wraps a Python dictionary. An image is
29 accessed via a get() method where a suitable key (e.g., "primary_image")
30 must be provided.
31 """
32 
33 
34 class Clipboard(object):
35  '''Container for images: maintains Python dictionary'''
36 
37  def __init__ (self):
38  """
39  Initialize the Clipboard by defining an initial dictionary
40  """
41  self.dict = {}
42  self.isShared = {}
43 
44  def __del__ (self):
45  """
46  Delete the Clipboard
47  """
48  # print 'Clipboard being deleted'
49  self.close()
50 
51  def close(self):
52  # print 'Clearing Clipboard dictionary'
53  self.dict.clear()
54 
55  def getKeys (self):
56  """
57  Returns the keys of the python dictionary (in the form of a python
58  list)
59  """
60  return self.dict.keys()
61 
62  def getSharedKeys (self):
63  """
64  Returns the shared keys of the python dictionary (in the form of a python
65  list)
66  """
67  fullKeySet = self.dict.keys()
68  sharedKeySet = []
69  for key in fullKeySet:
70  if (self.isShared[key] == True):
71  sharedKeySet.append(key)
72  return sharedKeySet
73 
74  def getItem (self, key):
75  """
76  Return the value within the dictionary that corresponds to the
77  provided key
78  """
79  # return self.dict[key]
80  return self.dict.__getitem__(key)
81 
82  def get (self, key, defValue=None):
83  """
84  Return the value within the dictionary that corresponds to the
85  provided key
86  """
87  return self.dict.get(key, defValue)
88 
89  def put (self, key, value, isShareable=False):
90  """
91  Add an entry to the dictionary using the provided name/value pair
92  Set the shared value as well if provided
93  """
94  self.dict[key] = value
95  self.isShared[key] = isShareable
96 
97  def setShared (self, key, isShareable):
98  """
99  Set the shared value for this key
100  """
101  self.isShared[key] = isShareable
102 
103  def contains (self, key):
104  """
105  Return the value True if the dictionary has a key "key";
106  otherwise return False.
107  """
108  if key in self.dict:
109  return True
110  else:
111  return False
112 
113  #
114  # Provide dictionary-like interface
115  #
116  __setitem__ = put
117  __getitem__ = getItem
118  clear = close
119  has_key = contains
120  keys = getKeys
121