ATLAS Offline Software
Loading...
Searching...
No Matches
PixelModuleFeMask_create_db.py
Go to the documentation of this file.
1import os, time,sys
2from PyCool import cool
3from CoolConvUtilities import AtlCoolLib
4import argparse
5# For resolving tags
6sys.path.append('/afs/cern.ch/user/a/atlcond/utils/python/')
7
8#try:
9# runnumber=int(input('Input:'))
10#except ValueError:
11# print ("Not a number")
12
13p = argparse.ArgumentParser()
14p.add_argument('-f', '--input_file', type=str, help='Please type the path to the input file!',default='000000')
15p.add_argument('-r', '--run', type=int, help='Please type the runnumber!',default='000000')
16args=p.parse_args()
17print("Input file: ",args.input_file)
18print("Run number: ",args.run)
19
20dbFile = 'PixelModuleFeMask_run'+str(args.run)+'.db'
21dbName = 'CONDBR2'
22path='/PIXEL/PixelModuleFeMask'
23tag = 'PixelModuleFeMask-RUN2-DATA-UPD4-05'
24print("Tag for database: ",tag)
25
26if os.path.isfile(dbFile):
27 os.remove(dbFile)
28
29
30dbSvc = cool.DatabaseSvcFactory.databaseService()
31dbString = "sqlite://;schema=%s;dbname=%s" % (dbFile, dbName)
32try:
33 db = dbSvc.createDatabase(dbString)
34except e:
35 print('Problem creating database', e)
36 sys.exit(-1)
37print ("Created database", dbString)
38
39spec = cool.RecordSpecification()
40spec.extend('data_array', cool.StorageType.String16M)
41desc = '<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader><typeName>CondAttrListCollection</typeName>'
42folderSpec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
43folder = db.createFolder(path, folderSpec, desc, True)
44data = cool.Record(spec)
45
46input_file = open(args.input_file,'r')
47nModules = sum(1 for line in input_file)
48input_file.close()
49
50input_file = open(args.input_file,'r')
51input_list=[[0 for x in range(4)] for y in range(nModules)]
52iterator=0
53for line in input_file:
54 input_list[iterator] = list(map(int, line.split()[0:4]))
55 iterator=iterator+1
56input_file.close()
57
58input_list = sorted(input_list, key=lambda x: x[0])
59
60runnumber_large=args.run << 32
61iov_start_min=100000000000000000000
62iov_end_max=0
63payload_list=[]
64module_old=0;
65FE_code_old=0;
66
67for k in range(10000): #number maybe needs to be set to a higher value if run has more than 10000 LBs
68 input_file = open(args.input_file,'r')
69 payload = ""
70
71 for i in range(nModules):
72 module=input_list[i][0]
73 FEcode=input_list[i][1]
74 iov_start=input_list[i][2]
75 iov_end=input_list[i][3]
76 stop=0
77 if (iov_start<=runnumber_large+k and iov_end>=runnumber_large+k) or (iov_start==0 and iov_end==0):
78 if(module_old==module):
79 if module==input_list[i-1][0] and FEcode!=0:
80 FEcode=0
81 if(FEcode!=0):
82 continue
83 remove='"'+str(module_old)+'":'+str(FE_code_old)+","
84 payload=payload.replace(remove,"")
85 module_old=module
86 FE_code_old=FEcode
87 #if(FEcode!=0):#only if FE information not wanted
88 #continue
89 payload=payload+'"'+str(module)+'":'+str(FEcode)+','
90 if iov_start<iov_start_min and iov_start!=0:
91 iov_start_min=iov_start
92 if iov_end>iov_end_max:
93 iov_end_max=iov_end
94 payload=payload[:-1]
95 payload="{"+payload+"}"
96 payload_list.append(payload)
97
98iov_end_max=iov_end_max-runnumber_large
99iov_start_min=iov_start_min-runnumber_large
100since_bool=False
101since=0
102until=0
103channel=0
104print(iov_end_max,iov_start_min, runnumber_large)
105for k in range(1000000):#4294967295
106 if(k>=iov_start_min and k<=iov_end_max):
107 if(k==iov_start_min):
108 since=runnumber_large+k
109
110 if (payload_list[k]==payload_list[k+1]):
111 if(since_bool==False):
112 since = runnumber_large+k
113 since_bool=True
114 else:
115 since_bool=False
116 until = runnumber_large+k+1
117 data['data_array'] = payload_list[k]
118 folder.storeObject(since,until,data,channel,tag)
119
120 if(since_bool==False):
121 since = runnumber_large+k+1
122
123input_file.close()
124db.closeDatabase()
if(febId1==febId2)
void print(char *figname, TCanvas *c1)
STL class.