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

Public Member Functions

 __init__ (self, db, folderPath, calibDrawerType, payload=None)
 register (self, since=(MINRUN, MINLBK), tag="", chan=-1, payload=None)
 create_container_with_blob (self, jdata, name=None, type=chai.Type.String)
 setComment (self, author, comment=None)
 getComment (self, split=False)
 getDrawer (self, ros, drawer, calibDrawerTemplate=None)
 zeroBlob (self, ros, drawer)

Private Attributes

 __db = CREST_HOST
 __folderPath = folderPath
 __payload = payload
 __calibDrawerType = calibDrawerType
 __TileCalibDrawer = TileCalibDrawerFlt
 __defVec = cppyy.gbl.std.vector('std::vector<float>')()
dict __drawerBlob = {drawerIdx:Blob() for drawerIdx in range(0, TileCalibUtils.max_draweridx())}
dict __drawer = {}
 __api_instance = chai.Database(f"crest:{self.__db}")

Detailed Description

TileBlobWriterCrest is a helper class, managing the details of
CREST interactions for the user of TileCalibBlobs.

Definition at line 606 of file TileCalibCrest.py.

Constructor & Destructor Documentation

◆ __init__()

python.TileCalibCrest.TileBlobWriterCrest.__init__ ( self,
db,
folderPath,
calibDrawerType,
payload = None )
Input:
- db        : db should be a database connection
- folderPath: full folder path to create or update

Definition at line 613 of file TileCalibCrest.py.

613 def __init__(self, db, folderPath, calibDrawerType, payload=None):
614 """
615 Input:
616 - db : db should be a database connection
617 - folderPath: full folder path to create or update
618 """
619
620 #=== initialize base class
621 TileCalibLogger.__init__(self, "TileBlobWriter")
622
623 #=== store db
624 if db is not None and 'CREST' in db and 'http' not in db:
625 self.__db = CREST_HOST
626 else:
627 self.__db = db
628 self.__folderPath = folderPath
629 self.__payload = payload
630 if payload is not None:
631 return
632
633 #=== create default vectors based on calibDrawerType
634 self.__calibDrawerType = calibDrawerType
635 if calibDrawerType in ['TileCalibDrawerFlt', 'Flt']:
636 self.__TileCalibDrawer = TileCalibDrawerFlt
637 self.__defVec = cppyy.gbl.std.vector('std::vector<float>')()
638 elif calibDrawerType in ['TileCalibDrawerBch', 'Bch']:
639 self.__TileCalibDrawer = TileCalibDrawerBch
640 self.__defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')()
641 elif calibDrawerType in ['TileCalibDrawerInt', 'Int']:
642 self.__TileCalibDrawer = TileCalibDrawerInt
643 self.__defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')()
644 elif calibDrawerType in ['CaloCondBlobFlt', 'CaloFlt']:
645 self.__TileCalibDrawer = cppyy.gbl.CaloCondBlobFlt
646 self.__defVec = cppyy.gbl.std.vector('std::vector<float>')()
647 else:
648 raise Exception("Unknown calibDrawerType: %s" % calibDrawerType)
649
650 # Always all drawers should be written
651 self.__drawerBlob = {drawerIdx:Blob() for drawerIdx in range(0, TileCalibUtils.max_draweridx())}
652 self.__drawer = {}
static unsigned int max_draweridx()
Python compatibility function.

Member Function Documentation

◆ create_container_with_blob()

python.TileCalibCrest.TileBlobWriterCrest.create_container_with_blob ( self,
jdata,
name = None,
type = chai.Type.String )
Create a container with the blob data (base64 encoded).

Args:
    jdata: all base64-encoded blob data in json format
    name:  name for field specification
    type:  type for field specification

Returns:
    Payload specification with all channels found in jdata
    Container with the base64-encoded blob data

This method uses String type with base64 encoding instead of Blob type
due to limitations in nanobind's handling of BlobData during serialization

Definition at line 736 of file TileCalibCrest.py.

736 def create_container_with_blob(self, jdata, name=None, type=chai.Type.String):
737 """
738 Create a container with the blob data (base64 encoded).
739
740 Args:
741 jdata: all base64-encoded blob data in json format
742 name: name for field specification
743 type: type for field specification
744
745 Returns:
746 Payload specification with all channels found in jdata
747 Container with the base64-encoded blob data
748
749 This method uses String type with base64 encoding instead of Blob type
750 due to limitations in nanobind's handling of BlobData during serialization
751 """
752 if name is None:
753 if self.__calibDrawerType in ['CaloCondBlobFlt', 'CaloFlt']:
754 name='CaloCondBlob16M'
755 else:
756 name='TileCalibBlob'
757
758 field_spec = chai.FieldSpec([chai.Field(name,type)])
759
760 spec = []
761 for id in jdata.items():
762 spec += [chai.Channel(int(id[0]), "")]
763 channel_spec = chai.ChannelSpec(spec)
764
765 # Create payload specification
766 payload_spec = chai.PayloadSpec(field_spec, channel_spec)
767
768 # Create container
769 container = chai.Container(payload_spec)
770
771 for id in jdata.items():
772 container[int(id[0])].push_string(id[1][0])
773
774 return (payload_spec,container)
775

