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 615 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 622 of file TileCalibTools.py.

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

Member Function Documentation

◆ getComment()

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

Definition at line 793 of file TileCalibTools.py.

793 def getComment(self, split=False):
794 """
795 Returns the general comment (default if none is set)
796 """
797 try:
799 data = self.__chanDictRecord.get(chanNum)
800 if not data:
801 return "<No general comment!>"
802 blob = data['TileCalibBlob']
804 if split:
805 return (cmt.getAuthor(),cmt.getComment(),cmt.getDate())
806 else:
807 return cmt.getFullComment()
808 except Exception as e:
809 self.log().critical( e )
810
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:132

◆ 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 812 of file TileCalibTools.py.

812 def getDrawer(self, ros, drawer, calibDrawerTemplate=None):
813 """
814 Returns a TileCalibDrawer object of requested type
815 for the given ROS and drawer.
816 """
817 try:
818
819 #=== check for already initialized calibDrawers
820 chanNum = TileCalibUtils.getDrawerIdx(ros,drawer)
821 calibDrawer = self.__chanDictDrawer.get(chanNum,None)
822
823 #=== initialize new calibDrawer if needed
824 if not calibDrawer:
825
826 #=== create new blob
827 spec = self.__folder.payloadSpecification()
828 data = cool.Record( spec )
829 self.__chanDictRecord[chanNum] = data
830 blob = data['TileCalibBlob']
831
832 #=== Create calibDrawer based on requested calibDrawerType
833 if self.__calibDrawerType=='Flt':
834 calibDrawer = TileCalibDrawerFlt.getInstance(blob,self.__defVec,0,0)
835 elif self.__calibDrawerType=='Int':
836 calibDrawer = TileCalibDrawerInt.getInstance(blob,self.__defVec,0,0)
837 elif self.__calibDrawerType=='Bch':
838 calibDrawer = TileCalibDrawerBch.getInstance(blob,self.__defVec,0,0)
839 else:
840 raise Exception( "Invalid blob type requested: %s" % type )
841
842 #=== clone if requested
843 if calibDrawerTemplate:
844 calibDrawer.clone(calibDrawerTemplate)
845
846 #=== put updated calibDrawer in dictionary and return
847 self.__chanDictDrawer[chanNum] = calibDrawer
848 return calibDrawer
849
850 except Exception as e:
851 self.log().critical( e )
852 return None
853
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 685 of file TileCalibTools.py.

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

772 def setComment(self, author, comment=None):
773 """
774 Sets a general comment in the comment channel.
775 """
776 try:
778 data = self.__chanDictRecord.get(chanNum)
779 if not data:
780 spec = self.__folder.payloadSpecification()
781 data = cool.Record( spec )
782 self.__chanDictRecord[chanNum] = data
783 blob = data['TileCalibBlob']
784 if isinstance(author,tuple) and len(author)==3:
785 tm=time.mktime(datetime.datetime.strptime(author[2], "%a %b %d %H:%M:%S %Y").timetuple())
786 TileCalibDrawerCmt.getInstance(blob,author[0],author[1],int(tm))
787 else:
788 TileCalibDrawerCmt.getInstance(blob,author,comment)
789 except Exception as e:
790 self.log().critical( e )
791

◆ zeroBlob()

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

Definition at line 855 of file TileCalibTools.py.

855 def zeroBlob(self, ros, drawer):
856 """
857 Resets blob size to zero
858 """
859 try:
860 chanNum = TileCalibUtils.getDrawerIdx(ros,drawer)
861 data = self.__chanDictRecord.get(chanNum)
862 if not data:
863 spec = self.__folder.payloadSpecification()
864 data = cool.Record( spec )
865 self.__chanDictRecord[chanNum] = data
866 blob = data['TileCalibBlob']
867 blob.resize(0)
868 except Exception as e:
869 self.log().critical( e )
870 return None
871
872
873
874#======================================================================
875#===
876#=== TileBlobReader
877#===
878#======================================================================
879
880#
881#______________________________________________________________________

Member Data Documentation

◆ __calibDrawerType

str python.TileCalibTools.TileBlobWriter.__calibDrawerType = calibDrawerType
private

Definition at line 675 of file TileCalibTools.py.

◆ __chanDictDrawer

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

Definition at line 672 of file TileCalibTools.py.

◆ __chanDictRecord

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

Definition at line 671 of file TileCalibTools.py.

◆ __db

python.TileCalibTools.TileBlobWriter.__db = db
private

Definition at line 634 of file TileCalibTools.py.

◆ __defVec

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

Definition at line 677 of file TileCalibTools.py.

◆ __folder

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

Definition at line 650 of file TileCalibTools.py.


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