Functions | Variables
gen_hdf5record Namespace Reference

Functions

def is_fundamental (type)
 
def translate_type (type)
 
def is_vector (type)
 
def vector_contents (type)
 
def is_array (type)
 
def array_type (type)
 
def array_size (type)
 
def type_to_hdf5_type (type)
 
def vetoed (type)
 
def base_class (klass)
 
def variables_inc_bases (klass)
 
def deps_emitted (klass)
 
def write_hd5record_h (klass)
 

Variables

list fundamental_types
 
list reserved = ['run', 'subrun', 'cycle', 'evt', 'subevt']
 
list enums = []
 
 headerDir = os.getcwd()
 
 cxxDir = os.getcwd()
 
 generator_path
 
 generator_name
 
string priv = os.environ['SRT_PRIVATE_CONTEXT']if'SRT_PRIVATE_CONTEXT'
 
string pub = os.environ['SRT_PUBLIC_CONTEXT']if'SRT_PUBLIC_CONTEXT'
 
 context = privifos.path.exists(priv+'/StandardRecord/')elsepub
 
list path = []
 
 config
 
 decls
 
 global_namespace = declarations.get_global_namespace(decls)
 
 ns = global_namespace.namespace('caf')
 
list emitted = []
 
string disclaimer
 
string funcs
 
 stdout
 
bool debug = False
 
bool anyWritten = False
 
bool anySkipped = False
 
 pt = type_to_hdf5_type(klass.name)
 
list inits = []
 
list types = []
 
list names = []
 
 inner_type = vector_contents(str(v.decl_type))
 
 size = array_size(str(v.decl_type))
 

Function Documentation

def gen_hdf5record.array_size (   type)

Definition at line 56 of file gen_hdf5record.py.

References makeTrainCVSamples.int, and is_array().

Referenced by write_hd5record_h().

56 def array_size(type):
57  assert is_array(type)
58  return int(type[type.find('[')+1:-1])
59 
60 
def array_size(type)
def is_array(type)
def gen_hdf5record.array_type (   type)

Definition at line 50 of file gen_hdf5record.py.

References is_array().

Referenced by deps_emitted(), and write_hd5record_h().

50 def array_type(type):
51  assert is_array(type)
52  # There always seems to be a space before the dimensions
53  return type[:type.find('[')-1]
54 
55 
def array_type(type)
def is_array(type)
def gen_hdf5record.base_class (   klass)

Definition at line 77 of file gen_hdf5record.py.

Referenced by deps_emitted(), variables_inc_bases(), and write_hd5record_h().

77 def base_class(klass):
78  assert len(klass.bases) < 2, 'Support for multiple base classes not implemented'
79  if len(klass.bases) == 1:
80  return klass.bases[0].related_class
81  return None
82 
83 # Recurse to find member variables including all base classes
def base_class(klass)
def gen_hdf5record.deps_emitted (   klass)

Definition at line 220 of file gen_hdf5record.py.

References array_type(), base_class(), is_array(), is_fundamental(), is_vector(), runNovaSAM.str, type_to_hdf5_type(), variables_inc_bases(), and vector_contents().

220 def deps_emitted(klass):
221  pt = type_to_hdf5_type(klass.name)
222  base = base_class(klass)
223  if base: base = type_to_hdf5_type(base.name)
224 
225  if base and base not in emitted:
226  if debug: sys.stderr.write('Skipping '+pt+' because of '+base+'\n')
227  return False
228 
229  for v in variables_inc_bases(klass):
230  if is_fundamental(str(v.decl_type)):
231  continue
232  elif is_vector(str(v.decl_type)):
233  type = vector_contents(str(v.decl_type))
234  if is_fundamental(type): continue
235  type = type_to_hdf5_type(type)
236  elif is_array(str(v.decl_type)):
237  assert is_fundamental(array_type(str(v.decl_type)))
238  continue
239  elif type_to_hdf5_type(str(v.decl_type)) in ['HDF5Vector3D', 'HDF5LorentzVector']:
240  continue
241  else:
242  type = type_to_hdf5_type(str(v.decl_type))
243 
244  if type not in emitted:
245  if debug: sys.stderr.write('Skipping '+pt+' because of '+type+'\n')
246  return False
247 
248  return True
249 
250 
def base_class(klass)
def array_type(type)
def is_vector(type)
def is_fundamental(type)
def type_to_hdf5_type(type)
def vector_contents(type)
def is_array(type)
def variables_inc_bases(klass)
def deps_emitted(klass)
def gen_hdf5record.is_array (   type)

Definition at line 46 of file gen_hdf5record.py.

Referenced by array_size(), array_type(), deps_emitted(), type_to_hdf5_type(), and write_hd5record_h().

46 def is_array(type):
47  return '[' in type
48 
49 
def is_array(type)
def gen_hdf5record.is_fundamental (   type)

Definition at line 24 of file gen_hdf5record.py.

