-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
edm4hep2json: All EDM4hep collections + ROOT legacy reader (#227)
* All EDM4hep collections + ROOT legacy reader * Add EDM4hep version to the output * Adding test which checks for all the collections
- Loading branch information
Showing
5 changed files
with
227 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
if (nlohmann_json_FOUND) | ||
add_test(NAME convert_events | ||
COMMAND edm4hep2json ${CMAKE_CURRENT_BINARY_DIR}/../edm4hep_events.root) | ||
set_property(TEST convert_events PROPERTY DEPENDS write_events) | ||
set_test_env(convert_events) | ||
|
||
add_test(NAME test_convert_all_collections | ||
COMMAND python ${CMAKE_CURRENT_LIST_DIR}/test_all_collections.py | ||
${PROJECT_SOURCE_DIR}/edm4hep.yaml | ||
${PROJECT_SOURCE_DIR}/tools/include/edm4hep2json.hxx) | ||
set_test_env(test_convert_all_collections) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
''' | ||
Tests if all datatypes are used in the cxx file. | ||
''' | ||
|
||
import sys | ||
import re | ||
import argparse | ||
import yaml | ||
|
||
|
||
def test(yamlfile_path, cxxfile_path): | ||
''' | ||
Test itself. | ||
Takes two parameters, Podio YAML file location and cxx file to be checked. | ||
''' | ||
|
||
with open(yamlfile_path, mode='r', encoding="utf-8") as yamlfile: | ||
datamodel = yaml.safe_load(yamlfile) | ||
|
||
# List stores lines of cxx code on which `insertToJson<CollType>` is used | ||
datatypes_found = [] | ||
|
||
with open(cxxfile_path, mode='r', encoding="utf-8") as cxxfile: | ||
for cxxline in cxxfile: | ||
cxxline = cxxfile.readline() | ||
result = re.search('insertIntoJson<edm4hep::(.+?)Collection>', | ||
cxxline) | ||
if result: | ||
datatypes_found += ['edm4hep::' + result.group(1)] | ||
|
||
datatypes_found = set(datatypes_found) | ||
|
||
datatypes = set(datamodel['datatypes']) | ||
|
||
if not datatypes.issubset(datatypes_found): | ||
missing_datatypes = datatypes - datatypes_found | ||
print('ERROR: One or more datatypes are not being converted:') | ||
for datatype in missing_datatypes: | ||
print(' ' + datatype) | ||
sys.exit(2) | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Test all collections') | ||
parser.add_argument('yamlfile') | ||
parser.add_argument('cxxfile') | ||
args = parser.parse_args() | ||
|
||
test(args.yamlfile, args.cxxfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.