Skip to content

Commit 8941d26

Browse files
committed
add comments
1 parent 9c22330 commit 8941d26

1 file changed

Lines changed: 54 additions & 11 deletions

File tree

common-tools/clas-detector/src/main/java/org/jlab/detector/serial/SerialHoncho.java

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void process(Event event) {
8484
if (evt.getRows() > 0) {
8585
event.remove(evt.getSchema());
8686
processHelicity(event, cfg, evt);
87-
processScalers(cfg, evt);
87+
processScalers(scalers.get(cfg.getLong("timestamp",0)), evt);
8888
event.write(evt);
8989
}
9090
}
@@ -126,13 +126,22 @@ public ConstantsManager getConstantsManager() {
126126
public SchemaFactory getSchemaFactory() {
127127
return schema;
128128
}
129-
129+
130+
/**
131+
* Recreate the HelicitySequence from the TreeSet of helicity states.
132+
*/
130133
public void updateHelicitySequence() {
131134
helicitySequence = new HelicitySequenceDelayed(
132135
conman.getConstants(run, "/runcontrol/helicity").getIntValue("delay",0,0,0));
133136
helicitySequence.addStream(helicities);
134137
}
135-
138+
139+
/**
140+
*
141+
* @param event
142+
* @param runConfig
143+
* @param helicityAdc
144+
*/
136145
void read(Event event, Bank runConfig, Bank helicityAdc) {
137146
scalers.add(event);
138147
helicities.add(HelicityState.createFromFadcBank(helicityAdc, runConfig, conman));
@@ -153,6 +162,9 @@ void read(Event event, Bank runConfig, Bank helicityAdc) {
153162
}
154163
}
155164

165+
/**
166+
* Trim down the helicity and scaler FIFOs to reasonable values.
167+
*/
156168
void prune() {
157169
// Estimated size of HelicityState is ~22 bytes.
158170
// 1 million states, ~22 MB, 1 minute at 10 kHz trigger.
@@ -164,6 +176,11 @@ void prune() {
164176
scalers.clear((int)1e4);
165177
}
166178

179+
/**
180+
* Get a new event with RUN::unix and RUN::config banks.
181+
* @param runConfig
182+
* @return
183+
*/
167184
Event getUnixEvent(Bank runConfig) {
168185
Bank unix = new Bank(schema.getSchema("RUN::unix"));
169186
unix.setRows(eventUnix.size());
@@ -179,6 +196,10 @@ Event getUnixEvent(Bank runConfig) {
179196
return e;
180197
}
181198

199+
/**
200+
* Get the unix time for a given RUN::config bank.
201+
* @return unix time
202+
*/
182203
int getUnixTime(Bank runConfig) {
183204
if (runConfig.getRows() < 1) {
184205
Integer key = eventUnix.floorKey(runConfig.getInt("event",0));
@@ -190,21 +211,22 @@ int getUnixTime(Bank runConfig) {
190211
return 0;
191212
}
192213

214+
/**
215+
* Update RUN::config's unixtime, and update the event.
216+
*/
193217
void processEventUnix(Event event, Bank runConfig) {
194218
int ut = getUnixTime(runConfig);
195219
event.remove(runConfig.getSchema());
196220
runConfig.putInt("unixtime", 0, ut);
197221
event.write(runConfig);
198222
}
199223

200-
void processScalers(Bank runConfig, Bank recEvent) {
201-
DaqScalers ds = scalers.get(runConfig.getLong("timestamp", 0));
202-
if (ds != null) {
203-
recEvent.putFloat("beamCharge",0, (float) ds.dsc2.getBeamChargeGated());
204-
recEvent.putDouble("liveTime",0,ds.dsc2.getLivetime());
205-
}
206-
}
207-
224+
/**
225+
* Update an event's helicity information, in REC::Event and HEL::scaler.
226+
* @param event
227+
* @param runConfig
228+
* @param recEvent
229+
*/
208230
void processHelicity(Event event, Bank runConfig, Bank recEvent) {
209231
HelicityBit hb = helicitySequence.search(runConfig.getLong("timestamp", 0));
210232
HelicityBit hbraw = helicitySequence.getHalfWavePlate() ? HelicityBit.getFlipped(hb) : hb;
@@ -219,6 +241,22 @@ void processHelicity(Event event, Bank runConfig, Bank recEvent) {
219241
}
220242
}
221243

244+
/**
245+
* Update a REC::EVent's bank beam-charge information.
246+
*/
247+
static void processScalers(DaqScalers ds, Bank recEvent) {
248+
if (ds != null) {
249+
recEvent.putFloat("beamCharge",0, (float) ds.dsc2.getBeamChargeGated());
250+
recEvent.putDouble("liveTime",0,ds.dsc2.getLivetime());
251+
}
252+
}
253+
254+
/**
255+
* For all states deeper than depth, remove consecutive helicity states that
256+
* differ only by timestamp.
257+
* @param helicities
258+
* @param depth
259+
*/
222260
static void pruneHelicities(TreeSet<HelicityState> helicities, int depth) {
223261
HelicityState prev = null;
224262
ListIterator<HelicityState> iter = (ListIterator)helicities.iterator();
@@ -230,6 +268,11 @@ static void pruneHelicities(TreeSet<HelicityState> helicities, int depth) {
230268
}
231269
}
232270

271+
/**
272+
* FIXME: Switch to lists and delete this.
273+
* @param tag1banks
274+
* @return
275+
*/
233276
static Bank[] createTaggedBanks(Schema[] tag1banks) {
234277
List<Bank> lbank = Arrays.asList(tag1banks).stream().map(s -> new Bank(s)).collect(Collectors.toList());
235278
ListIterator<Bank> ibank = lbank.listIterator();

0 commit comments

Comments
 (0)