ATLAS Offline Software
test_magFieldCondAlg.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #
5 # Test magnetic field conditions algs with varying currents.
6 #
7 
8 # Testing IOVs and currents: (since LB, solenoid, toroids)
9 # Default test - should read both mag field files, and turn off fields for events 5 to 9, and back on for 10 to 14
10 currents = [(0, 7730, 20400),
11  (5, 0, 0),
12  (10, 7730, 20400)]
13 
14 # Optional test: only toroid is on for whole run. Scale factor for solenoid will become 1 at event 5,
15 # but solenoid field will still be off
16 # currents = [(0, 0, 20400),
17 # (5, 7730, 20400),
18 # (10, 7730, 20400)]
19 
20 # Optional test: only solenoid is on for whole run. Scale factor for toroid will become 1 at event 5,
21 # but toroid field will still be off
22 # currents = [(0, 7730, 0),
23 # (5, 7730, 20400),
24 # (10, 7730, 20400)]
25 
26 # Folder name
27 folder = '/EXT/DCS/MAGNETS/SENSORDATA'
28 sqlite = 'magfield.db'
29 
30 def createDB():
31  """Create sqlite file with DCS currents"""
32  import os
33  os.environ['CLING_STANDARD_PCH'] = 'none' #See bug ROOT-10789
34  from PyCool import cool
35  from CoolConvUtilities import AtlCoolLib, AtlCoolTool
36 
37  # Cleanup previous file
38  if os.path.isfile(sqlite):
39  os.remove(sqlite)
40 
41  db = cool.DatabaseSvcFactory.databaseService().createDatabase(f'sqlite://;schema={sqlite};dbname=CONDBR2')
42  spec = cool.RecordSpecification()
43  spec.extend("value", cool.StorageType.Float)
44  spec.extend("quality_invalid", cool.StorageType.Bool)
45  f = AtlCoolLib.ensureFolder(db, folder, spec, AtlCoolLib.athenaDesc(True, 'CondAttrListCollection'))
46 
47  for v in currents:
48  sol = cool.Record(spec)
49  sol['value'] = v[1]
50  sol['quality_invalid'] = False
51  tor = cool.Record(spec)
52  tor['value'] = v[2]
53  tor['quality_invalid'] = False
54  f.storeObject(v[0], cool.ValidityKeyMax, sol, 1) # channel 1
55  f.storeObject(v[0], cool.ValidityKeyMax, tor, 3) # channel 3
56 
57  # print database content
58  act = AtlCoolTool.AtlCoolTool(db)
59  print (act.more(folder))
60 
61 
62 # Create sqlite file with DCS currents
63 createDB()
64 
65 from AthenaConfiguration.AllConfigFlags import initConfigFlags
66 from AthenaConfiguration.ComponentFactory import CompFactory
67 from AthenaConfiguration.MainServicesConfig import MainEvgenServicesCfg
68 
69 flags = initConfigFlags()
70 flags.Input.Files = []
71 flags.Concurrency.NumThreads = 1
72 flags.Exec.MaxEvents = currents[-1][0]+5 # 5 events per IOV
73 flags.IOVDb.GlobalTag = 'CONDBR2-BLKPA-RUN2-01'
74 flags.IOVDb.SqliteInput = sqlite
75 flags.IOVDb.SqliteFolders = (folder,)
76 flags.lock()
77 
79 acc.getService('EventSelector').EventsPerLB = 1
80 
81 from MagFieldServices.MagFieldServicesConfig import AtlasFieldCacheCondAlgCfg
82 acc.merge( AtlasFieldCacheCondAlgCfg(flags, LockMapCurrents=False) )
83 
84 acc.addEventAlgo( CompFactory.MagField.CondReader('MagFieldCondReader') )
85 
86 import sys
87 sys.exit(acc.run().isFailure())
test_magFieldCondAlg.createDB
def createDB()
Definition: test_magFieldCondAlg.py:30
python.MainServicesConfig.MainEvgenServicesCfg
def MainEvgenServicesCfg(flags, LoopMgr="AthenaEventLoopMgr", withSequences=True)
Definition: MainServicesConfig.py:349
taskman.createDatabase
createDatabase
Definition: taskman.py:100
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.MagFieldServicesConfig.AtlasFieldCacheCondAlgCfg
def AtlasFieldCacheCondAlgCfg(flags, **kwargs)
Definition: MagFieldServicesConfig.py:8