Skip to content

Commit 01c939c

Browse files
baltzellc-dilks
andauthored
Decoder cleanup (#792)
* relax * add decoder wrapper * cache data from xrootd * fix xrootd path, reduce job length * use old, working path for now * add constructor * reuse parser * fix up test/main method * add missing parse * restore not-really-supported options * Update .github/workflows/ci.yml Co-authored-by: Christopher Dilks <[email protected]> --------- Co-authored-by: Christopher Dilks <[email protected]>
1 parent de44807 commit 01c939c

File tree

4 files changed

+203
-23
lines changed

4 files changed

+203
-23
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ env:
3030

3131
jobs:
3232

33+
# download & cache
34+
#############################################################################
35+
36+
download_test_data:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- uses: actions/cache@v4
40+
id: cache
41+
with:
42+
key: raw_test_data # fixed key will always hit; clear cache to trigger cache miss
43+
path: clas_005038.evio.00000
44+
lookup-only: true
45+
- name: install xrootd-client
46+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
47+
run: |
48+
sudo apt -y update
49+
sudo apt -y install xrootd-client
50+
- name: download
51+
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
52+
run: |
53+
xrdcp xroot://sci-xrootd.jlab.org///osgpool/hallb/clas12/validation/clas_005038.evio.00000 ./
54+
3355
# build
3456
#############################################################################
3557

@@ -104,7 +126,7 @@ jobs:
104126
retention-days: 1
105127

106128
test_decoder:
107-
needs: [ build ]
129+
needs: [ build, download_test_data ]
108130
runs-on: ubuntu-latest
109131
steps:
110132
- uses: actions/checkout@v5
@@ -123,12 +145,14 @@ jobs:
123145
- uses: actions/download-artifact@v5
124146
with:
125147
name: build_ubuntu-latest
148+
- uses: actions/cache/restore@v4
149+
with:
150+
key: raw_test_data
151+
path: clas_005038.evio.00000
126152
- name: untar build
127153
run: tar xzvf coatjava.tar.gz
128154
- name: run test
129-
run: |
130-
xrdcp xroot://sci-xrootd.jlab.org///osgpool/hallb/clas12/validation/clas_005038.evio.00000 .
131-
./coatjava/bin/decoder -n 100000 -o dog.hipo ./clas_005038.evio.00000
155+
run: ./coatjava/bin/decoder -n 10000 -o dog.hipo ./clas_005038.evio.00000
132156

133157
test_coatjava:
134158
needs: [ build ]

common-tools/clas-detector/src/main/java/org/jlab/detector/decode/CLASDecoder4.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
*/
4242
public class CLASDecoder4 {
4343

44+
protected DetectorEventDecoder detectorDecoder = null;
45+
protected SchemaFactory schemaFactory = new SchemaFactory();
4446
private CodaEventDecoder codaDecoder = null;
45-
private DetectorEventDecoder detectorDecoder = null;
4647
private List<DetectorDataDgtz> dataList = new ArrayList<>();
4748
private HipoDataSync writer = null;
4849
private HipoDataEvent hipoEvent = null;
4950
private boolean isRunNumberFixed = false;
5051
private int decoderDebugMode = 0;
51-
private SchemaFactory schemaFactory = new SchemaFactory();
5252
private ModeAHDC ahdcExtractor = new ModeAHDC();
5353
private RCDBManager rcdbManager = new RCDBManager();
5454

@@ -815,21 +815,11 @@ public Event createTaggedEvent(Event e, String... banks) {
815815

816816
public static void main(String[] args){
817817

818-
OptionParser parser = new OptionParser("decoder");
819-
parser.setDescription("CLAS12 Data Decoder");
820-
parser.addOption("-n", "-1", "maximum number of events to process");
821-
parser.addOption("-c", "2", "compression type (0-NONE, 1-LZ4 Fast, 2-LZ4 Best, 3-GZIP)");
818+
OptionParser parser = CLASDecoder4U.getOptionParser();
822819
parser.addOption("-d", "0","debug mode, set >0 for more verbose output");
823820
parser.addOption("-m", "run","translation tables source (use -m devel for development tables)");
824821
parser.addOption("-b", "16","record buffer size in MB");
825-
parser.addOption("-r", "-1","run number in the header bank (-1 means use CODA run)");
826-
parser.addOption("-t", null,"torus current in the header bank (null means use RCDB)");
827-
parser.addOption("-s", null,"solenoid current in the header bank (null means use RCDB)");
828-
parser.addOption("-x", null,"CCDB timestamp (MM/DD/YYYY-HH:MM:SS)");
829-
parser.addOption("-v","default","CCDB variation");
830-
parser.addRequired("-o","output.hipo");
831822
parser.parse(args);
832-
833823
List<String> inputList = parser.getInputList();
834824

835825
if(inputList.isEmpty()==true){
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
package org.jlab.detector.decode;
2+
3+
import java.io.File;
4+
import java.util.ArrayList;
5+
import java.util.TreeSet;
6+
import org.jlab.detector.helicity.HelicitySequence;
7+
import org.jlab.detector.helicity.HelicityState;
8+
import org.jlab.io.evio.EvioDataEvent;
9+
import org.jlab.io.evio.EvioSource;
10+
import org.jlab.jnp.hipo4.data.Bank;
11+
import org.jlab.jnp.hipo4.data.Event;
12+
import org.jlab.jnp.hipo4.io.HipoWriterSorted;
13+
import org.jlab.utils.benchmark.ProgressPrintout;
14+
import org.jlab.utils.options.OptionParser;
15+
import org.jlab.utils.system.ClasUtilsFile;
16+
17+
/**
18+
* Wrapper of everything in CLAS12Decoder4's main method.
19+
*
20+
* @author baltzell
21+
*/
22+
public class CLASDecoder4U extends CLASDecoder4 {
23+
24+
private EvioSource reader;
25+
private HipoWriterSorted writer;
26+
private Bank config;
27+
private Bank helicity;
28+
private ArrayList<String> filenames;
29+
private TreeSet<HelicityState> helicities;
30+
private ProgressPrintout progress;
31+
private Double torus;
32+
private Double solenoid;
33+
private int runNumber;
34+
private int maxEvents;
35+
private int eventCounter;
36+
37+
public CLASDecoder4U(OptionParser o) {
38+
super();
39+
init(o);
40+
}
41+
42+
public CLASDecoder4U(String... filename) {
43+
super();
44+
OptionParser o = getOptionParser();
45+
o.parse(filename);
46+
init(o);
47+
}
48+
49+
public static OptionParser getOptionParser() {
50+
OptionParser p = new OptionParser("decoder");
51+
p.setDescription("CLAS12 Data Decoder");
52+
p.addOption("-n", "-1", "maximum number of events to process");
53+
p.addOption("-c", "2", "compression type (0-NONE, 1-LZ4 Fast, 2-LZ4 Best, 3-GZIP)");
54+
p.addOption("-r", "-1","run number in the header bank (-1 means use CODA run)");
55+
p.addOption("-t", null,"torus current in the header bank (null means use RCDB)");
56+
p.addOption("-s", null,"solenoid current in the header bank (null means use RCDB)");
57+
p.addOption("-x", null,"CCDB timestamp (MM/DD/YYYY-HH:MM:SS)");
58+
p.addOption("-V","default","CCDB variation");
59+
p.addOption("-o",null,"output HIPO filename");
60+
p.setRequiresInputList(true);
61+
return p;
62+
}
63+
64+
public void disableProgressMeter() { progress=null; }
65+
66+
/**
67+
* @return whether there's another event to get
68+
*/
69+
public boolean hasNext() {
70+
if (maxEvents > 0 && eventCounter > maxEvents) return false;
71+
if (reader != null && reader.hasEvent()) return true;
72+
return !filenames.isEmpty();
73+
}
74+
75+
/**
76+
* @return the next event
77+
*/
78+
public Event getNext() {
79+
EvioDataEvent evio = getNextEvioEvent();
80+
Event event = getDecodedEvent(evio, runNumber, eventCounter, torus, solenoid);
81+
if (writer != null) process(event);
82+
if (progress != null) progress.updateStatus();
83+
if (++eventCounter%25000 == 0) System.gc();
84+
return event;
85+
}
86+
87+
/**
88+
* Close the writer, after writing HEL::flip banks.
89+
*/
90+
public void close() {
91+
if (writer != null) {
92+
HelicitySequence.writeFlips(writer, helicities);
93+
writer.close();
94+
}
95+
}
96+
97+
/**
98+
* The command-line "decoder" program.
99+
* @param args
100+
*/
101+
public static void main(String[] args) {
102+
103+
// hijack arguments, when run from an IDE:
104+
if (System.console() == null && args.length == 0) {
105+
// delete output file, if necessary:
106+
File f = new File("tmp.hipo");
107+
if (f.exists()) f.delete();
108+
// setup decoder command-line options:
109+
args = new String[]{"-o","tmp.hipo",System.getenv("HOME")+"/data/clas_005038.evio.00001"};
110+
// try to find bankdefs:
111+
System.setProperty("CLAS12DIR", System.getenv("HOME")+"/sw/coatjava/dev/coatjava");
112+
}
113+
114+
// parse command-line options:
115+
OptionParser opts = CLASDecoder4U.getOptionParser();
116+
opts.parse(args);
117+
118+
// run the decoder:
119+
CLASDecoder4U decoder = new CLASDecoder4U(opts);
120+
while (decoder.hasNext()) decoder.getNext();
121+
decoder.close();
122+
}
123+
124+
private EvioDataEvent getNextEvioEvent() {
125+
if (reader == null || !reader.hasEvent()) {
126+
reader = new EvioSource();
127+
reader.open(filenames.remove(0));
128+
}
129+
return (EvioDataEvent)reader.getNextEvent();
130+
}
131+
132+
private void process(Event event) {
133+
event.read(config);
134+
event.read(helicity);
135+
helicities.add(HelicityState.createFromFadcBank(helicity, config, detectorDecoder.scalerManager));
136+
Event tag = createTaggedEvent(event, "RAW::epics","RAW::scaler","RUN::scaler","HEL::scaler");
137+
if (!tag.isEmpty())
138+
writer.addEvent(tag, 1);
139+
writer.addEvent(event,0);
140+
}
141+
142+
private void init(OptionParser o){
143+
eventCounter = 0;
144+
writer = null;
145+
filenames = new ArrayList<>(o.getInputList());
146+
config = new Bank(schemaFactory.getSchema("RUN::config"));
147+
helicity = new Bank(schemaFactory.getSchema("HEL::adc"));
148+
helicities = new TreeSet<>();
149+
progress = new ProgressPrintout();
150+
torus = o.getOption("-t").getValue()==null?null:o.getOption("-t").doubleValue();
151+
solenoid = o.getOption("-s").getValue()==null?null:o.getOption("-s").doubleValue();
152+
runNumber = o.getOption("-r").intValue();
153+
maxEvents = o.getOption("-n").intValue();
154+
if (runNumber > 0) setRunNumber(runNumber, true);
155+
if (o.getOption("-x").getValue() != null)
156+
detectorDecoder.setTimestamp(o.getOption("-x").stringValue());
157+
if (o.getOption("-v").getValue() != null)
158+
detectorDecoder.setVariation(o.getOption("-v").stringValue());
159+
if (o.getOption("-o").getValue() != null) {
160+
writer = new HipoWriterSorted();
161+
writer.setCompressionType(o.getOption("-c").intValue());
162+
writer.getSchemaFactory().initFromDirectory(ClasUtilsFile.getResourceDir("CLAS12DIR", "etc/bankdefs/hipo4"));
163+
writer.open(o.getOption("-o").stringValue());
164+
}
165+
}
166+
167+
}

common-tools/clas-utils/src/main/java/org/jlab/utils/options/OptionParser.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,15 @@ public static String getVersion(){
215215
}
216216

217217
public static void main(String[] args){
218-
OptionParser parser = new OptionParser();
218+
if (args.length == 0) args = new String[]{"-o","out.dat","in.dat"};
219+
OptionParser parser = new OptionParser("PotionParser");
219220
parser.addRequired("-o");
220221
parser.addOption("-r", "10");
221222
parser.addOption("-t", "25.0");
222223
parser.addOption("-d", "35");
223-
parser.addOption("-h","helpless");
224-
parser.addOption("-v","versionless");
225-
if (args.length == 0) parser.parse("-o","out.dat","in.dat");
226-
else parser.parse(args);
227-
parser.show();
224+
parser.show();
225+
parser.parse(args);
226+
System.out.println("INPUTLIST: "+parser.getInputList());
228227
parser.parse("-h");
229228
}
230229
}

0 commit comments

Comments
 (0)