Skip to content

Commit 06d5068

Browse files
committed
cleanup initialization
1 parent d5d6cd3 commit 06d5068

1 file changed

Lines changed: 18 additions & 32 deletions

File tree

‎common-tools/clara-io/src/main/java/org/jlab/io/clara/HipoToHipoWriter.java‎

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ public class HipoToHipoWriter extends AbstractEventWriterService<HipoWriterSorte
3030
private static final String CONF_SCHEMA_WILDCARD = "wildcard";
3131
private static final String CONF_SCHEMA_PRESCALE = "schema_prescale";
3232

33-
protected final List<Bank> schemaBankList = new ArrayList<Bank>();
33+
protected final List<Bank> schemaBankList = new ArrayList<>();
3434
private final StringSubstitutor envSubstitutor = new StringSubstitutor(System.getenv());
3535

36-
private int compression = 2;
3736
protected String filename;
3837

3938
private long schemaPrescaleEvents = 0;
@@ -54,22 +53,18 @@ protected HipoWriterSorted createWriter(Path file, JSONObject opts) throws Event
5453

5554
protected void configure(HipoWriterSorted writer, JSONObject opts) {
5655

57-
// set prescale:
58-
if (opts.has(CONF_SCHEMA_PRESCALE)) {
59-
schemaPrescale = opts.getInt(CONF_SCHEMA_PRESCALE);
60-
}
61-
62-
// set compression:
63-
if (opts.has(CONF_COMPRESSION)) {
64-
compression = opts.getInt(CONF_COMPRESSION);
65-
}
66-
writer.setCompressionType(compression);
56+
// set schema prescale factor:
57+
schemaPrescale = opts.optInt(CONF_SCHEMA_PRESCALE, 0);
6758

6859
// create full schema:
6960
SchemaFactory fullSchema = new SchemaFactory();
7061
fullSchema.initFromDirectory(FileUtils.getEnvironmentPath("CLAS12DIR","etc/bankdefs/hipo4"));
7162

72-
// choose user schema directory:
63+
// set writer compression and schema:
64+
writer.setCompressionType(opts.optInt(CONF_COMPRESSION, 2));
65+
writer.getSchemaFactory().copy(fullSchema);
66+
67+
// choose schema directory:
7368
String schemaDir = FileUtils.getEnvironmentPath("CLAS12DIR", "etc/bankdefs/hipo4");
7469
if (opts.has(CONF_SCHEMA_DIR)) {
7570
// Run YAML values throuh env-substitor:
@@ -81,37 +76,28 @@ protected void configure(HipoWriterSorted writer, JSONObject opts) {
8176
System.out.printf("%s service: schema directory = %s%n", getName(), schemaDir);
8277
}
8378

84-
// create user schemaa:
79+
// create schema from chosen directory:
8580
SchemaFactory factory = new SchemaFactory();
8681
factory.initFromDirectory(schemaDir);
8782

88-
// set the writer's schema factory:
89-
if(opts.has(CONF_SCHEMA_WILDCARD)==true){
90-
// apply a wildcard reduction on the user's schema:
91-
String wildcard = opts.getString("wildcard");
92-
SchemaFactory f2 = factory.reduce(wildcard);
93-
writer.getSchemaFactory().copy(f2);
94-
} else {
95-
writer.getSchemaFactory().copy(factory);
83+
// filter schema by wildcard:
84+
if (opts.has(CONF_SCHEMA_WILDCARD)) {
85+
factory = factory.reduce(opts.getString(CONF_SCHEMA_WILDCARD));
9686
}
97-
87+
9888
// set the bank list for filtering:
9989
schemaBankList.clear();
100-
if (opts.has(CONF_SCHEMA_DIR)==true||opts.has(CONF_SCHEMA_WILDCARD)==true) {
90+
if (opts.has(CONF_SCHEMA_DIR) || opts.has(CONF_SCHEMA_WILDCARD)) {
10191
boolean useFilter = opts.optBoolean(CONF_SCHEMA_FILTER, true);
10292
System.out.printf("%s service: schema filter = %b%n", getName(), useFilter);
103-
if(useFilter==true){
104-
int schemaSize = writer.getSchemaFactory().getSchemaList().size();
105-
for(int i = 0; i < schemaSize; i++){
106-
Bank dataBank = new Bank(writer.getSchemaFactory().getSchemaList().get(i));
107-
schemaBankList.add(dataBank);
93+
if (useFilter) {
94+
int schemaSize = factory.getSchemaList().size();
95+
for (int i = 0; i < schemaSize; i++) {
96+
schemaBankList.add(new Bank(factory.getSchemaList().get(i)));
10897
}
10998
}
11099
}
111100

112-
// set the writer's schema factory:
113-
writer.getSchemaFactory().copy(fullSchema);
114-
115101
System.out.printf("SERVICE WRITER :: [filter] %s\n",opts.has(HipoToHipoWriter.CONF_SCHEMA_FILTER));
116102
System.out.printf("SERVICE WRITER :: [dir] %s\n",opts.has(HipoToHipoWriter.CONF_SCHEMA_DIR));
117103
System.out.printf("SERVICE WRITER :: [wildcard] %s\n",opts.has(HipoToHipoWriter.CONF_SCHEMA_WILDCARD));

0 commit comments

Comments
 (0)