forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_ccdb.py
More file actions
executable file
·105 lines (89 loc) · 4 KB
/
update_ccdb.py
File metadata and controls
executable file
·105 lines (89 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python3
# Copyright CERN and copyright holders of ALICE O2. This software is
# distributed under the terms of the GNU General Public License v3 (GPL
# Version 3), copied verbatim in the file "COPYING".
#
# See http://alice-o2.web.cern.ch/license for full licensing information.
#
# In applying this license CERN does not waive the privileges and immunities
# granted to it by virtue of its status as an Intergovernmental Organization
# or submit itself to any jurisdiction.
"""
Script to update the CCDB with timestamp non-overlapping objects.
If an object is found in the range specified, the object is split into two.
If the requested range was overlapping three objects are uploaded on CCDB:
1) latest object with requested timestamp validity
2) old object with validity [old_lower_validity-requested_lower_bound]
3) old object with validity [requested_upper_bound, old_upper_validity]
Author: Nicolo' Jacazio on 2020-06-22
TODO add support for 3 files update
TODO add support for user input
"""
import subprocess
from datetime import datetime
import matplotlib.pyplot as plt
def convert_timestamp(ts):
return datetime.utcfromtimestamp(ts/1000).strftime('%Y-%m-%d %H:%M:%S')
def get_ccdb_obj(path, timestamp, dest = "/tmp/"):
print("Getting obj", path, "with timestamp",
timestamp, convert_timestamp(timestamp))
cmd=f"o2-ccdb-downloadccdbfile --path {path} --dest {dest} --timestamp {timestamp}"
subprocess.run(cmd.split())
def get_ccdb_obj_validity(path, dest = "/tmp/", verbose = True):
cmd=f"o2-ccdb-inspectccdbfile {dest}{path}/snapshot.root"
process=subprocess.Popen(cmd.split(), stdout = subprocess.PIPE)
output, error=process.communicate()
output=output.decode("utf-8").split("\n")
error=error.decode("utf-8").split("\n") if error is not None else error
if verbose:
print("out:")
print(*output, "\n")
print("err:")
print(error)
result=list(filter(lambda x: x.startswith('Valid-'), output))
ValidFrom = result[0].split()
ValidUntil = result[1].split()
print(*output, sep="\n")
return [int(ValidFrom[-1]), int(ValidUntil[-1])]
return {ValidFrom[0]: ValidFrom[-1], ValidUntil[0]: ValidUntil[-1]}
def upload_ccdb_obj(path, timestamp_from, timestamp_until, dest="/tmp/", meta=""):
print("Uploading obj", path, "with timestamp", [timestamp_from, timestamp_until],
convert_timestamp(timestamp_from), convert_timestamp(timestamp_until))
key=path.split("/")[-1]
cmd=f"o2-ccdb-upload -f {dest}{path}/snapshot.root "
cmd += f"--key {key} --path {path} "
cmd += f"--starttimestamp {timestamp_from} --endtimestamp {timestamp_until} --meta \"{meta}\""
subprocess.run(cmd.split())
def main(path, timestamp_from, timestamp_until):
get_ccdb_obj(path, timestamp_from-1)
val_before=get_ccdb_obj_validity(path)
get_ccdb_obj(path, timestamp_until+1)
val_after=get_ccdb_obj_validity(path)
overlap_before=val_before[1] > timestamp_from
overlap_after=val_after[0] < timestamp_until
print(overlap_before, overlap_after)
trimmed_before=val_before if not overlap_before else [
val_before[0], timestamp_from - 1]
trimmed_after = val_after if not overlap_after else [
timestamp_until+1, val_after[1]]
fig, ax = plt.subplots()
def bef_af(v, y):
return [v[0] - 1] + v + [v[1] + 1], [0, y, y, 0]
if True:
ax.plot(*bef_af(val_before, 0.95), label='before')
ax.plot(*bef_af(val_after, 1.05), label='after')
if False:
ax.plot(*bef_af(trimmed_before, 0.9), label='trimmed before')
ax.plot(*bef_af(trimmed_after, 1.1), label='trimmed after')
ax.plot(*bef_af([timestamp_from, timestamp_until], 1), label='object')
xlim = 10000000
plt.xlim([timestamp_from-xlim, timestamp_until+xlim])
plt.ylim(0, 2)
plt.xlabel('Timestamp')
plt.ylabel('Validity')
plt.legend()
plt.show()
if __name__ == "__main__":
main("qc/TOF/TOFTaskCompressed/hDiagnostic",
1588946517161 + 10000000,
1588946517161 + 40000000)