654 def register(self, since=(MINRUN,MINLBK), tag="", chan=-1, payload=None):
655 """
656 Registers the folder in the database.
657 - since: lower limit of IOV
658 - tag : The tag to write to
659 - chan : COOL channel to write, if negative - all COOL channels are written
660 Comment channel is always written
661
662 The interpretation of the 'since' inputs depends on their type:
663 - tuple(int,int) : run and lbk number
664 """
665
666 if self.__payload is None and payload is None:
667 jdata = {}
668 for drawerIdx,blob in self.__drawerBlob.items():
669 if chan<0 or drawerIdx==chan or drawerIdx==1000:
670 if blob is None or blob==0:
671 b64string = ''
672 else:
673 blob.seek(0)
674 b64string = str(base64.b64encode(blob.read()), 'ascii')
675 jdata[drawerIdx] = [b64string]
676 else:
677 if payload is not None:
678 self.__payload = payload
679 jdata = self.__payload
680
681 (sinceRun, sinceLumi) = since
682 fullTag = tag
683 if self.__folderPath and not (tag.upper().startswith('TILE') or tag.upper().startswith('CALO')):
685
686 if not self.__db or self.__db.endswith('.json'):
687
688 fileName = f"{fullTag}.{sinceRun}.{sinceLumi}.json"
689 if self.__db:
690 fileName = f'{self.__db[:-5]}.{fileName}'
691
692 with open(fileName, 'w') as the_file:
693 json.dump(jdata, the_file, separators=(',', ':'), sort_keys=True)
694 else:
695 if 'http' in self.__db:
696 self.log().info('Host %s' , (self.__db))
697 self.__api_instance = chai.Database(f"crest:{self.__db}")
698 fileName = 'remote host'
699 else:
700 self.log().info('Local db %s' , (self.__db))
701 self.__api_instance = chai.Database(f"crest_fs:{self.__db}")
702 fileName = self.__db + '/' + fullTag
703
704 (payload_spec,container) = self.create_container_with_blob(jdata)
705
706 try:
707 new_tag = self.__api_instance.create_tag(
708 fullTag,
709 "",
710 payload_spec,
711 '<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader><typeName>CondAttrListCollection</typeName>',
712 chai.IovType.RunNumberLumiBlock,
713 "crest-json-single-iov",
714 chai.Synchronization.All,
715 chai.TagStatus.Unlocked
716 )
717 except Exception as e:
718
719 try:
720 new_tag = self.__api_instance.get_tag(fullTag)
721 except Exception as e2:
722 self.log().
error(f
"Failed to create or get tag: {e}")
723 self.log().
error(f
"Additional error: {e2}")
724 raise Exception( "Failed to write data to %s" % (self.__db) )
725
726 new_tag.add_payload(container, (sinceRun<<32)+sinceLumi)
727
728
729 self.log().info( 'Writting tag "%s"', fullTag)
730 self.log().info( '... since : [%s,%s]' , sinceRun, sinceLumi)
731 if self.__payload is None:
732 self.log().info( '... with comment field: "%s"', self.getComment())
733 self.log().info( '... into file : %s' , fileName)
734
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.