54 parser = argparse.ArgumentParser(
55 description=
"Create ITkPixModIDMap-RUN4-00-00-TEST tag content via chai",
57 parser.add_argument(
"--tag", default=DEFAULT_TAG, help=f
"Tag name (default: {DEFAULT_TAG})")
58 parser.add_argument(
"--db", default=DEFAULT_DB, help=f
"DB connection string (default: {DEFAULT_DB})")
59 parser.add_argument(
"--since", type=int, default=0,
60 help=
"Start time for IOVs (default: 0)")
61 parser.add_argument(
"--until", type=
lambda x: int(x, 0), default=0xFFFFFFFFFFFFFFFF,
62 help=
"End time for IOVs (default: 0xFFFFFFFFFFFFFFFF)")
63 parser.add_argument(
"--dataA", type=str, default=
"data.json",
64 help=
"Path to the JSON file containing the data for A-side (default: data.json)")
65 args = parser.parse_args(args)
66 since = args.since
if args.since > 0
else None
67 until = args.until
if args.until > 0
else None
69 if(args.since > 0
and args.until > 0
and until < since):
70 print(f
"✗ Error: until = {until} and since = {since}")
73 sep(
"CHAI – Tag Content Creation")
74 print(f
" Tag : {args.tag}")
75 print(f
" DB : {args.db}")
76 print(f
" Data, side-A: {args.dataA}")
80 sep(
"1. Connect to CREST")
82 db = chai.Database(args.db)
84 except Exception
as exc:
85 print(f
"✗ Connection failed: {exc}")
91 sep(
"2. Retrieve / Create a tag")
95 existing_tag = db.get_tag(args.tag)
96 print(f
" Tag '{args.tag}' already exists")
97 print(f
" Removing existing tag...")
98 db.delete_tag(args.tag)
99 print(f
" ✓ Tag removed successfully")
100 except RuntimeError
as e:
102 print(f
" Tag '{args.tag}' does not exist (this is expected)")
107 sep(
"3. Tag metadata")
109 print(
" Creating payload specification:")
110 print(
" - Column 1: 'cabling' (String)")
113 chai.Field(
"cabling", chai.Type.String)
115 field_spec = chai.FieldSpec(fields)
118 print(
" Creating channel specification:")
119 print(
" - Channel 0: 'Channel_AC'")
122 chai.Channel(0,
"Channel_AC"),
124 channel_spec = chai.ChannelSpec(channels)
127 payload_spec = chai.PayloadSpec(field_spec, channel_spec)
128 print(f
" ✓ Payload specification created with {len(field_spec)} fields and {len(channel_spec)} channels")
134 "Test tag for demonstrating tag management operations",
138 "crest-json-single-iov",
139 chai.Synchronization.All,
140 chai.TagStatus.Unlocked
142 print(f
" ✓ Tag created successfully: {tag.name}")
143 print(f
" - Description: {tag.description}")
144 print(f
" - IOV Type: {tag.iov_type}")
145 print(f
" - Status: {tag.status}")
146 except Exception
as e:
147 print(f
" ✗ Failed to create tag: {e}")
151 print(f
" name : {tag.name}")
152 print(f
" description : {tag.description}")
153 print(f
" iov_type : {tag.iov_type}")
154 print(f
" object_type : {tag.object_type}")
155 print(f
" synchronization: {tag.synchronization}")
156 print(f
" status : {tag.status}")
157 print(f
" # IOVs : {len(tag)}")
162 sep(
"4. Payload specification")
163 pspec = tag.payload_spec
164 print(f
" Fields ({len(pspec.fields.fields)}):")
165 for f
in pspec.fields.fields:
166 print(f
" {f.name}: {f.type}")
168 channel_names = pspec.channels.channel_names
169 print(f
"\n Channels ({len(channel_names)}):")
170 items = list(channel_names.items())
172 for cid, cname
in shown:
173 suffix = f
" ({cname})" if cname
else ""
174 print(f
" {cid}{suffix}")
176 print(f
" ... and {len(items) - 10} more")
182 print(f
" Since: {args.since}")
185 with open(args.dataA,
"r")
as f:
186 json_dataA = json.load(f)
189 json_textA = json.dumps(json_dataA, separators=(
",",
":"), sort_keys=
True)
191 compressedA = gzip.compress(json_textA.encode(
"utf-8"))
192 cdataA = base64.b64encode(compressedA).decode(
"ascii")
195 cdataA = str(json.dumps(json_dataA).encode(
'utf-8'))
197 print(f
" Created clob dataA: {len(cdataA)} characters (compressed JSON)")
198 print(f
"Type of dataA is {type(cdataA)}")
201 print(f
" Container created with {container.num_channels} channel(s), {container.num_fields} field(s)")
208 tag.add_payload(container, since, until)
210 payload_json = container.to_json()
211 print(f
" ✓ Stored IOV: since={since}, until={until}")
212 print(f
" Payload size: {len(payload_json)} bytes")
213 print(f
" String length: {len(json.dumps(json_dataA))} characters")
215 except Exception
as e:
216 print(f
" ✗ Failed to store IOV: {e}")