Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ jobs:
tar xzf clara.tar.gz
tar xzf coatjava.tar.gz
- run: ls
- name: run mutil
run: ./coatjava/bin/reco-mutil -y ./etc/services/data-ai.yaml -t 4 -o rec.hipo ./clas_018779.evio.00001
- name: run test
run: ./bin/run-clara -y ./etc/services/data-ai.yaml -t 4 -n 500 -c ./clara -o ./tmp ./clas_018779.evio.00001
- name: ls tmp
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ hs_err_pid*

bin/evio2hipotest
export.sh

*.txt

17 changes: 14 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,24 @@ clara:
- run-clara -v -c $CLARA_HOME -t 4 -y ./etc/services/data-ai.yaml -n 30 -o out $EVIOFILE
- mv out/rec_$EVIOFILE.hipo claroded.hipo

reco-mutil:
stage: test
needs: [build,download]
dependencies: [build,download]
script:
- tar -xzf coatjava.tar.gz
- reco-mutil -t 4 -y ./etc/services/data-ai.yaml -n 30 -o rec_$EVIOFILE.hipo $EVIOFILE

profile:
extends: .clon
allow_failure: true
script:
- ./clara/plugins/clas12/libexec/profile -e cpu -o _clara -- run-clara -c ./clara -y ./etc/services/data-ai.yaml -o tmp1 -t 16 -l $EVIOFILE
- ./clara/plugins/clas12/libexec/profile -e alloc -o _clara -- run-clara -c ./clara -y ./etc/services/data-ai.yaml -o tmp2 -t 16 -l $EVIOFILE
- ./clara/plugins/clas12/libexec/profile -e lock -o _clara -- run-clara -c ./clara -y ./etc/services/data-ai.yaml -o tmp3 -t 16 -l $EVIOFILE
- ./clara/plugins/clas12/libexec/profile -e cpu -o _clara -- run-clara -c ./clara -y ./etc/services/data-ai.yaml -o tmp1 -t 16 $EVIOFILE
- ./clara/plugins/clas12/libexec/profile -e alloc -o _clara -- run-clara -c ./clara -y ./etc/services/data-ai.yaml -o tmp2 -t 16 $EVIOFILE
- ./clara/plugins/clas12/libexec/profile -e lock -o _clara -- run-clara -c ./clara -y ./etc/services/data-ai.yaml -o tmp3 -t 16 $EVIOFILE
- ./clara/plugins/clas12/libexec/profile -e cpu -o _mutil -- reco-mutil -y ./etc/services/data-ai.yaml -o mutil1.hipo -t 16 $EVIOFILE
- ./clara/plugins/clas12/libexec/profile -e alloc -o _mutil -- reco-mutil -y ./etc/services/data-ai.yaml -o mutil2.hipo -t 16 $EVIOFILE
- ./clara/plugins/clas12/libexec/profile -e lock -o _mutil -- reco-mutil -y ./etc/services/data-ai.yaml -o mutil3.hipo -t 16 $EVIOFILE
artifacts:
when: always
expire_in: 1 week
Expand Down
18 changes: 18 additions & 0 deletions bin/reco-mutil
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

. `dirname $0`/../libexec/env.sh

split_cli $@

export MALLOC_ARENA_MAX=1

#threads=$(get_threads)
#node=$(((RANDOM % 2)))
#cpus=$(get_all_numa_cpus $node)
#cpus=$(get_numa_cpus $node)
#taskset -c $cpus \

java ${JAVA_OPTS-} -XX:MaxRAMPercentage=40.0 -Xms10240m ${jvm_options[@]} \
-cp ${COATJAVA_CLASSPATH:-''} \
org.jlab.clas.reco.RecoMutil \
${class_options[@]}
2 changes: 1 addition & 1 deletion bin/recon-util
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

split_cli $@

export MALLOC_ARENA_MAX=1
export MALLOC_ARENA_MAX=12

java ${JAVA_OPTS-} -Xmx1536m -Xms1024m -XX:+UseSerialGC ${jvm_options[@]} \
-cp ${COATJAVA_CLASSPATH:-''} \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
package org.jlab.io.clara;

import java.io.File;
import java.nio.file.Path;
import java.util.List;
import org.jlab.clara.std.services.EventWriterException;
import org.jlab.detector.calib.utils.ConstantsManager;
import org.jlab.detector.helicity.HelicitySequenceDelayed;
import org.jlab.detector.serial.SerialHoncho;
import org.jlab.jnp.hipo4.data.Bank;
import org.jlab.detector.serial.Occupancer;
import org.jlab.io.utils.ParaTrigWriter;
import org.jlab.jnp.hipo4.data.Event;
import org.jlab.jnp.hipo4.data.SchemaFactory;
import org.jlab.jnp.hipo4.io.HipoWriterSorted;
import org.jlab.jnp.utils.file.FileUtils;
import org.json.JSONObject;

