ATLAS Offline Software
TileCalibBlobPython_writeTripsProbsFromASCII.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #
5 
6 import getopt,sys
7 
8 def usage():
9  print ("Usage: ",sys.argv[0]," [OPTION] ... ")
10  print ("Write the TileCal drawer trips probabilities from ASCII file into local sqlite file")
11  print ("ASCII file format:")
12  print ("#CondId | frag | trip probability")
13  print ("Trip 0x100 0.01")
14  print ("")
15  print ("-h, --help shows this help")
16  print ("-t, --tag= specify tag to use, by default TEST-00")
17  print ("-i, --input= input ASCII file, by default Tile.trips")
18  print ("-f, --folder= specify status folder to use OFL01 or OFL02, by default OFL01 ")
19 
20 
21 letters = "ht:i:f:"
22 keywords = ["help", "tag=", "input=","folder="]
23 
24 try:
25  opts, extraparams = getopt.getopt(sys.argv[1:], letters, keywords)
26 except getopt.GetoptError as err:
27  print (str(err))
28  usage()
29  sys.exit(2)
30 
31 
32 
33 folderPath = "/TILE/OFL01/STATUS/ADC"
34 tag = "TEST-00"
35 fileName = "Tile.trips"
36 
37 for o, a in opts:
38  a = a.strip()
39  if o in ("-i","--input"):
40  fileName = a
41  elif o in ("-t","--tag"):
42  tag = a
43  elif o in ("-f","--folder"):
44  folderPath = "/TILE/%s/STATUS/ADC" % a
45  elif o in ("-h","--help"):
46  usage()
47  sys.exit(2)
48  else:
49  raise RuntimeError("unhandled option")
50 
51 
52 import cppyy
53 
54 from TileCalibBlobPython import TileCalibTools
55 from TileCalibBlobObjs.Classes import TileCalibUtils
56 
57 #=== some preparation
58 from TileCalibBlobPython.TileCalibLogger import getLogger
59 log = getLogger("writeTripsProbs")
60 import logging
61 log.setLevel(logging.DEBUG)
62 
63 #
64 #________________________________________________________________________
65 def fillTripsProbs(fileTrips, folderPath, tag, since
66  , until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK)):
67 
68 
69  #=== get full folder tag
70  folderTag = TileCalibUtils.getFullTag(folderPath, tag)
71 
72  util = cppyy.gbl.TileCalibUtils()
73 
74  default = cppyy.gbl.std.vector('unsigned int')()
75  for i in range(util.max_drawer() + 1):
76  default.push_back( 0 )
77 
78  defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')()
79  defVec.push_back(default)
80 
81  #=====================================================
82  #=== fill
83  #=====================================================
84  writer = TileCalibTools.TileBlobWriter(db, folderPath, 'Bch')
85 
86  precisions = [[0 for drawer in range(util.max_drawer())] for ros in range(util.max_ros())]
87  trips = [[0 for drawer in range(util.max_drawer())] for ros in range(util.max_ros())]
88 
89  parser = TileCalibTools.TileASCIIParser3(fileTrips, "Trip")
90  dict = parser.getDict()
91  log.info("Updating dictionary from file with %i entries", len(dict))
92  log.info("... filename: %s", fileTrips )
93  for key, trip in list(dict.items()):
94  ros = key[0]
95  mod = key[1]
96  precisions[ros][mod] = len(trip[0]) - 2
97  trips[ros][mod] = float(trip[0])
98 
99 
100  tripsCalibDrawer = writer.getDrawer(util.trips_ros(), util.trips_drawer())
101  tripsCalibDrawer.init(defVec, util.max_ros(), 1)
102 
103  for ros in range(util.max_ros()):
104  denominator = 10**max(precisions[ros])
105  for mod in range(util.max_drawer()):
106  trip = int(trips[ros][mod] * denominator)
107  tripsCalibDrawer.setData(ros, 0, mod, trip)
108  tripsCalibDrawer.setData(ros, 0, util.max_drawer(), denominator)
109 
110 
111 
112  #=== register in DB
113  writer.register(since, until, folderTag)
114 
115 
116 #===================================================================
117 #====================== FILL DB BELOW ==============================
118 #===================================================================
119 
120 #=== open the database
121 db = TileCalibTools.openDb('SQLITE', 'OFLP200', 'UPDATE')
122 
123 #=== source data
124 runfrom = 0
125 fillTripsProbs(fileName, folderPath, tag, (runfrom,0))
126 
127 #=== close the database connection
128 db.closeDatabase()
max
#define max(a, b)
Definition: cfImp.cxx:41
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
TileCalibBlobPython_writeTripsProbsFromASCII.usage
def usage()
Definition: TileCalibBlobPython_writeTripsProbsFromASCII.py:8
TileCalibBlobPython_writeTripsProbsFromASCII.fillTripsProbs
def fillTripsProbs(fileTrips, folderPath, tag, since, until=(TileCalibTools.MAXRUN, TileCalibTools.MAXLBK))
Definition: TileCalibBlobPython_writeTripsProbsFromASCII.py:65
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
str
Definition: BTagTrackIpAccessor.cxx:11
readCCLHist.float
float
Definition: readCCLHist.py:83
python.CaloCondLogger.getLogger
def getLogger(name="CaloCond")
Definition: CaloCondLogger.py:16
TileCalibUtils::getFullTag
static std::string getFullTag(const std::string &folder, const std::string &tag)
Returns the full tag string, composed of camelized folder name and tag part.
Definition: TileCalibUtils.cxx:33