ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
python.TileCalibTools.TileBlobWriter Class Reference
Inheritance diagram for python.TileCalibTools.TileBlobWriter:
Collaboration diagram for python.TileCalibTools.TileBlobWriter:

Public Member Functions

def __init__ (self, db, folderPath, calibDrawerType, isMultiVersionFolder=True, isRunLumiTimeStamp=True)
 
def register (self, since=(MINRUN, MINLBK), until=(MAXRUN, MAXLBK), tag="", option=0)
 
def setComment (self, author, comment=None)
 
def getComment (self, split=False)
 
def getDrawer (self, ros, drawer, calibDrawerTemplate=None)
 
def zeroBlob (self, ros, drawer)
 

Private Attributes

 __db
 
 __folder
 
 __chanDictRecord
 
 __chanDictDrawer
 
 __calibDrawerType
 
 __defVec
 

Detailed Description

TileCalibBlobWriterBase is a helper class, managing the details of
COOL interactions for the user of TileCalibBlobs.

Definition at line 534 of file TileCalibTools.py.

Constructor & Destructor Documentation

◆ __init__()

def python.TileCalibTools.TileBlobWriter.__init__ (   self,
  db,
  folderPath,
  calibDrawerType,
  isMultiVersionFolder = True,
  isRunLumiTimeStamp = True 
)
Input:
- db        : db should be an open database connection
- folderPath: full folder path to create or update

Definition at line 541 of file TileCalibTools.py.

541  def __init__(self, db, folderPath, calibDrawerType,
542  isMultiVersionFolder=True, isRunLumiTimeStamp=True):
543  """
544  Input:
545  - db : db should be an open database connection
546  - folderPath: full folder path to create or update
547  """
548 
549  #=== initialize base class
550  TileCalibLogger.__init__(self,"TileBlobWriter")
551 
552  #=== store db
553  self.__db = db
554 
555  #=== determine folder mode
556  folderMode = cool.FolderVersioning.MULTI_VERSION
557  if not isMultiVersionFolder:
558  folderMode = cool.FolderVersioning.SINGLE_VERSION
559 
560  #=== determine folder description
561  folderDescr = getAthenaFolderDescr("run-lumi")
562  if not isRunLumiTimeStamp:
563  folderDescr = getAthenaFolderDescr("time")
564 
565  #=== access folder in db
566  try:
567  #=== create folder if it does not exist
568  if self.__db.existsFolder(folderPath):
569  self.__folder = self.__db.getFolder(folderPath)
570  #=== check folder mode
571  modeInCool = self.__folder.versioningMode()
572  if modeInCool!=folderMode:
573  str = "Incompatible folder mode detected, COOL folder has type "
574  if modeInCool==cool.FolderVersioning.MULTI_VERSION:
575  str += "MULTI"
576  else:
577  str += "SINGLE"
578  raise Exception(str)
579  else:
580  #=== create folder if it does not exist
581  payloadSpec = cool.RecordSpecification()
582  payloadSpec.extend( 'TileCalibBlob', cool.StorageType.Blob64k )
583  folderSpec = cool.FolderSpecification(folderMode, payloadSpec)
584  self.__folder = db.createFolder(folderPath, folderSpec, folderDescr, True)
585  except Exception as e:
586  self.log().critical( e )
587  raise
588 
589  #=== initialize channel dictionaries
590  self.__chanDictRecord = {} # <int, cool.Record >
591  self.__chanDictDrawer = {} # <int, TileCalibDrawer>
592 
593  #=== create default vectors based on calibDrawerType
594  self.__calibDrawerType = calibDrawerType
595  if calibDrawerType=='Flt':
596  self.__defVec = cppyy.gbl.std.vector('std::vector<float>')()
597  elif calibDrawerType=='Bch' or calibDrawerType=='Int':
598  self.__defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')()
599  else:
600  raise Exception("Unknown calibDrawerType: %s" % calibDrawerType)
601 
602 

