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 522 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 529 of file TileCalibCrest.py.

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

635 def getComment(self, split=False):
636 """
637 Returns the general comment (default if none is set)
638 """
640 comment = self.__drawer.get(drawerIdx, None)
641 if comment:
642 if split:
643 return (comment.getAuthor(), self.__comment.getComment(), self.__comment.getDate())
644 else:
645 return comment.getFullComment()
646 else:
647 return "<no comment found>"
648
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 650 of file TileCalibCrest.py.

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

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

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

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

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

Member Data Documentation

◆ __calibDrawerType

python.TileCalibCrest.TileBlobWriterCrest.__calibDrawerType = calibDrawerType
private

Definition at line 547 of file TileCalibCrest.py.

◆ __db

python.TileCalibCrest.TileBlobWriterCrest.__db = db
private

Definition at line 540 of file TileCalibCrest.py.

◆ __defVec

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

Definition at line 550 of file TileCalibCrest.py.

◆ __drawer

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

Definition at line 565 of file TileCalibCrest.py.

◆ __drawerBlob

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

Definition at line 564 of file TileCalibCrest.py.

◆ __folderPath

python.TileCalibCrest.TileBlobWriterCrest.__folderPath = folderPath
private

Definition at line 541 of file TileCalibCrest.py.

◆ __payload

python.TileCalibCrest.TileBlobWriterCrest.__payload = payload
private

Definition at line 542 of file TileCalibCrest.py.

◆ __TileCalibDrawer

python.TileCalibCrest.TileBlobWriterCrest.__TileCalibDrawer = TileCalibDrawerFlt
private

Definition at line 549 of file TileCalibCrest.py.


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