1- /*************
2- * cil
3- **************/
4-
1+ /**
2+ * @license
3+ * Copyright CERN and copyright holders of ALICE O2. This software is
4+ * distributed under the terms of the GNU General Public License v3 (GPL
5+ * Version 3), copied verbatim in the file "COPYING".
6+ *
7+ * See http://alice-o2.web.cern.ch/license for full licensing information.
8+ *
9+ * In applying this license CERN does not waive the privileges and immunities
10+ * granted to it by virtue of its status as an Intergovernmental Organization
11+ * or submit itself to any jurisdiction.
12+ */
513package alice .dip ;
614
715import java .io .BufferedWriter ;
2331import cern .dip .DipData ;
2432import cern .dip .TypeMismatch ;
2533
34+ import alice .dip .beam .mode .BeamModeEventsKafkaProducer ;
35+
2636/*
2737 * Process dip messages received from the DipClient
2838 * Receives DipData messages in a blocking Queue and then process them asynchronously
@@ -45,11 +55,13 @@ public class DipMessagesProcessor implements Runnable {
4555 private BlockingQueue <MessageItem > outputQueue = new ArrayBlockingQueue <>(100 );
4656
4757 private final LuminosityManager luminosityManager ;
58+ private volatile BeamModeEventsKafkaProducer beamModeEventsKafkaProducer ;
4859
4960 public DipMessagesProcessor (BookkeepingClient bookkeepingClient , LuminosityManager luminosityManager ) {
5061
5162 this .bookkeepingClient = bookkeepingClient ;
5263 this .luminosityManager = luminosityManager ;
64+ this .beamModeEventsKafkaProducer = null ;
5365
5466 Thread t = new Thread (this );
5567 t .start ();
@@ -58,6 +70,14 @@ public DipMessagesProcessor(BookkeepingClient bookkeepingClient, LuminosityManag
5870 loadState ();
5971 }
6072
73+ /**
74+ * Setter of events producer
75+ * @param beamModeEventsKafkaProducer - instance of BeamModeEventsKafkaProducer to be used to send events
76+ */
77+ public void setEventsProducer (BeamModeEventsKafkaProducer beamModeEventsKafkaProducer ) {
78+ this .beamModeEventsKafkaProducer = beamModeEventsKafkaProducer ;
79+ }
80+
6181 /*
6282 * This method is used for receiving DipData messages from the Dip Client
6383 */
@@ -299,25 +319,25 @@ private void handleSafeBeamMessage(DipData dipData) throws BadParameter, TypeMis
299319 if (currentFill == null ) return ;
300320
301321 String bm = currentFill .getBeamMode ();
302-
303- if (bm .contentEquals ("STABLE BEAMS" )) {
304- AliDip2BK .log (
305- 0 ,
306- "ProcData.newSafeBeams" ,
307- " VAL=" + safeBeamPayload + " isB1=" + isBeam1 + " isB2=" + isBeam2 + " isSB=" + isStableBeams
308- );
309-
310- if (!isBeam1 || !isBeam2 ) {
322+ AliDip2BK .log (
323+ 1 ,
324+ "ProcData.newSafeBeams" ,
325+ " VAL=" + safeBeamPayload + " isB1=" + isBeam1 + " isB2=" + isBeam2 + " isSB=" + isStableBeams
326+ );
327+ if (bm != null ) {
328+ if ((bm .contentEquals ("STABLE BEAMS" ) && (!isBeam1 || !isBeam2 ))) {
311329 currentFill .setBeamMode (time , "LOST BEAMS" );
330+ if (this .beamModeEventsKafkaProducer != null ) {
331+ this .beamModeEventsKafkaProducer .sendEvent (currentFill .fillNo , currentFill , time );
332+ }
312333 AliDip2BK .log (5 , "ProcData.newSafeBeams" , " CHANGE BEAM MODE TO LOST BEAMS !!! " );
334+ } else if (bm .contentEquals ("LOST BEAMS" ) && isBeam1 && isBeam2 ) {
335+ currentFill .setBeamMode (time , "STABLE BEAMS" );
336+ if (this .beamModeEventsKafkaProducer != null ) {
337+ this .beamModeEventsKafkaProducer .sendEvent (currentFill .fillNo , currentFill , time );
338+ }
339+ AliDip2BK .log (5 , "ProcData.newSafeBeams" , " RECOVER FROM BEAM LOST TO STABLE BEAMS " );
313340 }
314-
315- return ;
316- }
317-
318- if (bm .contentEquals ("LOST BEAMS" ) && isBeam1 && isBeam2 ) {
319- currentFill .setBeamMode (time , "STABLE BEAMS" );
320- AliDip2BK .log (5 , "ProcData.newSafeBeams" , " RECOVER FROM BEAM LOST TO STABLE BEAMS " );
321341 }
322342 }
323343
@@ -569,35 +589,18 @@ public void newFillNo(long date, String strFno, String par1, String par2, String
569589 }
570590
571591 public void newBeamMode (long date , String BeamMode ) {
572-
573592 if (currentFill != null ) {
593+ AliDip2BK .log (
594+ 2 ,
595+ "ProcData.newBeamMode" ,
596+ "New beam mode=" + BeamMode + " for FILL_NO=" + currentFill .fillNo
597+ );
574598 currentFill .setBeamMode (date , BeamMode );
599+ bookkeepingClient .updateLhcFill (currentFill );
600+ saveState ();
575601
576- int mc = -1 ;
577- for (int i = 0 ; i < AliDip2BK .endFillCases .length ; i ++) {
578- if (AliDip2BK .endFillCases [i ].equalsIgnoreCase (BeamMode )) mc = i ;
579- }
580- if (mc < 0 ) {
581-
582- AliDip2BK .log (
583- 2 ,
584- "ProcData.newBeamMode" ,
585- "New beam mode=" + BeamMode + " for FILL_NO=" + currentFill .fillNo
586- );
587- bookkeepingClient .updateLhcFill (currentFill );
588- saveState ();
589- } else {
590- currentFill .endedTime = date ;
591- bookkeepingClient .updateLhcFill (currentFill );
592- if (AliDip2BK .KEEP_FILLS_HISTORY_DIRECTORY != null ) {
593- writeFillHistFile (currentFill );
594- }
595- AliDip2BK .log (
596- 3 ,
597- "ProcData.newBeamMode" ,
598- "CLOSE Fill_NO=" + currentFill .fillNo + " Based on new beam mode=" + BeamMode
599- );
600- currentFill = null ;
602+ if (this .beamModeEventsKafkaProducer != null ) {
603+ this .beamModeEventsKafkaProducer .sendEvent (currentFill .fillNo , currentFill , date );
601604 }
602605 } else {
603606 AliDip2BK .log (4 , "ProcData.newBeamMode" , " ERROR new beam mode=" + BeamMode + " NO FILL NO for it" );
@@ -753,7 +756,7 @@ private void handleBookkeepingCtpClockMessage(DipData dipData) throws BadParamet
753756 var phaseShiftBeam2 = dipData .extractFloat ("PhaseShift_Beam2" );
754757
755758 AliDip2BK .log (
756- 2 ,
759+ 0 ,
757760 "ProcData.dispatch" ,
758761 " Bookkeeping CTP Clock: PhaseShift_Beam1=" + phaseShiftBeam1 + " PhaseShift_Beam2=" + phaseShiftBeam2
759762 );
0 commit comments