ATLAS Offline Software
Loading...
Searching...
No Matches
python.TileCalibTools.TileBlobWriter Class Reference
Inheritance diagram for python.TileCalibTools.TileBlobWriter:
Collaboration diagram for python.TileCalibTools.TileBlobWriter:

Public Member Functions

 __init__ (self, db, folderPath, calibDrawerType, isMultiVersionFolder=True, isRunLumiTimeStamp=True)
 register (self, since=(MINRUN, MINLBK), until=(MAXRUN, MAXLBK), tag="", option=0)
 setComment (self, author, comment=None)
 getComment (self, split=False)
 getDrawer (self, ros, drawer, calibDrawerTemplate=None)
 zeroBlob (self, ros, drawer)

Private Attributes

 __db = db
 __folder = self.__db.getFolder(folderPath)
dict __chanDictRecord = {}
dict __chanDictDrawer = {}
str __calibDrawerType = calibDrawerType
 __defVec = cppyy.gbl.std.vector('std::vector<float>')()

Detailed Description

TileCalibBlobWriterBase is a helper class, managing the details of
COOL interactions for the user of TileCalibBlobs.

Definition at line 603 of file TileCalibTools.py.

Constructor & Destructor Documentation

◆ __init__()

python.TileCalibTools.TileBlobWriter.__init__ ( self,
db,
folderPath,
calibDrawerType,
isMultiVersionFolder = True,
isRunLumiTimeStamp = True )
Input:
- db        : db should be an open database connection
- folderPath: full folder path to create or update

Definition at line 610 of file TileCalibTools.py.

611 isMultiVersionFolder=True, isRunLumiTimeStamp=True):
612 """
613 Input:
614 - db : db should be an open database connection
615 - folderPath: full folder path to create or update
616 """
617
618 #=== initialize base class
619 TileCalibLogger.__init__(self,"TileBlobWriter")
620
621 #=== store db
622 self.__db = db
623
624 #=== determine folder mode
625 folderMode = cool.FolderVersioning.MULTI_VERSION
626 if not isMultiVersionFolder:
627 folderMode = cool.FolderVersioning.SINGLE_VERSION
628
629 #=== determine folder description
630 folderDescr = getAthenaFolderDescr("run-lumi")
631 if not isRunLumiTimeStamp:
632 folderDescr = getAthenaFolderDescr("time")
633
634 #=== access folder in db
635 try:
636 #=== create folder if it does not exist
637 if self.__db.existsFolder(folderPath):
638 self.__folder = self.__db.getFolder(folderPath)
639 #=== check folder mode
640 modeInCool = self.__folder.versioningMode()
641 if modeInCool!=folderMode:
642 str = "Incompatible folder mode detected, COOL folder has type "
643 if modeInCool==cool.FolderVersioning.MULTI_VERSION:
644 str += "MULTI"
645 else:
646 str += "SINGLE"
647 raise Exception(str)
648 else:
649 #=== create folder if it does not exist
650 payloadSpec = cool.RecordSpecification()
651 payloadSpec.extend( 'TileCalibBlob', cool.StorageType.Blob64k )
652 folderSpec = cool.FolderSpecification(folderMode, payloadSpec)
653 self.__folder = db.createFolder(folderPath, folderSpec, folderDescr, True)
654 except Exception as e:
655 self.log().critical( e )
656 raise
657
658 #=== initialize channel dictionaries
659 self.__chanDictRecord = {} # <int, cool.Record >
660 self.__chanDictDrawer = {} # <int, TileCalibDrawer>
661
662 #=== create default vectors based on calibDrawerType
663 self.__calibDrawerType = calibDrawerType
664 if calibDrawerType=='Flt':
665 self.__defVec = cppyy.gbl.std.vector('std::vector<float>')()
666 elif calibDrawerType=='Bch' or calibDrawerType=='Int':
667 self.__defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')()
668 else:
669 raise Exception("Unknown calibDrawerType: %s" % calibDrawerType)
670
671

Member Function Documentation

◆ getComment()

python.TileCalibTools.TileBlobWriter.getComment ( self,
split = False )
Returns the general comment (default if none is set)

Definition at line 781 of file TileCalibTools.py.

781 def getComment(self, split=False):
782 """
783 Returns the general comment (default if none is set)
784 """
785 try:
787 data = self.__chanDictRecord.get(chanNum)
788 if not data:
789 return "<No general comment!>"
790 blob = data['TileCalibBlob']
792 if split:
793 return (cmt.getAuthor(),cmt.getComment(),cmt.getDate())
794 else:
795 return cmt.getFullComment()
796 except Exception as e:
797 self.log().critical( e )
798
static const TileCalibDrawerCmt * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerCmt.
static unsigned int getCommentChannel()
Returns the COOL channel number for the comment channel.
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition hcg.cxx:130

◆ getDrawer()

