@@ -31,7 +31,7 @@ public class HipoToHipoWriter extends AbstractEventWriterService<HipoWriterSorte
3131 private static final String CONF_SCHEMA_PRESCALE = "schema_prescale" ;
3232
3333 protected final List <Bank > schemaBankList = new ArrayList <>();
34- private final StringSubstitutor envSubstitutor = new StringSubstitutor (System .getenv ());
34+ private static final StringSubstitutor envSubstitutor = new StringSubstitutor (System .getenv ());
3535
3636 protected String filename ;
3737
@@ -51,6 +51,19 @@ protected HipoWriterSorted createWriter(Path file, JSONObject opts) throws Event
5151 }
5252 }
5353
54+ static String chooseSchemaDirectory (JSONObject opts ) {
55+ String schemaDir = FileUtils .getEnvironmentPath ("CLAS12DIR" , "etc/bankdefs/hipo4" );
56+ if (opts .has (CONF_SCHEMA_DIR )) {
57+ // Run YAML values throuh env-substitor:
58+ schemaDir = opts .getString (CONF_SCHEMA_DIR ).trim ();
59+ schemaDir = envSubstitutor .replace (schemaDir );
60+ // If it's not already an absolute path, assume it's the name of a
61+ // stock schema that comes with COATJAVA and get the full path to it:
62+ if (!schemaDir .startsWith ("/" )) schemaDir = ClaraYaml .getStockSchemaDirectory (schemaDir );
63+ }
64+ return schemaDir ;
65+ }
66+
5467 protected void configure (HipoWriterSorted writer , JSONObject opts ) {
5568
5669 // set schema prescale factor:
@@ -64,33 +77,18 @@ protected void configure(HipoWriterSorted writer, JSONObject opts) {
6477 writer .setCompressionType (opts .optInt (CONF_COMPRESSION , 2 ));
6578 writer .getSchemaFactory ().copy (fullSchema );
6679
67- // choose schema directory:
68- String schemaDir = FileUtils .getEnvironmentPath ("CLAS12DIR" , "etc/bankdefs/hipo4" );
69- if (opts .has (CONF_SCHEMA_DIR )) {
70- // Run YAML values throuh env-substitor:
71- schemaDir = opts .getString (CONF_SCHEMA_DIR ).trim ();
72- schemaDir = envSubstitutor .replace (schemaDir );
73- // If it's not already an absolute path, assume it's the name of a
74- // stock schema that comes with COATJAVA and get the full path to it:
75- if (!schemaDir .startsWith ("/" )) schemaDir = ClaraYaml .getStockSchemaDirectory (schemaDir );
76- System .out .printf ("%s service: schema directory = %s%n" , getName (), schemaDir );
77- }
78-
79- // create schema from chosen directory:
80+ // create schema from chosen directory and wildcard reduce:
81+ String schemaDir = chooseSchemaDirectory (opts );
8082 SchemaFactory factory = new SchemaFactory ();
8183 factory .initFromDirectory (schemaDir );
82-
83- // filter schema by wildcard:
8484 if (opts .has (CONF_SCHEMA_WILDCARD )) {
8585 factory = factory .reduce (opts .getString (CONF_SCHEMA_WILDCARD ));
8686 }
8787
88- // set the bank list for filtering:
88+ // set the resulting bank list for filtering:
8989 schemaBankList .clear ();
9090 if (opts .has (CONF_SCHEMA_DIR ) || opts .has (CONF_SCHEMA_WILDCARD )) {
91- boolean useFilter = opts .optBoolean (CONF_SCHEMA_FILTER , true );
92- System .out .printf ("%s service: schema filter = %b%n" , getName (), useFilter );
93- if (useFilter ) {
91+ if (opts .optBoolean (CONF_SCHEMA_FILTER , true )) {
9492 int schemaSize = factory .getSchemaList ().size ();
9593 for (int i = 0 ; i < schemaSize ; i ++) {
9694 schemaBankList .add (new Bank (factory .getSchemaList ().get (i )));
@@ -103,10 +101,6 @@ protected void configure(HipoWriterSorted writer, JSONObject opts) {
103101 System .out .printf ("SERVICE WRITER :: [wildcard] %s\n " ,opts .has (HipoToHipoWriter .CONF_SCHEMA_WILDCARD ));
104102 }
105103
106- private Method getSchemaFilterSetter () throws NoSuchMethodException , SecurityException {
107- return HipoWriter .class .getMethod ("setSchemaFilter" , boolean .class );
108- }
109-
110104 @ Override
111105 protected void closeWriter () {
112106 writer .close ();
0 commit comments