92def go(iov, systems, db, indb, timewise=False, use_flask=False):
93 """
94 Run the DCS calculator for `run` on the `systems` specified, saving the
95 result to the `database`.
96 """
97 since, until = iov
98
99 with timer("Read LBLB"):
100
101 lblb = fetch_iovs("LBLB", since, until, with_channel=False, database=(indb if indb.startswith('sqlite') else 'COOLONL_TRIGGER/%s' % indb))
102 assert lblb, "No luminosity blocks for desired range. [%s, %s)" % (since, until)
103
104
105 lbtime = inverse_lblb(lblb)
106
107
108 if timewise:
109 run_iovs = run_iovs_from_lblb(lbtime)
110 else:
111 run_iovs = run_iovs_from_lblb(lblb)
112
113 log.debug("Will process %i LBs over %i runs", len(lblb), len(run_iovs))
114
115 log.info("DCSC2 will run over range: %r %s", tuple(run_iovs.range_iov), "(%i lbs)" % len(lblb))
116
117
118
119 systems = [system() for system in systems
120 if not getattr(system, "__DISABLED__", False)]
121
122
123 result_iovs = run_sequential(systems, lbtime, run_iovs)
124
125
126
127
128
129 if log.isEnabledFor(logging.DEBUG):
130 pprint_objects(result_iovs)
131
132 log.info("Calculation complete")
133
134 if db != "None":
135 try:
136 with timer("write result (%i iovs)" % len(result_iovs)):
137 log.debug("Writing result (%i iovs)", len(result_iovs))
138 defect_iovs = list(filter(lambda iov: isinstance(iov, DefectIOV), result_iovs))
139 defect_iovs_full = [DefectIOVFull(recoverable=False, user='sys:defectcalculator', **_._asdict())
140 for _ in defect_iovs]
141 defect_iovs_full.append(DefectIOVFull(recoverable=False, user='sys:defectcalculator',
142 channel='GLOBAL_DCS_UNCHECKED', present=False,
143 comment='Calculator did run',
144 since=since, until=until))
145 if len(defect_iovs) > 0:
146 log.warning(f'db {db}, read_only {not use_flask}')
147 ddb = DefectsDB(db, read_only=use_flask, create=not use_flask)
148 defect_names =
set(i.channel
for i
in defect_iovs_full)
149 for defect in defect_names:
150 if defect in ddb.defect_id_map:
151 continue
152 ddb.create_defect(defect, "Created by DCSCalculator2")
153 with ddb.storage_buffer if not use_flask else nullcontext():
154 if use_flask:
155 import os
156 import json
157 secret_path = os.environ.get('COOLFLASK_SECRET', '/afs/cern.ch/user/a/atlasdqm/private/coolflask_secret/coolflask_secret.json')
158 auth = json.loads(open(secret_path).
read())
159 else:
160 auth = {}
161 ddb.insert_multiple(defect_iovs_full, use_flask=use_flask, flask_auth=auth)
162 except Exception:
163 log.warning("DCS Calculator failed to upload defects to DB")
164 if config.opts.email_on_failure:
165 from DataQualityUtils.panic import panic
166 from traceback import format_exc
167 runnum = lbtime[0].Run if len(lbtime)>0 else '??????'
168 panicmsg = "DCS Calculator failed to upload defects to database for run %s\n\n%s" % (runnum, format_exc())
169 panic(panicmsg)
170 raise
171
172
173 args = len(result_iovs), hash(result_iovs)
174 log.info("Success. Calculated %i iovs. Result hash: 0x%0x8.", *args)
175
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)