Skip to content

Commit e6df0d2

Browse files
baltzellNathan Baltzellraffaelladevita
authored
feat: detector changed hook (JeffersonLab#1211)
* remove unused stuff * add detectorChanged method (and remove unused imports) * fix formatting * implement all detectorChanged hooks (and cleanup/formatting) * synchronize and count changes * allow nulls * add empty list check * cleanup/formatting * use the same wrapper used in clara/recon-util * hardcode it to 11 for now * implement detectorChanged for cvt * implement detector changed for dc * use the same wrapper used in clara/recon-util * fix logic oops * rename processDataEvent/processEvent * make MLTDEngine respect run number like everyone else, unless overriden from YAML * add newly-required methods * restore initialization * allow run number override from YAML * add missing overrides * remove mc/data check * processDataEvent should be final * cleanup script * remove unused/unnecessary script * add neutron test * abort on error * fix rebase mistake * add missing overrides * add missing overrides * add missing overrides * accounting for tstart, tflight and tprop in MC tracks reconstruction * removed check on run number when setting the DC hit uncertainty * removed hardcoded change to default variation in BAND engine * apply TDC jitter correction only if TI timestamp is >0, excluding MC events * moved RF offsets to time written to RUN::rf bank * fixed bug in REC::Event.RFTime introduced with last commit * restored TDC jitter correction for timestamp=0 * switch to load geometry for real run number * fix env * add missing override * remove unused imports * add missing overrides * add missing overrides * propagate detectorChanged and method renaming to new UberEngine * changed EC to load the geometry with the real run number * fix merge mistake * undoing RF offset changes * add missing overrides * updated use of geometry factory in URWT engine * cleanup * add detector changed hooks * switch eb tests to gemc/6.0 * bugfix * updated yamls for MC --------- Co-authored-by: Nathan Baltzell <baltzell@baltzellmac.jlab.org> Co-authored-by: Raffaella De Vita <devita@ge.infn.it>
1 parent c964a4d commit e6df0d2

77 files changed

Lines changed: 497 additions & 662 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,16 @@ jobs:
271271
id:
272272
- kpp
273273
- eb-ep
274+
- eb-en
274275
- eb-eg
275276
- eb-epc
276277
- eb-enc
277278
- eb-eftpi
278279
include:
279-
# run all tests on ubuntu
280+
# run selected tests on ubuntu
280281
- { id: kpp, cmd: ./run-advanced-tests.sh }
281282
- { id: eb-ep, cmd: ./run-eb-tests.sh -100 electronproton }
283+
- { id: eb-en, cmd: ./run-eb-tests.sh -100 electronneutron }
282284
- { id: eb-eg, cmd: ./run-eb-tests.sh -100 electrongamma }
283285
- { id: eb-epc, cmd: ./run-eb-tests.sh -100 electronprotonC }
284286
- { id: eb-enc, cmd: ./run-eb-tests.sh -100 electronneutronC }

‎common-tools/clas-decay-tools/src/main/java/org/jlab/clas/decay/analysis/Analysis.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void setFieldsConfig(String fieldsConfig) {
6767

6868

6969
@Override
70-
public boolean processDataEvent(DataEvent event) {
70+
public boolean processDataEventUser(DataEvent event) {
7171
Reader reader ;
7272
this.FieldsConfig = this.getFieldsConfig();
7373
if (event.hasBank("RUN::config") == false) {
@@ -250,5 +250,7 @@ public double[] getBeamSpot(DataEvent event, IndexedTable beamPos) {
250250
}
251251
return xybeam;
252252
}
253+
254+
public void detectorChanged(int run) {}
253255

254256
}

‎common-tools/clas-io/src/main/java/org/jlab/utils/JsonUtils.java‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ public static JsonObject Map2Json(Map<String,Object> map) {
113113
ret.add(topKey,Map2Json((Map)entry.getValue()));
114114
}
115115
else {
116-
if(entry.getValue() != null) {
117-
ret.add(topKey, entry.getValue().toString());
118-
}
116+
ret.add(topKey, entry.getValue() == null ? null : entry.getValue().toString());
119117
}
120118
}
121119
return ret;

‎common-tools/clas-reco/src/main/java/org/jlab/clas/reco/EngineProcessor.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public void init(){
282282
public void processEvent(DataEvent event){
283283
for(Map.Entry<String,ReconstructionEngine> engine : this.processorEngines.entrySet()){
284284
try {
285-
engine.getValue().filterEvent(event);
285+
engine.getValue().processDataEvent(event);
286286
} catch (Exception e){
287287
LOGGER.log(Level.SEVERE, "[Exception] >>>>> engine : {0}\n\n", engine.getKey());
288288
e.printStackTrace();

‎common-tools/clas-reco/src/main/java/org/jlab/clas/reco/ReconstructionEngine.java‎

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.nio.ByteBuffer;
44
import java.nio.ByteOrder;
5+
import java.util.ArrayList;
56
import java.util.Arrays;
67
import java.util.HashMap;
78
import java.util.HashSet;
@@ -60,14 +61,22 @@ public abstract class ReconstructionEngine implements Engine {
6061
volatile boolean dropOutputBanks = false;
6162
private final Set<String> outputBanks = new HashSet<>();
6263

64+
private volatile List<Integer> runNumbers = new ArrayList<>();
65+
6366
private boolean ignoreInvalidRunNumbers = true;
6467

68+
private int runNumberOverride = -1;
69+
6570
volatile long triggerMask = 0xFFFFFFFFFFFFFFFFL;
6671

67-
String engineName = "UnknownEngine";
68-
String engineAuthor = "N.T.";
69-
String engineVersion = "0.0";
70-
String engineDescription = "CLARA Engine";
72+
String engineName = "UnknownEngine";
73+
String engineAuthor = "N.T.";
74+
String engineVersion = "0.0";
75+
String engineDescription = "CLARA Engine";
76+
77+
abstract public boolean processDataEventUser(DataEvent event);
78+
abstract public boolean init();
79+
abstract public void detectorChanged(int runNumber);
7180

7281
public ReconstructionEngine(String name, String author, String version){
7382
engineName = name;
@@ -108,9 +117,6 @@ protected RawBank getRawBankReader(String bankName, OrderType... order) {
108117
return new RawDataBank(bankName, order);
109118
}
110119

111-
abstract public boolean processDataEvent(DataEvent event);
112-
abstract public boolean init();
113-
114120
/**
115121
* Use a map just to avoid name clash in ConstantsManager.
116122
* @param tables map of table names to #indices
@@ -187,6 +193,9 @@ public EngineData configure(EngineData ed) {
187193
engineDictionary = new SchemaFactory();
188194
LOGGER.log(Level.FINEST,"--- engine configuration is called " + this.getDescription());
189195
try {
196+
if (this.getEngineConfigString("runNumberOverride")!=null) {
197+
this.runNumberOverride = Integer.valueOf(this.getEngineConfigString("runNumberOverride"));
198+
}
190199
if (this.getEngineConfigString("rawBankGroup")!=null) {
191200
this.rawBankOrders = RawBank.getFilterGroup(this.getEngineConfigString("rawBankGroup"));
192201
}
@@ -227,8 +236,7 @@ public EngineData configure(EngineData ed) {
227236
}
228237

229238
protected String getStringConfigParameter(String jsonString,
230-
String key) throws Exception {
231-
Object js;
239+
String key) throws Exception {
232240
String variation = "";
233241
try {
234242
JSONObject base = new JSONObject(jsonString);
@@ -238,13 +246,6 @@ protected String getStringConfigParameter(String jsonString,
238246
} else {
239247
LOGGER.log(Level.FINE,"[JSON]" + this.getName() + " **** warning **** does not contain key = " + key);
240248
}
241-
/*
242-
js = base.get(key);
243-
if (js instanceof String) {
244-
return (String) js;
245-
} else {
246-
throw new Exception("JSONObject[" + "] not a string.");
247-
}*/
248249
} catch (JSONException e) {
249250
throw new Exception(e.getMessage());
250251
}
@@ -345,17 +346,22 @@ public void dropBanks(DataEvent event) {
345346
}
346347
}
347348
}
348-
349-
public boolean checkRunNumber(DataEvent event) {
350-
if (!this.ignoreInvalidRunNumbers) return true;
351-
int run = 0;
352-
if (event.hasBank("RUN::config")) {
353-
run = event.getBank("RUN::config").getInt("run",0);
349+
350+
public synchronized boolean checkRunNumber(DataEvent event) {
351+
int r = runNumberOverride;
352+
if (r <= 0 && event.hasBank("RUN::config")) {
353+
r = event.getBank("RUN::config").getInt("run",0);
354354
}
355-
return run>0;
355+
if (r > 0) {
356+
if (this.runNumbers.isEmpty() || r != this.runNumbers.get(this.runNumbers.size()-1)) {
357+
this.runNumbers.add(r);
358+
this.detectorChanged(r);
359+
}
360+
}
361+
return !this.ignoreInvalidRunNumbers || r>0;
356362
}
357363

358-
public void filterEvent(DataEvent dataEvent) {
364+
public void processDataEvent(DataEvent dataEvent) {
359365
if (!this.wroteConfig) {
360366
this.wroteConfig = true;
361367
JsonUtils.extend(dataEvent, CONFIG_BANK_NAME, "json", this.generateConfig());
@@ -365,7 +371,7 @@ public void filterEvent(DataEvent dataEvent) {
365371
}
366372
if(this.applyTriggerMask(dataEvent)) {
367373
if (this.checkRunNumber(dataEvent)) {
368-
this.processDataEvent(dataEvent);
374+
this.processDataEventUser(dataEvent);
369375
}
370376
}
371377
}
@@ -404,7 +410,7 @@ public EngineData execute(EngineData input) {
404410
}
405411

406412
try {
407-
this.filterEvent(dataEventHipo);
413+
this.processDataEvent(dataEventHipo);
408414
output.setData(mt, dataEventHipo.getHipoEvent());
409415
} catch (Exception e) {
410416
String msg = String.format("Error processing input event%n%n%s", ClaraUtil.reportException(e));
@@ -519,16 +525,21 @@ public Reco(){
519525
super("a","b","c");
520526
}
521527
@Override
522-
public boolean processDataEvent(DataEvent event) {
523-
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
528+
public boolean processDataEventUser(DataEvent event) {
529+
throw new UnsupportedOperationException("Not supported yet.");
524530
}
525531

526532
@Override
527533
public boolean init() {
528-
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
534+
throw new UnsupportedOperationException("Not supported yet.");
529535
}
530-
531-
}
536+
537+
@Override
538+
public void detectorChanged(int runNumber) {
539+
throw new UnsupportedOperationException("Not supported yet.");
540+
}
541+
}
542+
532543
public static void main(String[] args){
533544
System.setProperty("CLAS12DIR", "/Users/gavalian/Work/Software/project-3a.0.0/Distribution/clas12-offline-software/coatjava");
534545
try {
@@ -549,7 +560,6 @@ public static void main(String[] args){
549560
"\"timestamp\":333\n" +
550561
"}";
551562
System.out.println(json);
552-
//json = "{ \"ccdb\":{\"run\":10,\"variation\":\"default\"}, \"variation\":\"cosmic\"}";
553563
Reco reco = new Reco();
554564
String variation = reco.getStringConfigParameter(json, "variation");
555565
System.out.println(" Variation : " + variation);

‎common-tools/clas-reco/src/main/java/org/jlab/clas/reco/UberEngine.java‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected void add(ReconstructionEngine... e) {
3030
}
3131

3232
@Override
33-
public boolean processDataEvent(DataEvent event) {
33+
public boolean processDataEventUser(DataEvent event) {
3434
throw new RuntimeException("UberEngine does not implement processDataEvent.");
3535
}
3636

@@ -39,9 +39,9 @@ public boolean processDataEvent(DataEvent event) {
3939
* @param event
4040
*/
4141
@Override
42-
public final void filterEvent(DataEvent event) {
42+
public final void processDataEvent(DataEvent event) {
4343
for (ReconstructionEngine e : engines)
44-
e.filterEvent(event);
44+
e.processDataEvent(event);
4545
}
4646

4747
/**
@@ -55,6 +55,16 @@ public final boolean init() {
5555
if (!e.init()) ret = false;
5656
return ret;
5757
}
58+
59+
/**
60+
* Run all engines' dettectorChanged methods.
61+
* @param runNumber
62+
*/
63+
@Override
64+
public final void detectorChanged(int runNumber) {
65+
for (ReconstructionEngine e : engines)
66+
e.detectorChanged(runNumber);
67+
}
5868

5969
/**
6070
* Run all engines' configure methods.

‎common-tools/swim-tools/src/main/java/org/jlab/clas/swimtools/MagFieldsEngine.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private void loadTables() {
162162
}
163163

164164
@Override
165-
public boolean processDataEvent(DataEvent event) {
165+
public boolean processDataEventUser(DataEvent event) {
166166
DataBank bank = event.getBank("RUN::config");
167167
// Load the constants
168168
// -------------------
@@ -195,4 +195,6 @@ public boolean init() {
195195
return true;
196196
}
197197

198+
@Override
199+
public void detectorChanged(int runNumber) {}
198200
}

‎etc/services/mc-ai.yaml‎

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,14 @@ services:
1818
name: FTEB
1919
- class: org.jlab.service.raster.RasterEngine
2020
name: RASTER
21-
# DC clustering: nominal algoritm, filled the cluster bank for ai and conventional tracking
21+
- class: org.jlab.service.ai.DCDenoiseEngine
22+
name: DCDN
2223
- class: org.jlab.service.dc.DCHBClustering
2324
name: DCCR
24-
# This is where the AI plugin would go. THe AI code reads the HB clusters.
25-
- class: org.jlab.service.mltn.MLTDEngine
26-
name: MLTD
27-
# DC using clustering on AI hits: NN assisted HB tracking
28-
- class: org.jlab.service.dc.DCHBPostClusterAI
29-
name: DCHAI
25+
- class: org.jlab.service.ai.DCClsComboEngine
26+
name: DCCC
27+
- class: org.jlab.service.dc.DCHBTrackingAI
28+
name: DCHTAI
3029
- class: org.jlab.service.ftof.FTOFHBEngine
3130
name: FTOFHB
3231
- class: org.jlab.service.ec.ECEngine
@@ -64,11 +63,10 @@ services:
6463
- class: org.jlab.calibration.service.CalibBanksEngine
6564
name: CALIB
6665
configuration:
67-
# global:
68-
# variation: rga_fall2018_mc
69-
# timestamp: 12/31/2020-00:00:00
70-
# dcMinistagger: "NOTONREFWIRE"
71-
# dcFeedthroughs: "OFF"
66+
global:
67+
variation: mc2026
68+
dcMinistagger: "NOTONREFWIRE"
69+
dcFeedthroughs: "OFF"
7270
io-services:
7371
writer:
7472
schema_dir: dst
@@ -77,9 +75,7 @@ configuration:
7775
MAGFIELDS:
7876
magfieldSolenoidMap: Symm_solenoid_r601_phi1_z1201_13June2018.dat
7977
magfieldTorusMap: Symm_torus_r2501_phi16_z251_24Apr2018.dat
80-
MLTD:
81-
run: "6302"
82-
DCHAI:
78+
DCHTAI:
8379
outputBankPrefix: "HB"
8480
RTPC:
8581
rtpcSimulation: "true"

‎etc/services/mc-aicv.yaml‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,16 @@ services:
1818
name: FTEB
1919
- class: org.jlab.service.raster.RasterEngine
2020
name: RASTER
21-
# DC clustering: nominal algoritm, filled the cluster bank for ai and conventional tracking
21+
# - class: org.jlab.service.ai.DCDenoiseEngine
22+
# name: DCDN
2223
- class: org.jlab.service.dc.DCHBClustering
2324
name: DCCR
24-
# This is where the AI plugin would go. THe AI code reads the HB clusters.
25-
- class: org.jlab.service.mltn.MLTDEngine
26-
name: MLTD
27-
# DC using clustering: regular HB tracking
25+
- class: org.jlab.service.ai.DCClsComboEngine
26+
name: DCCC
2827
- class: org.jlab.service.dc.DCHBPostClusterConv
2928
name: DCHB
30-
# DC using clustering on AI hits: NN assisted HB tracking
31-
- class: org.jlab.service.dc.DCHBPostClusterAI
32-
name: DCHAI
29+
- class: org.jlab.service.dc.DCHBTrackingAI
30+
name: DCHTAI
3331
- class: org.jlab.service.ftof.FTOFHBEngine
3432
name: FTOFHB
3533
- class: org.jlab.service.ec.ECEngine
@@ -75,10 +73,10 @@ services:
7573
- class: org.jlab.calibration.service.CalibBanksEngine
7674
name: CALIB
7775
configuration:
78-
# global:
79-
# variation: rga_fall2018_mc
80-
# dcMinistagger: "NOTONREFWIRE"
81-
# dcFeedthroughs: "OFF"
76+
global:
77+
variation: mc2026
78+
dcMinistagger: "NOTONREFWIRE"
79+
dcFeedthroughs: "OFF"
8280
io-services:
8381
writer:
8482
schema_dir: mc-aicv

‎etc/services/mc-cv.yaml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ services:
6262
- class: org.jlab.calibration.service.CalibBanksEngine
6363
name: CALIB
6464
configuration:
65-
# global:
66-
# variation: rga_fall2018_mc
67-
# dcMinistagger: "NOTONREFWIRE"
68-
# dcFeedthroughs: "OFF"
65+
global:
66+
variation: mc2026
67+
dcMinistagger: "NOTONREFWIRE"
68+
dcFeedthroughs: "OFF"
6969
io-services:
7070
writer:
7171
schema_dir: dst

0 commit comments

Comments
 (0)