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

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

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

◆ 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)
607 the_file.write('\n')
608
609 #=== print info
610 self.log().info( 'Writting tag "%s"', fullTag)
611 self.log().info( '... since : [%s,%s]' , sinceRun, sinceLumi)
612 if self.__payload is None:
613 self.log().info( '... with comment field: "%s"', self.getComment())
614 self.log().info( '... into file : %s' , fileName)
615
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 617 of file TileCalibCrest.py.

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

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

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: