def cpp_dump(self): pub_members_list = '\n'.join(i.cpp_var() for i in self.branches + self.objects if i.var_public) priv_members_list = '\n'.join(i.cpp_var() for i in self.branches + self.objects if not i.var_public) members_init = ',\n'.join(i.cpp_init() for i in self.branches + self.objects) branch_setting = '\n'.join( i.cpp_set_branch() for i in self.branches \ if not i.is_object ) load_methods = '\n'.join(i.cpp_load() for i in self.objects) structs = '\n'.join(i.as_struct.cpp_dump() for i in self.objects) obj_getters = '\n'.join(i.cpp_obj_getter() for i in self.objects) destruct = '\n'.join(i.cpp_clear() for i in self.objects) links = '\n'.join(i.as_struct.cpp_link() for i in self.objects) return cpp_format(StreamerMeta.cpp_template, OBJECTS_STRUCTS=structs, PUBLIC_MEMBER_LIST=pub_members_list, PRIVATE_MEMBER_LIST=priv_members_list, MEMBER_INIT=members_init, BRANCH_SETTING=branch_setting, LOAD_METHODS=load_methods, OBJ_GETTERS=obj_getters, EVT_CLEAR=destruct)
def cpp_dump(self): members = '\n'.join(i.cpp_var() for i in self.members) inputs = ','.join(i.cpp_input() for i in self.members) init = '' #',\n'.join( ## i.cpp_init() for i in self.members ## ) void_init = ',\n'.join(i.cpp_void_init() for i in self.members) getters = '\n'.join(i.cpp_getter() for i in self.members) setters = '\n'.join(i.cpp_setter() for i in self.members) inheritance = "" if len(self.lorentz_members) > 0: inheritance = ': public TLorentzVector' if len(self.lorentz_members) == 2: #pt/et, phi setters += '\nvoid %s(float pt, float phi){SetPtEtaPhiM(pt, 0., phi, 0.);}' % _lorentz_setter elif len(self.lorentz_members) == 3: #pt/et, eta, phi setters += '\nvoid %s(float pt, float eta, float phi){SetPtEtaPhiM(pt, eta, phi, 0.);}' % _lorentz_setter elif len(self.lorentz_members) == 4: #pt/et, eta, phi, mass setters += '\nvoid %s(float pt, float eta, float phi, float mass){SetPtEtaPhiM(pt, eta, phi, mass);}' % _lorentz_setter void_init = '%s\n%s' % ('TLorentzVector(),', void_init) #getters += '\nClassDef(%s, 1);' % self.name #creates dreaded undefined reference to vtable without LinkDef return cpp_format( ObjStruct.cpp_template, INHERITANCE=inheritance, NAME=self.name, MEMBERS=members, INPUTS=inputs, MEMBERS_INIT=init, MEMBERS_VOID_INIT=void_init, GETTERS=getters, SETTERS=setters, )
def _single_getter(self): dump = '\n'.join('obj.set%s(%s);' % (i.attr, i.var) for i in self.branches if i.attr not in _lorentz_vector_members) val = cpp_format(ObjectMeta.getter_template, RET_TYPE=self.as_struct.name, NAME=self.prefix, BRANCH_DUMP=dump) return val
def cpp_dump(self): vlinks = '\n'.join( '#pragma link C++ class vector<%s>+;' % i.as_struct.name \ for i in self.objects if i.is_vector ) obj_links = '\n'.join( '#pragma link C++ class %s+;' % i.as_struct.name \ for i in self.objects ) return cpp_format( LinkDefMeta.cpp_template, LINK_VOBJS=vlinks, LINK_OBJS=obj_links, )
def _vobj_getter(self): #make iterators #self.as_struct.name #iterators = '\n'.join( #'auto it_{var} = {var}->begin();'.format( #var = i.var) for i in self.branches #) vsize = '%s->size()' % self.branches[0].var iterators = '\n'.join( 'auto it_{var} = {var}->cbegin();'.format(var=i.var) for i in self.branches) end_cond = 'it_{var} != {var}->cend()'.format(var=self.branches[0].var) it_increment = '\n'.join('++it_%s;' % i.var for i in self.branches) it_dump = '\n'.join('obj.set%s(*it_%s);' % (i.attr, i.var) for i in self.branches if i.attr not in _lorentz_vector_members) lv_pars = dict((i.attr, i.var) for i in self.branches if i.attr in _lorentz_vector_members) if len(lv_pars) >= 2: if 'pt' not in lv_pars: lv_pars['pt'] = lv_pars['et'] del lv_pars['et'] if len(lv_pars) == 2: #pt/et, phi it_dump += '\nobj.%s(*it_%s, *it_%s);' \ % (_lorentz_setter, lv_pars['pt'], lv_pars['phi']) elif len(lv_pars) == 3: #pt/et, eta, phi it_dump += '\nobj.%s(*it_%s, *it_%s, *it_%s);' \ % (_lorentz_setter, lv_pars['pt'], lv_pars['eta'], lv_pars['phi']) elif len(lv_pars) == 4: #pt/et, eta, phi, mass it_dump += '\nobj.%s(*it_%s, *it_%s, *it_%s, *it_%s);' \ % (_lorentz_setter, lv_pars['pt'], lv_pars['eta'], lv_pars['phi'], lv_pars['mass']) else: it_dump += '\n' + '\n'.join('obj.set%s(*it_%s);' % (i.attr, i.var) for i in self.branches if i.attr in _lorentz_vector_members) return cpp_format( ObjectMeta.vgetter_template, OBJ_VAR=self.obj_container, VSIZE=vsize, RET_TYPE=self.as_struct.name, NAME=self.prefix, ITRATORS=iterators, END_COND=end_cond, IT_INCREMENT=it_increment, IT_DUMP=it_dump, )
def cpp_load(self, tname='tree_'): '''C++ activate and set branch made in a separate function to allow customized load of the objects''' return cpp_format( ObjectMeta.cpp_template, NAME=self.name, LOAD_VAR=self.load_var, BRANCH_SETTING='\n'.join( i.cpp_set_branch(tname) \ for i in self.branches ) )
def cpp_dump(self): members = '\n'.join( i.cpp_var() for i in self.members ) inputs = ','.join( i.cpp_input() for i in self.members ) init = ''#',\n'.join( ## i.cpp_init() for i in self.members ## ) void_init = ',\n'.join( i.cpp_void_init() for i in self.members ) getters = '\n'.join( i.cpp_getter() for i in self.members ) setters = '\n'.join( i.cpp_setter() for i in self.members ) inheritance = "" if len(self.lorentz_members) > 0: inheritance = ': public TLorentzVector' if len(self.lorentz_members) == 2 and 'px' in self.lorentz_members and 'py' in self.lorentz_members: setters += '\nvoid %s(float px, float py){SetXYZM(px, py, 0., 0.);}' % _lorentz_setter elif len(self.lorentz_members) == 3: #pt/et, eta, phi setters += '\nvoid %s(float pt, float eta, float phi){SetPtEtaPhiM(pt, eta, phi, 0.);}' % _lorentz_setter elif len(self.lorentz_members) == 4 and 'e' in self.lorentz_members and 'pt' in self.lorentz_members: #pt/et, eta, phi, e setters += '\nvoid %s(float pt, float eta, float phi, float e){SetPtEtaPhiE(pt, eta, phi, e);}' % _lorentz_setter elif len(self.lorentz_members) == 4 and 'mass' in self.lorentz_members and 'pt' in self.lorentz_members: #pt/et, eta, phi, mass setters += '\nvoid %s(float pt, float eta, float phi, float mass){SetPtEtaPhiM(pt, eta, phi, mass);}' % _lorentz_setter elif len(self.lorentz_members) == 4 and 'e' in self.lorentz_members and 'px' in self.lorentz_members: setters += '\nvoid %s(float px, float py, float pz, float e){SetPxPyPzE(px, py, pz, e);}' % _lorentz_setter void_init = '%s\n%s' % ('TLorentzVector(),', void_init) getters += '\nClassDef(%s, 1);' % self.name return cpp_format( ObjStruct.cpp_template, INHERITANCE=inheritance, NAME=self.name, MEMBERS=members, INPUTS=inputs, MEMBERS_INIT=init, MEMBERS_VOID_INIT=void_init, GETTERS=getters, SETTERS=setters, )