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 486 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 493 of file TileCalibTools.py.

493  def __init__(self, db, folderPath, calibDrawerType,
494  isMultiVersionFolder=True, isRunLumiTimeStamp=True):
495  """
496  Input:
497  - db : db should be an open database connection
498  - folderPath: full folder path to create or update
499  """
500 
501  #=== initialize base class
502  TileCalibLogger.__init__(self,"TileBlobWriter")
503 
504  #=== store db
505  self.__db = db
506 
507  #=== determine folder mode
508  folderMode = cool.FolderVersioning.MULTI_VERSION
509  if not isMultiVersionFolder:
510  folderMode = cool.FolderVersioning.SINGLE_VERSION
511 
512  #=== determine folder description
513  folderDescr = getAthenaFolderDescr("run-lumi")
514  if not isRunLumiTimeStamp:
515  folderDescr = getAthenaFolderDescr("time")
516 
517  #=== access folder in db
518  try:
519  #=== create folder if it does not exist
520  if self.__db.existsFolder(folderPath):
521  self.__folder = self.__db.getFolder(folderPath)
522  #=== check folder mode
523  modeInCool = self.__folder.versioningMode()
524  if modeInCool!=folderMode:
525  str = "Incompatible folder mode detected, COOL folder has type "
526  if modeInCool==cool.FolderVersioning.MULTI_VERSION:
527  str += "MULTI"
528  else:
529  str += "SINGLE"
530  raise Exception(str)
531  else:
532  #=== create folder if it does not exist
533  payloadSpec = cool.RecordSpecification()
534  payloadSpec.extend( 'TileCalibBlob', cool.StorageType.Blob64k )
535  folderSpec = cool.FolderSpecification(folderMode, payloadSpec)
536  self.__folder = db.createFolder(folderPath, folderSpec, folderDescr, True)
537  except Exception as e:
538  self.log().critical( e )
539  raise
540 
541  #=== initialize channel dictionaries
542  self.__chanDictRecord = {} # <int, cool.Record >
543  self.__chanDictDrawer = {} # <int, TileCalibDrawer>
544 
545  #=== create default vectors based on calibDrawerType
546  self.__calibDrawerType = calibDrawerType
547  if calibDrawerType=='Flt':
548  self.__defVec = cppyy.gbl.std.vector('std::vector<float>')()
549  elif calibDrawerType=='Bch' or calibDrawerType=='Int':
550  self.__defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')()
551  else:
552  raise Exception("Unknown calibDrawerType: %s" % calibDrawerType)
553 
554 

Member Function Documentation

◆ getComment()

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

Definition at line 664 of file TileCalibTools.py.

664  def getComment(self, split=False):
665  """
666  Returns the general comment (default if none is set)
667  """
668  try:
670  data = self.__chanDictRecord.get(chanNum)
671  if not data:
672  return "<No general comment!>"
673  blob = data['TileCalibBlob']
675  if split:
676  return (cmt.getAuthor(),cmt.getComment(),cmt.getDate())
677  else:
678  return cmt.getFullComment()
679  except Exception as e:
680  self.log().critical( e )
681 

◆ 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 683 of file TileCalibTools.py.

683  def getDrawer(self, ros, drawer, calibDrawerTemplate=None):
684  """
685  Returns a TileCalibDrawer object of requested type
686  for the given ROS and drawer.
687  """
688  try:
689 
690  #=== check for already initialized calibDrawers
691  chanNum = TileCalibUtils.getDrawerIdx(ros,drawer)
692  calibDrawer = self.__chanDictDrawer.get(chanNum,None)
693 
694  #=== initialize new calibDrawer if needed
695  if not calibDrawer:
696 
697  #=== create new blob
698  spec = self.__folder.payloadSpecification()
699  data = cool.Record( spec )
700  self.__chanDictRecord[chanNum] = data
701  blob = data['TileCalibBlob']
702 
703  #=== Create calibDrawer based on requested calibDrawerType
704  if self.__calibDrawerType=='Flt':
705  calibDrawer = TileCalibDrawerFlt.getInstance(blob,self.__defVec,0,0)
706  elif self.__calibDrawerType=='Int':
707  calibDrawer = TileCalibDrawerInt.getInstance(blob,self.__defVec,0,0)
708  elif self.__calibDrawerType=='Bch':
709  calibDrawer = TileCalibDrawerBch.getInstance(blob,self.__defVec,0,0)
710  else:
711  raise Exception( "Invalid blob type requested: %s" % type )
712 
713  #=== clone if requested
714  if calibDrawerTemplate:
715  calibDrawer.clone(calibDrawerTemplate)
716 
717  #=== put updated calibDrawer in dictionary and return
718  self.__chanDictDrawer[chanNum] = calibDrawer
719  return calibDrawer
720 
721  except Exception as e:
722  self.log().critical( e )
723  return None
724 

◆ 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 556 of file TileCalibTools.py.

