5"""Configure and initialize ITkPixelCsvWaferIdAlg.
7This script is a lightweight AthenaConfiguration entry point for the CSV-based
8wafer identifier algorithm. It currently validates that the algorithm can be
9configured and executed, and prints the lookup request that would be passed to
10its waferId() implementation.
13from argparse
import ArgumentParser, BooleanOptionalAction
17from AthenaCommon.Logging
import log
18from AthenaConfiguration.AllConfigFlags
import initConfigFlags
19from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
20from PixelGeoModelXml.ITkPixelGeoModelConfig
import ITkPixelReadoutGeometryCfg
22from ITkPixelByteStreamCnv.ITkPixelByteStreamCnvConfig
import ITkPixelCsvWaferIdAlgCfg
24import csv, json, sys, os
27parser = ArgumentParser(
"RunITkPixelCsvWaferIdAlg.py")
30 default=
"/eos/atlas/atlascerngroupdisk/det-itk/general/pixels/identifiers/AT2-IP-ES-0016_v1.41_INCOMPLETE-ModuleA_slim.csv",
31 help=
"CSV file to load. The default is resolved through DATAPATH."
35 default=
"ITkPixelWaferIds.txt",
36 help=
"Output csv file for one 32-bit waferID identifier per line."
40 action=BooleanOptionalAction,
42 help=
"Upload to CREST database."
46 default=
"ITkPixModIDMap-RUN4-00-00-TEST",
47 help=
"TAG used for CREST upload."
51 default=
"crest:https://atlas-crest-dev.cern.ch/api-v6.4",
52 help=
"CREST server address, of the type: crest:https://atlas-crest-dev.cern.ch/api-v6.4"
57 help=
"start time of IOV"
61 default=
"0xFFFFFFFFFFFFFFFF",
62 help=
"end time of IOV"
67 help=
"Print the full Athena configuration and properties.",
69args = parser.parse_args()
73flags = initConfigFlags()
74flags.Input.isMC =
True
79from AthenaConfiguration.TestDefaults
import defaultGeometryTags
80flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
81flags.GeoModel.Align.Dynamic =
False
83from AthenaConfiguration.TestDefaults
import defaultConditionsTags
84flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
88cfg = MainServicesCfg(flags)
89cfg.merge(ITkPixelReadoutGeometryCfg(flags))
90cfg.merge(ITkPixelCsvWaferIdAlgCfg(flags,
91 CsvFile=args.csv_file,
92 OutputFile=args.output_file))
95 cfg.printConfig(withDetails=
True, summariseProps=
True, printDefaults=
True)
100print(
"Configured ITkPixelCsvWaferIdAlg")
101print(f
" Input CSV file: {args.csv_file}")
102print(f
" Output file: {args.output_file}")
103print(
" Note: the algorithm execution writes one front end per line to the output file.")
104print(
" 32-bit waferID+feID, 32-bit waferID+feID, FELIX Card Name, Uplink Pin, DMA buffer, SourceID")
106print(
" Converting csv to json....")
108print(
"JSON retaining: 32-bit waferID+feID, 32-bit waferID+feID, SourceID")
109if os.path.isfile(args.output_file+
".json"):
110 print(f
"File {args.output_file}.json exists, will overwrite it")
112with open(args.output_file+
".json",
"w")
as f, open(args.output_file, newline=
'')
as csvfile:
113 reader = csv.DictReader(csvfile)
114 fieldnames = reader.fieldnames
or []
115 desired_names = [
"DetectorResourceID",
"TrueDetectorResourceID",
"SourceID"]
116 selected_names = [name
for name
in desired_names
if name
in fieldnames]
117 if not selected_names:
118 selected_indices = [0, 1, 5]
119 selected_names = [fieldnames[i]
for i
in selected_indices
if i < len(fieldnames)]
120 rows = [{name: row[name]
for name
in selected_names}
for row
in reader]
121 f.write(json.dumps(rows))
124print(
"Wrote output !")
127if(args.crest_upload ==
True):
128 print(
"Now uploading to CREST Conditions DataBase")
131 "--tag", args.crest_tag,
132 "--db", args.crest_db,
133 "--dataA", args.output_file+
".json",
134 "--since", args.crest_since,
135 "--until", args.crest_until
139print(
" CREST upload Done !!")
void print(char *figname, TCanvas *c1)