diff --git a/common-tools/clara-io/src/main/java/org/jlab/io/clara/HipoToHipoWriter.java b/common-tools/clara-io/src/main/java/org/jlab/io/clara/HipoToHipoWriter.java index df83b1c069..cda04c0232 100644 --- a/common-tools/clara-io/src/main/java/org/jlab/io/clara/HipoToHipoWriter.java +++ b/common-tools/clara-io/src/main/java/org/jlab/io/clara/HipoToHipoWriter.java @@ -28,13 +28,16 @@ public class HipoToHipoWriter extends AbstractEventWriterService schemaBankList = new ArrayList(); - private final StringSubstitutor envSubstitutor = new StringSubstitutor(System.getenv()); + protected final List schemaBankList = new ArrayList<>(); + private static final StringSubstitutor envSubstitutor = new StringSubstitutor(System.getenv()); - private int compression = 2; protected String filename; + private long schemaPrescaleEvents = 0; + private int schemaPrescale = 0; + @Override protected HipoWriterSorted createWriter(Path file, JSONObject opts) throws EventWriterException { try { @@ -48,14 +51,7 @@ protected HipoWriterSorted createWriter(Path file, JSONObject opts) throws Event } } - protected void configure(HipoWriterSorted writer, JSONObject opts) { - schemaBankList.clear(); - if (opts.has(CONF_COMPRESSION)) { - compression = opts.getInt(CONF_COMPRESSION); - System.out.printf("%s service: compression level = %d%n", getName(), compression); - } - writer.setCompressionType(compression); - + static String chooseSchemaDirectory(JSONObject opts) { String schemaDir = FileUtils.getEnvironmentPath("CLAS12DIR", "etc/bankdefs/hipo4"); if (opts.has(CONF_SCHEMA_DIR)) { // Run YAML values throuh env-substitor: @@ -64,28 +60,38 @@ protected void configure(HipoWriterSorted writer, JSONObject opts) { // If it's not already an absolute path, assume it's the name of a // stock schema that comes with COATJAVA and get the full path to it: if (!schemaDir.startsWith("/")) schemaDir = ClaraYaml.getStockSchemaDirectory(schemaDir); - System.out.printf("%s service: schema directory = %s%n", getName(), schemaDir); } + return schemaDir; + } + + protected void configure(HipoWriterSorted writer, JSONObject opts) { + + // set schema prescale factor: + schemaPrescale = opts.optInt(CONF_SCHEMA_PRESCALE, 0); + // create full schema: + SchemaFactory fullSchema = new SchemaFactory(); + fullSchema.initFromDirectory(FileUtils.getEnvironmentPath("CLAS12DIR","etc/bankdefs/hipo4")); + + // set writer compression and schema: + writer.setCompressionType(opts.optInt(CONF_COMPRESSION, 2)); + writer.getSchemaFactory().copy(fullSchema); + + // create schema from chosen directory and wildcard reduce: + String schemaDir = chooseSchemaDirectory(opts); SchemaFactory factory = new SchemaFactory(); factory.initFromDirectory(schemaDir); - - if(opts.has(CONF_SCHEMA_WILDCARD)==true){ - String wildcard = opts.getString("wildcard"); - SchemaFactory f2 = factory.reduce(wildcard); - writer.getSchemaFactory().copy(f2); - } else { - writer.getSchemaFactory().copy(factory); + if (opts.has(CONF_SCHEMA_WILDCARD)) { + factory = factory.reduce(opts.getString(CONF_SCHEMA_WILDCARD)); } - if (opts.has(CONF_SCHEMA_DIR)==true||opts.has(CONF_SCHEMA_WILDCARD)==true) { - boolean useFilter = opts.optBoolean(CONF_SCHEMA_FILTER, true); - System.out.printf("%s service: schema filter = %b%n", getName(), useFilter); - if(useFilter==true){ - int schemaSize = writer.getSchemaFactory().getSchemaList().size(); - for(int i = 0; i < schemaSize; i++){ - Bank dataBank = new Bank(writer.getSchemaFactory().getSchemaList().get(i)); - schemaBankList.add(dataBank); + // set the resulting bank list for filtering: + schemaBankList.clear(); + if (opts.has(CONF_SCHEMA_DIR) || opts.has(CONF_SCHEMA_WILDCARD)) { + if (opts.optBoolean(CONF_SCHEMA_FILTER, true)) { + int schemaSize = factory.getSchemaList().size(); + for (int i = 0; i < schemaSize; i++) { + schemaBankList.add(new Bank(factory.getSchemaList().get(i))); } } } @@ -95,10 +101,6 @@ protected void configure(HipoWriterSorted writer, JSONObject opts) { System.out.printf("SERVICE WRITER :: [wildcard] %s\n",opts.has(HipoToHipoWriter.CONF_SCHEMA_WILDCARD)); } - private Method getSchemaFilterSetter() throws NoSuchMethodException, SecurityException { - return HipoWriter.class.getMethod("setSchemaFilter", boolean.class); - } - @Override protected void closeWriter() { writer.close(); @@ -107,7 +109,7 @@ protected void closeWriter() { public static void writeEvent(HipoWriterSorted w, Event e, List schema) { int tag = e.getEventTag(); - if (tag==1 || schema.isEmpty()) { + if (tag==1 || schema == null || schema.isEmpty()) { w.addEvent(e,tag); } else { @@ -118,7 +120,10 @@ public static void writeEvent(HipoWriterSorted w, Event e, List schema) { @Override protected void writeEvent(Object event) throws EventWriterException { try { - writeEvent(writer, (Event)event, schemaBankList); + if (schemaPrescale <= 0 || (++schemaPrescaleEvents % schemaPrescale) != 0) + writeEvent(writer, (Event)event, schemaBankList); + else + writeEvent(writer, (Event)event, null); } catch (Exception e) { throw new EventWriterException(e); } diff --git a/etc/services/rgd-clarode.yml b/etc/services/rgd-clarode.yml index e46daddc7e..5625ac0b2a 100644 --- a/etc/services/rgd-clarode.yml +++ b/etc/services/rgd-clarode.yml @@ -7,6 +7,7 @@ configuration: io-services: writer: schema_dir: dst + schema_prescale: 100 services: MAGFIELDS: magfieldSolenoidMap: Symm_solenoid_r601_phi1_z1201_13June2018.dat