Referenced by deps_emitted(), type_to_hdf5_type(), and write_hd5record_h().

24 def is_fundamental(type):
25  if type in fundamental_types: return True
26  if type in enums: return True
27  if type[:5] == 'caf::': return is_fundamental(type[5:])
28  return False
29 
30 
def is_fundamental(type)
def gen_hdf5record.is_vector (   type)

Definition at line 37 of file gen_hdf5record.py.

Referenced by deps_emitted(), type_to_hdf5_type(), vector_contents(), and write_hd5record_h().

37 def is_vector(type):
38  return type[:12] == 'std::vector<'
39 
40 
def is_vector(type)
def gen_hdf5record.translate_type (   type)

Definition at line 31 of file gen_hdf5record.py.

Referenced by write_hd5record_h().

31 def translate_type(type):
32  if type in enums or type == 'bool': return 'unsigned short'
33  if type[:5] == 'caf::': return translate_type(type[5:])
34  return type
35 
36 
def translate_type(type)
def gen_hdf5record.type_to_hdf5_type (   type)

Definition at line 61 of file gen_hdf5record.py.

References is_array(), is_fundamental(), and is_vector().

Referenced by deps_emitted(), and write_hd5record_h().

62  assert not is_fundamental(type)
63  assert not is_vector(type)
64  assert not is_array(type)
65 
66  if type[:5] == 'caf::': return type_to_hdf5_type(type[5:])
67 
68  if type == 'StandardRecord': return 'HDF5Record'
69 
70  return 'HDF5'+type[2:]
71 
72 
def is_vector(type)
def is_fundamental(type)
def type_to_hdf5_type(type)
def is_array(type)
def gen_hdf5record.variables_inc_bases (   klass)

Definition at line 84 of file gen_hdf5record.py.

References base_class(), parse_dependency_file_t.list, print, runNovaSAM.str, and vetoed().

Referenced by deps_emitted(), and write_hd5record_h().

85  vars = []
86  for v in list(klass.variables()):
87  if vetoed(str(v.decl_type)):
88  sys.stderr.write('Skipping '+str(v.decl_type)+' '+v.name+'\n')
89  else:
90  vars += [v]
91  base = base_class(klass)
92  if base: vars += variables_inc_bases(base)
93  return vars
94 
95 
def base_class(klass)
def vetoed(type)
def variables_inc_bases(klass)
def gen_hdf5record.vector_contents (   type)

Definition at line 41 of file gen_hdf5record.py.

References is_vector().

Referenced by deps_emitted(), and write_hd5record_h().

41 def vector_contents(type):
42  assert is_vector(type)
43  return type[12:type.find(',')]
44 
45 
def is_vector(type)
def vector_contents(type)
def gen_hdf5record.vetoed (   type)

Definition at line 73 of file gen_hdf5record.py.

Referenced by variables_inc_bases().

73 def vetoed(type):
74  if type == 'std::string': return True
75  return False
76 
def vetoed(type)
def gen_hdf5record.write_hd5record_h (   klass)

Definition at line 251 of file gen_hdf5record.py.

References array_size(), array_type(), base_class(), is_array(), is_fundamental(), is_vector(), print, runNovaSAM.str, translate_type(), type_to_hdf5_type(), variables_inc_bases(), and vector_contents().

251 def write_hd5record_h(klass):
252  base = base_class(klass)
253  if base: base = type_to_hdf5_type(base.name)
254 
255  print('/// HDF5 encoding of \\ref', klass.name)
256 # if base:
257 # print 'class', pt+': public', base
258 # else:
259  print('template<class... Tidx> class', pt)
260 
261  print('{')
262  print('public:')
263  print(' template<class... Cols> '+pt+'(hid_t f, const std::string& name, const plist_init& cprop, Cols... cols);')
264  print()
265  print(' void Fill(Tidx... idxs, const caf::'+klass.name+'& sr);')
266  print()
267 
268  types = []
269  names = []
270  for v in variables_inc_bases(klass):
271  type = str(v.decl_type)
272 
273  if is_fundamental(type):
274  if v.name not in reserved:
275  types += [translate_type(type)]
276  names += [v.name]
277  elif is_vector(type):
278  inner_type = vector_contents(str(v.decl_type))
279  if not is_fundamental(inner_type):
280  print(' std::unique_ptr<'+type_to_hdf5_type(inner_type)+'<Tidx..., unsigned int>>', v.name+';')
281  else:
282  print(' std::unique_ptr<Wrapped<'+inner_type+', Tidx..., unsigned int>>', v.name+';')
283  elif is_array(type):
284  inner_type = array_type(type)
285  size = array_size(type)
286  assert is_fundamental(inner_type)
287  types += [inner_type]
288  names += [v.name]
289  elif type_to_hdf5_type(type) == 'HDF5Vector3D':
290  types += ['float', 'float', 'float']
291  names += [v.name+'.x', v.name+'.y', v.name+'.z']
292  elif type_to_hdf5_type(type) == 'HDF5LorentzVector':
293  types += ['float', 'float', 'float', 'float']
294  names += [v.name+'.E', v.name+'.px', v.name+'.py', v.name+'.pz']
295  else:
296  print(' std::unique_ptr<'+type_to_hdf5_type(str(v.decl_type))+'<Tidx...>>', v.name+';')
297 
298  if len(types) > 0:
299  print(' // '+', '.join(names))
300  print(' hep_hpc::hdf5::Ntuple<Tidx..., '+', '.join(types)+'> vals;')
301 
302  print('};');
303  print()
304 
305  if debug: sys.stderr.write('Wrote '+pt+'\n')
306 
307 
def base_class(klass)
def array_type(type)
def is_vector(type)
def is_fundamental(type)
def type_to_hdf5_type(type)
def translate_type(type)
def vector_contents(type)
bool print
def array_size(type)
def is_array(type)
def variables_inc_bases(klass)
def write_hd5record_h(klass)

