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 481 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 488 of file TileCalibTools.py.

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

Member Function Documentation

◆ getComment()

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

Definition at line 659 of file TileCalibTools.py.

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

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

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

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

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

◆ setComment()

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

Definition at line 638 of file TileCalibTools.py.

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

◆ zeroBlob()

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

Definition at line 721 of file TileCalibTools.py.

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

Member Data Documentation

◆ __calibDrawerType

python.TileCalibTools.TileBlobWriter.__calibDrawerType
private

Definition at line 540 of file TileCalibTools.py.

◆ __chanDictDrawer

python.TileCalibTools.TileBlobWriter.__chanDictDrawer
private

Definition at line 537 of file TileCalibTools.py.

◆ __chanDictRecord

python.TileCalibTools.TileBlobWriter.__chanDictRecord
private

Definition at line 536 of file TileCalibTools.py.

◆ __db

python.TileCalibTools.TileBlobWriter.__db
private

Definition at line 499 of file TileCalibTools.py.

◆ __defVec

python.TileCalibTools.TileBlobWriter.__defVec
private

Definition at line 542 of file TileCalibTools.py.

◆ __folder

python.TileCalibTools.TileBlobWriter.__folder
private

Definition at line 515 of file TileCalibTools.py.


The documentation for this class was generated from the following file:
grepfile.info
info
Definition: grepfile.py:38
TileCalibDrawerBch::getInstance
static const TileCalibDrawerBch * getInstance(const coral::Blob &blob)
Returns a pointer to a const TileCalibDrawerBch.
Definition: TileCalibDrawerBch.cxx:28
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
CscCalibQuery.fullPath
string fullPath
Definition: CscCalibQuery.py:360
register
#define register
Definition: dictionary.h:21
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
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
min
#define min(a, b)
Definition: cfImp.cxx:40
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.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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:790
TileCalibUtils::getDrawerIdx
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.
Definition: TileCalibUtils.cxx:60