556  def register(self, since=(MINRUN,MINLBK), until=(MAXRUN,MAXLBK), tag="", option=0):
557  """
558  Registers the folder in the database.
559  - since: lower limit of IOV
560  - until: upper limit of IOV
561  - tag : The cool folder tag to write to
562 
563  The interpretation of the 'since' and 'until' inputs depends on their type:
564  - tuple(int,int) : run and lbk number
565  - integer : Values are interpreted as unix time stamps
566  If since<0, current time is assumed
567  If until<0, infinity is assumed
568  - string : time stamp of format 'yyyy-mm-dd hh:mm:ss'
569  """
570 
571  #=== check for inconsistent input
572  if type(since)!=type(until):
573  raise Exception("Inconsistent types: since=%s, until=%s" % (type(since),type(until)))
574 
575  #=== write to user tag only if multiversion mode
576  userTagOnly = True
577  if self.__folder.versioningMode()==cool.FolderVersioning.SINGLE_VERSION:
578  userTagOnly = False
579  #=== no folder Tag allowed for singleversion
580  if tag!="":
581  self.log().warning( "Trying to store with tag \"%s\" to SINGLE_VERSION folder", tag )
582  self.log().warning( "... resetting tag to \"\"!" )
583  tag=""
584 
585  #=== get IOV limits
586  sinceCool = getCoolValidityKey(since, True )
587  untilCool = getCoolValidityKey(until, False)
588  if untilCool <= sinceCool:
589  raise Exception("Until(%i) <= Since(%i)" % (untilCool,sinceCool))
590 
591  #=== build IOV string
592  iovString = ""
593  if isinstance(since, tuple):
594  iovString = "[%i,%i] - [%i,%i]" % (since[0],since[1],until[0],until[1])
595  else:
596  sinceInfo = time.localtime( sinceCool//UNIX2COOL )
597  untilInfo = time.localtime(min(UNIXTMAX, (untilCool//UNIX2COOL)))
598  untilStr = "<infinity>"
599  if untilCool<cool.ValidityKeyMax:
600  untilStr = time.asctime(untilInfo)
601  if (untilCool//UNIX2COOL)>UNIXTMAX:
602  untilStr = " > "+untilStr
603  iovString = "[%s] - [%s]" % (time.asctime(sinceInfo), untilStr)
604 
605  #=== build tag
606  folderTag=tag
607 
608  #=== print info
609  comment=self.getComment()
610  onlyComment = (option<0)
611  noComment = (comment is None) or (comment == "None") or (comment.startswith("None") and comment.endswith("None")) or (option>0)
612  self.log().info( "Registering folder %s with tag \"%s\"", self.__folder.fullPath(),folderTag)
613  self.log().info( "... with IOV : %s" , iovString )
614  if noComment:
615  if (option<=0):
616  self.log().info( "... WITHOUT comment field" )
617  else:
618  self.log().info( "... with comment field: \"%s\"", self.getComment() )
619 
620  #=== register all channels by increasing channel number
621  if onlyComment:
622  chanList = [1000]
623  else:
624  chanList = sorted(self.__chanDictRecord.keys())
625  cnt=0
626  for chanNum in chanList:
627  if chanNum==1000 and noComment:
628  continue
629  data = self.__chanDictRecord[chanNum]
630  strout = "cool channel=%4i" % chanNum
631  self.log().debug("Registering %s %s", strout, data)
632  channelId = cool.ChannelId(chanNum)
633  self.__folder.storeObject(sinceCool, untilCool, data, channelId, folderTag, userTagOnly)
634  cnt+=1
635  if noComment:
636  self.log().info( "... %d cool channels have been written in total", cnt )
637  elif onlyComment:
638  self.log().info( "... 1 cool channel with comment field has been written" )
639  else:
640  self.log().info( "... %d cool channels have been written in total (including comment field)", cnt )
641 

◆ setComment()

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

Definition at line 643 of file TileCalibTools.py.

643  def setComment(self, author, comment=None):
644  """
645  Sets a general comment in the comment channel.
646  """
647  try:
649  data = self.__chanDictRecord.get(chanNum)
650  if not data:
651  spec = self.__folder.payloadSpecification()
652  data = cool.Record( spec )
653  self.__chanDictRecord[chanNum] = data
654  blob = data['TileCalibBlob']
655  if isinstance(author,tuple) and len(author)==3:
656  tm=time.mktime(datetime.datetime.strptime(author[2], "%a %b %d %H:%M:%S %Y").timetuple())
657  TileCalibDrawerCmt.getInstance(blob,author[0],author[1],int(tm))
658  else:
659  TileCalibDrawerCmt.getInstance(blob,author,comment)
660  except Exception as e:
661  self.log().critical( e )
662 

◆ zeroBlob()

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

Definition at line 726 of file TileCalibTools.py.

726  def zeroBlob(self, ros, drawer):
727  """
728  Resets blob size to zero
729  """
730  try:
731  chanNum = TileCalibUtils.getDrawerIdx(ros,drawer)
732  data = self.__chanDictRecord.get(chanNum)
733  if not data:
734  spec = self.__folder.payloadSpecification()
735  data = cool.Record( spec )
736  self.__chanDictRecord[chanNum] = data
737  blob = data['TileCalibBlob']
738  blob.resize(0)
739  except Exception as e:
740  self.log().critical( e )
741  return None
742 
743 
744 
745 #======================================================================
746 #===
747 #=== TileBlobReader
748 #===
749 #======================================================================
750 
751 #
752 #______________________________________________________________________

Member Data Documentation

◆ __calibDrawerType

python.TileCalibTools.TileBlobWriter.__calibDrawerType
private

Definition at line 545 of file TileCalibTools.py.

◆ __chanDictDrawer

python.TileCalibTools.TileBlobWriter.__chanDictDrawer
private

Definition at line 542 of file TileCalibTools.py.

◆ __chanDictRecord

python.TileCalibTools.TileBlobWriter.__chanDictRecord
private

Definition at line 541 of file TileCalibTools.py.

◆ __db

python.TileCalibTools.TileBlobWriter.__db
private

Definition at line 504 of file TileCalibTools.py.

◆ __defVec

python.TileCalibTools.TileBlobWriter.__defVec
private

Definition at line 547 of file TileCalibTools.py.

◆ __folder

python.TileCalibTools.TileBlobWriter.__folder
private

Definition at line 520 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
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:334
debug
const bool debug
Definition: MakeUncertaintyPlots.cxx:53
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
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:127
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