Variable Documentation

bool gen_hdf5record.anySkipped = False

Definition at line 310 of file gen_hdf5record.py.

bool gen_hdf5record.anyWritten = False

Definition at line 309 of file gen_hdf5record.py.

gen_hdf5record.config
Initial value:
1 = parser.xml_generator_configuration_t(
2  xml_generator_path=generator_path,
3  xml_generator=generator_name,
4  include_paths=path,
5  cflags='-std=c++1z -Wno-unknown-warning-option'#,
6 # start_with_declarations='caf::StandardRecord'
7  )

Definition at line 122 of file gen_hdf5record.py.

gen_hdf5record.context = privifos.path.exists(priv+'/StandardRecord/')elsepub

Definition at line 115 of file gen_hdf5record.py.

gen_hdf5record.cxxDir = os.getcwd()

Definition at line 102 of file gen_hdf5record.py.

bool gen_hdf5record.debug = False
gen_hdf5record.decls
Initial value:
1 = parser.parse([context+'/StandardRecord/StandardRecord.h'],
2  config)

Definition at line 130 of file gen_hdf5record.py.

string gen_hdf5record.disclaimer
Initial value:
1 = '''// This file was auto-generated by gen_hdf5record.py.
2 // DO NOT EDIT IT DIRECTLY.
3 // For documentation of the fields see the regular StandardRecord.h'''

Definition at line 143 of file gen_hdf5record.py.

list gen_hdf5record.emitted = []

Definition at line 140 of file gen_hdf5record.py.

list gen_hdf5record.enums = []

Definition at line 22 of file gen_hdf5record.py.

string gen_hdf5record.funcs

Definition at line 147 of file gen_hdf5record.py.

list gen_hdf5record.fundamental_types
Initial value:
1 = ['int', 'float', 'double', 'bool', 'unsigned int',
2  'short', 'short int', 'short unsigned int',
3  'long', 'long unsigned int',
4  'long long int', 'unsigned char',
5  'size_t']

Definition at line 13 of file gen_hdf5record.py.

gen_hdf5record.generator_name

Definition at line 106 of file gen_hdf5record.py.

gen_hdf5record.generator_path

Definition at line 106 of file gen_hdf5record.py.

gen_hdf5record.global_namespace = declarations.get_global_namespace(decls)

Definition at line 133 of file gen_hdf5record.py.

gen_hdf5record.headerDir = os.getcwd()

Definition at line 100 of file gen_hdf5record.py.

list gen_hdf5record.inits = []

Definition at line 360 of file gen_hdf5record.py.

gen_hdf5record.inner_type = vector_contents(str(v.decl_type))

Definition at line 366 of file gen_hdf5record.py.

list gen_hdf5record.names = []
gen_hdf5record.ns = global_namespace.namespace('caf')

Definition at line 134 of file gen_hdf5record.py.

list gen_hdf5record.path = []

Definition at line 117 of file gen_hdf5record.py.

string gen_hdf5record.priv = os.environ['SRT_PRIVATE_CONTEXT']if'SRT_PRIVATE_CONTEXT'

Definition at line 109 of file gen_hdf5record.py.

gen_hdf5record.pt = type_to_hdf5_type(klass.name)

Definition at line 313 of file gen_hdf5record.py.

gen_hdf5record.pub = os.environ['SRT_PUBLIC_CONTEXT']if'SRT_PUBLIC_CONTEXT'

Definition at line 110 of file gen_hdf5record.py.

list gen_hdf5record.reserved = ['run', 'subrun', 'cycle', 'evt', 'subevt']

Definition at line 20 of file gen_hdf5record.py.

Referenced by test_numupred2017().

gen_hdf5record.size = array_size(str(v.decl_type))

Definition at line 373 of file gen_hdf5record.py.

gen_hdf5record.stdout

Definition at line 200 of file gen_hdf5record.py.

list gen_hdf5record.types = []