Classes | Functions | Variables
nova_art_metadata Namespace Reference

Classes

class  NovaArt
 

Functions

def unCamelCase (s)
 
def _createMetadata (data, filename, group, filesizebytes)
 

Variables

 novaArtExtractor = NovaArt()
 

Function Documentation

def nova_art_metadata._createMetadata (   data,
  filename,
  group,
  filesizebytes 
)
private

Definition at line 21 of file nova_art_metadata.py.

References site_stats_from_log.get, hadd_reco_validation.group, makeTrainCVSamples.int, runNovaSAM.str, and unCamelCase().

Referenced by nova_art_metadata.NovaArt.extract().

21 def _createMetadata(data, filename, group, filesizebytes):
22  md = {'file_name': filename, 'group':group, 'file_size': filesizebytes}
23 
24  # If have a transpose file force the PlaneNumber into the metadata
25  if "outplane" in filename:
26  try:
27  plane = re.search('^.*outplane(\d*).pclist.root', filename).group(1)
28  print "Plane number:", plane, ". Is a transpose file"
29  md['Calibration.PlaneNumber'] = plane
30  except:
31  print "No plane number found in transpose file"
32 
33  dumperDict = json.loads(data)
34 
35  for dumperKey in dumperDict:
36  if str(filename) in str(dumperKey):
37  tmpMD = dumperDict[dumperKey]
38 
39  for k,v in tmpMD.iteritems():
40  if '.' not in k:
41  k = unCamelCase(k)
42  else:
43  k.lower()
44  v = str(v)
45 
46  if k == 'parents':
47  #parents contains a list, either of ints, strings, or dictionaries with "file_name" and "file_id" as keys
48  vTmp = []
49  for entry in v:
50  if isinstance(entry, int):
51  pass
52  elif isinstance(entry, basestring):
53  entry = os.path.basename(entry)
54  if entry.endswith('sim.g4.root'):
55  entry = re.sub( r'sim.g4.root$', r'fcl', entry )
56  elif isinstance(entry, dict):
57  if "file_name" in entry:
58  entry["file_name"] = os.path.basename( entry["file_name"] )
59 # Types are incorrect here, and we've never actually run with this code. If
60 # it's needed it should be fixed before being uncommented.
61 # if entry.endswith('sim.g4.root'):
62 # entry = re.sub( r'sim.g4.root$', r'fcl', entry )
63  vTmp.append(entry)
64  v = vTmp
65 
66  if k == 'process_name' and md.get('application',[]).get('name') is None:
67  k = 'application_name'
68  elif k == 'stream_name':
69  k = 'data_stream'
70 
71  if k in ('start_date', 'end_date'):
72  v = long(v)
73 
74  if k in ('first_event', 'last_event'):
75  try:
76  v = int(v)
77  except TypeError:
78  if len(v) == 3:
79  v = v[2]
80  else:
81  continue
82 
83  if k.startswith('application_'):
84  if 'application' not in md:
85  md['application'] = {}
86  md['application'][k[12:]] = v
87  elif k in ('file_format_era', 'file_format_version'):
88  pass
89  else:
90  md[k] = v
91 
92  ### HACKETTY HACK HACK For Calib Transpose
93  if "outplane" in md['data_stream']:
94  md['data_stream'] = "outpclist"
95 
96  return md
97 
def _createMetadata(data, filename, group, filesizebytes)
def nova_art_metadata.unCamelCase (   s)
Convert CamelCase to camel_case 

Definition at line 12 of file nova_art_metadata.py.

Referenced by _createMetadata().

12 def unCamelCase(s):
13  """ Convert CamelCase to camel_case """
14 
15  # \B matches an empty string which is NOT at the beginning of a word
16  # so requiring this means no _ will be inserted at the start
17 
18  return re.sub( r'\B([A-Z])', r'_\1', s).lower()
19 
20 

Variable Documentation

nova_art_metadata.novaArtExtractor = NovaArt()

Definition at line 139 of file nova_art_metadata.py.