Skip to content

Commit 977f37b

Browse files
committed
cleanup
1 parent 0439469 commit 977f37b

2 files changed

Lines changed: 81 additions & 30 deletions

File tree

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

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ String parseThreads(String t) {
225225
taskset = String.valueOf(t.charAt(t.length()-1));
226226
if (t.contains(",")) {
227227
if (taskset.equals("+"))
228-
ReconUtil.taskset(0, Arrays.stream(getThreadCounts(t)).sorted().max().getAsInt());
228+
ReconUtil.taskset(0, Arrays.stream(getThreads(t)).sorted().max().getAsInt());
229229
else
230-
ReconUtil.taskset(0, Arrays.stream(getThreadCounts(t)).sorted().min().getAsInt());
230+
ReconUtil.taskset(0, Arrays.stream(getThreads(t)).sorted().min().getAsInt());
231231
}
232232
else if (taskset.equals("-"))
233233
ReconUtil.taskset(0, Integer.parseInt(String.valueOf(t.charAt(0))));
@@ -237,17 +237,63 @@ else if (taskset.equals("+"))
237237
return t;
238238
}
239239

240+
/**
241+
* Sort and preserve +/- suffix.
242+
* @param threads
243+
* @return
244+
*/
245+
static String sortThreads(String threads) {
246+
if (threads.contains(",")) {
247+
String suffix = "";
248+
if (threads.endsWith("+") || threads.endsWith("-"))
249+
suffix = String.valueOf(threads.charAt(threads.length()-1));
250+
threads = String.join(",",Arrays.stream(threads.replace("+","").replace("-","").split(","))
251+
.mapToInt(s -> Integer.parseInt(s)).sorted().boxed().map(i -> String.valueOf(i)).toList());
252+
threads += suffix;
253+
}
254+
return threads;
255+
}
256+
257+
static int[] getThreads(String threadlist) {
258+
return Arrays.stream(threadlist.replace("+","").replace("-","").split(","))
259+
.mapToInt(s -> Integer.parseInt(s)).sorted().toArray();
260+
}
261+
262+
String taskset(String threads) {
263+
taskset = "";
264+
if (threads.endsWith("+") || threads.endsWith("-")) {
265+
taskset = String.valueOf(threads.charAt(threads.length()-1));
266+
if (threads.contains(",")) {
267+
if (taskset.equals("+"))
268+
ReconUtil.taskset(0, 0);
269+
else
270+
ReconUtil.taskset(0, Arrays.stream(getThreads(threads)).min().getAsInt());
271+
}
272+
else if (taskset.equals("-"))
273+
ReconUtil.taskset(0, Integer.parseInt(String.valueOf(threads.charAt(0))));
274+
else if (taskset.equals("+"))
275+
ReconUtil.taskset(0, 0);
276+
}
277+
return threads;
278+
}
279+
240280
/**
241281
* Initialize ReconMutil.
242282
* @param parser
243283
*/
244284
final void init(OptionParser parser) {
245-
parser.getOption("-t").setValue(parseThreads(parser.getOption("-t").stringValue()));
285+
286+
parser.getOption("-t").setValue(sortThreads(parser.getOption("-t").stringValue()));
287+
288+
taskset(parser.getOption("-t").stringValue());
289+
246290
parser.syncLogLevel(Logger.getLogger(ReconMutil.class.getPackage().getName()));
291+
247292
maxEvents = parser.getOption("-n").intValue();
248293
skipEvents = parser.getOption("-s").intValue();
249294
serial = new SerialHoncho(fullSchema);
250295
engines = new LinkedHashMap<>();
296+
251297
if (!parser.getOption("-y").isDefault()) {
252298
yaml = new ClaraYaml(parser.getOption("-y").stringValue());
253299
for (JSONObject service : yaml.services()) {
@@ -282,12 +328,6 @@ else if (!parser.getOption("-c").isDefault()) {
282328
benchmark = new Benchmark("ReconMutil",BENCHMARK_NAMES);
283329
}
284330

285-
static int[] getThreadCounts(String threadlist) {
286-
return Arrays.stream(threadlist.replace("+","").replace("-","").split(","))
287-
.filter(s -> !s.contains("+") && !s.contains("-"))
288-
.mapToInt(s -> Integer.parseInt(s)).sorted().toArray();
289-
}
290-
291331
/**
292332
* The command-line entry-point known as "recon-mutil".
293333
* @param args command-line arguments
@@ -313,7 +353,7 @@ public static void main(String[] args) {
313353
if (!opt.getOption("-o").isDefault())
314354
f.openWriter(opt.getOption("-S"), opt.getOption("-o").stringValue());
315355

316-
f.launch(getThreadCounts(opt.getOption("-t").stringValue()),
356+
f.launch(getThreads(opt.getOption("-t").stringValue()),
317357
opt.getInputList().stream().toArray(String[]::new));
318358
}
319359

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

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -489,35 +489,44 @@ void stopProcessing() {
489489
procQueue.clear();
490490
writeQueue.clear();
491491
}
492-
493-
String parseThreads(String t) {
494-
if (t.contains(",")) {
495-
int offset = t.endsWith("+") || t.endsWith("-") ? 1 : 0;
496-
String extra = t.endsWith("+") || t.endsWith("-") ? String.valueOf(t.charAt(t.length()-1)) : "";
497-
t = String.join(",",Arrays.stream(t.substring(0,t.length()-offset).split(","))
498-
.mapToInt(s -> Integer.parseInt(s)).sorted().mapToObj(i -> String.valueOf(i)).toList())
499-
+ extra;
492+
493+
/**
494+
* Sort and preserve +/- suffix.
495+
* @param threads
496+
* @return
497+
*/
498+
static String sortThreads(String threads) {
499+
if (threads.contains(",")) {
500+
String suffix = "";
501+
if (threads.endsWith("+") || threads.endsWith("-"))
502+
suffix = String.valueOf(threads.charAt(threads.length()-1));
503+
threads = String.join(",",Arrays.stream(threads.replace("+","").replace("-","").split(","))
504+
.mapToInt(s -> Integer.parseInt(s)).sorted().boxed().map(i -> String.valueOf(i)).toList());
505+
threads += suffix;
500506
}
507+
return threads;
508+
}
509+
510+
String taskset(String threads) {
501511
taskset = "";
502-
if (t.endsWith("+") || t.endsWith("-")) {
503-
taskset = String.valueOf(t.charAt(t.length()-1));
504-
if (t.contains(",")) {
512+
if (threads.endsWith("+") || threads.endsWith("-")) {
513+
taskset = String.valueOf(threads.charAt(threads.length()-1));
514+
if (threads.contains(",")) {
505515
if (taskset.equals("+"))
506-
ReconUtil.taskset(0, Arrays.stream(getThreadCounts(t)).sorted().max().getAsInt());
516+
ReconUtil.taskset(0, 0);
507517
else
508-
ReconUtil.taskset(0, Arrays.stream(getThreadCounts(t)).sorted().min().getAsInt());
518+
ReconUtil.taskset(0, Arrays.stream(getThreads(threads)).min().getAsInt());
509519
}
510520
else if (taskset.equals("-"))
511-
ReconUtil.taskset(0, Integer.parseInt(String.valueOf(t.charAt(0))));
521+
ReconUtil.taskset(0, Integer.parseInt(String.valueOf(threads.charAt(0))));
512522
else if (taskset.equals("+"))
513523
ReconUtil.taskset(0, 0);
514524
}
515-
return t;
525+
return threads;
516526
}
517527

518-
static int[] getThreadCounts(String threadlist) {
528+
static int[] getThreads(String threadlist) {
519529
return Arrays.stream(threadlist.replace("+","").replace("-","").split(","))
520-
.filter(s -> !s.contains("+") && !s.contains("-"))
521530
.mapToInt(s -> Integer.parseInt(s)).sorted().toArray();
522531
}
523532

@@ -527,8 +536,10 @@ static int[] getThreadCounts(String threadlist) {
527536
*/
528537
void init(OptionParser parser) {
529538

530-
parser.getOption("-t").setValue(parseThreads(parser.getOption("-t").stringValue()));
531-
539+
parser.getOption("-t").setValue(sortThreads(parser.getOption("-t").stringValue()));
540+
541+
taskset(parser.getOption("-t").stringValue());
542+
532543
fullSchema = new SchemaFactory();
533544
fullSchema.initFromDirectory(ClasUtilsFile.getResourceDir("CLAS12DIR","etc/bankdefs/hipo4"));
534545
this.parser = parser;
@@ -609,7 +620,7 @@ public static void main(String[] args) {
609620
o.setRequiresInputList(true);
610621
o.parse(args);
611622
ReconMutil r = new ReconMutil(o);
612-
r.launch(getThreadCounts(o.getOption("-t").stringValue()),
623+
r.launch(getThreads(o.getOption("-t").stringValue()),
613624
o.getOption("-o").stringValue(),
614625
o.getInputList().stream().toArray(String[]::new));
615626
}

0 commit comments

Comments
 (0)