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)
 setComment (self, author, comment=None)
 getComment (self, split=False)
 getDrawer (self, ros, drawer, calibDrawerTemplate=None)
 zeroBlob (self, ros, drawer)

Private Attributes

 __db = db
 __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 = {}

Detailed Description

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

Definition at line 520 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 527 of file TileCalibCrest.py.

527 def __init__(self, db, folderPath, calibDrawerType, payload=None):
528 """
529 Input:
530 - db : db should be a database connection
531 - folderPath: full folder path to create or update
532 """
533
534 #=== initialize base class
535 TileCalibLogger.__init__(self, "TileBlobWriter")
536
537 #=== store db
538 self.__db = db
539 self.__folderPath = folderPath
540 self.__payload = payload
541 if payload is not None:
542 return
543
544 #=== create default vectors based on calibDrawerType
545 self.__calibDrawerType = calibDrawerType
546 if calibDrawerType in ['TileCalibDrawerFlt', 'Flt']:
547 self.__TileCalibDrawer = TileCalibDrawerFlt
548 self.__defVec = cppyy.gbl.std.vector('std::vector<float>')()
549 elif calibDrawerType in ['TileCalibDrawerBch', 'Bch']:
550 self.__TileCalibDrawer = TileCalibDrawerBch
551 self.__defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')()
552 elif calibDrawerType in ['TileCalibDrawerInt', 'Int']:
553 self.__TileCalibDrawer = TileCalibDrawerInt
554 self.__defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')()
555 elif calibDrawerType in ['CaloCondBlobFlt', 'CaloFlt']:
556 self.__TileCalibDrawer = cppyy.gbl.CaloCondBlobFlt
557 self.__defVec = cppyy.gbl.std.vector('std::vector<float>')()
558 else:
559 raise Exception("Unknown calibDrawerType: %s" % calibDrawerType)
560
561 # Always all drawers should be written
562 self.__drawerBlob = {drawerIdx:Blob() for drawerIdx in range(0, TileCalibUtils.max_draweridx())}
563 self.__drawer = {}
static unsigned int max_draweridx()
Python compatibility function.

Member Function Documentation

◆ getComment()

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

Definition at line 634 of file TileCalibCrest.py.

634 def getComment(self, split=False):
635 """
636 Returns the general comment (default if none is set)
637 """
639 comment = self.__drawer.get(drawerIdx, None)
640 if comment:
641 if split:
642 return (comment.getAuthor(), self.__comment.getComment(), self.__comment.getDate())
643 else:
644 return comment.getFullComment()
645 else:
646 return "<no comment found>"
647
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.TileCalibCrest.TileBlobWriterCrest.getDrawer ( self,
ros,
drawer,
calibDrawerTemplate = None )
Returns a TileCalibDrawer object of requested type
for the given ROS and drawer.

Definition at line 649 of file TileCalibCrest.py.

649 def getDrawer(self, ros, drawer, calibDrawerTemplate=None):
650 """
651 Returns a TileCalibDrawer object of requested type
652 for the given ROS and drawer.
653 """
654
655 try:
656 drawerIdx = getDrawerIdx(ros, drawer)
657 calibDrawer = self.__drawer.get(drawerIdx, None)
658
659 if not calibDrawer:
660 if self.__calibDrawerType in ['CaloCondBlobFlt', 'CaloFlt']:
661 calibDrawer = self.__TileCalibDrawer.getInstance(self.__drawerBlob[drawerIdx])
662 else:
663 calibDrawer = self.__TileCalibDrawer.getInstance(self.__drawerBlob[drawerIdx], self.__defVec,0,0)
664 self.__drawer[drawerIdx] = calibDrawer
665
666 #=== clone if requested
667 if calibDrawerTemplate:
668 calibDrawer.clone(calibDrawerTemplate)
669
670 return calibDrawer
671
672 except Exception as e:
673 self.log().critical( e )
674 return None
675

◆ 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 565 of file TileCalibCrest.py.

