ATLAS Offline Software
Loading...
Searching...
No Matches
TRT_StatusPoolGenerator.py
Go to the documentation of this file.
2# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
6
7from AthenaConfiguration.AllConfigFlags import initConfigFlags
8from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
9from AthenaConfiguration.ComponentFactory import CompFactory
10from AthenaConfiguration.MainServicesConfig import MainServicesCfg
11
12def TRTStrawStatusWriteCfg(flags, name="TRTStrawStatusWriteAlg", tagList=[], objectList=[], **kwargs):
13 acc = ComponentAccumulator()
14
15 if "StatusInputFile" not in kwargs:
16 kwargs.setdefault("StatusInputFile", "straws.txt")
17
18 from IOVDbSvc.IOVDbSvcConfig import IOVDbSvcCfg
19 acc.merge(IOVDbSvcCfg(flags))
20
21 from RegistrationServices.OutputConditionsAlgConfig import OutputConditionsAlgCfg
22 OutputCond = OutputConditionsAlgCfg(
23 flags,
24 name="OutputConditionsAlg",
25 outputFile="pooloutputfile.root",
26 ObjectList=objectList,
27 IOVTagList=tagList,
28 WriteIOV=True,
29 Run1=0,
30 LB1=0,
31 Run2=2147483647,
32 LB2=4294967295
33 )
34 acc.merge(OutputCond)
35
36 # Add pool output stream tool
37 from AthenaPoolCnvSvc.PoolWriteConfig import PoolWriteCfg
38 acc.merge(PoolWriteCfg(flags))
39
40 acc.addEventAlgo(CompFactory.TRTStrawStatusWrite(name=name, **kwargs))
41 return acc
42
43
44def TRTStrawStatusReadCfg(flags, name="TRTStrawStatusRead", statusTag="", permTag="", htTag="", ReadCOOL=True, **kwargs):
45 acc = ComponentAccumulator()
46
47 if "OutputFile" not in kwargs:
48 kwargs.setdefault("OutputFile", "caliboutput.txt")
49
50 if "TRT_StrawStatusSummaryTool" not in kwargs:
51 from TRT_ConditionsServices.TRT_ConditionsServicesConfig import TRT_StrawStatusSummaryToolCfg
52 kwargs.setdefault("TRT_StrawStatusSummaryTool", acc.popToolsAndMerge(TRT_StrawStatusSummaryToolCfg(flags)))
53
54 if not ReadCOOL:
55 # TRT folders from local SQLite
56 from IOVDbSvc.IOVDbSvcConfig import addOverride
57 if kwargs["FolderToPrint"] == "Status":
58 acc.merge(addOverride( flags, "/TRT/Cond/Status", tag=statusTag, db=flags.IOVDb.DBConnection))
59
60 if kwargs["FolderToPrint"] == "StatusPermanent":
61 acc.merge(addOverride( flags, "/TRT/Cond/StatusPermanent", tag=permTag, db=flags.IOVDb.DBConnection))
62
63 if kwargs["FolderToPrint"] == "StatusHT":
64 acc.merge(addOverride( flags, "/TRT/Cond/StatusHT", tag=htTag, db=flags.IOVDb.DBConnection))
65
66 else:
67 from IOVDbSvc.IOVDbSvcConfig import addFoldersSplitOnline
68 acc.merge(addFoldersSplitOnline(flags, "TRT",
69 onlineFolders = ["/TRT/Onl/Cond/Status",
70 "/TRT/Onl/Cond/StatusPermanent",
71 "/TRT/Onl/Cond/StatusHT"], # Argon straw list
72 offlineFolders = ["/TRT/Cond/Status",
73 "/TRT/Cond/StatusPermanent",
74 "/TRT/Cond/StatusHT"], # Argon straw list
75 className = "TRTCond::StrawStatusMultChanContainer"))
76
77 # TRT CondRead Algorithm
78 TRTStrawStatusRead = CompFactory.TRTStrawStatusRead(name=name, **kwargs)
79 acc.addEventAlgo(TRTStrawStatusRead)
80
81 return acc
82
83if __name__ == "__main__":
84
85 import argparse
86 parser = argparse.ArgumentParser(prog='python -m TRT_ConditionsAlgs.TRT_StatusPoolGenerator',
87 description="Write or Read TRT conditions. For writing you can provide the three folder, however for reading must be one by one")
88
89 parser.add_argument('-r','--read',action='store_true' ,help="By default writes. If set the it reads from local DB")
90 parser.add_argument('-m','--isMC',action='store_true' ,help="This is to tell athena if it is MC or Data (OFLP200 or CONDBR2)")
91 parser.add_argument('--status' ,action='store_false' ,help="For straw status tag")
92 parser.add_argument('--permanent',action='store_true' ,help="For permanent straws")
93 parser.add_argument('--ht' ,action='store_true',help="For HT straws")
94 parser.add_argument('-f','--inputFile', default="straws.txt" ,help="DB folder name for reader")
95 parser.add_argument('-c','--condRunNumber', type=int, default=-1, help=" choose the IoV covering this run number")
96 parser.add_argument('--dbname', default="mycool.db" ,help="DB folder name for reader")
97 parser.add_argument('--outputtxt', default="" ,help="Output file for the TRT")
98
99 args = parser.parse_args()
100
101
102 if not args.status and not args.permanent and not args.ht:
103 print("ERROR: you should provide at least one folder --status and/or --permanent and/or --ht")
104 exit(1)
105
106 flags = initConfigFlags()
107
108 from AthenaConfiguration.TestDefaults import defaultGeometryTags, defaultTestFiles, defaultConditionsTags
109 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN3
110
111 if args.isMC:
112 flags.Input.Files = defaultTestFiles.RDO_RUN3
113 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN3_MC
114 else:
115 flags.Input.Files = defaultTestFiles.RAW_RUN3
116 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN3_DATA
117
118
119 ReadCOOL = False
120 textOutput = args.outputtxt if args.outputtxt else "caliboutput.txt"
121 if args.condRunNumber > 0:
122 flags.Input.RunNumbers = [args.condRunNumber]
123 flags.Input.OverrideRunNumber=True
124 ReadCOOL = True
125 textOutput = args.outputtxt if args.outputtxt else f"caliboutput_{args.condRunNumber}.txt"
126 else:
127 flags.IOVDb.DBConnection = f"sqlite://;schema={args.dbname};dbname=" + ("OFLP200" if args.isMC else "CONDBR2")
128
129 flags.Detector.GeometryTRT = True
130 flags.Detector.EnableTRT = True
131 flags.Output.ESDFileName = "trtcalibout.pool.root"
132 flags.Exec.MaxEvents = 1
133
134 # For debug output INFO=3
135 flags.Exec.OutputLevel = 3
136
137 flags.lock()
138 flags.dump()
139
140 # Main services accumulator
141 acc = MainServicesCfg(flags)
142
143 # Add Detector geometry
144 from AtlasGeoModel.GeoModelConfig import GeoModelCfg
145 acc.merge(GeoModelCfg(flags))
146
147 mytagList = []
148 myobjectList = []
149 folder2read = ""
150
151 if args.status:
152 folder2read = "Status"
153 mytagList.append("TextStatus")
154 myobjectList.append("TRTCond::StrawStatusMultChanContainer#/TRT/Cond/Status")
155
156 if not args.read:
157 # Add TRT conditions writing
158 acc.merge(TRTStrawStatusWriteCfg(flags, StatusInputFile=args.inputFile, tagList=mytagList, objectList=myobjectList))
159 else:
160 acc.merge(TRTStrawStatusReadCfg(flags, statusTag="TextStatus", permTag="TextPermanent", htTag="TextHT", ReadCOOL=ReadCOOL, OutputFile=textOutput, FolderToPrint=folder2read))
161
162
163
164 # Run the configuration
165 with open("TRT_StatusPoolGenerator.pkl", "wb") as f:
166 acc.store(f)
167 f.close()
168
169 import sys
170 sys.exit(not acc.run().isSuccess())
void print(char *figname, TCanvas *c1)
TRTStrawStatusReadCfg(flags, name="TRTStrawStatusRead", statusTag="", permTag="", htTag="", ReadCOOL=True, **kwargs)
TRTStrawStatusWriteCfg(flags, name="TRTStrawStatusWriteAlg", tagList=[], objectList=[], **kwargs)