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, isMultiVersionFolder=True)
 register (self, since=(MINRUN, MINLBK), tag="")
 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
 __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 429 of file TileCalibCrest.py.

Constructor & Destructor Documentation

◆ __init__()

python.TileCalibCrest.TileBlobWriterCrest.__init__ ( self,
db,
folderPath,
calibDrawerType,
isMultiVersionFolder = True )
Input:
- db        : db should be a database connection
- folderPath: full folder path to create or update

Definition at line 436 of file TileCalibCrest.py.

436 def __init__(self, db, folderPath, calibDrawerType, isMultiVersionFolder=True):
437 """
438 Input:
439 - db : db should be a database connection
440 - folderPath: full folder path to create or update
441 """
442
443 #=== initialize base class
444 TileCalibLogger.__init__(self, "TileBlobWriter")
445
446 #=== store db
447 self.__db = db
448 self.__folderPath = folderPath
449
450 #=== create default vectors based on calibDrawerType
451 self.__calibDrawerType = calibDrawerType
452 if calibDrawerType in ['TileCalibDrawerFlt', 'Flt']:
453 self.__TileCalibDrawer = TileCalibDrawerFlt
454 self.__defVec = cppyy.gbl.std.vector('std::vector<float>')()
455 elif calibDrawerType in ['TileCalibDrawerBch', 'Bch']:
456 self.__TileCalibDrawer = TileCalibDrawerBch
457 self.__defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')()
458 elif calibDrawerType in ['TileCalibDrawerInt', 'Int']:
459 self.__TileCalibDrawer = TileCalibDrawerInt
460 self.__defVec = cppyy.gbl.std.vector('std::vector<unsigned int>')()
461 else:
462 raise Exception("Unknown calibDrawerType: %s" % calibDrawerType)
463
464 # Always all drawers should be written
465 self.__drawerBlob = {drawerIdx:Blob() for drawerIdx in range(0, TileCalibUtils.max_draweridx())}
466 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 525 of file TileCalibCrest.py.

525 def getComment(self, split=False):
526 """
527 Returns the general comment (default if none is set)
528 """
530 comment = self.__drawer.get(drawerIdx, None)
531 if comment:
532 if split:
533 return (comment.getAuthor(), self.__comment.getComment(), self.__comment.getDate())
534 else:
535 return comment.getFullComment()
536 else:
537 return "<No general comment!>"
538
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:130

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

540 def getDrawer(self, ros, drawer, calibDrawerTemplate=None):
541 """
542 Returns a TileCalibDrawer object of requested type
543 for the given ROS and drawer.
544 """
545
546 try:
547 drawerIdx = TileCalibUtils.getDrawerIdx(ros, drawer)
548 calibDrawer = self.__drawer.get(drawerIdx, None)
549
550 if not calibDrawer:
551 calibDrawer = self.__TileCalibDrawer.getInstance(self.__drawerBlob[drawerIdx], self.__defVec,0,0)
552 self.__drawer[drawerIdx] = calibDrawer
553
554 #=== clone if requested
555 if calibDrawerTemplate:
556 calibDrawer.clone(calibDrawerTemplate)
557
558 return calibDrawer
559
560 except Exception as e:
561 self.log().critical( e )
562 return None
563
static unsigned int getDrawerIdx(unsigned int ros, unsigned int drawer)
Returns a drawer hash.

◆ register()

python.TileCalibCrest.TileBlobWriterCrest.register ( self,
since = (MINRUN,MINLBK),
tag = "" )
Registers the folder in the database.
- since: lower limit of IOV
- tag  : The tag to write to

The interpretation of the 'since' inputs depends on their type:
- tuple(int,int) : run and lbk number

Definition at line 468 of file TileCalibCrest.py.

468 def register(self, since=(MINRUN,MINLBK), tag=""):
469 """
470 Registers the folder in the database.
471 - since: lower limit of IOV
472 - tag : The tag to write to
473
474 The interpretation of the 'since' inputs depends on their type:
475 - tuple(int,int) : run and lbk number
476 """
477
478 jdata = {}
479 for drawerIdx,blob in self.__drawerBlob.items():
480 if blob is None or blob==0:
481 b64string = ''
482 else:
483 b64string = str(base64.b64encode(blob.read()), 'ascii')
484 jdata[drawerIdx] = [b64string]
485
486 (sinceRun, sinceLumi) = since
487
488 if not self.__db or (self.__db and self.__db.endswith('.json')):
489 # Writting into the json file
490 fullTag = tag
491 if self.__folderPath and not (tag.upper().startswith('TILE') or tag.upper().startswith('CALO')):
492 fullTag = TileCalibUtils.getFullTag(self.__folderPath, tag)
493 fileName = f"{fullTag}.{sinceRun}.{sinceLumi}.json"
494 if self.__db:
495 fileName = f'{self.__db[:-5]}.{fileName}'
496
497 with open(fileName, 'w') as the_file:
498 json.dump(jdata, the_file)
499 the_file.write('\n')
500
501 #=== print info
502 self.log().info( 'Writting tag "%s"', fullTag)
503 self.log().info( '... since : [%s,%s]' , sinceRun, sinceLumi)
504 self.log().info( '... with comment field: "%s"', self.getComment())
505 self.log().info( '... into file : %s' , fileName)
506
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.
#define register
Definition dictionary.h:21

◆ setComment()

python.TileCalibCrest.TileBlobWriterCrest.setComment ( self,
author,
comment = None )
Sets a general comment in the comment channel.

Definition at line 508 of file TileCalibCrest.py.

508 def setComment(self, author, comment=None):
509 """
510 Sets a general comment in the comment channel.
511 """
513 commentBlob = self.__drawer.get(drawerIdx, None)
514 if not commentBlob:
515 commentBlob = Blob()
516 self.__drawerBlob[drawerIdx] = commentBlob
517
518 if isinstance(author, tuple) and len(author) == 3:
519 tm = time.mktime(datetime.datetime.strptime(author[2], "%a %b %d %H:%M:%S %Y").timetuple())
520 self.__drawer[drawerIdx] = TileCalibDrawerCmt.getInstance(commentBlob, author[0], author[1], int(tm))
521 else:
522 self.__drawer[drawerIdx] = TileCalibDrawerCmt.getInstance(commentBlob, author, comment)
523
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 565 of file TileCalibCrest.py.

565 def zeroBlob(self, ros, drawer):
566 """
567 Resets blob size to zero
568 """
569 try:
570 drawerIdx = TileCalibUtils.getDrawerIdx(ros, drawer)
571 blob = self.__drawerBlob[drawerIdx]
572 blob.resize(0)
573 except Exception as e:
574 self.log().critical( e )
575 return None

Member Data Documentation

◆ __calibDrawerType

python.TileCalibCrest.TileBlobWriterCrest.__calibDrawerType = calibDrawerType
private

Definition at line 451 of file TileCalibCrest.py.

◆ __db

python.TileCalibCrest.TileBlobWriterCrest.__db = db
private

Definition at line 447 of file TileCalibCrest.py.

◆ __defVec

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

Definition at line 454 of file TileCalibCrest.py.

◆ __drawer

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

Definition at line 466 of file TileCalibCrest.py.

◆ __drawerBlob

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

Definition at line 465 of file TileCalibCrest.py.

◆ __folderPath

python.TileCalibCrest.TileBlobWriterCrest.__folderPath = folderPath
private

Definition at line 448 of file TileCalibCrest.py.

◆ __TileCalibDrawer

python.TileCalibCrest.TileBlobWriterCrest.__TileCalibDrawer = TileCalibDrawerFlt
private

Definition at line 453 of file TileCalibCrest.py.


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