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

 action
 
 category
 
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 = privif(priv and os.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 60 of file gen_hdf5record.py.

References makeTrainCVSamples.int, and is_array().

Referenced by write_hd5record_h().

60 def array_size(type):
61  assert is_array(type)
62  return int(type[type.find('[')+1:-1])
63 
64 
def array_size(type)
def is_array(type)
def gen_hdf5record.array_type (   type)

Definition at line 54 of file gen_hdf5record.py.

References is_array().

Referenced by deps_emitted(), and write_hd5record_h().

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

Definition at line 81 of file gen_hdf5record.py.

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

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

Definition at line 224 of file gen_hdf5record.py.

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

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

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

50 def is_array(type):
51  return '[' in type
52 
53 
def is_array(type)
def gen_hdf5record.is_fundamental (   type)

Definition at line 28 of file gen_hdf5record.py.

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

28 def is_fundamental(type):
29  if type in fundamental_types: return True
30  if type in enums: return True
31  if type[:5] == 'caf::': return is_fundamental(type[5:])
32  return False
33 
34 
def is_fundamental(type)
def gen_hdf5record.is_vector (   type)

Definition at line 41 of file gen_hdf5record.py.

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

41 def is_vector(type):
42  return type[:12] == 'std::vector<'
43 
44 
def is_vector(type)
def gen_hdf5record.translate_type (   type)

Definition at line 35 of file gen_hdf5record.py.

Referenced by write_hd5record_h().

35 def translate_type(type):
36  if type in enums or type == 'bool': return 'unsigned short'
37  if type[:5] == 'caf::': return translate_type(type[5:])
38  return type
39 
40 
def translate_type(type)
def gen_hdf5record.type_to_hdf5_type (   type)

Definition at line 65 of file gen_hdf5record.py.

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

Referenced by deps_emitted(), and write_hd5record_h().

66  assert not is_fundamental(type)
67  assert not is_vector(type)
68  assert not is_array(type)
69 
70  if type[:5] == 'caf::': return type_to_hdf5_type(type[5:])
71 
72  if type == 'StandardRecord': return 'HDF5Record'
73 
74  return 'HDF5'+type[2:]
75 
76 
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 88 of file gen_hdf5record.py.

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

Referenced by deps_emitted(), and write_hd5record_h().

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

Definition at line 45 of file gen_hdf5record.py.

References is_vector().

Referenced by deps_emitted(), and write_hd5record_h().

45 def vector_contents(type):
46  assert is_vector(type)
47  return type[12:type.find(',')]
48 
49 
def is_vector(type)
def vector_contents(type)
def gen_hdf5record.vetoed (   type)

Definition at line 77 of file gen_hdf5record.py.

Referenced by variables_inc_bases().

77 def vetoed(type):
78  if type == 'std::string': return True
79  return False
80 
def vetoed(type)
def gen_hdf5record.write_hd5record_h (   klass)

Definition at line 255 of file gen_hdf5record.py.

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

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

gen_hdf5record.action

Definition at line 13 of file gen_hdf5record.py.

bool gen_hdf5record.anySkipped = False

Definition at line 314 of file gen_hdf5record.py.

bool gen_hdf5record.anyWritten = False

Definition at line 313 of file gen_hdf5record.py.

gen_hdf5record.category

Definition at line 13 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 126 of file gen_hdf5record.py.

gen_hdf5record.context = privif(priv and os.path.exists(priv+'/StandardRecord/'))elsepub

Definition at line 119 of file gen_hdf5record.py.

gen_hdf5record.cxxDir = os.getcwd()

Definition at line 106 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 134 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 147 of file gen_hdf5record.py.

list gen_hdf5record.emitted = []

Definition at line 144 of file gen_hdf5record.py.

list gen_hdf5record.enums = []

Definition at line 26 of file gen_hdf5record.py.

string gen_hdf5record.funcs

Definition at line 151 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 17 of file gen_hdf5record.py.

gen_hdf5record.generator_name

Definition at line 110 of file gen_hdf5record.py.

gen_hdf5record.generator_path

Definition at line 110 of file gen_hdf5record.py.

gen_hdf5record.global_namespace = declarations.get_global_namespace(decls)

Definition at line 137 of file gen_hdf5record.py.

gen_hdf5record.headerDir = os.getcwd()

Definition at line 104 of file gen_hdf5record.py.

list gen_hdf5record.inits = []

Definition at line 364 of file gen_hdf5record.py.

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

Definition at line 370 of file gen_hdf5record.py.

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

Definition at line 138 of file gen_hdf5record.py.

list gen_hdf5record.path = []

Definition at line 121 of file gen_hdf5record.py.

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

Definition at line 113 of file gen_hdf5record.py.

gen_hdf5record.pt = type_to_hdf5_type(klass.name)

Definition at line 317 of file gen_hdf5record.py.

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

Definition at line 114 of file gen_hdf5record.py.

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

Definition at line 24 of file gen_hdf5record.py.

Referenced by test_numupred2017().

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

Definition at line 377 of file gen_hdf5record.py.

gen_hdf5record.stdout

Definition at line 204 of file gen_hdf5record.py.

list gen_hdf5record.types = []