6 from argparse
import ArgumentParser
8 from pathlib
import Path
11 from PyCool
import cool
13 logging.basicConfig(format=
'%(levelname)s: %(message)s', level=logging.INFO)
15 parser = ArgumentParser(
"ItkPixelChargeCalibration.py")
16 parser.add_argument(
"-i",
"--identifiers", type=str, help=
"Identifiers dump", default=
"ITkPixelIdentifiers.dat")
17 args = parser.parse_args()
19 logging.info(
"Identifiers file: %s", args.identifiers)
22 dbFolder =
"/ITk/PixelChargeCalib"
23 dbTag =
"PixelChargeCalib_LUTTest-00-01"
24 dbFile =
"ITkPixelChargeCalib-00-01.db"
29 logging.info(
"Database name: %s", dbName)
30 logging.info(
"Folder name: %s", dbFolder)
31 logging.info(
"Folder tag: %s", dbTag)
32 logging.info(
"Output file: %s", dbFile)
33 logging.info(
"Run range: %s - %s", runSince, runUntil)
35 dbFilePath = Path(dbFile)
36 if dbFilePath.exists():
40 dbSvc = cool.DatabaseSvcFactory.databaseService()
42 dbString = f
"sqlite://;schema={dbFile};dbname={dbName}"
44 db = dbSvc.createDatabase(dbString)
45 except Exception
as e:
46 logging.error(
"Problem creating database %s", e)
48 logging.info(
"Created database %s", dbString)
51 spec = cool.RecordSpecification()
53 spec.extend(
'data_array', cool.StorageType.String16M)
55 desc =
'<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader><typeName>CondAttrListCollection</typeName>'
59 folderSpec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
60 folder = db.createFolder(dbFolder, folderSpec, desc,
True)
62 data = cool.Record(spec)
65 iovMin = runSince << 32 | 0
66 iovMax = cool.ValidityKeyMax
if runUntil ==
'inf' else runUntil << 32 | 0
68 logging.info(
"IoV range: %s - %s", iovMin, iovMax)
78 [1000, 75, 1000, 75, 2080, 2957, 4000, 5163, 6824, 8700, 11285, 14709, 19600, 27500, 40400, 69500, 166400, 3000000, 999999999., 999999999.],
82 [1500, 75, 1500, 75, 2080, 2957, 4000, 5163, 6824, 8700, 11285, 14709, 19600, 27500, 40400, 69500, 166400, 3000000, 999999999., 999999999.],
88 with open(args.identifiers,
"r")
as identifiers:
89 for line
in identifiers:
94 if ids[-1] ==
"4" or (ids[2] ==
"0" and ids[3] ==
"0"):
95 output[ids[0]] = calibL0andL1
97 output[ids[0]] = calibL2toL4
99 data[
"data_array"] = dumps(output, separators=(
',',
':'))
100 folder.storeObject(iovMin, iovMax, data, 0, dbTag)