|
| 1 | +package org.jlab.io.clara; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import org.jlab.jnp.hipo4.data.Bank; |
| 5 | +import org.jlab.jnp.hipo4.data.Event; |
| 6 | +import org.jlab.jnp.hipo4.data.SchemaFactory; |
| 7 | +import org.jlab.jnp.hipo4.io.HipoWriterSorted; |
| 8 | + |
| 9 | +public class Tagger { |
| 10 | + |
| 11 | + byte tag; |
| 12 | + Bank runConfig; |
| 13 | + ArrayList<Bank> taggerBanks; |
| 14 | + ArrayList<Bank> antiTaggerBanks; |
| 15 | + SchemaFactory schemaFactory; |
| 16 | + |
| 17 | + public Tagger(SchemaFactory schema, int tag, String... banks) { |
| 18 | + this.tag = (byte)tag; |
| 19 | + taggerBanks = new ArrayList<>(); |
| 20 | + schemaFactory = schema; |
| 21 | + runConfig = new Bank(schemaFactory.getSchema("RUN::config")); |
| 22 | + for (String bank : banks) taggerBanks.add(new Bank(schema.getSchema(bank))); |
| 23 | + for (Bank sBank : schema.getBanks()) { |
| 24 | + boolean found = false; |
| 25 | + for (Bank tBank : taggerBanks) { |
| 26 | + if (tBank.getSchema().getName().equals(sBank.getSchema().getName())) { |
| 27 | + found = true; |
| 28 | + break; |
| 29 | + } |
| 30 | + } |
| 31 | + if (!found) antiTaggerBanks.add(new Bank(sBank.getSchema())); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + public void tagAndWrite(HipoWriterSorted writer, Event event) { |
| 36 | + if (event.getEventTag() == 0) { |
| 37 | + Event t = new Event(); |
| 38 | + for (Bank b : taggerBanks) { |
| 39 | + event.read(b); |
| 40 | + if (b.getRows() > 0) t.write(b); |
| 41 | + } |
| 42 | + if (!t.isEmpty()) { |
| 43 | + event.read(runConfig); |
| 44 | + t.write(runConfig); |
| 45 | + writer.addEvent(t, tag); |
| 46 | + event.reduceEvent(antiTaggerBanks); |
| 47 | + } |
| 48 | + } |
| 49 | + writer.addEvent(event, event.getEventTag()); |
| 50 | + } |
| 51 | +} |
0 commit comments