python.TileCalibTools.TileBlobWriter.getDrawer ( self,
ros,
drawer,
calibDrawerTemplate = None )
Returns a TileCalibDrawer object of requested type
for the given ROS and drawer.

Definition at line 800 of file TileCalibTools.py.

800 def getDrawer(self, ros, drawer, calibDrawerTemplate=None):
801 """
802 Returns a TileCalibDrawer object of requested type
803 for the given ROS and drawer.
804 """
805 try:
806
807 #=== check for already initialized calibDrawers
808 chanNum = TileCalibUtils.getDrawerIdx(ros,drawer)
809 calibDrawer = self.__chanDictDrawer.get(chanNum,None)
810
811 #=== initialize new calibDrawer if needed
812 if not calibDrawer:
813
814 #=== create new blob
815 spec = self.__folder.payloadSpecification()
816 data = cool.Record( spec )
817 self.__chanDictRecord[chanNum] = data
818 blob = data['TileCalibBlob']
819
820 #=== Create calibDrawer based on requested calibDrawerType
821 if self.__calibDrawerType=='Flt':
822 calibDrawer = TileCalibDrawerFlt.getInstance(blob,self.__defVec,0,0)
823 elif self.__calibDrawerType=='Int':
824 calibDrawer = TileCalibDrawerInt.getInstance(blob,self.__defVec,0,0)
825 elif self.__calibDrawerType=='Bch':
826 calibDrawer = TileCalibDrawerBch.getInstance(blob,self.__defVec,0,0)
827 else:
828 raise Exception( "Invalid blob type requested: %s" % type )
829
830 #=== clone if requested
831 if calibDrawerTemplate:
832 calibDrawer.clone(calibDrawerTemplate)
833
834 #=== put updated calibDrawer in dictionary and return
835 self.__chanDictDrawer[chanNum] = calibDrawer
836 return calibDrawer
837
838 except Exception as e:
839 self.log().critical( e )
840 return None
841
static const TileCalibDrawerBch * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerBch.
static const TileCalibDrawerFlt * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerFlt.
static const TileCalibDrawerInt * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerBch.
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.

◆ register()

python.TileCalibTools.TileBlobWriter.register ( self,
since = (MINRUN,MINLBK),
until = (MAXRUN,MAXLBK),
tag = "",
option = 0 )
Registers the folder in the database.
- since: lower limit of IOV
- until: upper limit of IOV
- tag  : The cool folder tag to write to

The interpretation of the 'since' and 'until' inputs depends on their type:
- tuple(int,int) : run and lbk number
- integer        : Values are interpreted as unix time stamps
                   If since<0, current time is assumed
                   If until<0, infinity is assumed
- string         : time stamp of format 'yyyy-mm-dd hh:mm:ss'

Definition at line 673 of file TileCalibTools.py.

