ATLAS Offline Software
Loading...
Searching...
No Matches
RunITkPixelCsvWaferIdTool.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4
5"""Configure and initialize ITkPixelCsvWaferIdAlg.
6
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.
11"""
12
13from argparse import ArgumentParser, BooleanOptionalAction
14
15from AthenaCommon.Constants import INFO
16from AthenaCommon.Constants import DEBUG
17from AthenaCommon.Logging import log
18from AthenaConfiguration.AllConfigFlags import initConfigFlags
19from AthenaConfiguration.MainServicesConfig import MainServicesCfg
20from PixelGeoModelXml.ITkPixelGeoModelConfig import ITkPixelReadoutGeometryCfg
21
22from ITkPixelByteStreamCnv.ITkPixelByteStreamCnvConfig import ITkPixelCsvWaferIdAlgCfg
23
24import csv, json, sys, os
25import chai_addDID
26
27parser = ArgumentParser("RunITkPixelCsvWaferIdAlg.py")
28parser.add_argument(
29 "--csv-file",
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."
32)
33parser.add_argument(
34 "--output-file",
35 default="ITkPixelWaferIds.txt",
36 help="Output csv file for one 32-bit waferID identifier per line."
37)
38parser.add_argument(
39 "--crest-upload",
40 action=BooleanOptionalAction,
41 default="False",
42 help="Upload to CREST database."
43)
44parser.add_argument(
45 "--crest-tag",
46 default="ITkPixModIDMap-RUN4-00-00-TEST",
47 help="TAG used for CREST upload."
48)
49parser.add_argument(
50 "--crest-db",
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"
53)
54parser.add_argument(
55 "--crest-since",
56 default="0",
57 help="start time of IOV"
58)
59parser.add_argument(
60 "--crest-until",
61 default="0xFFFFFFFFFFFFFFFF",
62 help="end time of IOV"
63)
64parser.add_argument(
65 "--verbose",
66 action="store_true",
67 help="Print the full Athena configuration and properties.",
68)
69args = parser.parse_args()
70
71log.setLevel(INFO)
72
73flags = initConfigFlags()
74flags.Input.isMC = True
75flags.Input.Files = [] # No input files needed for this test
76
77#flags.Exec.OutputLevel=DEBUG
78
79from AthenaConfiguration.TestDefaults import defaultGeometryTags
80flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN4
81flags.GeoModel.Align.Dynamic = False
82
83from AthenaConfiguration.TestDefaults import defaultConditionsTags
84flags.IOVDb.GlobalTag = defaultConditionsTags.RUN4_MC
85
86flags.lock()
87
88cfg = MainServicesCfg(flags)
89cfg.merge(ITkPixelReadoutGeometryCfg(flags))
90cfg.merge(ITkPixelCsvWaferIdAlgCfg(flags,
91 CsvFile=args.csv_file,
92 OutputFile=args.output_file))
93
94if args.verbose:
95 cfg.printConfig(withDetails=True, summariseProps=True, printDefaults=True)
96
97# Run the application to initialize and execute
98cfg.run(1)
99
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")
105
106print(" Converting csv to json....")
107
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")
111
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))
122
123
124print("Wrote output !")
125
126# TODO make if statement, print argument...
127if(args.crest_upload == True):
128 print("Now uploading to CREST Conditions DataBase")
129
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
136 ])
137
138
139print(" CREST upload Done !!")
if(pathvar)
void print(char *figname, TCanvas *c1)
main(args=None)