/**
*
* 1. Copies certain banks on-the-fly to new tag-1 events
* 2. Caches helicity states, scaler readouts, and unix time
* 3. Writes HEL::flip, RUN/HEL::scaler, and RUN::unix to new tag-1 events
* 4. Runs post-processing, writing tag-1 information to all events
* 5. Adds .hipo to the output filename, if necessary
* 6. Outputs a parallel file of select trigger bits with a raw schema
* @author baltzell
*/
public class Clas12Writer extends HipoToHipoWriter {

Occupancer occupancer;
SerialHoncho serial;
Bank runConfig;
ConstantsManager conman;
SchemaFactory fullSchema;

HipoWriterSorted paraWriter;
long paraCount;
ParaTrigWriter paraWriter;
long paraTriggerMask;
int paraTriggerPrescale;

private void init(JSONObject opts) {
fullSchema = new SchemaFactory();
fullSchema.initFromDirectory(FileUtils.getEnvironmentPath("CLAS12DIR","etc/bankdefs/hipo4"));
serial = new SerialHoncho(fullSchema);
runConfig = new Bank(fullSchema.getSchema("RUN::config"));
occupancer = new Occupancer();
serial = new SerialHoncho();
conman = new ConstantsManager();
conman.init("/runcontrol/hwp","/runcontrol/helicity");
paraTriggerMask = opts.optLong("paraTriggerMask", 0);
Expand All @@ -59,8 +49,7 @@ protected HipoWriterSorted createWriter(Path file, JSONObject opts) throws Event
String basename = file.getFileName().toString();
if (!basename.endsWith(".hipo")) basename += ".hipo";
if (paraTriggerMask > 0) {
paraWriter = new HipoWriterSorted();
paraWriter.getSchemaFactory().copy(fullSchema);
paraWriter = new ParaTrigWriter(paraTriggerMask, paraTriggerPrescale);
paraWriter.open(dirname + "/tb" + basename.substring(basename.indexOf("_")));
}
w.open(dirname + "/" + basename);
Expand All @@ -74,17 +63,11 @@ protected HipoWriterSorted createWriter(Path file, JSONObject opts) throws Event
protected void writeEvent(Object event) throws EventWriterException {
Event t = serial.read((Event)event);
if (!t.isEmpty()) writer.addEvent(t, 1);
occupancer.process(((Event)event));
super.writeEvent(event);
writeRaw((Event)event, t);
}

void writeRaw(Event physics, Event tagged) {
if (paraTriggerMask > 0) {
physics.read(runConfig);
if (runConfig.getRows()>0 && (runConfig.getLong("trigger",0) & paraTriggerMask) != 0)
if (paraTriggerPrescale<=0 || (++paraCount % paraTriggerPrescale) == 0)
paraWriter.addEvent(physics);
if (!tagged.isEmpty()) paraWriter.addEvent(tagged, tagged.getEventTag());
paraWriter.addEvent((Event)event);
if (!t.isEmpty()) paraWriter.addEvent(t, t.getEventTag());
}
}

Expand All @@ -95,5 +78,5 @@ protected void closeWriter() {
serial.clear();
if (paraTriggerMask > 0) paraWriter.close();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
package org.jlab.detector.serial;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Map;
import org.jlab.detector.banks.RawBank;
import org.jlab.utils.groups.IndexedTable;
import org.jlab.utils.groups.IndexedTable.IndexedEntry;
import org.jlab.detector.banks.RawBank.OrderGroups;
import org.jlab.jnp.hipo4.data.Bank;
import org.jlab.jnp.hipo4.data.Event;
import org.jlab.jnp.hipo4.data.Schema;
import org.jlab.jnp.hipo4.data.SchemaFactory;
import org.jlab.utils.CLASResources;
import org.jlab.utils.system.ClasUtilsFile;

/**
* Occupancy bookkeeper based on IndexedTable, with I/O helpers for indexed banks.
*
* @author baltzell
*/
public class Occupancer extends ArrayList<Occupancer.OccupanceTable> {

static final String BANKDIR = ClasUtilsFile.getResourceDir("CLAS12DIR","etc/bankdefs/hipo4/singles/occupancy");
static final SchemaFactory FULL_SCHEMA = CLASResources.getFullSchema();

int prescale = 1000;
int nevents = 0;

public Occupancer() {
super();
init();
}

public Occupancer(int prescale) {
super();
this.prescale = prescale;
init();
}

private void init() {
try {
// Initialize OccupanceTable list, by reading occupancy bank filenames
// and stripping ".json" suffix and "OCC::" prefix to get hit bank name:
addAll(Files.list(Paths.get(BANKDIR))
.filter(Files::isRegularFile)
.map(p -> p.getFileName().toString())
.map(s -> s.substring(0, s.length()-5))
.map(s -> s.substring(5, s.length()))
.map(OccupanceTable::new).toList());
} catch (IOException ex) {
System.getLogger(Occupancer.class.getName()).log(System.Logger.Level.ERROR, (String) null, ex);
}
}

public boolean process(Event event) {
forEach(t -> { t.fill(event, false); });
if (++nevents % prescale == 0) {
forEach(t -> {
if (t.getTable().getRowCount() > 0) {
event.write(t.create(nevents, event));
}
t.reset();
});
nevents = 0;
}
return true;
}

public void reset() {
forEach(t -> { t.reset(); nevents = 0; });
}

public static class OccupanceTable {

Schema occSchema;
Schema hitSchema;
IndexedTable table;

/**
* A 3-index table, e.g., sector/layer/component.
* @param hitBank name of the hit bank
*/
public OccupanceTable(String hitBank) {
hitSchema = FULL_SCHEMA.getSchema(hitBank);
occSchema = FULL_SCHEMA.getSchema("OCC::" + hitBank);
table = new IndexedTable(occSchema.hasEntry("order")?4:3, new String[]{"occ/F"});
}

/**
* An N-index table.
* @param hitBank name of the hit bank
* @param indexCount number of inidices in the hit bank
*/
public OccupanceTable(String hitBank, int indexCount) {
hitSchema = FULL_SCHEMA.getSchema(hitBank);
occSchema = FULL_SCHEMA.getSchema("OCC::" + hitBank);
table = new IndexedTable(indexCount, new String[]{"occ/F"});
}

public final IndexedTable getTable() { return table; }

/**
* Zero the occupancy table.
*/
public final void reset() {
table = new IndexedTable(table.getList().getIndexSize(), new String[]{"occ/F"});
}

/**
* Get the occupancy table, normalized by number of events.
* @param events
* @return
*/
public final IndexedTable getOccupancy(long events) {
IndexedTable t = new IndexedTable(table.getList().getIndexSize(), new String[]{"occ/F"});
for (long hash : ((Map<Long,IndexedEntry>)table.getList().getMap()).keySet()) {
t.addEntry(IndexedTable.DEFAULT_GENERATOR.getIndices(hash, table.getList().getIndexSize()));
t.setDoubleValueByHash((table.getDoubleValueByHash(0, hash))/events, 0, hash);
}
return t;
}

/**
* Fill the occupancy table.
* @param weight
* @param index
*/
public final void fill(float weight, int... index) {
for (int i=0; i<index.length; i++) if (index[i] < 0) return;
final long hash = IndexedTable.DEFAULT_GENERATOR.hashCode(index);
if (!table.hasEntryByHash(hash)) {
table.addEntry(index);
table.setDoubleValueByHash(0.0d, 0, hash);
}
table.setDoubleValueByHash(table.getDoubleValueByHash(0, hash) + weight, 0, hash);
}

/**
* Fill occupancy table from a user-defined bank.
* @param event
* @param weighted
*/
public void fill(Event event, boolean weighted) {
RawBank bank = new RawBank(hitSchema, 1000, OrderGroups.DEFAULT);
bank.read(event);
final int rows = bank.rows();
int[] idx = new int[table.getList().getIndexSize()];
for (int i=0; i<rows; i++) {
for (int j=0; j<table.getList().getIndexSize(); j++) {
if (j==2) idx[j] = bank.getShort(j,i);
else idx[j] = bank.getByte(j,i);
}
if (weighted) fill(bank.getFloat(table.getList().getIndexSize(),i),idx);
else fill(1.0f, idx);
}
}

/**
* Get an occupancy bank, normalized by number of events.
* @param events
* @param event
* @return
*/
public Bank create(long events, Event event) {
Bank b = new Bank(occSchema, table.getRowCount());
Map<Long,IndexedEntry> m = table.getList().getMap();
int i = 0;
for (long hash : m.keySet()) {
int[] idx = IndexedTable.DEFAULT_GENERATOR.getIndices(hash, table.getList().getIndexSize());
for (int j=0; j<table.getList().getIndexSize(); j++) {
if (j == 2) b.putShort(j, i, (short)idx[j]);
else b.putByte(j, i, (byte)idx[j]);
}
b.putFloat(table.getList().getIndexSize(), i, ((float)m.get(hash).getValue(0).intValue())/events);
i++;
}
return b;
}
}
}
Loading
Loading