Skip to content
Open
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ target
/docs/javadoc/*
/clara-home
tmp
/common-tools/clas-io/src/main/java/org/jlab/io/banks

# deployment
/myLocalMvnRepo
Expand Down
41 changes: 41 additions & 0 deletions common-tools/clas-io/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,45 @@

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>bank-schema-enums</id>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<inherited>false</inherited>
<configuration>
<target>
<exec executable="python3">
<arg value="../../libexec/bank-schema-enums"/>
</exec>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<filesets>
<fileset>
<directory>src/main/java/org/jlab/io/banks</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>

</project>
18 changes: 18 additions & 0 deletions libexec/bank-schema-enums
Comment thread
baltzell marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3
import os,glob,json
top = os.path.normpath(os.path.dirname(os.path.abspath(__file__))+'/..')
idir = top+'/etc/bankdefs/hipo4'
odir = top+'/common-tools/clas-io/src/main/java/org/jlab/io/banks'
print(f'INFO: Creating schema enums at {odir}')
os.makedirs(odir, exist_ok=True)
for x in glob.glob(f'{idir}/*.json'):
for bank in json.load(open(x,'r')):
class_name = bank['name'].replace('::','_').replace(':','_')
with open(f'{odir}/{class_name}.java','w') as f:
f.write('package org.jlab.io.banks;\n')
f.write(f'public class {class_name} {{\n')
for i,entry in enumerate(bank['entries']):
var_name = entry['name']
f.write(f' public static final short {var_name} = {i};\n')
f.write('}\n')
f.close()