Skip to content

Commit 38f121c

Browse files
Add lumi information (cherry pick from future PR) (#7)
* Add lumi information (cherry pick from future PR) * Revert indentation change * Fix missing parameter * Fix bug of missing token * Remove file --------- Co-authored-by: George Raduta <[email protected]>
1 parent 1c8dea8 commit 38f121c

File tree

8 files changed

+218
-65
lines changed

8 files changed

+218
-65
lines changed

src/alice/dip/AliDip2BK.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public AliDip2BK() {
6565
verifyDirs();
6666

6767
bookkeepingClient = new BookkeepingClient(bookkeepingUrl, bookkeepingToken);
68-
dipMessagesProcessor = new DipMessagesProcessor(bookkeepingClient);
68+
var luminosityManager = new LuminosityManager();
69+
dipMessagesProcessor = new DipMessagesProcessor(bookkeepingClient, luminosityManager);
6970
if (AliDip2BK.simulateDipEvents) {
7071
new SimDipEventsFill(dipMessagesProcessor);
7172
}

src/alice/dip/BookkeepingClient.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,26 @@ public void updateRun(RunInfoObj runObj) {
272272
hasModifications = true;
273273
}
274274

275+
if (runObj.getTriggerEfficiency().isPresent()) {
276+
requestBody += "\n\"triggerEfficiency\":" + runObj.getTriggerEfficiency().get() + ",";
277+
}
278+
279+
if (runObj.getTriggerAcceptance().isPresent()) {
280+
requestBody += "\n\"triggerAcceptance\":" + runObj.getTriggerAcceptance().get() + ",";
281+
}
282+
283+
if (runObj.getCrossSection().isPresent()) {
284+
requestBody += "\n\"crossSection\":" + runObj.getCrossSection().get() + ",";
285+
}
286+
287+
if (runObj.getPhaseShiftAtStart().isPresent()) {
288+
requestBody += "\n\"phaseShiftAtStart\":" + runObj.getPhaseShiftAtStart().get() + ",";
289+
}
290+
291+
if (runObj.getPhaseShiftAtStop().isPresent()) {
292+
requestBody += "\n\"phaseShiftAtEnd\":" + runObj.getPhaseShiftAtStop().get() + ",";
293+
}
294+
275295
if (!hasModifications) { // no updates to be done !
276296
AliDip2BK.log(3, "BKwriter.UpdateRun", "No data to update for Run=" + runObj.RunNo);
277297
return;
@@ -289,7 +309,7 @@ public void updateRun(RunInfoObj runObj) {
289309
String patchRunRequest = bookkeepingUrl + "/api/runs?runNumber=" + runObj.RunNo;
290310

291311
if (bookkeepingToken != null) {
292-
patchRunRequest += bookkeepingToken;
312+
patchRunRequest += "&token=" + bookkeepingToken;
293313
}
294314

295315
HttpRequest request = HttpRequest.newBuilder()

src/alice/dip/DipMessagesProcessor.java

Lines changed: 99 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import java.util.concurrent.ArrayBlockingQueue;
2020
import java.util.concurrent.BlockingQueue;
2121

22+
import cern.dip.BadParameter;
2223
import cern.dip.DipData;
2324
import cern.dip.DipTimestamp;
25+
import cern.dip.TypeMismatch;
2426

2527
/*
2628
* Process dip messages received from the DipClient
@@ -43,9 +45,12 @@ public class DipMessagesProcessor implements Runnable {
4345
ArrayList<RunInfoObj> ActiveRuns = new ArrayList<RunInfoObj>();
4446
private BlockingQueue<MessageItem> outputQueue = new ArrayBlockingQueue<MessageItem>(100);
4547

46-
public DipMessagesProcessor(BookkeepingClient bookkeepingClient) {
48+
private final LuminosityManager luminosityManager;
49+
50+
public DipMessagesProcessor(BookkeepingClient bookkeepingClient, LuminosityManager luminosityManager) {
4751

4852
this.bookkeepingClient = bookkeepingClient;
53+
this.luminosityManager = luminosityManager;
4954

5055
Thread t = new Thread(this);
5156
t.start();
@@ -121,12 +126,18 @@ public synchronized void newRunSignal(long date, int runNumber) {
121126

122127
if (rio == null) {
123128
if (currentFill != null) {
124-
RunInfoObj newrun = new RunInfoObj(date, runNumber, currentFill.clone(), currentAlice.clone());
129+
RunInfoObj newrun = new RunInfoObj(
130+
date,
131+
runNumber,
132+
currentFill.clone(),
133+
currentAlice.clone(),
134+
luminosityManager.getView()
135+
);
125136
ActiveRuns.add(newrun);
126137
AliDip2BK.log(
127-
2,
128-
"ProcData.newRunSignal",
129-
" NEW RUN NO =" + runNumber + " with FillNo=" + currentFill.fillNo
138+
2,
139+
"ProcData.newRunSignal",
140+
" NEW RUN NO =" + runNumber + " with FillNo=" + currentFill.fillNo
130141
);
131142
bookkeepingClient.updateRun(newrun);
132143

@@ -144,20 +155,26 @@ public synchronized void newRunSignal(long date, int runNumber) {
144155
llist = llist + ">>";
145156

146157
AliDip2BK.log(
147-
7,
148-
"ProcData.newRunSignal",
149-
" LOST RUN No Signal! " + llist + " New RUN NO =" + runNumber + " Last Run No=" + LastRunNumber
158+
7,
159+
"ProcData.newRunSignal",
160+
" LOST RUN No Signal! " + llist + " New RUN NO =" + runNumber + " Last Run No=" + LastRunNumber
150161
);
151162
LastRunNumber = runNumber;
152163
}
153164
}
154165
} else {
155-
RunInfoObj newrun = new RunInfoObj(date, runNumber, null, currentAlice.clone());
166+
RunInfoObj newrun = new RunInfoObj(
167+
date,
168+
runNumber,
169+
null,
170+
currentAlice.clone(),
171+
luminosityManager.getView()
172+
);
156173
ActiveRuns.add(newrun);
157174
AliDip2BK.log(
158-
2,
159-
"ProcData.newRunSignal",
160-
" NEW RUN NO =" + runNumber + " currentFILL is NULL Perhaps Cosmics Run"
175+
2,
176+
"ProcData.newRunSignal",
177+
" NEW RUN NO =" + runNumber + " currentFILL is NULL Perhaps Cosmics Run"
161178
);
162179
bookkeepingClient.updateRun(newrun);
163180
}
@@ -177,6 +194,8 @@ public synchronized void stopRunSignal(long time, int runNumber) {
177194
rio.setEORtime(time);
178195
if (currentFill != null) rio.LHC_info_stop = currentFill.clone();
179196
rio.alice_info_stop = currentAlice.clone();
197+
rio.setLuminosityAtStop(luminosityManager.getView());
198+
bookkeepingClient.updateRun(rio);
180199

181200
EndRun(rio);
182201
} else {
@@ -203,17 +222,17 @@ public void processNextInQueue(MessageItem messageItem) {
203222
String strNO_BUNCHES = messageItem.data.extractString("NO_BUNCHES");
204223

205224
AliDip2BK.log(
206-
1,
207-
"ProcData.dispach",
208-
" RunConfigurttion FILL No = " + fillno + " AIS=" + ais + " IP2_COLL=" + strIP2_NO_COLLISIONS
225+
1,
226+
"ProcData.dispach",
227+
" RunConfigurttion FILL No = " + fillno + " AIS=" + ais + " IP2_COLL=" + strIP2_NO_COLLISIONS
209228
);
210229

211230
newFillNo(time, fillno, par1, par2, ais, strIP2_NO_COLLISIONS, strNO_BUNCHES);
212231
} catch (Exception e) {
213232
AliDip2BK.log(
214-
4,
215-
"ProcData.dispach",
216-
" ERROR in RunConfiguration P=" + messageItem.param_name + " Ans=" + ans + " ex=" + e
233+
4,
234+
"ProcData.dispach",
235+
" ERROR in RunConfiguration P=" + messageItem.param_name + " Ans=" + ans + " ex=" + e
217236
);
218237
}
219238
// SafeBeam
@@ -279,9 +298,9 @@ public void processNextInQueue(MessageItem messageItem) {
279298
newL3magnetCurrent(time, v);
280299
} catch (Exception e) {
281300
AliDip2BK.log(
282-
2,
283-
"ProcData.dispach",
284-
" ERROR on Solenoid Curr P=" + messageItem.param_name + " ex=" + e
301+
2,
302+
"ProcData.dispach",
303+
" ERROR on Solenoid Curr P=" + messageItem.param_name + " ex=" + e
285304
);
286305
}
287306
} else if (messageItem.param_name.contentEquals("dip/ALICE/MCS/Dipole/Current")) {
@@ -293,9 +312,9 @@ public void processNextInQueue(MessageItem messageItem) {
293312
newDipoleCurrent(time, v);
294313
} catch (Exception e) {
295314
AliDip2BK.log(
296-
2,
297-
"ProcData.dispach",
298-
" ERROR on Dipole Curr on P=" + messageItem.param_name + " ex=" + e
315+
2,
316+
"ProcData.dispach",
317+
" ERROR on Dipole Curr on P=" + messageItem.param_name + " ex=" + e
299318
);
300319
}
301320
} else if (messageItem.param_name.contentEquals("dip/ALICE/MCS/Solenoid/Polarity")) {
@@ -330,17 +349,30 @@ public void processNextInQueue(MessageItem messageItem) {
330349
AliDip2BK.log(2, "ProcData.dispach", " Dipole Polarity=" + currentAlice.Dipole_polarity);
331350
} catch (Exception e) {
332351
AliDip2BK.log(
333-
2,
334-
"ProcData.dispach",
335-
" ERROR on Dipole Polarity P=" + messageItem.param_name + " ex=" + e
352+
2,
353+
"ProcData.dispach",
354+
" ERROR on Dipole Polarity P=" + messageItem.param_name + " ex=" + e
336355
);
337356
// e.printStackTrace();
338357
}
358+
} else if (messageItem.param_name.contentEquals("dip/ALICE/LHC/Bookkeeping/Source")) {
359+
try {
360+
handleBookkeepingSourceMessage(messageItem.data);
361+
} catch (Exception e) {
362+
AliDip2BK.log(2, "ProcData.dispach", " ERROR on BKP source=" + messageItem.param_name + " ex=" + e);
363+
}
364+
} else if (messageItem.param_name.contentEquals("dip/ALICE/LHC/Bookkeeping/CTPClock")) {
365+
try {
366+
handleBookkeepingCtpClockMessage(messageItem.data);
367+
AliDip2BK.log(2, "ProcData.dispach", " L3 Polarity=" + currentAlice.L3_polarity);
368+
} catch (Exception e) {
369+
AliDip2BK.log(2, "ProcData.dispach", " ERROR on BKP CTPClock=" + messageItem.param_name + " ex=" + e);
370+
}
339371
} else {
340372
AliDip2BK.log(
341-
4,
342-
"ProcData.dispach",
343-
"!!!!!!!!!! Unimplemented Data Process for P=" + messageItem.param_name
373+
4,
374+
"ProcData.dispach",
375+
"!!!!!!!!!! Unimplemented Data Process for P=" + messageItem.param_name
344376
);
345377
}
346378
}
@@ -358,9 +390,9 @@ public void newSafeMode(long time, int val) {
358390
boolean isSB = BigInteger.valueOf(val).testBit(2);
359391

360392
AliDip2BK.log(
361-
0,
362-
"ProcData.newSafeBeams",
363-
" VAL=" + val + " isB1=" + isB1 + " isB2=" + isB2 + " isSB=" + isSB
393+
0,
394+
"ProcData.newSafeBeams",
395+
" VAL=" + val + " isB1=" + isB1 + " isB2=" + isB2 + " isSB=" + isSB
364396
);
365397
if (isB1 && isB2) {
366398
return;
@@ -449,18 +481,18 @@ public void EndRun(RunInfoObj r1) {
449481
}
450482

451483
AliDip2BK.log(
452-
2,
453-
"ProcData.EndRun",
454-
" Correctly closed runNo=" + r1.RunNo + " ActiveRuns size=" + ActiveRuns.size() + " " + runList1
484+
2,
485+
"ProcData.EndRun",
486+
" Correctly closed runNo=" + r1.RunNo + " ActiveRuns size=" + ActiveRuns.size() + " " + runList1
455487
);
456488

457489
if (r1.LHC_info_start.fillNo != r1.LHC_info_stop.fillNo) {
458490

459491
AliDip2BK.log(
460-
5,
461-
"ProcData.EndRun",
462-
" !!!! RUN =" + r1.RunNo + " Statred FillNo=" + r1.LHC_info_start.fillNo
463-
+ " and STOPED with FillNo=" + r1.LHC_info_stop.fillNo
492+
5,
493+
"ProcData.EndRun",
494+
" !!!! RUN =" + r1.RunNo + " Statred FillNo=" + r1.LHC_info_start.fillNo
495+
+ " and STOPED with FillNo=" + r1.LHC_info_stop.fillNo
464496
);
465497
}
466498
}
@@ -511,10 +543,10 @@ public void newFillNo(long date, String strFno, String par1, String par2, String
511543
}
512544
} else {
513545
AliDip2BK.log(
514-
3,
515-
"ProcData.newFillNo",
516-
" Received new FILL no=" + no + " BUT is an active FILL =" + currentFill.fillNo
517-
+ " Close the old one and created the new one"
546+
3,
547+
"ProcData.newFillNo",
548+
" Received new FILL no=" + no + " BUT is an active FILL =" + currentFill.fillNo
549+
+ " Close the old one and created the new one"
518550
);
519551
currentFill.endedTime = (new Date()).getTime();
520552
if (AliDip2BK.KEEP_FILLS_HISTORY_DIRECTORY != null) {
@@ -542,9 +574,9 @@ public void newBeamMode(long date, String BeamMode) {
542574
if (mc < 0) {
543575

544576
AliDip2BK.log(
545-
2,
546-
"ProcData.newBeamMode",
547-
"New beam mode=" + BeamMode + " for FILL_NO=" + currentFill.fillNo
577+
2,
578+
"ProcData.newBeamMode",
579+
"New beam mode=" + BeamMode + " for FILL_NO=" + currentFill.fillNo
548580
);
549581
bookkeepingClient.updateLhcFill(currentFill);
550582
saveState();
@@ -555,9 +587,9 @@ public void newBeamMode(long date, String BeamMode) {
555587
writeFillHistFile(currentFill);
556588
}
557589
AliDip2BK.log(
558-
3,
559-
"ProcData.newBeamMode",
560-
"CLOSE Fill_NO=" + currentFill.fillNo + " Based on new beam mode=" + BeamMode
590+
3,
591+
"ProcData.newBeamMode",
592+
"CLOSE Fill_NO=" + currentFill.fillNo + " Based on new beam mode=" + BeamMode
561593
);
562594
currentFill = null;
563595
}
@@ -750,4 +782,21 @@ public void writeHistFile(String filename, ArrayList<TimestampedFloat> A) {
750782
AliDip2BK.log(4, "ProcData.writeHistFile", " ERROR writing file=" + filename + " ex=" + e);
751783
}
752784
}
785+
786+
private void handleBookkeepingSourceMessage(DipData dipData) throws BadParameter, TypeMismatch {
787+
var acceptance = dipData.extractFloat("Acceptance");
788+
var crossSection = dipData.extractFloat("CrossSection");
789+
var efficiency = dipData.extractFloat("Efficiency");
790+
791+
luminosityManager.setTriggerEfficiency(efficiency);
792+
luminosityManager.setTriggerAcceptance(acceptance);
793+
luminosityManager.setCrossSection(crossSection);
794+
}
795+
796+
private void handleBookkeepingCtpClockMessage(DipData dipData) throws BadParameter, TypeMismatch {
797+
var phaseShiftBeam1 = dipData.extractFloat("PhaseShift_Beam1");
798+
var phaseShiftBeam2 = dipData.extractFloat("PhaseShift_Beam2");
799+
800+
luminosityManager.setPhaseShift(new PhaseShift(phaseShiftBeam1, phaseShiftBeam2));
801+
}
753802
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package alice.dip;
2+
3+
import java.util.Optional;
4+
5+
public class LuminosityManager {
6+
private Optional<Float> triggerAcceptance;
7+
private Optional<Float> triggerEfficiency;
8+
private Optional<Float> crossSection;
9+
private Optional<PhaseShift> phaseShift;
10+
11+
public LuminosityView getView() {
12+
return new LuminosityView(triggerAcceptance, triggerEfficiency, crossSection, phaseShift);
13+
}
14+
15+
public void setTriggerAcceptance(float triggerAcceptance) {
16+
this.triggerAcceptance = Optional.of(triggerAcceptance);
17+
}
18+
19+
public void setTriggerEfficiency(float triggerEfficiency) {
20+
this.triggerEfficiency = Optional.of(triggerEfficiency);
21+
}
22+
23+
public void setCrossSection(float crossSection) {
24+
this.crossSection = Optional.of(crossSection);
25+
}
26+
27+
public void setPhaseShift(PhaseShift phaseShift) {
28+
this.phaseShift = Optional.of(phaseShift);
29+
}
30+
}

src/alice/dip/LuminosityView.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package alice.dip;
2+
3+
import java.util.Optional;
4+
5+
public record LuminosityView(
6+
Optional<Float> triggerAcceptance,
7+
Optional<Float> triggerEfficiency,
8+
Optional<Float> crossSection,
9+
Optional<PhaseShift> phaseShift
10+
) {
11+
@Override
12+
public String toString() {
13+
var ans = " TriggerAcceptance=" + triggerAcceptance;
14+
ans += " CrossSection=" + crossSection;
15+
ans += " Efficiency=" + triggerEfficiency;
16+
if (phaseShift.isPresent()) {
17+
ans += " PhaseShiftBeam1=" + phaseShift.get().beam1();
18+
ans += " PhaseShiftBeam2=" + phaseShift.get().beam2();
19+
}
20+
21+
return ans;
22+
}
23+
}

src/alice/dip/PhaseShift.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package alice.dip;
2+
3+
public record PhaseShift(
4+
float beam1,
5+
float beam2
6+
) {
7+
}

0 commit comments

Comments
 (0)