565 def register(self, since=(MINRUN,MINLBK), tag="", chan=-1, payload=None):
566 """
567 Registers the folder in the database.
568 - since: lower limit of IOV
569 - tag : The tag to write to
570 - chan : COOL channel to write, if negative - all COOL channels are written
571 Comment channel is always written
572
573 The interpretation of the 'since' inputs depends on their type:
574 - tuple(int,int) : run and lbk number
575 """
576
577 if self.__payload is None and payload is None:
578 jdata = {}
579 for drawerIdx,blob in self.__drawerBlob.items():
580 if chan<0 or drawerIdx==chan or drawerIdx==1000:
581 if blob is None or blob==0:
582 b64string = ''
583 else:
584 blob.seek(0)
585 b64string = str(base64.b64encode(blob.read()), 'ascii')
586 jdata[drawerIdx] = [b64string]
587 else:
588 if payload is not None:
589 self.__payload = payload
590 jdata = self.__payload
591
592 (sinceRun, sinceLumi) = since
593
594 if not self.__db or (self.__db and self.__db.endswith('.json')):
595 # Writting into the json file
596 fullTag = tag
597 if self.__folderPath and not (tag.upper().startswith('TILE') or tag.upper().startswith('CALO')):
598 fullTag = TileCalibUtils.getFullTag(self.__folderPath, tag)
599 fileName = f"{fullTag}.{sinceRun}.{sinceLumi}.json"
600 if self.__db:
601 fileName = f'{self.__db[:-5]}.{fileName}'
602
603 with open(fileName, 'w') as the_file:
604 json.dump(jdata, the_file)
605 the_file.write('\n')
606
607 #=== print info
608 self.log().info( 'Writting tag "%s"', fullTag)
609 self.log().info( '... since : [%s,%s]' , sinceRun, sinceLumi)
610 if self.__payload is None:
611 self.log().info( '... with comment field: "%s"', self.getComment())
612 self.log().info( '... into file : %s' , fileName)
613
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 615 of file TileCalibCrest.py.

615 def setComment(self, author, comment=None):
616 """
617 Sets a general comment in the comment channel.
618 """
620 commentBlob = self.__drawerBlob.get(drawerIdx, None)
621 if commentBlob:
622 commentBlob.resize(0)
623 else:
624 commentBlob = Blob()
625 self.__drawerBlob[drawerIdx] = commentBlob
626
627 if isinstance(author, tuple) and len(author) == 3:
628 tm = time.mktime(datetime.datetime.strptime(author[2], "%a %b %d %H:%M:%S %Y").timetuple())
629 self.__drawer[drawerIdx] = TileCalibDrawerCmt.getInstance(commentBlob, author[0], author[1], int(tm))
630 else:
631 self.__drawer[drawerIdx] = TileCalibDrawerCmt.getInstance(commentBlob, author, comment)
632
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 677 of file TileCalibCrest.py.

677 def zeroBlob(self, ros, drawer):
678 """
679 Resets blob size to zero
680 """
681 try:
682 drawerIdx = getDrawerIdx(ros, drawer)
683 blob = self.__drawerBlob[drawerIdx]
684 blob.resize(0)
685 except Exception as e:
686 self.log().critical( e )
687 return None
688
689
690#____________________________________________________________________

Member Data Documentation

◆ __calibDrawerType

python.TileCalibCrest.TileBlobWriterCrest.__calibDrawerType = calibDrawerType
private

Definition at line 545 of file TileCalibCrest.py.

◆ __db

python.TileCalibCrest.TileBlobWriterCrest.__db = db
private

Definition at line 538 of file TileCalibCrest.py.

◆ __defVec

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

Definition at line 548 of file TileCalibCrest.py.

◆ __drawer

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

Definition at line 563 of file TileCalibCrest.py.

◆ __drawerBlob

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

Definition at line 562 of file TileCalibCrest.py.

◆ __folderPath

python.TileCalibCrest.TileBlobWriterCrest.__folderPath = folderPath
private

Definition at line 539 of file TileCalibCrest.py.

◆ __payload

python.TileCalibCrest.TileBlobWriterCrest.__payload = payload
private

Definition at line 540 of file TileCalibCrest.py.

◆ __TileCalibDrawer

python.TileCalibCrest.TileBlobWriterCrest.__TileCalibDrawer = TileCalibDrawerFlt
private

Definition at line 547 of file TileCalibCrest.py.


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