Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 487 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 494 of file TileCalibTools.py.

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

Member Function Documentation

◆ getComment()

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

Definition at line 665 of file TileCalibTools.py.

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

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

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

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

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

◆ setComment()

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

Definition at line 644 of file TileCalibTools.py.

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

◆ zeroBlob()

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

Definition at line 727 of file TileCalibTools.py.

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

Member Data Documentation

◆ __calibDrawerType

python.TileCalibTools.TileBlobWriter.__calibDrawerType
private

Definition at line 546 of file TileCalibTools.py.

◆ __chanDictDrawer

python.TileCalibTools.TileBlobWriter.__chanDictDrawer
private

Definition at line 543 of file TileCalibTools.py.

◆ __chanDictRecord

python.TileCalibTools.TileBlobWriter.__chanDictRecord
private

Definition at line 542 of file TileCalibTools.py.

◆ __db

python.TileCalibTools.TileBlobWriter.__db
private

Definition at line 505 of file TileCalibTools.py.

◆ __defVec

python.TileCalibTools.TileBlobWriter.__defVec
private

Definition at line 548 of file TileCalibTools.py.

◆ __folder

python.TileCalibTools.TileBlobWriter.__folder
private

Definition at line 521 of file TileCalibTools.py.


The documentation for this class was generated from the following file:
grepfile.info
info
Definition: grepfile.py:38
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:360
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:335
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:180
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:798
TileCalibUtils::getDrawerIdx
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
Definition: TileCalibUtils.cxx:60