1111 * or submit itself to any jurisdiction.
1212 */
1313
14+ const {
15+ EcsOperationAndStepStatus : {
16+ DONE_ERROR ,
17+ DONE_TIMEOUT
18+ }
19+ } = require ( '../common/ecsOperationAndStepStatus.enum.js' ) ;
20+
1421/**
15- * DcsIntegratedEventAdapter - Given an AliECS Integrated Service Event for DCS.SOR, build a DCS Integrated Event
22+ * @class DcsIntegratedEventAdapter - Given an AliECS Integrated Service Event for DCS.SOR, build a DCS Integrated Event
1623 *
1724 * The DCS SOR event is a special event that comes from either:
1825 * * the DCS service itself (when containing the payload "dcsEvent") and it is for one detector only
@@ -26,7 +33,77 @@ class DcsIntegratedEventAdapter {
2633 }
2734
2835 /**
29- * Build a DCS Integrated Event from an AliECS Integrated Service Event. If it is a DCSevent, the detector will replace detectors array
36+ * Build a DCS Integrated Event from an AliECS Integrated Service Event - SOR. If it is a DCSevent, the detector will replace detectors array
37+ *
38+ * // IntegratedService event, related to SOR but with a failure on ECS side (such as timeout)
39+ * @example
40+ * {
41+ * "timestamp": 1733497646607,
42+ * "integratedServiceEvent": {
43+ * "name": "readout-dataflow.dcs.sor",
44+ * "error": "DCS SOR timed out after 1s: rpc error: code = DeadlineExceeded desc = Deadline Exceeded",
45+ * "operationName": "dcs.StartOfRun()",
46+ * "operationStatus": "ONGOING",
47+ * "operationStep": "perform DCS call: StartOfRun",
48+ * "operationStepStatus": "DONE_TIMEOUT",
49+ * "environmentId": "2rRm96N9k7E",
50+ * "payload": "{\"detectors\":[\"EMC\"],\"detectorsReadiness\":{\"EMC\":\"SOR_AVAILABLE\"},\"runNumber\":1601 }"
51+ * }
52+ * // IntegratedService event with final state DONE_ERROR following the DONE_TIMEOUT from above
53+ * @example
54+ * {
55+ * "timestamp": 1734004912438,
56+ * "integratedServiceEvent": {
57+ * "name": "readout-dataflow.dcs.sor",
58+ * "error": "DCS SOR timed out after 100ms: rpc error: code = DeadlineExceeded desc = context deadline exceeded : SOR failed for EMC, FDD, DCS EOR will run anyway for this run",
59+ * "operationName": "dcs.StartOfRun()",
60+ * "operationStatus": "DONE_ERROR",
61+ * "operationStep": "perform DCS call: StartOfRun",
62+ * "operationStepStatus": "DONE_ERROR",
63+ * "environmentId": "2rYQabnjWy2",
64+ * "payload": "{\"detectors\":[\"EMC\",\"FDD\"],\"detectorsReadiness\":{\"EMC\":\"SOR_AVAILABLE\",\"FDD\":\"SOR_AVAILABLE\"},\"failedDetectors\":[\"EMC\",\"FDD\"],\"runNumber\":1622 }"
65+ * }
66+ *
67+ * // IntegratedService event, related to SOR_PROGRESSING with payload from DCS
68+ * @example
69+ * {
70+ * "timestamp": 1734004912360,
71+ * "timestampNano": 1734004912360675322,
72+ * "environmentEvent": null,
73+ * "taskEvent": null,
74+ * "roleEvent": null,
75+ * "callEvent": null,
76+ * "integratedServiceEvent": {
77+ * "name": "readout-dataflow.dcs.sor",
78+ * "error": null,
79+ * "operationName": "dcs.StartOfRun()",
80+ * "operationStatus": "ONGOING",
81+ * "operationStep": "perform DCS call: StartOfRun",
82+ * "operationStepStatus": "ONGOING",
83+ * "environmentId": "2rYQabnjWy2",
84+ * "payload": \"{
85+ * \"dcsEvent\": {
86+ * \"eventtype\":20,
87+ * \"detector\":2,
88+ * \"state\":5,\"
89+ * extraParameters\":{
90+ * \"run_no\":\"1622\"
91+ * },
92+ * \"timestamp\":\"2024-12-12 13:01:52.358\",
93+ * \"message\":\"run_type\"
94+ * },
95+ * \"detector\":\"EMC\",
96+ * \"detectors\":[\"EMC\",\"FDD\"],
97+ * \"detectorsReadiness\":{
98+ * \"EMC\":\"SOR_AVAILABLE\",
99+ * \"FDD\":\"SOR_AVAILABLE\"
100+ * },
101+ * \"runNumber\":1622,
102+ * \"state\":\"SOR_PROGRESSING\"
103+ * }"
104+ * }
105+ *
106+ * Final OperationStates: DONE_TIMEOUT/DONE_ERROR/DONE_OK
30107 * @param {object } event - AliECS Integrated Service Event
31108 * @param {number } timestamp - timestamp of the event (int64 as per proto file definition)
32109 * @return {object } DCS Integrated Event
@@ -37,7 +114,13 @@ class DcsIntegratedEventAdapter {
37114
38115 const payloadJSON = JSON . parse ( payload ) ;
39116 const { dcsEvent, runNumber, detector = null , state } = payloadJSON ;
40- if ( ! dcsEvent ) {
117+
118+ if ( ! dcsEvent
119+ && operationStatus !== DONE_ERROR && operationStatus !== DONE_TIMEOUT
120+ && operationStepStatus !== DONE_ERROR && operationStepStatus !== DONE_TIMEOUT
121+ ) {
122+ // if there is no DCS event and status is not final error or timeout, we ignore the event as we expect to have `RUN_OK` from DCS as final state
123+ // or DONE_TIMEOUT or DONE_ERROR from ECS. We are not interested in DONE_OK from ECS as this means all detectors in RUN_OK which we already look for
41124 return null ;
42125 }
43126 let { detectors } = payloadJSON ;
0 commit comments