ATLAS Offline Software
PixelModuleFeMask_create_db.py
Go to the documentation of this file.
1 import os, time,sys
2 from PyCool import cool
3 from CoolConvUtilities import AtlCoolLib
4 import argparse
5 # For resolving tags
6 sys.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 
13 p = argparse.ArgumentParser()
14 p.add_argument('-f', '--input_file', type=str, help='Please type the path to the input file!',default='000000')
15 p.add_argument('-r', '--run', type=int, help='Please type the runnumber!',default='000000')
16 args=p.parse_args()
17 print("Input file: ",args.input_file)
18 print("Run number: ",args.run)
19 
20 dbFile = 'PixelModuleFeMask_run'+str(args.run)+'.db'
21 dbName = 'CONDBR2'
22 path='/PIXEL/PixelModuleFeMask'
23 tag = 'PixelModuleFeMask-RUN2-DATA-UPD4-05'
24 print("Tag for database: ",tag)
25 
26 if os.path.isfile(dbFile):
27  os.remove(dbFile)
28 
29 
30 dbSvc = cool.DatabaseSvcFactory.databaseService()
31 dbString = "sqlite://;schema=%s;dbname=%s" % (dbFile, dbName)
32 try:
33  db = dbSvc.createDatabase(dbString)
34 except e:
35  print('Problem creating database', e)
36  sys.exit(-1)
37 print ("Created database", dbString)
38 
39 spec = cool.RecordSpecification()
40 spec.extend('data_array', cool.StorageType.String16M)
41 desc = '<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader><typeName>CondAttrListCollection</typeName>'
42 folderSpec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
43 folder = db.createFolder(path, folderSpec, desc, True)
44 data = cool.Record(spec)
45 
46 input_file = open(args.input_file,'r')
47 nModules = sum(1 for line in input_file)
48 input_file.close()
49 
50 input_file = open(args.input_file,'r')
51 input_list=[[0 for x in range(4)] for y in range(nModules)]
52 iterator=0
53 for line in input_file:
54  input_list[iterator] = list(map(int, line.split()[0:4]))
55  iterator=iterator+1
56 input_file.close()
57 
58 input_list = sorted(input_list, key=lambda x: x[0])
59 
60 runnumber_large=args.run << 32
61 iov_start_min=100000000000000000000
62 iov_end_max=0
63 payload_list=[]
64 module_old=0;
65 FE_code_old=0;
66 
67 for 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 
98 iov_end_max=iov_end_max-runnumber_large
99 iov_start_min=iov_start_min-runnumber_large
100 since_bool=False
101 since=0
102 until=0
103 channel=0
104 print(iov_end_max,iov_start_min, runnumber_large)
105 for 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 
123 input_file.close()
124 db.closeDatabase()
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
Trk::open
@ open
Definition: BinningType.h:40
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
str
Definition: BTagTrackIpAccessor.cxx:11
dbg::print
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition: SGImplSvc.cxx:70