◆ getComment()

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

Definition at line 796 of file TileCalibCrest.py.

796 def getComment(self, split=False):
797 """
798 Returns the general comment (default if none is set)
799 """
801 comment = self.__drawer.get(drawerIdx, None)
802 if comment:
803 if split:
804 return (comment.getAuthor(), self.__comment.getComment(), self.__comment.getDate())
805 else:
806 return comment.getFullComment()
807 else:
808 return "<no comment found>"
809
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.TileCalibCrest.TileBlobWriterCrest.getDrawer ( self,
ros,
drawer,
calibDrawerTemplate = None )
Returns a TileCalibDrawer object of requested type
for the given ROS and drawer.

Definition at line 811 of file TileCalibCrest.py.

811 def getDrawer(self, ros, drawer, calibDrawerTemplate=None):
812 """
813 Returns a TileCalibDrawer object of requested type
814 for the given ROS and drawer.
815 """
816
817 try:
818 drawerIdx = getDrawerIdx(ros, drawer)
819 calibDrawer = self.__drawer.get(drawerIdx, None)
820
821 if not calibDrawer:
822 if self.__calibDrawerType in ['CaloCondBlobFlt', 'CaloFlt']:
823 calibDrawer = self.__TileCalibDrawer.getInstance(self.__drawerBlob[drawerIdx])
824 else:
825 calibDrawer = self.__TileCalibDrawer.getInstance(self.__drawerBlob[drawerIdx], self.__defVec,0,0)
826 self.__drawer[drawerIdx] = calibDrawer
827
828 #=== clone if requested
829 if calibDrawerTemplate:
830 calibDrawer.clone(calibDrawerTemplate)
831
832 return calibDrawer
833
834 except Exception as e:
835 self.log().critical( e )
836 return None
837

◆ register()

python.TileCalibCrest.TileBlobWriterCrest.register ( self,
since = (MINRUN,MINLBK),
tag = "",
chan = -1,
payload = None )
Registers the folder in the database.
- since: lower limit of IOV
- tag  : The tag to write to
- chan : COOL channel to write, if negative - all COOL channels are written
         Comment channel is always written

The interpretation of the 'since' inputs depends on their type:
- tuple(int,int) : run and lbk number

Definition at line 654 of file TileCalibCrest.py.

654 def register(self, since=(MINRUN,MINLBK), tag="", chan=-1, payload=None):
655 """
656 Registers the folder in the database.
657 - since: lower limit of IOV
658 - tag : The tag to write to
659 - chan : COOL channel to write, if negative - all COOL channels are written
660 Comment channel is always written
661
662 The interpretation of the 'since' inputs depends on their type:
663 - tuple(int,int) : run and lbk number
664 """
665
666 if self.__payload is None and payload is None:
667 jdata = {}
668 for drawerIdx,blob in self.__drawerBlob.items():
669 if chan<0 or drawerIdx==chan or drawerIdx==1000:
670 if blob is None or blob==0:
671 b64string = ''
672 else:
673 blob.seek(0)
674 b64string = str(base64.b64encode(blob.read()), 'ascii')
675 jdata[drawerIdx] = [b64string]
676 else:
677 if payload is not None:
678 self.__payload = payload
679 jdata = self.__payload
680
681 (sinceRun, sinceLumi) = since
682 fullTag = tag
683 if self.__folderPath and not (tag.upper().startswith('TILE') or tag.upper().startswith('CALO')):
684 fullTag = TileCalibUtils.getFullTag(self.__folderPath, tag)
685
686 if not self.__db or self.__db.endswith('.json'):
687 # Writting into the json file
688 fileName = f"{fullTag}.{sinceRun}.{sinceLumi}.json"
689 if self.__db:
690 fileName = f'{self.__db[:-5]}.{fileName}'
691
692 with open(fileName, 'w') as the_file:
693 json.dump(jdata, the_file, separators=(',', ':'), sort_keys=True)
694 else:
695 if 'http' in self.__db:
696 self.log().info('Host %s' , (self.__db))
697 self.__api_instance = chai.Database(f"crest:{self.__db}")
698 fileName = 'remote host'
699 else:
700 self.log().info('Local db %s' , (self.__db))
701 self.__api_instance = chai.Database(f"crest_fs:{self.__db}")
702 fileName = self.__db + '/' + fullTag
703
704 (payload_spec,container) = self.create_container_with_blob(jdata)
705
706 try:
707 new_tag = self.__api_instance.create_tag(
708 fullTag,
709 "", # tag description
710 payload_spec,
711 '<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader><typeName>CondAttrListCollection</typeName>',
712 chai.IovType.RunNumberLumiBlock,
713 "crest-json-single-iov",
714 chai.Synchronization.All,
715 chai.TagStatus.Unlocked
716 )
717 except Exception as e:
718 # Tag might already exist, try to get it
719 try:
720 new_tag = self.__api_instance.get_tag(fullTag)
721 except Exception as e2:
722 self.log().error(f"Failed to create or get tag: {e}")
723 self.log().error(f"Additional error: {e2}")
724 raise Exception( "Failed to write data to %s" % (self.__db) )
725
726 new_tag.add_payload(container, (sinceRun<<32)+sinceLumi)
727
728 #=== print info
729 self.log().info( 'Writting tag "%s"', fullTag)
730 self.log().info( '... since : [%s,%s]' , sinceRun, sinceLumi)
731 if self.__payload is None:
732 self.log().info( '... with comment field: "%s"', self.getComment())
733 self.log().info( '... into file : %s' , fileName)
734
static std::string getFullTag(const std::string &folder, const std::string &tag)
Returns the full tag string, composed of camelized folder name and tag part.

