|
@@ -16,6 +16,7 @@ class {obj_name}Collection {{
|
|
|
iter operator++() {{ ++idx; return *this; }}
|
|
|
bool operator!=(const iter & other) {{ return idx != other.idx; }}
|
|
|
const {obj_name} operator*() const;
|
|
|
+ TrackingDataSet* tds;
|
|
|
private:
|
|
|
const {obj_name}Collection* collection;
|
|
|
size_t idx;
|
|
@@ -27,15 +28,12 @@ class {obj_name}Collection {{
|
|
|
name = field['name']
|
|
|
type_ = field['type']
|
|
|
src.append(f' Value<vector<{type_}>>* val_{name};')
|
|
|
+ src.append(f' bool {name}_loaded;')
|
|
|
|
|
|
src.append(f'\n {obj_name}Collection() {{ }}\n')
|
|
|
|
|
|
- src.append(' void init(TrackingDataSet& tds){')
|
|
|
- for field in obj_attrs['fields']:
|
|
|
- name = field['name']
|
|
|
- type_ = field['type']
|
|
|
- prefix = obj_attrs['treename_prefix']+'_'
|
|
|
- src.append(f' val_{name} = tds.track_branch_obj<vector<{type_}>>("{prefix}{name}");')
|
|
|
+ src.append(' void init(TrackingDataSet* tds){')
|
|
|
+ src.append(' this->tds = tds;')
|
|
|
src.append(' }\n')
|
|
|
first_obj_name = list(obj_attrs['fields'])[0]['name']
|
|
|
src.append(f' size_t size() const {{ return (*val_{first_obj_name})().size();}}\n')
|
|
@@ -55,7 +53,15 @@ struct {obj_name} {{
|
|
|
for field in obj_attrs['fields']:
|
|
|
name = field['name']
|
|
|
type_ = field['type']
|
|
|
- src.append(f' const {type_}& {name}() const {{return (*collection->val_{name})().at(idx);}}')
|
|
|
+ prefix = obj_attrs['treename_prefix']+'_'
|
|
|
+ src.append(f'''\
|
|
|
+ const {type_}& {name}() const {{
|
|
|
+ if (!collection->{name}_loaded) {{
|
|
|
+ collection->val_{name} = collection->tds->track_branch_obj<vector<{type_}>>("{prefix}{name}");
|
|
|
+ collection->{name}_loaded = true;
|
|
|
+ }}
|
|
|
+ return (*collection->val_{name})().at(idx);}}
|
|
|
+''')
|
|
|
src.append('};')
|
|
|
|
|
|
src.append(f'''
|