673 def register(self, since=(MINRUN,MINLBK), until=(MAXRUN,MAXLBK), tag="", option=0):
674 """
675 Registers the folder in the database.
676 - since: lower limit of IOV
677 - until: upper limit of IOV
678 - tag : The cool folder tag to write to
679
680 The interpretation of the 'since' and 'until' inputs depends on their type:
681 - tuple(int,int) : run and lbk number
682 - integer : Values are interpreted as unix time stamps
683 If since<0, current time is assumed
684 If until<0, infinity is assumed
685 - string : time stamp of format 'yyyy-mm-dd hh:mm:ss'
686 """
687
688 #=== check for inconsistent input
689 if type(since)!=type(until):
690 raise Exception("Inconsistent types: since=%s, until=%s" % (type(since),type(until)))
691
692 #=== write to user tag only if multiversion mode
693 userTagOnly = True
694 if self.__folder.versioningMode()==cool.FolderVersioning.SINGLE_VERSION:
695 userTagOnly = False
696 #=== no folder Tag allowed for singleversion
697 if tag!="":
698 self.log().warning( "Trying to store with tag \"%s\" to SINGLE_VERSION folder", tag )
699 self.log().warning( "... resetting tag to \"\"!" )
700 tag=""
701
702 #=== get IOV limits
703 sinceCool = getCoolValidityKey(since, True )
704 untilCool = getCoolValidityKey(until, False)
705 if untilCool <= sinceCool:
706 raise Exception("Until(%i) <= Since(%i)" % (untilCool,sinceCool))
707
708 #=== build IOV string
709 iovString = ""
710 if isinstance(since, tuple):
711 iovString = "[%i,%i] - [%i,%i]" % (since[0],since[1],until[0],until[1])
712 else:
713 sinceInfo = time.localtime( sinceCool//UNIX2COOL )
714 untilInfo = time.localtime(min(UNIXTMAX, (untilCool//UNIX2COOL)))
715 untilStr = "<infinity>"
716 if untilCool<cool.ValidityKeyMax:
717 untilStr = time.asctime(untilInfo)
718 if (untilCool//UNIX2COOL)>UNIXTMAX:
719 untilStr = " > "+untilStr
720 iovString = "[%s] - [%s]" % (time.asctime(sinceInfo), untilStr)
721
722 #=== build tag
723 folderTag=tag
724
725 #=== print info
726 comment=self.getComment()
727 onlyComment = (option<0)
728 noComment = (comment is None) or (comment == "None") or (comment.startswith("None") and comment.endswith("None")) or (option>0)
729 self.log().info( "Registering folder %s with tag \"%s\"", self.__folder.fullPath(),folderTag)
730 self.log().info( "... with IOV : %s" , iovString )
731 if noComment:
732 if (option<=0):
733 self.log().info( "... WITHOUT comment field" )
734 else:
735 self.log().info( "... with comment field: \"%s\"", self.getComment() )
736
737 #=== register all channels by increasing channel number
738 if onlyComment:
739 chanList = [1000]
740 else:
741 chanList = sorted(self.__chanDictRecord.keys())
742 cnt=0
743 for chanNum in chanList:
744 if chanNum==1000 and noComment:
745 continue
746 data = self.__chanDictRecord[chanNum]
747 strout = "cool channel=%4i" % chanNum
748 self.log().debug("Registering %s %s", strout, data)
749 channelId = cool.ChannelId(chanNum)
750 self.__folder.storeObject(sinceCool, untilCool, data, channelId, folderTag, userTagOnly)
751 cnt+=1
752 if noComment:
753 self.log().info( "... %d cool channels have been written in total", cnt )
754 elif onlyComment:
755 self.log().info( "... 1 cool channel with comment field has been written" )
756 else:
757 self.log().info( "... %d cool channels have been written in total (including comment field)", cnt )
758
const bool debug
#define min(a, b)
Definition cfImp.cxx:40

◆ setComment()

python.TileCalibTools.TileBlobWriter.setComment ( self,
author,
comment = None )
Sets a general comment in the comment channel.

Definition at line 760 of file TileCalibTools.py.

760 def setComment(self, author, comment=None):
761 """
762 Sets a general comment in the comment channel.
763 """
764 try:
766 data = self.__chanDictRecord.get(chanNum)
767 if not data:
768 spec = self.__folder.payloadSpecification()
769 data = cool.Record( spec )
770 self.__chanDictRecord[chanNum] = data
771 blob = data['TileCalibBlob']
772 if isinstance(author,tuple) and len(author)==3:
773 tm=time.mktime(datetime.datetime.strptime(author[2], "%a %b %d %H:%M:%S %Y").timetuple())
774 TileCalibDrawerCmt.getInstance(blob,author[0],author[1],int(tm))
775 else:
776 TileCalibDrawerCmt.getInstance(blob,author,comment)
777 except Exception as e:
778 self.log().critical( e )
779

◆ zeroBlob()

python.TileCalibTools.TileBlobWriter.zeroBlob ( self,
ros,
drawer )
Resets blob size to zero

Definition at line 843 of file TileCalibTools.py.

843 def zeroBlob(self, ros, drawer):
844 """
845 Resets blob size to zero
846 """
847 try:
848 chanNum = TileCalibUtils.getDrawerIdx(ros,drawer)
849 data = self.__chanDictRecord.get(chanNum)
850 if not data:
851 spec = self.__folder.payloadSpecification()
852 data = cool.Record( spec )
853 self.__chanDictRecord[chanNum] = data
854 blob = data['TileCalibBlob']
855 blob.resize(0)
856 except Exception as e:
857 self.log().critical( e )
858 return None
859
860
861
862#======================================================================
863#===
864#=== TileBlobReader
865#===
866#======================================================================
867
868#
869#______________________________________________________________________

Member Data Documentation

◆ __calibDrawerType

str python.TileCalibTools.TileBlobWriter.__calibDrawerType = calibDrawerType
private

Definition at line 663 of file TileCalibTools.py.

◆ __chanDictDrawer

dict python.TileCalibTools.TileBlobWriter.__chanDictDrawer = {}
private

Definition at line 660 of file TileCalibTools.py.

◆ __chanDictRecord

dict python.TileCalibTools.TileBlobWriter.__chanDictRecord = {}
private

Definition at line 659 of file TileCalibTools.py.

◆ __db

python.TileCalibTools.TileBlobWriter.__db = db
private

Definition at line 622 of file TileCalibTools.py.

◆ __defVec

python.TileCalibTools.TileBlobWriter.__defVec = cppyy.gbl.std.vector('std::vector<float>')()
private

Definition at line 665 of file TileCalibTools.py.

◆ __folder

python.TileCalibTools.TileBlobWriter.__folder = self.__db.getFolder(folderPath)
private

Definition at line 638 of file TileCalibTools.py.


The documentation for this class was generated from the following file: