6 Module to test beamspot updates using a local sqlite file. Two steps are necessary:
8 1) Create a modified bytestream file that contains the correct COOL update information
9 in the CTP fragment. To do this simply run this script with a RAW file and it will
10 write a modified file into the current directory with beamspot updates on LBs as
11 specified in Config.lb_updateBeamspot.
13 2) Configure a job with the BeamSpotWriteAlg in the topSequence. This algorithm will
14 write a new beamspot into the sqlite file one LB before the actual update is
15 triggered via the CTP fragment. See TrigP1Test/python/BeamSpotReader.py
23 from TrigByteStreamTools
import trigbs_modifyEvent
24 from TrigByteStreamTools
import CTPfragment
25 from AthenaPython
import PyAthena
28 """Configuration options for this module"""
29 lb_updateBeamspot = {3:(4,4),
34 trigbs_modifyEvent.Config.eventsPerLB = 5
36 log = logging.getLogger(__name__)
39 """Algorithm to write a new Beamspot to COOL (sqlite file) for given LBs"""
41 def __init__(self, name='BeamSpotWriteAlg', **kwargs):
42 super(BeamSpotWriteAlg, self).
__init__(name, **kwargs)
47 if self.getContext()
is None:
48 self.log.
info(
'No EventContext available')
49 return PyAthena.StatusCode.Success
54 lb = self.getContext().eventID().lumi_block() + 1
55 if lb
in Config.lb_updateBeamspot:
56 l, status = Config.lb_updateBeamspot.pop(lb)
57 setBeamSpot(run, l, l/100.0, 1+l/100.0, -4-l/10.0, status)
59 return PyAthena.StatusCode.Success
64 dbname='sqlite://;schema=beampos.db;dbname=CONDBR2
',
65 tag='IndetBeamposOnl-HLT-UPD1-001-00'):
67 log.info(
'============================= Creating new beamspot in COOL ===================================')
68 log.info(
'run=%d, lb=%d, x=%f, y=%f, z=%f', run, lb, x, y, z)
70 os.system(
"beamSpotOnl_set.py --output=sqlite:beampos.db --run=%d --lbn=%d %d %f %f %f" % (run,lb,status,x,y,z))
71 if log.level<=logging.DEBUG:
72 log.info(
'Current content of beampos.db sqlite file:')
73 os.system(
"AtlCoolConsole.py 'sqlite://;schema=beampos.db;dbname=CONDBR2' <<< 'more Indet/Onl/Beampos'")
74 log.info(
'===============================================================================================')
79 """Add COOL folder update to event"""
81 ctp_robs = [rob
for rob
in event
if rob.source_id().subdetector_id()==eformat.helper.SubDetector.TDAQ_CTP]
84 log.error(
"Cannot find CTP ROB in event")
88 new_event = eformat.write.FullEventFragment()
89 new_event.copy_header(event)
91 if r.source_id().subdetector_id() != eformat.helper.SubDetector.TDAQ_CTP:
92 new_event.append(eformat.write.ROBFragment(r))
96 x = CTPfragment.ExtraPayload()
97 for f
in folderList: x.updateFolder(f)
98 new_ctp_rob = CTPfragment.setHltExtraPayloadWords(rob, [d
for d
in x.serialize()])
99 new_event.append(eformat.write.ROBFragment(new_ctp_rob))
105 event = eformat.write.FullEventFragment(event)
108 newevt = trigbs_modifyEvent.modify(event)
109 lb = newevt.lumi_block()
112 if lb
in Config.lb_updateBeamspot:
113 lb_for_update,status = Config.lb_updateBeamspot.pop(lb)
115 fe = CTPfragment.FolderEntry()
117 fe.lumiBlock = lb_for_update
118 folderList.append(fe)
119 log.info(
'Added COOL folder update to event: folderIndex=%d, LB=%d', fe.folderIndex,fe.lumiBlock)
127 log.info(
'Will perform beamspot udpate on these LBs (LB,status): %s',
sorted(Config.lb_updateBeamspot.values()))
131 os.remove(
'beampos.db')
140 """CA cfg function to be used from athenaHLT"""
143 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
144 from AthenaConfiguration.ComponentFactory
import CompFactory
145 from IOVDbSvc.IOVDbSvcConfig
import addFolders
147 from pathlib
import Path
153 Path(
'beampos.db').touch()
156 cfg.merge(
addFolders(flags,
'/Indet/Onl/Beampos <key>/Indet/Beampos</key>',
158 tag=
'IndetBeamposOnl-HLT-UPD1-001-00',
159 className=
'AthenaAttributeList',
163 cfg.addEventAlgo( CompFactory.InDet.InDetBeamSpotReader(VxContainer =
"") )
164 cfg.addCondAlgo( CompFactory.BeamSpotCondAlg(OutputLevel = DEBUG) )
170 if __name__ ==
'__main__':
172 from eformat
import EventStorage
174 parser = argparse.ArgumentParser(description=__doc__)
175 parser.add_argument(
'file', metavar=
'FILE', nargs=1, help=
'input file')
176 parser.add_argument(
'-n',
'--events', type=int, default=-1, help=
'number of events to process')
177 parser.add_argument(
'-o',
'--output', type=str, help=
'core output file name')
179 args = parser.parse_args()
180 dr = EventStorage.pickDataReader(args.file[0])
181 output = eformat.ostream(core_name = args.output
or dr.fileNameCore(),
182 run_number = dr.runNumber(),
183 trigger_type = dr.triggerType(),
184 detector_mask = dr.detectorMask(),
185 beam_type = dr.beamType(),
186 beam_energy = dr.beamEnergy(),
187 meta_data_strings=dr.freeMetaDataStrings(),
188 compression=dr.compression())
191 for event
in eformat.istream(args.file[0]):
193 if args.events>0
and i>args.events: