1919import java .util .concurrent .ArrayBlockingQueue ;
2020import java .util .concurrent .BlockingQueue ;
2121
22+ import cern .dip .BadParameter ;
2223import cern .dip .DipData ;
2324import 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}
0 commit comments