Skip to content

Commit f6cfe68

Browse files
committed
Merge branch 'main' of github.com:AliceO2Group/BKP-LHC-Client into refactor-dip-messages-processor-uniformize-handlers
2 parents ed7b3d8 + 422095f commit f6cfe68

File tree

10 files changed

+222
-45
lines changed

10 files changed

+222
-45
lines changed

TselectLHC.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
#Data Provides we need
1+
#Data Provides we need - https://confluence.cern.ch/display/expcomm/DIP+LHC
22
dip/acc/LHC/RunControl/RunConfiguration
33
dip/acc/LHC/RunControl/BeamMode
44
dip/acc/LHC/Beam/BetaStar/Bstar2
55
dip/acc/LHC/Beam/Energy
6+
dip/acc/LHC/RunControl/SafeBeam
7+
8+
# LHC_IF data added specifically for Bookkeeping
9+
dip/ALICE/LHC/Bookkeeping/Source
10+
dip/ALICE/LHC/Bookkeeping/CTPClock
11+
612
dip/ALICE/MCS/Dipole/Current
713
dip/ALICE/MCS/Solenoid/Current
814
dip/ALICE/MCS/Dipole/Polarity
915
dip/ALICE/MCS/Solenoid/Polarity
10-
dip/acc/LHC/RunControl/SafeBeam
16+
1117
#
1218
#dip/ALICE/LHClogbook/RunControl/CirculatingBunchConfig/Beam2
1319
#dip/acc/LHC/Beam/Intensity/Beam2

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</javac>
1818
</target>
1919
<target name="create_run_jar" depends="compile">
20-
<jar destfile="${dir.jarfile}/AliDip2BK.jar">
20+
<jar destfile="${dir.jarfile}/o2-bkp-lhc-client-v2.1.2.jar">
2121
<manifest>
2222
<attribute name="Main-Class" value="alice.dip.Dip2BK"/>
2323
</manifest>

src/alice/dip/AliDip2BK.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.util.Properties;
2020

