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