Public Member Functions | Public Attributes | List of all members
python.extractor_dict.expMetaData Class Reference
Inheritance diagram for python.extractor_dict.expMetaData:
python.extractor_dict.MetaData

Public Member Functions

def __init__ (self, expname, inputfile)
 
def translateKey (self, key)
 
def md_gen (self, mdart, md0={})
 
def getmetadata (self, md0={})
 

Public Attributes

 expname
 
 translateKeyf
 
 md
 

Additional Inherited Members

Detailed Description

Class to hold/interpret experiment-specific metadata

Definition at line 103 of file extractor_dict.py.

Constructor & Destructor Documentation

def python.extractor_dict.expMetaData.__init__ (   self,
  expname,
  inputfile 
)

Definition at line 105 of file extractor_dict.py.

105  def __init__(self, expname, inputfile):
106  MetaData.__init__(self, inputfile)
107  self.expname = expname
108  #self.exp_md_keyfile = expname + '_metadata_key'
109  try:
110  #translateMetaData = __import__("experiment_utilities", "MetaDataKey")
111  from experiment_utilities import MetaDataKey
112  except ImportError:
113  print("You have not defined an experiment-specific metadata and key-translating module in experiment_utilities. Exiting")
114  raise
115 
116  metaDataModule = MetaDataKey()
117  self.metadataList, self.translateKeyf = metaDataModule.metadataList(), metaDataModule.translateKey
118 
def __init__(self, expname, inputfile)

Member Function Documentation

def python.extractor_dict.expMetaData.getmetadata (   self,
  md0 = {} 
)
Get metadata from input file and return as python dictionary.
Calls other methods in class and returns metadata dictionary

Definition at line 220 of file extractor_dict.py.

220  def getmetadata(self, md0={}):
221  """ Get metadata from input file and return as python dictionary.
222  Calls other methods in class and returns metadata dictionary"""
223  proc = self.extract_metadata_to_pipe()
224  jobt = self.get_job(proc)
225  mdart = self.mdart_gen(jobt)
226  return self.md_gen(mdart, md0)
227 
def md_gen(self, mdart, md0={})
def python.extractor_dict.expMetaData.md_gen (   self,
  mdart,
  md0 = {} 
)
Loop through art metdata, generate metadata dictionary

Definition at line 123 of file extractor_dict.py.

123  def md_gen(self, mdart, md0={}):
124  """Loop through art metdata, generate metadata dictionary"""
125  # define an empty python dictionary which will hold sam metadata.
126  # Some fields can be copied directly from art metadata to sam metadata.
127  # Other fields require conversion.
128  md = {}
129 
130 
131 
132  # Loop over art metadata.
133  mixparents = []
134  for mdkey, mdval in list(mdart.items()):
135  # mdval = mdart[mdkey]
136 
137  # Skip some art-specific fields.
138  # Ignore primary run_type field (if any).
139  # Instead, get run_type from runs field.
140  if mdkey in ['file_format_version', 'file_format_era', 'run_type']:
141  pass
142  elif mdkey in ['art.file_format_version', 'art.file_format_era', 'art.run_type']:
143  pass
144 
145  # Ignore new-style first/last event (old-style first/last handled below).
146  elif mdkey in ['art.first_event', 'art.last_event']:
147  pass
148 
149  # Ignore data_stream if it begins with "out".
150  # These kinds of stream names are probably junk module labels.
151 
152  # First check if the data_stream is just "out" Catches an edge case
153  # where the stream does not have a number
154 
155  elif mdkey == 'data_stream' and mdval == 'out':
156  pass
157 
158  elif mdkey == 'data_stream' and mdval[:3] == 'out' and \
159  mdval[3] >= '0' and mdval[3] <= '9':
160  pass
161 
162  # Application family/name/version.
163  elif mdkey == 'applicationFamily' or mdkey == 'application.family':
164  md['application'], md['application']['family'] = self.md_handle_application(md), mdval
165  elif mdkey == 'process_name' or mdkey == 'art.process_name':
166  md['application'], md['application']['name'] = self.md_handle_application(md), mdval
167  elif mdkey == 'applicationVersion' or mdkey == 'application.version':
168  md['application'], md['application']['version'] = self.md_handle_application(md), mdval
169 
170  # Parents.
171  elif mdkey == 'parents':
172  md['parents'] = [{'file_name': parent} for parent in mdval]
173 
174  elif mdkey.startswith('mixparent'):
175  mixparents.append(mdval.strip(' ,"') )
176 
177  # Other fields where the key or value requires minor conversion.
178  elif mdkey in ['first_event', 'last_event']:
179  if (type(mdval) == type([]) or type(mdval) == type(())) and len(mdval) >= 3:
180  md[mdkey] = mdval[2]
181  else:
182  md[mdkey] = mdval
183  elif mdkey in self.metadataList:
184  #print mdkey
185  trkey = self.translateKey(mdkey)
186  #print trkey
187  md[trkey] = mdval
188  elif mdkey == 'fclName':
189  md['fcl.name'] = mdval
190  elif mdkey == 'fclVersion':
191  md['fcl.version'] = mdval
192 
193  #For all other keys, copy art metadata directly to sam metadata.
194  #This works for run-tuple (run, subrun, runtype) and time stamps.
195  else:
196  md[mdkey] = mdval
197 
198  # Merge mix parents into normal parents.
199 
200  for mixparent in mixparents:
201  mixparent_dict = {'file_name': mixparent}
202  md['parents'].append(mixparent_dict)
203 
204  # Get the other meta data field parameters.
205 
206  md['file_name'] = self.inputfile.split("/")[-1]
207  if 'file_size' in md0:
208  md['file_size'] = md0['file_size']
209  else:
210  md['file_size'] = os.path.getsize(self.inputfile)
211  if 'crc' in md0:
212  md['crc'] = md0['crc']
213  else:
214  md['crc'] = root_metadata.fileEnstoreChecksum(self.inputfile)
215 
216  # In case we ever want to check out what md is for any instance of MetaData by calling instance.md
217  self.md = md
218  return self.md
219 
def md_gen(self, mdart, md0={})
def python.extractor_dict.expMetaData.translateKey (   self,
  key 
)
Returns the output of the imported translateKey function (as translateKeyf) called on key

Definition at line 119 of file extractor_dict.py.

119  def translateKey(self, key):
120  """Returns the output of the imported translateKey function (as translateKeyf) called on key"""
121  return self.translateKeyf(key)
122 

Member Data Documentation

python.extractor_dict.expMetaData.expname

Definition at line 107 of file extractor_dict.py.

python.extractor_dict.expMetaData.md

Definition at line 217 of file extractor_dict.py.

python.extractor_dict.expMetaData.translateKeyf

Definition at line 117 of file extractor_dict.py.


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