Public Member Functions | Public Attributes | List of all members
extractor_dict.expMetaData Class Reference
Inheritance diagram for extractor_dict.expMetaData:
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 98 of file extractor_dict.py.

Constructor & Destructor Documentation

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

Definition at line 100 of file extractor_dict.py.

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

Member Function Documentation

def 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 235 of file extractor_dict.py.

235  def getmetadata(self, md0={}):
236  """ Get metadata from input file and return as python dictionary.
237  Calls other methods in class and returns metadata dictionary"""
238  proc = self.extract_metadata_to_pipe()
239  jobt = self.get_job(proc)
240  mdart = self.mdart_gen(jobt)
241  return self.md_gen(mdart, md0)
242 
def get_job(self, proc)
def getmetadata(self, md0={})
def md_gen(self, mdart, md0={})
def extract_metadata_to_pipe(self)
def extractor_dict.expMetaData.md_gen (   self,
  mdart,
  md0 = {} 
)
Loop through art metdata, generate metadata dictionary

Definition at line 118 of file extractor_dict.py.

118  def md_gen(self, mdart, md0={}):
119  """Loop through art metdata, generate metadata dictionary"""
120  # define an empty python dictionary which will hold sam metadata.
121  # Some fields can be copied directly from art metadata to sam metadata.
122  # Other fields require conversion.
123  md = {}
124 
125  # Loop over art metadata.
126  for mdkey in mdart.keys():
127  mdval = mdart[mdkey]
128 
129  # Skip some art-specific fields.
130 
131  if mdkey == 'file_format_version':
132  pass
133  elif mdkey == 'file_format_era':
134  pass
135 
136  # Ignore primary run_type field (if any).
137  # Instead, get run_type from runs field.
138 
139  elif mdkey == 'run_type':
140  pass
141 
142  # Ignore data_stream for now.
143 
144  elif mdkey == 'data_stream':
145  pass
146 
147  # Ignore process_name for now.
148 
149  elif mdkey == 'process_name':
150  pass
151 
152  # Application family/name/version.
153 
154  elif mdkey == 'applicationFamily':
155  if not md.has_key('application'):
156  md['application'] = {}
157  md['application']['family'] = mdval
158  elif mdkey == 'StageName':
159  if not md.has_key('application'):
160  md['application'] = {}
161  md['application']['name'] = mdval
162  elif mdkey == 'applicationVersion':
163  if not md.has_key('application'):
164  md['application'] = {}
165  md['application']['version'] = mdval
166 
167  # Parents.
168 
169  elif mdkey == 'parents':
170  mdparents = []
171  for parent in mdval:
172  parent_dict = {'file_name': parent}
173  mdparents.append(parent_dict)
174  md['parents'] = mdparents
175 
176  # Other fields where the key or value requires minor conversion.
177 
178  elif mdkey == 'first_event':
179  md[mdkey] = mdval[2]
180  elif mdkey == 'last_event':
181  md[mdkey] = mdval[2]
182  elif mdkey == 'lbneMCGenerators':
183  md['lbne_MC.generators'] = mdval
184  elif mdkey == 'lbneMCOscillationP':
185  md['lbne_MC.oscillationP'] = mdval
186  elif mdkey == 'lbneMCTriggerListVersion':
187  md['lbne_MC.trigger-list-version'] = mdval
188  elif mdkey == 'lbneMCBeamEnergy':
189  md['lbne_MC.beam_energy'] = mdval
190  elif mdkey == 'lbneMCBeamFluxID':
191  md['lbne_MC.beam_flux_ID'] = mdval
192  elif mdkey == 'lbneMCName':
193  md['lbne_MC.name'] = mdval
194  elif mdkey == 'lbneMCDetectorType':
195  md['lbne_MC.detector_type'] = mdval
196  elif mdkey == 'lbneMCNeutrinoFlavors':
197  md['lbne_MC.neutrino_flavors'] = mdval
198  elif mdkey == 'lbneMCMassHierarchy':
199  md['lbne_MC.mass_hierarchy'] = mdval
200  elif mdkey == 'lbneMCMiscellaneous':
201  md['lbne_MC.miscellaneous'] = mdval
202  elif mdkey == 'lbneMCGeometryVersion':
203  md['lbne_MC.geometry_version'] = mdval
204  elif mdkey == 'lbneMCOverlay':
205  md['lbne_MC.overlay'] = mdval
206  elif mdkey == 'lbneDataRunMode':
207  md['lbne_data.run_mode'] = mdval
208  elif mdkey == 'lbneDataDetectorType':
209  md['lbne_data.detector_type'] = mdval
210  elif mdkey == 'lbneDataName':
211  md['lbne_data.name'] = mdval
212 
213  # For all other keys, copy art metadata directly to sam metadata.
214  # This works for run-tuple (run, subrun, runtype) and time stamps.
215 
216  else:
217  md[mdkey] = mdart[mdkey]
218 
219 
220  # Get the other meta data field parameters
221  md['file_name'] = self.inputfile.split("/")[-1]
222  if 'file_size' in md0:
223  md['file_size'] = md0['file_size']
224  else:
225  md['file_size'] = os.path.getsize(self.inputfile)
226  if 'crc' in md0:
227  md['crc'] = md0['crc']
228  else:
229  md['crc'] = root_metadata.fileEnstoreChecksum(self.inputfile)
230 
231  # In case we ever want to check out what md is for any instance of MetaData by calling instance.md
232  self.md = md
233  return self.md
234 
def md_gen(self, mdart, md0={})
def extractor_dict.expMetaData.translateKey (   self,
  key 
)
Returns the output of the imported translateKey function (as translateKeyf) called on key

Definition at line 114 of file extractor_dict.py.

114  def translateKey(self, key):
115  """Returns the output of the imported translateKey function (as translateKeyf) called on key"""
116  return self.translateKeyf(key)
117 

Member Data Documentation

extractor_dict.expMetaData.expname

Definition at line 102 of file extractor_dict.py.

extractor_dict.expMetaData.md

Definition at line 232 of file extractor_dict.py.

extractor_dict.expMetaData.translateKeyf

Definition at line 112 of file extractor_dict.py.


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