12 Python helper module for managing COOL DB connections and TileCalibBlobs.
16 from PyCool
import cool
17 import datetime, time, re, os
20 from urllib.request
import urlopen
23 from urllib2
import urlopen
27 from TileCalibBlobObjs.Classes
import TileCalibUtils, TileCalibDrawerCmt, \
28 TileCalibDrawerInt, TileCalibDrawerOfc, TileCalibDrawerBch, \
29 TileCalibDrawerFlt, TileCalibType
32 from TileCalibBlobPython.TileCalibLogger
import TileCalibLogger, getLogger
47 MAXRUN = cool.Int32Max
48 MAXLBK = cool.UInt32Max
49 UNIX2COOL = 1000000000
50 UNIXTMAX = cool.Int32Max
58 Return the run number of next run to be taken in the pit
61 urls = [
"http://atlas-service-db-runlist.web.cern.ch/atlas-service-db-runlist/cgi-bin/latestRun.py",
62 "http://pcata007.cern.ch/cgi-bin/getLastRunNumber.py",
63 "http://pcata007.cern.ch/latestRun"]
68 for line
in urlopen(url).readlines():
78 return max(run+1,222222)
84 Return the minimal run number of runs in prompt calibration loop
90 fin =
open(
"/afs/cern.ch/user/a/atlcond/scratch0/nemo/prod/web/calibruns.txt",
"r").
read().
split()
94 promptCalibRuns.append(
int(line) )
100 if len(promptCalibRuns)==0:
102 urls = [
"http://pcata007.cern.ch/cgi-bin/getBulkRunNumber.py",
103 "http://pcata007.cern.ch/latestRun"]
108 for line
in urlopen(url).readlines():
114 promptCalibRuns=[run]
119 if len(promptCalibRuns) >= 1:
120 promptCalibRuns.sort()
121 return promptCalibRuns[0]
129 Return name of top-level tag for 'Current' or 'CurrentES' or 'Next' or 'NextES' aliases
132 aliasfolder =
'/afs/cern.ch/atlas/conditions/poolcond/buffer/BestKnowledge'
134 falias =
open(
'%s/%s' % (aliasfolder, aliastype))
135 alias = falias.readline()
137 return alias.replace(
'\n',
'').
replace(
'*',
'')
140 aliasfolder = os.getcwd()+
'/BestKnowledge'
141 print(
"Looking for %s in %s" % (aliastype,aliasfolder))
143 falias =
open(
'%s/%s' % (aliasfolder, aliastype))
144 alias = falias.readline()
146 return alias.replace(
'\n',
'').
replace(
'*',
'')
148 return aliastype.upper()
154 Returns the common Tile prefix used for all COOL folders.
155 ofl = False ... single version folders
156 ofl = True ... multiversion folders
157 splitOnlInOflSchema = False ... offline only folders or
158 splitOnline folders in Online schema
159 splitOnlInOflSchema = True ... splitOnlineFolders in
163 if splitOnlInOflSchema:
164 return "/TILE/OFL02/"
166 return "/TILE/OFL01/"
168 return "/TILE/ONL01/"
174 Returns a list of all TILE folder prefixes
176 return [
"/TILE/ONL01/",
"/TILE/OFL01/",
"/TILE/OFL02/"]
182 Returns the run-lumi type folder description needed to read back the folder content
183 as a CondAttrListCollection in Athena.
185 desc =
'<timeStamp>'+type+
'</timeStamp>'
186 desc+=
'<addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader>'
187 desc+=
'<typeName>CondAttrListCollection</typeName>'
193 type = re.compile(
".*<timeStamp>(.*)</timeStamp>.*").
search(folderDescr)
195 raise Exception(
"No folder type info found in \'%s\'" % folderDescr)
196 return type.groups()[0]
200 def openDb(db, instance, mode="READONLY", schema="COOLOFL_TILE", sqlfn="tileSqlite.db"):
202 Opens a COOL db connection.
203 - db: The DB type. The following names are recognized:
204 * SQLITE: Opens file mentioned in sqlfn parameter
205 * ORACLE or FRONTIER: Opens ORACLE DB, forces READONLY
206 - instance: One of valid instances - CONDBR2 OFLP200 COMP200 CMCP200
207 - mode: Can be READONLY (default), RECREATE or UPDATE
208 - schema: One of valid schemas - COOLONL_CALO COOLOFL_CALO COOLONL_LAR COOLOFL_LAR COOLONL_TILE COOLOFL_TILE
209 - sqlfn: Name of sqlite file if db is SQLITE
213 validDb = [
"SQLITE",
"ORACLE",
"FRONTIER"]
214 if db
not in validDb:
215 raise Exception(
"DB not valid: %s, valid DBs are: %s" % (db,validDb) )
216 elif db ==
"ORACLE" or db ==
"FRONTIER":
220 validInstance = [
"COMP200",
"CONDBR2",
"CMCP200",
"OFLP200"]
221 if instance
not in validInstance:
222 raise Exception(
"Instance not valid: %s, valid instance are: %s" % (instance,validInstance) )
225 validSchema = [
"COOLONL_TILE",
"COOLOFL_TILE"]
226 if schema
not in validSchema:
227 raise Exception(
"Schema not valid: %s, valid schemas are: %s" % (schema,validSchema) )
232 if mode==
"READONLY" and not os.path.exists(sqlfn):
233 raise Exception(
"Sqlite file %s does not exist" % (sqlfn) )
234 if (mode==
"RECREATE" or mode==
"UPDATE")
and not os.path.exists(os.path.dirname(sqlfn)):
235 dirn=os.path.dirname(sqlfn)
238 connStr=
"sqlite://X;schema=%s;dbname=%s" % (sqlfn,instance)
240 connStr=
'frontier://ATLF/()/;schema=ATLAS_%s;dbname=%s' % (schema,instance)
242 connStr=
'oracle://%s;schema=ATLAS_%s;dbname=%s' % (
'ATLAS_COOLPROD',schema,instance)
244 connStr=schema+
'/'+instance
252 Opens a COOL db connection.
253 - connStr: The DB connection string
254 - mode: Can be READONLY (default), RECREATE or UPDATE
255 or ORACLE or FRONTIER if connStr is only short name of the database
259 splitname=connStr.split(
'/')
260 if (len(splitname)!=2):
264 instance=splitname[1]
266 connStr_new=
'oracle://%s;schema=ATLAS_%s;dbname=%s' % (
'ATLAS_COOLPROD',schema,instance)
268 connStr_new=
'frontier://ATLF/()/;schema=ATLAS_%s;dbname=%s' % (schema,instance)
271 dbSvc = cool.DatabaseSvcFactory.databaseService()
272 log.info(
"---------------------------------------------------------------------------------" )
273 log.info(
"-------------------------- TileCalibTools.openDbConn ----------------------------" )
274 log.info(
"- using COOL version %s", dbSvc.serviceVersion() )
275 log.info(
"- opening TileDb: %s",connStr_new )
276 log.info(
"- mode: %s", mode )
277 log.info(
"---------------------------------------------------------------------------------" )
280 if mode
in [
"READONLY",
"ORACLE",
"FRONTIER",
"",
None]:
283 db=dbSvc.openDatabase(connStr_new,
True)
284 except Exception
as e:
286 log.critical(
"Could not connect to %s" % connStr_new )
289 elif mode==
"RECREATE":
291 dbSvc.dropDatabase(connStr_new)
293 db = dbSvc.createDatabase(connStr_new)
294 except Exception
as e:
296 log.critical(
"Could not create database, giving up..." )
302 db=dbSvc.openDatabase(connStr_new,
False)
303 except Exception
as e:
305 log.warning(
"Could not connect to \'%s\', trying to create it....", connStr_new )
307 db=dbSvc.createDatabase(connStr_new)
308 except Exception
as e:
310 log.critical(
"Could not create database, giving up..." )
314 log.error(
"Mode \"%s\" not recognized", mode )
321 Returns COOL timeStamp build from run and lumi block numbers
323 return (
int(runNum)<<32) +
int(lbkNum)
329 Retruns UNIX time stamp given an input time string
331 return int(time.mktime(time.strptime(timeString,
"%Y-%m-%d %H:%M:%S")))
337 The interpretation of pointInTime depends on their type:
338 - tuple(int,int) : run and lbk number
339 - integer : Values are interpreted as unix time stamps
340 - string : time stamp of format 'yyyy-mm-dd hh:mm:ss'
346 if isinstance(pointInTime, str):
350 if isinstance(pointInTime, int):
352 validityKey = pointInTime * UNIX2COOL
355 validityKey =
int(time.time()) * UNIX2COOL
357 validityKey = cool.ValidityKeyMax
359 elif isinstance(pointInTime, tuple):
363 raise Exception(
"Unrecognized pointInTime type=%s" %
type(pointInTime))
364 return cool.ValidityKey(validityKey)
372 if globalTag.startswith(
"/")
or globalTag.startswith(
"TileO"):
374 log.warning(
"Using tag as-is for folder %s", folderPath)
375 elif '/TILE/ONL01' in folderPath:
376 log.info(
"Using empty tag for single-version folder %s", folderPath)
377 elif globalTag.startswith(
" "):
378 log.warning(
"Using empty tag for folder %s", folderPath)
381 log.warning(
"Using tag with empty suffix for folder %s", folderPath)
383 schema=
'COOLOFL_TILE/CONDBR2'
384 if isinstance(db, six.string_types):
385 if 'OFLP200' in db
or 'MC' in db:
386 schema=
'COOLOFL_TILE/OFLP200'
387 if not globalTag.startswith(
"OFLCOND"):
388 if globalTag.startswith(
"RUN"):
389 globalTag=
'OFLCOND-'+globalTag
390 log.info(
"Using Simulation global tag \'%s\'", globalTag)
391 elif 'COMP200' in db
or 'RUN1' in db:
392 schema=
'COOLOFL_TILE/COMP200'
393 if globalTag!=
'UPD1' and globalTag!=
'UPD4' and (
'UPD1' in globalTag
or 'UPD4' in globalTag
or 'COND' not in globalTag):
394 log.info(
"Using suffix \'%s\' as it is", globalTag)
396 globalTag=
'COMCOND-BLKPA-RUN1-06'
397 log.info(
"Using RUN1 global tag \'%s\'", globalTag)
398 if schema ==
'COOLOFL_TILE/CONDBR2':
399 if globalTag==
'CURRENT' or globalTag==
'UPD4' or globalTag==
'':
401 log.info(
"Resolved CURRENT globalTag to \'%s\'", globalTag)
402 elif globalTag==
'CURRENTES' or globalTag==
'UPD1':
404 log.info(
"Resolved CURRENT ES globalTag to \'%s\'", globalTag)
405 elif globalTag==
'NEXT':
407 log.info(
"Resolved NEXT globalTag to \'%s\'", globalTag)
408 elif globalTag==
'NEXTES':
410 log.info(
"Resolved NEXT ES globalTag to \'%s\'", globalTag)
411 globalTag=globalTag.replace(
'*',
'')
412 if 'UPD1' in globalTag
or 'UPD4' in globalTag
or 'COND' not in globalTag:
414 log.info(
"Resolved localTag \'%s\' to folderTag \'%s\'", globalTag,tag)
416 if not isinstance(db, six.string_types):
418 folder = db.getFolder(folderPath)
419 tag = folder.resolveTag(globalTag)
420 log.info(
"Resolved globalTag \'%s\' to folderTag \'%s\'", globalTag,tag)
422 except Exception
as e:
424 log.warning(
"Using %s to resolve globalTag",schema)
427 folder = dbr.getFolder(folderPath)
428 tag = folder.resolveTag(globalTag)
430 log.info(
"Resolved globalTag \'%s\' to folderTag \'%s\'", globalTag,tag)
437 return (
int(iov >> 32),
int(iov & 0xFFFFFFFF))
441 def copyFolder(dbr, dbw, folder, tagr, tagw, chanNum, pointInTime1, pointInTime2):
443 log.info(
"Copy channel %i", chanNum)
445 folderR = dbr.getFolder(folder)
446 folderW = dbw.getFolder(folder)
448 chansel = cool.ChannelSelection(chanNum)
455 objs = folderR.browseObjects(iov1,iov2,chansel)
458 objs = folderR.browseObjects(iov1,iov2,chansel,tagr)
459 while objs.goToNext():
460 obj=objs.currentRef()
461 sinceCool=obj.since()
464 untilCool=obj.until()
468 log.debug(
"Copy entry: [%i,%i] - [%i,%i]: %s", sinceTup[0],sinceTup[1],untilTup[0],untilTup[1], data)
469 folderW.storeObject(sinceCool, untilCool, data, chanNum, tagw, multiVersion)
483 TileCalibBlobWriterBase is a helper class, managing the details of
484 COOL interactions for the user of TileCalibBlobs.
488 def __init__(self, db, folderPath, calibDrawerType,
489 isMultiVersionFolder=True, isRunLumiTimeStamp=True):
492 - db : db should be an open database connection
493 - folderPath: full folder path to create or update
497 TileCalibLogger.__init__(self,
"TileBlobWriter")
503 folderMode = cool.FolderVersioning.MULTI_VERSION
504 if not isMultiVersionFolder:
505 folderMode = cool.FolderVersioning.SINGLE_VERSION
509 if not isRunLumiTimeStamp:
515 if self.
__db.existsFolder(folderPath):
518 modeInCool = self.
__folder.versioningMode()
519 if modeInCool!=folderMode:
520 str =
"Incompatible folder mode detected, COOL folder has type "
521 if modeInCool==cool.FolderVersioning.MULTI_VERSION:
528 payloadSpec = cool.RecordSpecification()
529 payloadSpec.extend(
'TileCalibBlob', cool.StorageType.Blob64k )
530 folderSpec = cool.FolderSpecification(folderMode, payloadSpec)
531 self.
__folder = db.createFolder(folderPath, folderSpec, folderDescr,
True)
532 except Exception
as e:
533 self.log().critical( e )
542 if calibDrawerType==
'Flt':
543 self.
__defVec = cppyy.gbl.std.vector(
'std::vector<float>')()
544 elif calibDrawerType==
'Bch' or calibDrawerType==
'Int':
545 self.
__defVec = cppyy.gbl.std.vector(
'std::vector<unsigned int>')()
547 raise Exception(
"Unknown calibDrawerType: %s" % calibDrawerType)
551 def register(self, since=(MINRUN,MINLBK), until=(MAXRUN,MAXLBK), tag=
"", option=0):
553 Registers the folder in the database.
554 - since: lower limit of IOV
555 - until: upper limit of IOV
556 - tag : The cool folder tag to write to
558 The interpretation of the 'since' and 'until' inputs depends on their type:
559 - tuple(int,int) : run and lbk number
560 - integer : Values are interpreted as unix time stamps
561 If since<0, current time is assumed
562 If until<0, infinity is assumed
563 - string : time stamp of format 'yyyy-mm-dd hh:mm:ss'
568 raise Exception(
"Inconsistent types: since=%s, until=%s" % (
type(since),
type(until)))
572 if self.
__folder.versioningMode()==cool.FolderVersioning.SINGLE_VERSION:
576 self.log().warning(
"Trying to store with tag \"%s\" to SINGLE_VERSION folder", tag )
577 self.log().warning(
"... resetting tag to \"\"!" )
583 if untilCool <= sinceCool:
584 raise Exception(
"Until(%i) <= Since(%i)" % (untilCool,sinceCool))
588 if isinstance(since, tuple):
589 iovString =
"[%i,%i] - [%i,%i]" % (since[0],since[1],until[0],until[1])
591 sinceInfo = time.localtime( sinceCool//UNIX2COOL )
592 untilInfo = time.localtime(
min(UNIXTMAX, (untilCool//UNIX2COOL)))
593 untilStr =
"<infinity>"
594 if untilCool<cool.ValidityKeyMax:
595 untilStr = time.asctime(untilInfo)
596 if (untilCool//UNIX2COOL)>UNIXTMAX:
597 untilStr =
" > "+untilStr
598 iovString =
"[%s] - [%s]" % (time.asctime(sinceInfo), untilStr)
605 onlyComment = (option<0)
606 noComment = (comment
is None)
or (comment ==
"None")
or (comment.startswith(
"None")
and comment.endswith(
"None"))
or (option>0)
608 self.log().
info(
"... with IOV : %s" , iovString )
611 self.log().
info(
"... WITHOUT comment field" )
613 self.log().
info(
"... with comment field: \"%s\"", self.
getComment() )
621 for chanNum
in chanList:
622 if chanNum==1000
and noComment:
625 strout =
"cool channel=%4i" % chanNum
626 self.log().
debug(
"Registering %s %s", strout, data)
627 channelId = cool.ChannelId(chanNum)
628 self.
__folder.storeObject(sinceCool, untilCool, data, channelId, folderTag, userTagOnly)
631 self.log().
info(
"... %d cool channels have been written in total", cnt )
633 self.log().
info(
"... 1 cool channel with comment field has been written" )
635 self.log().
info(
"... %d cool channels have been written in total (including comment field)", cnt )
640 Sets a general comment in the comment channel.
646 spec = self.
__folder.payloadSpecification()
647 data = cool.Record( spec )
649 blob = data[
'TileCalibBlob']
650 if isinstance(author,tuple)
and len(author)==3:
651 tm=time.mktime(datetime.datetime.strptime(author[2],
"%a %b %d %H:%M:%S %Y").timetuple())
655 except Exception
as e:
656 self.log().critical( e )
661 Returns the general comment (default if none is set)
667 return "<No general comment!>"
668 blob = data[
'TileCalibBlob']
671 return (cmt.getAuthor(),cmt.getComment(),cmt.getDate())
673 return cmt.getFullComment()
674 except Exception
as e:
675 self.log().critical( e )
678 def getDrawer(self, ros, drawer, calibDrawerTemplate=None):
680 Returns a TileCalibDrawer object of requested type
681 for the given ROS and drawer.
693 spec = self.
__folder.payloadSpecification()
694 data = cool.Record( spec )
696 blob = data[
'TileCalibBlob']
706 raise Exception(
"Invalid blob type requested: %s" % type )
709 if calibDrawerTemplate:
710 calibDrawer.clone(calibDrawerTemplate)
716 except Exception
as e:
717 self.log().critical( e )
723 Resets blob size to zero
729 spec = self.
__folder.payloadSpecification()
730 data = cool.Record( spec )
732 blob = data[
'TileCalibBlob']
734 except Exception
as e:
735 self.log().critical( e )
750 TileCalibBlobReader is a helper class, managing the details of COOL interactions for
751 the user of TileCalibBlobs.
758 - db : db should be an open database connection
759 - folder: full folder path
760 - tag : The folder tag, e.g. \"000-00\"
763 TileCalibLogger.__init__(self,
"TileBlobReader")
769 except Exception
as e:
770 self.log().critical( e )
774 validFolderTypes = (
"run-lumi",
"time")
778 raise Exception(
"Invalid folder type found: \'%s\'" % self.
__folderType)
790 Returns the general comment (default if none is set)
795 obj = self.
__folder.findObject(validityKey, chanNum, self.
__tag)
796 self.log().
debug(
"getComment:Fetching from DB: %s", obj)
797 blob = obj.payload()[0]
800 return (cmt.getAuthor(),cmt.getComment(),cmt.getDate())
802 return cmt.getFullComment()
804 return "<no comment found>"
809 Returns a default drawer number (among first 20 COOL channels) for any drawer in any partition
812 if drawer<=4
or drawer==12
or drawer>=20:
818 elif ros==1
or ros==2:
821 OffsetEBA = [ 0, 0, 0, 0, 0, 0, 3, 2,
822 0, 0, 0, 0, 7, 6, 5, 7,
823 7, 6, 6, 7, 0, 0, 0, 2,
824 3, 0, 0, 0, 0, 0, 0, 0,
825 0, 0, 0, 0, 0, 0, 1, 1,
826 1, 1, 2, 3, 0, 0, 0, 0,
827 0, 0, 0, 0, 3, 2, 1, 1,
828 1, 1, 0, 0, 0, 0, 0, 0]
829 drawer1 = 12 + OffsetEBA[drawer]
831 OffsetEBC = [ 0, 0, 0, 0, 0, 0, 3, 2,
832 0, 0, 0, 0, 7, 6, 6, 7,
833 7, 5, 6, 7, 0, 0, 0, 2,
834 3, 0, 0, 3, 4, 0, 3, 4,
835 0, 4, 3, 0, 4, 3, 1, 1,
836 1, 1, 2, 3, 0, 0, 0, 0,
837 0, 0, 0, 0, 3, 2, 1, 1,
838 1, 1, 0, 0, 0, 0, 0, 0]
839 drawer1 = 12 + OffsetEBC[drawer]
846 def getDrawer(self, ros, drawer, pointInTime, printError=True, useDefault=True):
848 Returns a TileCalibDrawer object for the given ROS and drawer.
852 self.log().
debug(
"Validity key is %s", validityKey)
856 key = (ros,drawer,validityKey)
861 obj = self.
__folder.findObject(validityKey, chanNum, self.
__tag)
862 self.log().
debug(
"Fetching from DB: %s", obj)
863 blob = obj.payload()[0]
864 self.log().
debug(
"blob size: %d", blob.size())
866 if not useDefault
and blob.size()==0:
868 while blob.size()==0:
870 if ros==0
and drawer==0:
871 raise Exception(
'No default available')
875 obj = self.
__folder.findObject(validityKey, chanNum, self.
__tag)
876 blob = obj.payload()[0]
880 blob = obj.payload()[0]
881 self.log().
debug(
"blob size: %d", blob.size())
887 if typeName==
'TileCalibDrawerFlt':
889 self.log().
debug(
"typeName = Flt " )
890 elif typeName==
'TileCalibDrawerInt':
892 self.log().
debug(
"typeName = Int " )
893 elif typeName==
'TileCalibDrawerBch':
895 self.log().
debug(
"typeName = Bch " )
896 elif typeName==
'TileCalibDrawerOfc':
898 self.log().
debug(
"typeName = Ofc " )
900 raise Exception(
"Invalid blob type requested: %s" % typeName )
902 except Exception
as e:
904 self.log().
error(
"TileCalibTools.getDrawer(): Fetching of ros=%i, drawer=%i failed with exception %s", ros,drawer,e)
910 Returns a TileCalibDrawer object for the given ROS and drawer.
914 self.log().
debug(
"Validity key is %s", validityKey)
918 key = (ros,drawer,validityKey)
923 obj = self.
__folder.findObject(validityKey, chanNum, self.
__tag)
924 self.log().
debug(
"Fetching from DB: %s", obj)
925 blob = obj.payload()[0]
926 self.log().
debug(
"blob size: %d", blob.size())
928 while blob.size()==0:
930 if ros==0
and drawer==0:
931 raise Exception(
'No default available')
935 obj = self.
__folder.findObject(validityKey, chanNum, self.
__tag)
936 blob = obj.payload()[0]
940 blob = obj.payload()[0]
941 self.log().
debug(
"blob size: %d", blob.size())
947 if typeName==
'TileCalibDrawerFlt':
949 self.log().
debug(
"typeName = Flt " )
950 elif typeName==
'TileCalibDrawerInt':
952 self.log().
debug(
"typeName = Int " )
953 elif typeName==
'TileCalibDrawerBch':
955 self.log().
debug(
"typeName = Bch " )
956 elif typeName==
'TileCalibDrawerOfc':
958 self.log().
debug(
"typeName = Ofc " )
960 raise Exception(
"Invalid blob type requested: %s" % typeName )
962 except Exception
as e:
964 self.log().
error(
"TileCalibTools.getDefaultDrawer(): Fetching of ros=%i, drawer=%i failed with exception %s", ros,drawer,e)
968 def getDBobjsWithinRange(self, ros, drawer, point1inTime=(0,0), point2inTime=(2147483647,4294967295), printError=
True):
970 Returns all DB objects for the given ROS and drawer, within given validity range -- default: [0-Infty)
971 Check getBlobsWithinRange for an example on how to loop over objects and check validity ranges.
978 self.log().
debug(
"Validity key range is %s - %s", validityKey1,validityKey2)
983 dbChanSel = cool.ChannelSelection(dbChanNum)
985 objs = self.
__folder.browseObjects(validityKey1,validityKey2,dbChanSel,self.
__tag)
986 except Exception
as e:
988 self.log().
error(
"TileCalibTools.getDBobjsWithinRange(): Fetching of ros=%i, drawer=%i failed with exception %s", ros,drawer,e)
993 def getIOVsWithinRange(self, ros, drawer, point1inTime=(0,0), point2inTime=(2147483647,4294967295), printError=
True):
995 Returns list of IOVS for the given ROS and drawer, within given validity range -- default: [0-Infty)
1000 log.warning(
"Warning: can not read IOVs for ros %d drawer %d from input DB file", ros,drawer )
1002 while dbobjs.goToNext():
1003 obj = dbobjs.currentRef()
1004 objsince = obj.since()
1005 sinceRun = objsince >> 32
1006 sinceLum = objsince & 0xFFFFFFFF
1007 since = (sinceRun, sinceLum)
1014 Returns all blob objects for the given ROS and drawer, within given validity range -- default: [0-Infty)
1015 Note: the blobs don't contain validity range info. Check method getDBobjsWithinRange()
1021 print (
"Validity keys range is %s - %s" % (validityKey1, validityKey2))
1022 self.log().
debug(
"Validity key range is %s - %s", validityKey1,validityKey2)
1029 while objs.goToNext():
1030 obj=objs.currentRef()
1031 sinceCool=obj.since()
1032 if sinceCool < validityKey1:
1033 sinceCool = validityKey1
1034 untilCool=obj.until()
1035 blob = obj.payload()[0]
1036 print (
"[%d,%d)-[%d,%d) - %s" % ((sinceCool>>32),(sinceCool&0xFFFFFFFF),(untilCool>>32),(untilCool&0xFFFFFFFF),blob))
1037 self.log().
debug(
"blob size: %d", blob.size())
1040 while blob.size()==0:
1042 if ros==0
and drawer==0:
1043 raise Exception(
'No default available')
1047 obj = self.
__folder.findObject(sinceCool, chanNum, self.
__tag)
1048 blob = obj.payload()[0]
1049 self.log().
debug(
"blob size: 0 --> default: %d", blob.size())
1058 if typeName==
'TileCalibDrawerFlt':
1060 self.log().
debug(
"typeName = Flt " )
1061 elif typeName==
'TileCalibDrawerInt':
1063 self.log().
debug(
"typeName = Int " )
1064 elif typeName==
'TileCalibDrawerBch':
1066 self.log().
debug(
"typeName = Bch " )
1067 elif typeName==
'TileCalibDrawerOfc':
1069 self.log().
debug(
"typeName = Ofc " )
1071 raise Exception(
"Invalid blob type requested: %s" % typeName )
1073 blobs.append( calibDrawer )
1080 Returns true if MultiVersion folder is connected
1082 if self.
__folder.versioningMode()==cool.FolderVersioning.MULTI_VERSION:
1098 This is a class capable of parsing TileCal conditions data stored in
1099 ASCII files. Both the single and multi-line formats are supported.
1103 def __init__(self, fileName, calibId, isSingleLineFormat=True):
1106 - fileName : input file name
1107 - isSingleLineFormat: if False, multi line format is assumed
1110 TileCalibLogger.__init__(self,
"TileASCIIParser")
1113 lines =
open(fileName,
"r").readlines()
1114 except Exception
as e:
1115 self.log().
error(
"TileCalibASCIIParser::ERROR: Problem opening input file:" )
1116 self.log().
error( e )
1120 fields = line.strip().
split()
1122 if not len(fields) :
1124 if fields[0].startswith(
"#"):
1132 if not isSingleLineFormat:
1133 raise Exception(
"Multiline format not implemented yet")
1137 raise Exception(
"%s is not calibId=%s" % (type,calibId))
1140 if not (frag.startswith(
'0x')
or frag.startswith(
'-0x')
or frag.startswith(
'h_')):
1141 raise Exception(
"Misformated fragment %s" % frag)
1142 if frag.startswith(
'0x')
or frag.startswith(
'-0x'):
1150 elif frag.startswith(
'h_'):
1151 part_dict = {
'LBA':1,
'LBC':2,
'EBA':3,
'EBC':4}
1152 partname =
str(frag[2:5])
1153 ros=part_dict[partname]
1154 mod =
int(frag[5:])-1
1155 if (chan.startswith(
'ch')):
1162 dictKey = (ros,mod,chn)
1167 dictKey = (
int(ros),
int(drawer),
int(channel))
1178 "Reorder the PMTs (SV: how to get that from region.py???)"
1179 "This takes ros [1-4], drawer [0-63], pmt [1-48]"
1181 PMT2chan_Special={1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,10:9,
1182 11:10,12:11,13:12,14:13,15:14,16:15,17:16,18:17, 19:18, 20:19,
1183 21:20,22:21,23:22,24:23,27:24,26:25,25:26,31:27,32:28,28:29,
1184 33:30,29:31,30:32,36:33,35:34,34:35,44:36,38:37,37:38,43:39,42:40,
1185 41:41,45:42,39:43,40:44,48:45,47:46,46:47}
1188 PMT2chan_LB={1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,10:9,
1189 11:10,12:11,13:12,14:13,15:14,16:15,17:16,18:17,19:18,20:19,
1190 21:20,22:21,23:22,24:23,27:24,26:25,25:26,30:27,29:28,28:29,
1191 33:30,32:31,31:32,36:33,35:34,34:35,39:36,38:37,37:38,42:39,41:40,
1192 40:41,45:42,44:43,43:44,48:45,47:46,46:47}
1195 PMT2chan_EB={1:0,2:1,3:2,4:3,5:4,6:5,7:6,8:7,9:8,10:9,
1196 11:10,12:11,13:12,14:13,15:14,16:15,17:16,18:17,19:18,20:19,
1197 21:20,22:21,23:22,24:23,25:24,26:25,27:26,28:27,31:28,32:29,
1198 33:30,29:31,30:32,35:33,36:34,34:35,44:36,38:37,37:38,43:39,42:40,
1199 41:41,39:42,40:43,45:44,46:45,47:46,48:47}
1202 chan = PMT2chan_LB[pmt]
1203 elif (ros == 3
and drawer == 14)
or (ros == 4
and drawer == 17):
1204 chan = PMT2chan_Special[pmt]
1206 chan = PMT2chan_EB[pmt]
1220 This is a class capable of parsing TileCal conditions data stored in
1221 ASCII files. This version of parser can be used when mutiple IOVs are
1222 given in the file. First column is (run,lumi) pair in this case
1226 def __init__(self, fileName, calibId="", readGain=True):
1229 - fileName : input file name
1230 - calibId : like Ped, Las, ... or (r,l) or (run,lumi) but can be empty string as well
1231 - readGain : if False, no gain field in input file
1234 TileCalibLogger.__init__(self,
"TileASCIIParser2")
1242 lines =
open(fileName,
"r").readlines()
1243 except Exception
as e:
1244 self.log().
error(
"TileCalibASCIIParser2::ERROR: Problem opening input file:" )
1245 self.log().
error( e )
1248 self.log().
info(
"Parsing file %s",fileName)
1250 self.log().
info(
"Looking for prefix %s",calibId)
1253 fields = line.strip().
split()
1255 if not len(fields) :
1257 if fields[0].startswith(
"#"):
1265 if str(chan)[0:2].lower() ==
"pm":
1275 iov=tuple(
int(i)
for i
in pref[1:-1].
split(
","))
1276 if len(iov)!=2
or pref[0]!=
"(" or pref[-1]!=
")":
1277 raise Exception(
"%s is not %s IOV" % (pref,calibId))
1279 raise Exception(
"%s is not calibId=%s" % (pref,calibId))
1283 if str(chan)[0:2].lower() ==
"pm":
1292 if frag.startswith(
'0x')
or frag.startswith(
'-0x'):
1299 elif (frag.startswith(
"AUX")
or
1300 frag.startswith(
"LBA")
or
1301 frag.startswith(
"LBC")
or
1302 frag.startswith(
"EBA")
or
1303 frag.startswith(
"EBC")
or
1304 frag.startswith(
"ALL")
or
1305 frag.startswith(
"XXX") ):
1306 part_dict = {
'AUX':0,
'LBA':1,
'LBC':2,
'EBA':3,
'EBC':4,
'ALL':5,
'XXX':-1}
1307 partname =
str(frag[0:3])
1308 ros=part_dict[partname]
1309 mod =
int(frag[3:])-1
1311 raise Exception(
"Unknown fragment %s" % frag)
1327 if mod<0
or mod>=64:
1341 allchannels=(chn==-1)
1356 for ros
in range(rosmin,rosmax):
1357 for mod
in range(modmin,modmax):
1358 for chn
in range(chnmin,chnmax):
1359 if allchannels
or self.
channel2PMT(ros,mod,chn)>0:
1360 for adc
in range (adcmin,adcmax):
1361 dictKey = (ros,mod,chn,adc)
1371 def getData(self, ros, drawer, channel, adc, iov=(MAXRUN,MAXLBK)):
1372 dictKey = (
int(ros),
int(drawer),
int(channel),
int(adc))
1375 before= [i
for i
in sorted(data)
if i[0] <= iov ]
1377 data = before[-1][1]
1389 "Convert channel numbet to PMT number, negative for disconnected channels"
1390 "This takes ros [1-4], drawer [0-63], chan [0-47]"
1392 chan2PMT_LB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1393 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1394 27, 26, 25, 30, 29, 28,-33,-32, 31, 36, 35, 34,
1395 39, 38, 37, 42, 41, 40, 45,-44, 43, 48, 47, 46 ]
1397 chan2PMT_EB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1398 13, 14, 15, 16, 17, 18,-19,-20, 21, 22, 23, 24,
1399 -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
1400 44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46 ]
1402 chan2PMT_Sp=[ -1, -2, -3, -4, 5, 6, 7, 8, 9, 10, 11, 12,
1403 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1404 -27,-26,-25,-31,-32,-28, 33, 29, 30,-36,-35, 34,
1405 44, 38, 37, 43, 42, 41,-45,-39,-40,-48,-47,-46 ]
1408 pmt = chan2PMT_LB[chan]
1409 elif (ros == 3
and drawer == 14)
or (ros == 4
and drawer == 17):
1410 pmt = chan2PMT_Sp[chan]
1412 pmt = chan2PMT_EB[chan]
1418 "Convert PMT number to channel numbet"
1419 "This takes partition (LBA,LBC,EBA,EBC) and pmt [1-48]"
1421 chan2PMT_LB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1422 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1423 27, 26, 25, 30, 29, 28, 33, 32, 31, 36, 35, 34,
1424 39, 38, 37, 42, 41, 40, 45, 44, 43, 48, 47, 46 ]
1426 chan2PMT_EB=[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1427 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
1428 27, 26, 25, 31, 32, 28, 33, 29, 30, 36, 35, 34,
1429 44, 38, 37, 43, 42, 41, 45, 39, 40, 48, 47, 46 ]
1435 if str(partition)[0].
upper() ==
"E":
1436 chan = chan2PMT_EB.index(pm)
1438 chan = chan2PMT_LB.index(pm)
1451 This is a class capable of parsing TileCal conditions data stored in
1459 - fileName : input file name
1460 - calibId : like Trip, ...
1463 TileCalibLogger.__init__(self,
"TileASCIIParser3")
1466 lines =
open(fileName,
"r").readlines()
1467 except Exception
as e:
1468 self.log().
error(
"TileCalibASCIIParser3::ERROR: Problem opening input file:" )
1469 self.log().
error( e )
1473 fields = line.strip().
split()
1475 if not len(fields) :
1477 if fields[0].startswith(
"#"):
1487 raise Exception(
"%s is not calibId=%s" % (type, calibId))
1490 if not (frag.startswith(
'0x')
or frag.startswith(
'-0x')):
1491 raise Exception(
"Misformated fragment %s" % frag)
1501 dictKey = (ros, mod)
1506 dictKey = (
int(ros),
int(drawer))