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

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

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

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

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

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

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

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

Member Data Documentation

◆ __calibDrawerType

python.TileCalibCrest.TileBlobWriterCrest.__calibDrawerType = calibDrawerType
private

Definition at line 549 of file TileCalibCrest.py.

◆ __db

python.TileCalibCrest.TileBlobWriterCrest.__db = db
private

Definition at line 542 of file TileCalibCrest.py.

◆ __defVec

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

Definition at line 552 of file TileCalibCrest.py.

◆ __drawer

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

Definition at line 567 of file TileCalibCrest.py.

◆ __drawerBlob

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

Definition at line 566 of file TileCalibCrest.py.

◆ __folderPath

python.TileCalibCrest.TileBlobWriterCrest.__folderPath = folderPath
private

Definition at line 543 of file TileCalibCrest.py.

◆ __payload

python.TileCalibCrest.TileBlobWriterCrest.__payload = payload
private

Definition at line 544 of file TileCalibCrest.py.

◆ __TileCalibDrawer

python.TileCalibCrest.TileBlobWriterCrest.__TileCalibDrawer = TileCalibDrawerFlt
private

Definition at line 551 of file TileCalibCrest.py.


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