Member Function Documentation

◆ getComment()

def python.TileCalibTools.TileBlobWriter.getComment (   self,
  split = False 
)
Returns the general comment (default if none is set)

Definition at line 712 of file TileCalibTools.py.

712  def getComment(self, split=False):
713  """
714  Returns the general comment (default if none is set)
715  """
716  try:
718  data = self.__chanDictRecord.get(chanNum)
719  if not data:
720  return "<No general comment!>"
721  blob = data['TileCalibBlob']
723  if split:
724  return (cmt.getAuthor(),cmt.getComment(),cmt.getDate())
725  else:
726  return cmt.getFullComment()
727  except Exception as e:
728  self.log().critical( e )
729 

◆ getDrawer()

def python.TileCalibTools.TileBlobWriter.getDrawer (   self,
  ros,
  drawer,
  calibDrawerTemplate = None 
)
Returns a TileCalibDrawer object of requested type
for the given ROS and drawer.

Definition at line 731 of file TileCalibTools.py.

731  def getDrawer(self, ros, drawer, calibDrawerTemplate=None):
732  """
733  Returns a TileCalibDrawer object of requested type
734  for the given ROS and drawer.
735  """
736  try:
737 
738  #=== check for already initialized calibDrawers
739  chanNum = TileCalibUtils.getDrawerIdx(ros,drawer)
740  calibDrawer = self.__chanDictDrawer.get(chanNum,None)
741 
742  #=== initialize new calibDrawer if needed
743  if not calibDrawer:
744 
745  #=== create new blob
746  spec = self.__folder.payloadSpecification()
747  data = cool.Record( spec )
748  self.__chanDictRecord[chanNum] = data
749  blob = data['TileCalibBlob']
750 
751  #=== Create calibDrawer based on requested calibDrawerType
752  if self.__calibDrawerType=='Flt':
753  calibDrawer = TileCalibDrawerFlt.getInstance(blob,self.__defVec,0,0)
754  elif self.__calibDrawerType=='Int':
755  calibDrawer = TileCalibDrawerInt.getInstance(blob,self.__defVec,0,0)
756  elif self.__calibDrawerType=='Bch':
757  calibDrawer = TileCalibDrawerBch.getInstance(blob,self.__defVec,0,0)
758  else:
759  raise Exception( "Invalid blob type requested: %s" % type )
760 
761  #=== clone if requested
762  if calibDrawerTemplate:
763  calibDrawer.clone(calibDrawerTemplate)
764 
765  #=== put updated calibDrawer in dictionary and return
766  self.__chanDictDrawer[chanNum] = calibDrawer
767  return calibDrawer
768 
769  except Exception as e:
770  self.log().critical( e )
771  return None
772 

◆ register()

def python.TileCalibTools.TileBlobWriter.register (   self,
  since = (MINRUN,MINLBK),
  until = (MAXRUN,MAXLBK),
  tag = "",
  option = 0 
)
Registers the folder in the database.
- since: lower limit of IOV
- until: upper limit of IOV
- tag  : The cool folder tag to write to

The interpretation of the 'since' and 'until' inputs depends on their type:
- tuple(int,int) : run and lbk number
- integer        : Values are interpreted as unix time stamps
           If since<0, current time is assumed
           If until<0, infinity is assumed
- string         : time stamp of format 'yyyy-mm-dd hh:mm:ss'

Definition at line 604 of file TileCalibTools.py.