◆ setComment()

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

Definition at line 777 of file TileCalibCrest.py.

777 def setComment(self, author, comment=None):
778 """
779 Sets a general comment in the comment channel.
780 """
782 commentBlob = self.__drawerBlob.get(drawerIdx, None)
783 if commentBlob:
784 commentBlob.resize(0)
785 else:
786 commentBlob = Blob()
787 self.__drawerBlob[drawerIdx] = commentBlob
788
789 if isinstance(author, tuple) and len(author) == 3:
790 tm = time.mktime(datetime.datetime.strptime(author[2], "%a %b %d %H:%M:%S %Y").timetuple())
791 self.__drawer[drawerIdx] = TileCalibDrawerCmt.getInstance(commentBlob, author[0], author[1], int(tm))
792 else:
793 self.__drawer[drawerIdx] = TileCalibDrawerCmt.getInstance(commentBlob, author, comment)
794
static const TileCalibDrawerCmt * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerCmt.

◆ zeroBlob()

python.TileCalibCrest.TileBlobWriterCrest.zeroBlob ( self,
ros,
drawer )
Resets blob size to zero

Definition at line 839 of file TileCalibCrest.py.

839 def zeroBlob(self, ros, drawer):
840 """
841 Resets blob size to zero
842 """
843 try:
844 drawerIdx = getDrawerIdx(ros, drawer)
845 blob = self.__drawerBlob[drawerIdx]
846 blob.resize(0)
847 except Exception as e:
848 self.log().critical( e )
849 return None
850
851
852#____________________________________________________________________

Member Data Documentation

◆ __api_instance

python.TileCalibCrest.TileBlobWriterCrest.__api_instance = chai.Database(f"crest:{self.__db}")
private

Definition at line 697 of file TileCalibCrest.py.

◆ __calibDrawerType

python.TileCalibCrest.TileBlobWriterCrest.__calibDrawerType = calibDrawerType
private

Definition at line 634 of file TileCalibCrest.py.

◆ __db

python.TileCalibCrest.TileBlobWriterCrest.__db = CREST_HOST
private

Definition at line 625 of file TileCalibCrest.py.

◆ __defVec

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

Definition at line 637 of file TileCalibCrest.py.

◆ __drawer

dict python.TileCalibCrest.TileBlobWriterCrest.__drawer = {}
private

Definition at line 652 of file TileCalibCrest.py.

◆ __drawerBlob

dict python.TileCalibCrest.TileBlobWriterCrest.__drawerBlob = {drawerIdx:Blob() for drawerIdx in range(0, TileCalibUtils.max_draweridx())}
private

Definition at line 651 of file TileCalibCrest.py.

◆ __folderPath

python.TileCalibCrest.TileBlobWriterCrest.__folderPath = folderPath
private

Definition at line 628 of file TileCalibCrest.py.

◆ __payload

python.TileCalibCrest.TileBlobWriterCrest.__payload = payload
private

Definition at line 629 of file TileCalibCrest.py.

◆ __TileCalibDrawer

python.TileCalibCrest.TileBlobWriterCrest.__TileCalibDrawer = TileCalibDrawerFlt
private

Definition at line 636 of file TileCalibCrest.py.


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