2121
public class AliDip2BK implements Runnable {
22-
public static String Version = "2.0 14-Nov-2023";
22+
public static String Version = "2.1.2 22-Jul-2025";
2323
public static String DNSnode = "dipnsdev.cern.ch";
2424
public static String[] endFillCases = {"CUCU"};
2525
public static boolean LIST_PARAM = false;
@@ -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: 24 additions & 4 deletions
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.getPhaseShiftAtStartAsJson() + ",";
289+
}
290+
291+
if (runObj.getPhaseShiftAtStop().isPresent()) {
292+
requestBody += "\n\"phaseShiftAtEnd\":" + runObj.getPhaseShiftAtStopAsJson() + ",";
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;
@@ -284,14 +304,14 @@ public void updateRun(RunInfoObj runObj) {
284304

285305
requestBody += "\n}";
286306

287-
AliDip2BK.log(1, "BKwriter.UpdateRun", "RUN =" + runObj.RunNo + " UPDATE JSON request=\n" + requestBody);
307+
AliDip2BK.log(3, "BKwriter.UpdateRun", "RUN =" + runObj.RunNo + " UPDATE JSON request=\n" + requestBody);
288308

289309
String patchRunRequest = bookkeepingUrl + "/api/runs?runNumber=" + runObj.RunNo;
290310

291311
if (bookkeepingToken != null) {
292-
patchRunRequest += bookkeepingToken;
312+
patchRunRequest += "&token=" + bookkeepingToken;
293313
}
294-
314+
AliDip2BK.log(2, "BKwriter.Format of Update", requestBody);
295315
HttpRequest request = HttpRequest.newBuilder()
296316
.uri(URI.create(patchRunRequest))
297317
.header("Content-Type", "application/json")
@@ -303,7 +323,7 @@ public void updateRun(RunInfoObj runObj) {
303323
response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());
304324

305325
if (response.statusCode() == 200) {
306-
AliDip2BK.log(2, "BKwriter.UpdateRun", "Succesful Update for RUN=" + runObj.RunNo);
326+
AliDip2BK.log(2, "BKwriter.UpdateRun", "Successful Update for RUN=" + runObj.RunNo);
307327
} else {
308328
AliDip2BK.log(3, "BKwriter.UpdateRun", "ERROR for RUN=" + runObj.RunNo + " Code=" + +response.statusCode() + " Message=" + response.body());
309329
}

src/alice/dip/DipMessagesProcessor.java

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,12 @@ public class DipMessagesProcessor implements Runnable {
4444
ArrayList<RunInfoObj> ActiveRuns = new ArrayList<>();
4545
private BlockingQueue<MessageItem> outputQueue = new ArrayBlockingQueue<>(100);
4646

47-
public DipMessagesProcessor(BookkeepingClient bookkeepingClient) {
47+
private final LuminosityManager luminosityManager;
48+
49+
public DipMessagesProcessor(BookkeepingClient bookkeepingClient, LuminosityManager luminosityManager) {
4850

4951
this.bookkeepingClient = bookkeepingClient;
52+
this.luminosityManager = luminosityManager;
5053

5154
Thread t = new Thread(this);
5255
t.start();
@@ -122,7 +125,13 @@ public synchronized void newRunSignal(long date, int runNumber) {
122125

123126
if (rio == null) {
124127
if (currentFill != null) {
125-
RunInfoObj newrun = new RunInfoObj(date, runNumber, currentFill.clone(), currentAlice.clone());
128+
RunInfoObj newrun = new RunInfoObj(
129+
date,
130+
runNumber,
131+
currentFill.clone(),
132+
currentAlice.clone(),
133+
luminosityManager.getView()
134+
);
126135
ActiveRuns.add(newrun);
127136
AliDip2BK.log(
128137
2,
@@ -154,12 +163,18 @@ public synchronized void newRunSignal(long date, int runNumber) {
154163
}
155164
}
156165
} else {
157-
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+
);
158173
ActiveRuns.add(newrun);
159174
AliDip2BK.log(
160-
2,
161-
"ProcData.newRunSignal",
162-
" 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"
163178
);
164179
bookkeepingClient.updateRun(newrun);
165180
}
@@ -179,6 +194,8 @@ public synchronized void stopRunSignal(long time, int runNumber) {
179194
rio.setEORtime(time);
180195
if (currentFill != null) rio.LHC_info_stop = currentFill.clone();
181196
rio.alice_info_stop = currentAlice.clone();
197+
rio.setLuminosityAtStop(luminosityManager.getView());
198+
bookkeepingClient.updateRun(rio);
182199

183200
EndRun(rio);
184201
} else {
@@ -220,6 +237,12 @@ public void processNextInQueue(MessageItem messageItem) {
220237
case "dip/ALICE/MCS/Dipole/Polarity":
221238
handleDipolePolarityMessage(messageItem.data);
222239
break;
240+
case "dip/ALICE/LHC/Bookkeeping/Source":
241+
handleBookkeepingSourceMessage(messageItem.data);
242+
break;
243+
case "dip/ALICE/LHC/Bookkeeping/CTPClock":
244+
handleBookkeepingCtpClockMessage(messageItem.data);
245+
break;
223246
default:
224247
AliDip2BK.log(
225248
4,
@@ -464,18 +487,18 @@ public void EndRun(RunInfoObj r1) {
464487
}
465488

466489
AliDip2BK.log(
467-
2,
468-
"ProcData.EndRun",
469-
" Correctly closed runNo=" + r1.RunNo + " ActiveRuns size=" + ActiveRuns.size() + " " + runList1
490+
2,
491+
"ProcData.EndRun",
492+
" Correctly closed runNo=" + r1.RunNo + " ActiveRuns size=" + ActiveRuns.size() + " " + runList1
470493
);
471494

472495
if (r1.LHC_info_start.fillNo != r1.LHC_info_stop.fillNo) {
473496

474497
AliDip2BK.log(
475-
5,
476-
"ProcData.EndRun",
477-
" !!!! RUN =" + r1.RunNo + " Statred FillNo=" + r1.LHC_info_start.fillNo
478-
+ " and STOPED with FillNo=" + r1.LHC_info_stop.fillNo
498+
5,
499+
"ProcData.EndRun",
500+
" !!!! RUN =" + r1.RunNo + " Statred FillNo=" + r1.LHC_info_start.fillNo
501+
+ " and STOPED with FillNo=" + r1.LHC_info_stop.fillNo
479502
);
480503
}
481504
}
@@ -526,10 +549,10 @@ public void newFillNo(long date, String strFno, String par1, String par2, String
526549
}
527550
} else {
528551
AliDip2BK.log(
529-
3,
530-
"ProcData.newFillNo",
531-
" Received new FILL no=" + no + " BUT is an active FILL =" + currentFill.fillNo
532-
+ " Close the old one and created the new one"
552+
3,
553+
"ProcData.newFillNo",
554+
" Received new FILL no=" + no + " BUT is an active FILL =" + currentFill.fillNo
555+
+ " Close the old one and created the new one"
533556
);
534557
currentFill.endedTime = (new Date()).getTime();
535558
if (AliDip2BK.KEEP_FILLS_HISTORY_DIRECTORY != null) {
@@ -557,9 +580,9 @@ public void newBeamMode(long date, String BeamMode) {
557580
if (mc < 0) {
558581

559582
AliDip2BK.log(
560-
2,
561-
"ProcData.newBeamMode",
562-
"New beam mode=" + BeamMode + " for FILL_NO=" + currentFill.fillNo
583+
2,
584+
"ProcData.newBeamMode",
585+
"New beam mode=" + BeamMode + " for FILL_NO=" + currentFill.fillNo
563586
);
564587
bookkeepingClient.updateLhcFill(currentFill);
565588
saveState();
@@ -570,9 +593,9 @@ public void newBeamMode(long date, String BeamMode) {
570593
writeFillHistFile(currentFill);
571594
}
572595
AliDip2BK.log(
573-
3,
574-
"ProcData.newBeamMode",
575-
"CLOSE Fill_NO=" + currentFill.fillNo + " Based on new beam mode=" + BeamMode
596+
3,
597+
"ProcData.newBeamMode",
598+
"CLOSE Fill_NO=" + currentFill.fillNo + " Based on new beam mode=" + BeamMode
576599
);
577600
currentFill = null;
578601
}
@@ -710,4 +733,31 @@ public void writeHistFile(String filename, ArrayList<TimestampedFloat> A) {
710733
AliDip2BK.log(4, "ProcData.writeHistFile", " ERROR writing file=" + filename + " ex=" + e);
711734
}
712735
}
736+
737+
private void handleBookkeepingSourceMessage(DipData dipData) throws BadParameter, TypeMismatch {
738+
var acceptance = dipData.extractFloat("Acceptance");
739+
var crossSection = dipData.extractFloat("CrossSection");
740+
var efficiency = dipData.extractFloat("Efficiency");
741+
AliDip2BK.log(
742+
2,
743+
"ProcData.dispatch",
744+
" Bookkeeping Source: Acceptance=" + acceptance + " CrossSection=" + crossSection
745+
+ " Efficiency=" + efficiency
746+
);
747+
luminosityManager.setTriggerEfficiency(efficiency);
748+
luminosityManager.setTriggerAcceptance(acceptance);
749+
luminosityManager.setCrossSection(crossSection);
750+
}
751+
752+
private void handleBookkeepingCtpClockMessage(DipData dipData) throws BadParameter, TypeMismatch {
753+
var phaseShiftBeam1 = dipData.extractFloat("PhaseShift_Beam1");
754+
var phaseShiftBeam2 = dipData.extractFloat("PhaseShift_Beam2");
755+
756+
AliDip2BK.log(
757+
2,
758+
"ProcData.dispatch",
759+
" Bookkeeping CTP Clock: PhaseShift_Beam1=" + phaseShiftBeam1 + " PhaseShift_Beam2=" + phaseShiftBeam2
760+
);
761+
luminosityManager.setPhaseShift(new PhaseShift(phaseShiftBeam1, phaseShiftBeam2));
762+
}
713763
}
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 = Optional.empty();
7+
private Optional<Float> triggerEfficiency = Optional.empty();
8+
private Optional<Float> crossSection = Optional.empty();
9+
private Optional<PhaseShift> phaseShift = Optional.empty();
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)