604  def register(self, since=(MINRUN,MINLBK), until=(MAXRUN,MAXLBK), tag="", option=0):
605  """
606  Registers the folder in the database.
607  - since: lower limit of IOV
608  - until: upper limit of IOV
609  - tag : The cool folder tag to write to
610 
611  The interpretation of the 'since' and 'until' inputs depends on their type:
612  - tuple(int,int) : run and lbk number
613  - integer : Values are interpreted as unix time stamps
614  If since<0, current time is assumed
615  If until<0, infinity is assumed
616  - string : time stamp of format 'yyyy-mm-dd hh:mm:ss'
617  """
618 
619  #=== check for inconsistent input
620  if type(since)!=type(until):
621  raise Exception("Inconsistent types: since=%s, until=%s" % (type(since),type(until)))
622 
623  #=== write to user tag only if multiversion mode
624  userTagOnly = True
625  if self.__folder.versioningMode()==cool.FolderVersioning.SINGLE_VERSION:
626  userTagOnly = False
627  #=== no folder Tag allowed for singleversion
628  if tag!="":
629  self.log().warning( "Trying to store with tag \"%s\" to SINGLE_VERSION folder", tag )
630  self.log().warning( "... resetting tag to \"\"!" )
631  tag=""
632 
633  #=== get IOV limits
634  sinceCool = getCoolValidityKey(since, True )
635  untilCool = getCoolValidityKey(until, False)
636  if untilCool <= sinceCool:
637  raise Exception("Until(%i) <= Since(%i)" % (untilCool,sinceCool))
638 
639  #=== build IOV string
640  iovString = ""
641  if isinstance(since, tuple):
642  iovString = "[%i,%i] - [%i,%i]" % (since[0],since[1],until[0],until[1])
643  else:
644  sinceInfo = time.localtime( sinceCool//UNIX2COOL )
645  untilInfo = time.localtime(min(UNIXTMAX, (untilCool//UNIX2COOL)))
646  untilStr = "<infinity>"
647  if untilCool<cool.ValidityKeyMax:
648  untilStr = time.asctime(untilInfo)
649  if (untilCool//UNIX2COOL)>UNIXTMAX:
650  untilStr = " > "+untilStr
651  iovString = "[%s] - [%s]" % (time.asctime(sinceInfo), untilStr)
652 
653  #=== build tag
654  folderTag=tag
655 
656  #=== print info
657  comment=self.getComment()
658  onlyComment = (option<0)
659  noComment = (comment is None) or (comment == "None") or (comment.startswith("None") and comment.endswith("None")) or (option>0)
660  self.log().info( "Registering folder %s with tag \"%s\"", self.__folder.fullPath(),folderTag)
661  self.log().info( "... with IOV : %s" , iovString )
662  if noComment:
663  if (option<=0):
664  self.log().info( "... WITHOUT comment field" )
665  else:
666  self.log().info( "... with comment field: \"%s\"", self.getComment() )
667 
668  #=== register all channels by increasing channel number
669  if onlyComment:
670  chanList = [1000]
671  else:
672  chanList = sorted(self.__chanDictRecord.keys())
673  cnt=0
674  for chanNum in chanList:
675  if chanNum==1000 and noComment:
676  continue
677  data = self.__chanDictRecord[chanNum]
678  strout = "cool channel=%4i" % chanNum
679  self.log().debug("Registering %s %s", strout, data)
680  channelId = cool.ChannelId(chanNum)
681  self.__folder.storeObject(sinceCool, untilCool, data, channelId, folderTag, userTagOnly)
682  cnt+=1
683  if noComment:
684  self.log().info( "... %d cool channels have been written in total", cnt )
685  elif onlyComment:
686  self.log().info( "... 1 cool channel with comment field has been written" )
687  else:
688  self.log().info( "... %d cool channels have been written in total (including comment field)", cnt )
689 

◆ setComment()

def python.TileCalibTools.TileBlobWriter.setComment (   self,
  author,
  comment = None 
)
Sets a general comment in the comment channel.

Definition at line 691 of file TileCalibTools.py.

691  def setComment(self, author, comment=None):
692  """
693  Sets a general comment in the comment channel.
694  """
695  try:
697  data = self.__chanDictRecord.get(chanNum)
698  if not data:
699  spec = self.__folder.payloadSpecification()
700  data = cool.Record( spec )
701  self.__chanDictRecord[chanNum] = data
702  blob = data['TileCalibBlob']
703  if isinstance(author,tuple) and len(author)==3:
704  tm=time.mktime(datetime.datetime.strptime(author[2], "%a %b %d %H:%M:%S %Y").timetuple())
705  TileCalibDrawerCmt.getInstance(blob,author[0],author[1],int(tm))
706  else:
707  TileCalibDrawerCmt.getInstance(blob,author,comment)
708  except Exception as e:
709  self.log().critical( e )
710 

◆ zeroBlob()

def python.TileCalibTools.TileBlobWriter.zeroBlob (   self,
  ros,
  drawer 
)
Resets blob size to zero

Definition at line 774 of file TileCalibTools.py.

774  def zeroBlob(self, ros, drawer):
775  """
776  Resets blob size to zero
777  """
778  try:
779  chanNum = TileCalibUtils.getDrawerIdx(ros,drawer)
780  data = self.__chanDictRecord.get(chanNum)
781  if not data:
782  spec = self.__folder.payloadSpecification()
783  data = cool.Record( spec )
784  self.__chanDictRecord[chanNum] = data
785  blob = data['TileCalibBlob']
786  blob.resize(0)
787  except Exception as e:
788  self.log().critical( e )
789  return None
790 
791 
792 
793 #======================================================================
794 #===
795 #=== TileBlobReader
796 #===
797 #======================================================================
798 
799 #
800 #______________________________________________________________________

Member Data Documentation

◆ __calibDrawerType

python.TileCalibTools.TileBlobWriter.__calibDrawerType
private

Definition at line 593 of file TileCalibTools.py.

◆ __chanDictDrawer

python.TileCalibTools.TileBlobWriter.__chanDictDrawer
private

Definition at line 590 of file TileCalibTools.py.

◆ __chanDictRecord

python.TileCalibTools.TileBlobWriter.__chanDictRecord
private

Definition at line 589 of file TileCalibTools.py.

◆ __db

python.TileCalibTools.TileBlobWriter.__db
private

Definition at line 552 of file TileCalibTools.py.

◆ __defVec

python.TileCalibTools.TileBlobWriter.__defVec
private

Definition at line 595 of file TileCalibTools.py.

◆ __folder

python.TileCalibTools.TileBlobWriter.__folder
private

Definition at line 568 of file TileCalibTools.py.


The documentation for this class was generated from the following file:
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
TileCalibDrawerBch::getInstance
static const TileCalibDrawerBch * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerBch.
Definition: TileCalibDrawerBch.cxx:28
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
CscCalibQuery.fullPath
string fullPath
Definition: CscCalibQuery.py:359
python.processes.powheg.ZZj_MiNNLO.ZZj_MiNNLO.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZj_MiNNLO.py:18
register
#define register
Definition: dictionary.h:21
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
TileCalibDrawerInt::getInstance
static const TileCalibDrawerInt * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerBch.
Definition: TileCalibDrawerInt.cxx:27
TileCalibDrawerFlt::getInstance
static const TileCalibDrawerFlt * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerFlt.
Definition: TileCalibDrawerFlt.cxx:13
TileCalibUtils::getCommentChannel
static unsigned int getCommentChannel()
Returns the COOL channel number for the comment channel.
Definition: TileCalibUtils.h:82
python.TileCalibTools.getCoolValidityKey
def getCoolValidityKey(pointInTime, isSince=True)
Definition: TileCalibTools.py:360
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
python.TileCalibTools.getAthenaFolderDescr
def getAthenaFolderDescr(type="run-lumi")
Definition: TileCalibTools.py:179
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
TileCalibDrawerCmt::getInstance
static const TileCalibDrawerCmt * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerCmt.
Definition: TileCalibDrawerCmt.cxx:24
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:130
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:801
TileCalibUtils::getDrawerIdx
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
Definition: TileCalibUtils.cxx:60
python.ParticleTypeUtil.info
def info
Definition: ParticleTypeUtil.py:87