685 def register(self, since=(MINRUN,MINLBK), until=(MAXRUN,MAXLBK), tag="", option=0):
686 """
687 Registers the folder in the database.
688 - since: lower limit of IOV
689 - until: upper limit of IOV
690 - tag : The cool folder tag to write to
691
692 The interpretation of the 'since' and 'until' inputs depends on their type:
693 - tuple(int,int) : run and lbk number
694 - integer : Values are interpreted as unix time stamps
695 If since<0, current time is assumed
696 If until<0, infinity is assumed
697 - string : time stamp of format 'yyyy-mm-dd hh:mm:ss'
698 """
699
700
702 raise Exception(
"Inconsistent types: since=%s, until=%s" % (
type(since),
type(until)))
703
704
705 userTagOnly = True
706 if self.__folder.versioningMode()==cool.FolderVersioning.SINGLE_VERSION:
707 userTagOnly = False
708
709 if tag!="":
710 self.log().warning( "Trying to store with tag \"%s\" to SINGLE_VERSION folder", tag )
711 self.log().warning( "... resetting tag to \"\"!" )
712 tag=""
713
714
715 sinceCool = getCoolValidityKey(since, True )
716 untilCool = getCoolValidityKey(until, False)
717 if untilCool <= sinceCool:
718 raise Exception("Until(%i) <= Since(%i)" % (untilCool,sinceCool))
719
720
721 iovString = ""
722 if isinstance(since, tuple):
723 iovString = "[%i,%i] - [%i,%i]" % (since[0],since[1],until[0],until[1])
724 else:
725 sinceInfo = time.localtime( sinceCool//UNIX2COOL )
726 untilInfo = time.localtime(
min(UNIXTMAX, (untilCool//UNIX2COOL)))
727 untilStr = "<infinity>"
728 if untilCool<cool.ValidityKeyMax:
729 untilStr = time.asctime(untilInfo)
730 if (untilCool//UNIX2COOL)>UNIXTMAX:
731 untilStr = " > "+untilStr
732 iovString = "[%s] - [%s]" % (time.asctime(sinceInfo), untilStr)
733
734
735 folderTag=tag
736
737
738 comment=self.getComment()
739 onlyComment = (option<0)
740 noComment = (comment is None) or (comment == "None") or (comment.startswith("None") and comment.endswith("None")) or (option>0)
741 self.log().info( "Registering folder %s with tag \"%s\"", self.__folder.fullPath(),folderTag)
742 self.log().info( "... with IOV : %s" , iovString )
743 if noComment:
744 if (option<=0):
745 self.log().info( "... WITHOUT comment field" )
746 else:
747 self.log().info( "... with comment field: \"%s\"", self.getComment() )
748
749
750 if onlyComment:
751 chanList = [1000]
752 else:
753 chanList = sorted(self.__chanDictRecord.keys())
754 cnt=0
755 for chanNum in chanList:
756 if chanNum==1000 and noComment:
757 continue
758 data = self.__chanDictRecord[chanNum]
759 strout = "cool channel=%4i" % chanNum
760 self.log().
debug(
"Registering %s %s", strout, data)
761 channelId = cool.ChannelId(chanNum)
762 self.__folder.storeObject(sinceCool, untilCool, data, channelId, folderTag, userTagOnly)
763 cnt+=1
764 if noComment:
765 self.log().info( "... %d cool channels have been written in total", cnt )
766 elif onlyComment:
767 self.log().info( "... 1 cool channel with comment field has been written" )
768 else:
769 self.log().info( "... %d cool channels have been written in total (including comment field)", cnt )
770