187 def generate(map_blobs=False, class_name=None):
189 Base = declarative_base()
190 schema = {
"schema" :
"CMS_CONDITIONS"}
191 fk_schema_prefix = (
"%s." % schema[
"schema"])
if schema
else "" 194 __table_args__ = schema
195 __tablename__ =
'GLOBAL_TAG' 197 headers = [
"name",
"validity",
"description",
"release",
"insertion_time",
"snapshot_time",
"scenario",
"workflow",
"type"]
199 name = Column(String(100), unique=
True, nullable=
False, primary_key=
True)
200 validity = Column(Integer, nullable=
False)
201 description = Column(String(4000), nullable=
False)
202 release = Column(String(100), nullable=
False)
203 insertion_time = Column(DateTime, nullable=
False)
204 snapshot_time = Column(DateTime, nullable=
False)
205 scenario = Column(String(100))
206 workflow = Column(String(100))
207 type = Column(String(1))
208 tag_map = relationship(
'GlobalTagMap', backref=
'global_tag')
210 def __init__(self, dictionary={}, convert_timestamps=True):
212 for key
in dictionary:
214 if convert_timestamps:
217 self.__dict__[key] = dictionary[key]
218 except KeyError
as k:
222 return '<GlobalTag %r>' % self.name
224 def as_dicts(self, convert_timestamps=False):
226 Returns dictionary form of Global Tag object. 230 'validity': self.validity,
231 'description': self.description,
232 'release': self.release,
233 'insertion_time':
to_timestamp(self.insertion_time)
if convert_timestamps
else self.insertion_time,
234 'snapshot_time':
to_timestamp(self.snapshot_time)
if convert_timestamps
else self.snapshot_time,
235 'scenario': self.scenario,
236 'workflow': self.workflow,
242 return [self.name, self.release,
to_timestamp(self.insertion_time),
to_timestamp(self.snapshot_time), self.description]
244 def all(self, **kwargs):
246 Returns `amount` Global Tags ordered by Global Tag name. 248 query = self.session.
query(GlobalTag)
250 amount = kwargs[
"amount"]
if "amount" in list(kwargs.keys())
else None 251 query_result = query.order_by(GlobalTag.name).
limit(amount).
all()
255 def tags(self, **kwargs):
257 Returns `amount` *Global Tag Maps* belonging to this Global Tag. 259 kwargs[
"global_tag_name"] = self.name
260 all_tags = self.session.
query(GlobalTagMap.global_tag_name, GlobalTagMap.record, GlobalTagMap.label, GlobalTagMap.tag_name)
262 amount = kwargs[
"amount"]
if "amount" in list(kwargs.keys())
else None 263 all_tags = all_tags.order_by(GlobalTagMap.tag_name).
limit(amount).
all()
264 column_names = [
"global_tag_name",
"record",
"label",
"tag_name"]
265 all_tags = [dict(list(
zip(column_names, list(
map(to_timestamp, row)))))
for row
in all_tags]
269 def iovs(self, **kwargs):
271 Returns `amount` IOVs belonging to all Tags held in this Global Tag. 272 For large Global Tags (which is most of them), VERY slow. 273 Highly recommended to instead used `tags().get_members("tag_name").data()` to get a `list` of tag names, 274 and then get IOVs from each Tag name. 276 At some point, this method may replace the method currently used. 282 tag_names = self.tags().get_members(
"tag_name").
data()
283 iovs_all_tags = self.session.
query(IOV).
filter(IOV.tag_name.in_(tag_names))
285 amount = kwargs[
"amount"]
if "amount" in list(kwargs.keys())
else None 286 iovs_all_tags = iovs_all_tags.limit(amount).subquery()
289 iovs_gt_tags = self.session.
query(GlobalTagMap.tag_name, iovs_all_tags.c.since,\
290 iovs_all_tags.c.payload_hash, iovs_all_tags.c.insertion_time)\
291 .
filter(GlobalTagMap.global_tag_name == self.name)\
292 .
join(iovs_all_tags, GlobalTagMap.tag_name == iovs_all_tags.c.tag_name)
294 iovs_gt_tags = iovs_gt_tags.order_by(iovs_all_tags.c.since).
all()
296 column_names = [
"tag_name",
"since",
"payload_hash",
"insertion_time"]
297 all_iovs = [dict(list(
zip(column_names, row)))
for row
in iovs_gt_tags]
302 def __sub__(self, other):
304 Allows Global Tag objects to be used with the "-" arithmetic operator to find their difference. 305 Note: gt1 - gt2 = gt1.diff(gt2) ( = gt2 - gt1 = gt2.diff(gt1)) 307 return self.diff(other)
311 Returns the json_list of differences in the form of tuples: 313 (record, label, tag name of gt1 (self), tag name of gt2 (gt)) 316 record_label_to_tag_name1 = dict([((gt_map.record, gt_map.label), gt_map.tag_name)
for gt_map
in self.tags().
data()])
317 record_label_to_tag_name2 = dict([((gt_map.record, gt_map.label), gt_map.tag_name)
for gt_map
in gt.tags().
data()])
319 record_label_pairs = sorted(set(record_label_to_tag_name1) | set(record_label_to_tag_name2))
322 tags_pairs_with_differences = []
324 for record_label
in record_label_pairs:
325 tag_name1 = record_label_to_tag_name1.get(record_label)
326 tag_name2 = record_label_to_tag_name2.get(record_label)
328 if tag_name1 ==
None or tag_name2 ==
None or tag_name1 != tag_name2:
330 "Record" : record_label[0],
331 "Label" : record_label[1],
332 (
"%s Tag" % self.name) : tag_name1,
333 (
"%s Tag" % gt.name) : tag_name2
338 class GlobalTagMap(
Base):
339 __table_args__ = schema
340 __tablename__ =
'GLOBAL_TAG_MAP' 342 headers = [
"global_tag_name",
"record",
"label",
"tag_name"]
344 global_tag_name = Column(String(100), ForeignKey(fk_schema_prefix +
'GLOBAL_TAG.name'), primary_key=
True, nullable=
False)
345 record = Column(String(100), ForeignKey(fk_schema_prefix +
'RECORDS.record'), primary_key=
True, nullable=
False)
346 label = Column(String(100), primary_key=
True, nullable=
False)
347 tag_name = Column(String(100), ForeignKey(fk_schema_prefix +
'TAG.name'), nullable=
False)
349 def __init__(self, dictionary={}, convert_timestamps=True):
351 for key
in dictionary:
353 if convert_timestamps:
356 self.__dict__[key] = dictionary[key]
357 except KeyError
as k:
361 return '<GlobalTagMap %r>' % self.global_tag_name
363 def as_dicts(self, convert_timestamps=False):
365 Returns dictionary form of this Global Tag Map. 368 "global_tag_name" :
str(self.global_tag_name),
369 "record" :
str(self.record),
370 "label" :
str(self.label),
371 "tag_name" :
str(self.tag_name)
376 class GlobalTagMapRequest(
Base):
377 __table_args__ = schema
378 __tablename__ =
'GLOBAL_TAG_MAP_REQUEST' 380 queue = Column(String(100), primary_key=
True, nullable=
False)
381 tag = Column(String(100), ForeignKey(fk_schema_prefix +
'TAG.name'), primary_key=
True, nullable=
False)
382 record = Column(String(100), ForeignKey(fk_schema_prefix +
'RECORDS.record'), primary_key=
True, nullable=
False)
383 label = Column(String(100), primary_key=
True, nullable=
False)
384 status = Column(String(1), nullable=
False)
385 description = Column(String(4000), nullable=
False)
386 submitter_id = Column(Integer, nullable=
False)
387 time_submitted = Column(DateTime, nullable=
False)
388 last_edited = Column(DateTime, nullable=
False)
390 def __init__(self, dictionary={}, convert_timestamps=True):
392 for key
in dictionary:
394 if convert_timestamps:
397 self.__dict__[key] = dictionary[key]
398 except KeyError
as k:
401 headers = [
"queue",
"tag",
"record",
"label",
"status",
"description",
"submitter_id",
"time_submitted",
"last_edited"]
405 Returns dictionary form of this Global Tag Map Request. 408 "queue" : self.queue,
410 "record" : self.record,
411 "label" : self.label,
412 "status" : self.status,
413 "description" : self.description,
414 "submitter_id" : self.submitter_id,
415 "time_submitted" : self.time_submitted,
416 "last_edited" : self.last_edited
420 return '<GlobalTagMapRequest %r>' % self.queue
426 __table_args__ = schema
427 __tablename__ =
'IOV' 429 headers = [
"tag_name",
"since",
"payload_hash",
"insertion_time"]
431 tag_name = Column(String(4000), ForeignKey(fk_schema_prefix +
'TAG.name'), primary_key=
True, nullable=
False)
432 since = Column(Integer, primary_key=
True, nullable=
False)
433 payload_hash = Column(String(40), ForeignKey(fk_schema_prefix +
'PAYLOAD.hash'), nullable=
False)
434 insertion_time = Column(DateTime, primary_key=
True, nullable=
False)
436 def __init__(self, dictionary={}, convert_timestamps=True):
438 for key
in dictionary:
440 if convert_timestamps:
443 self.__dict__[key] = dictionary[key]
444 except KeyError
as k:
447 def as_dicts(self, convert_timestamps=False):
449 Returns dictionary form of this IOV. 452 "tag_name" : self.tag_name,
453 "since" : self.since,
454 "payload_hash" : self.payload_hash,
455 "insertion_time" :
to_timestamp(self.insertion_time)
if convert_timestamps
else self.insertion_time
459 return '<IOV %r>' % self.tag_name
462 return [self.since,
to_timestamp(self.insertion_time), self.payload_hash]
464 def all(self, **kwargs):
466 Returns `amount` IOVs ordered by since. 468 query = self.session.
query(IOV)
470 amount = kwargs[
"amount"]
if "amount" in list(kwargs.keys())
else None 471 query_result = query.order_by(IOV.tag_name).order_by(IOV.since).
limit(amount).
all()
476 __table_args__ = schema
477 __tablename__ =
'PAYLOAD' 479 headers = [
"hash",
"object_type",
"version",
"insertion_time"]
481 hash = Column(String(40), primary_key=
True, nullable=
False)
482 object_type = Column(String(4000), nullable=
False)
483 version = Column(String(4000), nullable=
False)
484 insertion_time = Column(DateTime, nullable=
False)
486 data = Column(Binary, nullable=
False)
487 streamer_info = Column(Binary, nullable=
False)
488 blobs_mapped = map_blobs
490 def __init__(self, dictionary={}, convert_timestamps=True):
492 for key
in dictionary:
494 if convert_timestamps:
497 self.__dict__[key] = dictionary[key]
498 except KeyError
as k:
502 def as_dicts(self, convert_timestamps=False):
504 Returns dictionary form of this Payload's metadata (not the actual Payload). 508 "object_type" : self.object_type,
509 "version" : self.version,
510 "insertion_time" :
to_timestamp(self.insertion_time)
if convert_timestamps
else self.insertion_time,
512 "streamer_info" : self.streamer_info
515 def as_dicts(self, convert_timestamps=False):
517 Returns dictionary form of this Payload's metadata (not the actual Payload). 521 "object_type" : self.object_type,
522 "version" : self.version,
523 "insertion_time" :
to_timestamp(self.insertion_time)
if convert_timestamps
else self.insertion_time
527 return '<Payload %r>' % self.hash
530 return [self.hash, self.object_type, self.version,
to_timestamp(self.insertion_time)]
532 def parent_tags(self, **kwargs):
534 Returns `amount` parent Tags ordered by Tag name. 540 kwargs[
"payload_hash"] = self.hash
541 query = self.session.
query(IOV.tag_name)
543 query_result = query.all()
544 tag_names = [entry[0]
for entry
in query_result]
545 amount = kwargs[
"amount"]
if "amount" in list(kwargs.keys())
else None 546 tags = self.session.
query(Tag).
filter(Tag.name.in_(tag_names)).order_by(Tag.name).
limit(amount).
all()
549 def all(self, **kwargs):
551 Returns `amount` Payloads ordered by Payload hash. 553 query = self.session.
query(Payload)
555 amount = kwargs[
"amount"]
if "amount" in list(kwargs.keys())
else None 556 query_result = query.order_by(Payload.hash).
limit(amount).
all()
561 __table_args__ = schema
562 __tablename__ =
'RECORDS' 564 headers = [
"record",
"object",
"type"]
566 record = Column(String(100), primary_key=
True, nullable=
False)
567 object = Column(String(200), nullable=
False)
568 type = Column(String(20), nullable=
False)
572 Returns dictionary form of this Record. 575 "record" : self.record,
576 "object" : self.object,
581 return '<Record %r>' % self.record
584 return [self.record, self.object]
586 def all(self, **kwargs):
588 Returns `amount` Records ordered by Record record. 590 query = self.session.
query(Record)
592 amount = kwargs[
"amount"]
if "amount" in list(kwargs.keys())
else None 593 query_result = query.order_by(Record.record).
limit(amount).
all()
598 __table_args__ = schema
599 __tablename__ =
'TAG' 601 headers = [
"name",
"time_type",
"object_type",
"synchronization",
"end_of_validity",\
602 "description",
"last_validated_time",
"insertion_time",
"modification_time",
"protection_code"]
604 name = Column(String(4000), primary_key=
True, nullable=
False)
605 time_type = Column(String(4000), nullable=
False)
606 object_type = Column(String(4000), nullable=
False)
607 synchronization = Column(String(4000), nullable=
False)
608 end_of_validity = Column(Integer, nullable=
False)
609 description = Column(String(4000), nullable=
False)
610 last_validated_time = Column(BigInteger, nullable=
False)
611 insertion_time = Column(DateTime, nullable=
False)
612 modification_time = Column(DateTime, nullable=
False)
613 protection_code = Column(Integer, nullable=
False)
618 iovs_list = relationship(
'IOV', backref=
'tag')
620 def __init__(self, dictionary={}, convert_timestamps=True):
622 for key
in dictionary:
624 if convert_timestamps:
627 self.__dict__[key] = dictionary[key]
628 except KeyError
as k:
631 def as_dicts(self, convert_timestamps=False):
633 Returns dictionary form of this Tag. 637 "time_type" : self.time_type,
638 "object_type" : self.object_type,
639 "synchronization" : self.synchronization,
640 "end_of_validity" : self.end_of_validity,
641 "description" : self.description,
642 "last_validated_time" : self.last_validated_time,
643 "insertion_time" :
to_timestamp(self.insertion_time)
if convert_timestamps
else self.insertion_time,
644 "modification_time" :
to_timestamp(self.modification_time)
if convert_timestamps
else self.modification_time,
645 "record" : self.record,
650 return '<Tag %r>' % self.name
653 return [self.name, self.time_type, self.object_type, self.synchronization,
to_timestamp(self.insertion_time), self.description]
655 def parent_global_tags(self, **kwargs):
657 Returns `amount` Global Tags that contain this Tag. 662 kwargs[
"tag_name"] = self.name
663 query = self.session.
query(GlobalTagMap.global_tag_name)
665 query_result = query.all()
666 if len(query_result) != 0:
667 global_tag_names = [entry[0]
for entry
in query_result]
668 amount = kwargs[
"amount"]
if "amount" in list(kwargs.keys())
else None 669 global_tags = self.session.
query(GlobalTag).
filter(GlobalTag.name.in_(global_tag_names)).order_by(GlobalTag.name).
limit(amount).
all()
674 def all(self, **kwargs):
676 Returns `amount` Tags ordered by Tag name. 678 query = self.session.
query(Tag)
680 amount = kwargs[
"amount"]
if "amount" in list(kwargs.keys())
else None 681 query_result = query.order_by(Tag.name).
limit(amount).
all()
684 def iovs(self, **kwargs):
686 Returns `amount` IOVs that belong to this Tag ordered by IOV since. 689 iovs_query = self.session.
query(IOV).
filter(IOV.tag_name == self.name)
691 amount = kwargs[
"amount"]
if "amount" in list(kwargs.keys())
else None 692 iovs = iovs_query.order_by(IOV.since).
limit(amount).
all()
695 def latest_iov(self):
697 Returns the single highest since held by this Tag. 698 Insertion times do not matter - if there are two IOVs at since > all others, both have the highest since. 700 iov = self.session.
query(IOV).
filter(IOV.tag_name == self.name).order_by(IOV.since.desc()).
first()
703 def __sub__(self, other):
705 Allows the arithmetic operator "-" to be applied to find the difference between two tags. 706 Note: diff() is symmetric, hence tag1 - tag2 = tag2 - tag1. 708 return self.diff(other)
710 def diff(self, tag, short=False):
712 Returns the `diff` of the first Tag, and the Tag given. 713 Summary of algorithm: 715 Compute the ordered set of iov sinces from both tags, and construct a list of triples, (since, tag1 hash, tag2 hash). 716 Set previous_payload1 and previous_payload2 to be the first hash values from each tag for the first since in the merged list. 717 Note: depending on where each Tag's IOVs start, 1 or both of these values can be None. 718 Set the first_since_in_equality_range = -1, which holds the since at which the last hashes were equal in the Tags. 719 For each triple (since, hash1, hash2), 721 If the first_since_in_equality_range = None, 722 We are at the first since in the merged list, so set first_since... = since 723 Note: this is so set the previous... values for the second row, since the first row will never result in a print because 724 a row is only printed when past iovs have been processed. 726 If either hash1 or hash2 is None, set it to the previous hash found 727 Note: if a Tag defines a hash for one since and then not another for n rows, the last defined hash will be carried through because of this. 729 If the previous found hashes were equal, that means we have equality on the range [first_since_in_equality_range, since) 730 Note: we CANNOT conclude anything about the hashes corresponding to sinces >= since 731 because we have no looked forward, but we do know about the previous hashes. 734 The region of equality has ended, and so we have that [first_since_in_equality_range, since) is equal for both Tags 735 Hence, print that for this range we have equal hashes denoted by "=" in each hash column. 739 The previous hashes were not equal, BUT we must check that ths hashes on this row are not identical... 740 If the hashes on this row are the same as the hashes above (hash1 == previous_payload1 and hash2 == previous_payload2), 741 then we have not found the end of a region of equality! 742 If the hashes have changed, print a row. 745 if tag.__class__.__name__ !=
"Tag":
746 raise TypeError(
"Tag given must be a CondDBFW Tag object.")
749 iovs1 = dict([(iov.since, iov.payload_hash)
for iov
in self.iovs().
data()])
750 iovs2 = dict([(iov.since, iov.payload_hash)
for iov
in tag.iovs().
data()])
752 iovs = [(x, iovs1.get(x), iovs2.get(x))
for x
in sorted(set(iovs1) | set(iovs2))]
753 iovs.append((
"Infinity", 1, 2))
756 previous_hash1 =
None 757 previous_hash2 =
None 758 first_since_in_equality_range =
None 759 previous_equal =
False 761 for since, hash1, hash2
in iovs:
763 if first_since_in_equality_range ==
None:
768 first_since_in_equality_range = since
769 previous_hash1 = hash1
770 previous_hash2 = hash2
771 previous_equal = hash1 == hash2
777 hash1 = previous_hash1
779 hash2 = previous_hash2
784 table.append({
"since" :
"[%s, %s)" % (first_since_in_equality_range, since), self.name :
"=", tag.name :
"="})
786 first_since_in_equality_range = since
792 if not(hash1 == previous_hash1
and hash2 == previous_hash2):
793 table.append({
"since" :
"[%s, %s)" % (first_since_in_equality_range, since), self.name : previous_hash1, tag.name : previous_hash2})
794 first_since_in_equality_range = since
796 previous_hash1 = hash1
797 previous_hash2 = hash2
798 previous_equal = hash1 == hash2
805 Given another connection, apply the 'merge' algorithm to merge the IOVs from this Tag 806 into the IOVs of the other Tag. 808 tag : CondDBFW Tag object that the IOVs from this Tag should be merged into. 810 range_object : CondDBFW.data_sources.Range object to describe the subset of IOVs that should be copied 811 from the database this Tag belongs to. 813 Script originally written by Joshua Dawes, 814 and adapted by Giacomo Govi, Gianluca Cerminara and Giovanni Franzoni. 818 merged_tag_name = oracle_tag.name +
"_merged" 821 since_range = range_object
827 if sqlite_tag ==
None:
828 raise TypeError(
"Tag to be merged cannot be None.")
830 sqlite_iovs = sqlite_tag.iovs().
data()
831 sqlite_tag.iovs().as_table()
833 new_tag = self.connection.models[
"tag"](sqlite_tag.as_dicts(convert_timestamps=
False), convert_timestamps=
False)
834 new_tag.name = merged_tag_name
836 imported_iovs = oracle_tag.iovs(since=since_range).
data()
838 for i
in range(0, len(imported_iovs)):
839 imported_iovs[i].source =
"oracle" 841 sqlite_iovs_sinces=[]
842 for i
in range(0, len(sqlite_iovs)):
843 sqlite_iovs[i].source =
"sqlite" 844 sqlite_iovs_sinces.append(sqlite_iovs[i].since)
847 print(sqlite_iovs_sinces)
849 new_iovs_list = imported_iovs + sqlite_iovs
850 new_iovs_list = sorted(new_iovs_list, key=
lambda iov : iov.since)
852 for (n, iov)
in enumerate(new_iovs_list):
854 if iov.source ==
"oracle":
855 if new_iovs_list[n].since
in sqlite_iovs_sinces:
858 iov.source =
"tobedeleted" 862 for i
in reversed(list(
range(0,n))):
863 if new_iovs_list[i].source ==
"sqlite":
864 print(
"change %s to %s at since %d" % (iov.payload_hash, new_iovs_list[i].payload_hash, iov.since))
865 iov.payload_hash = new_iovs_list[i].payload_hash
869 new_iov_list_copied = []
871 for iov
in new_iovs_list:
873 if iov.source !=
"tobedeleted":
874 new_iov_list_copied.append(iov)
876 new_iov_list_copied = sorted(new_iov_list_copied, key=
lambda iov : iov.since)
878 now = datetime.datetime.utcnow()
881 for iov
in new_iov_list_copied:
882 new_iovs.append( self.connection.models[
"iov"](iov.as_dicts(convert_timestamps=
False), convert_timestamps=
False) )
884 iov.insertion_time = now
885 iov.tag_name = merged_tag_name
887 new_tag.iovs_list = new_iovs
893 class TagAuthorization(
Base):
894 __table_args__ = schema
895 __tablename__ =
'TAG_AUTHORIZATION' 897 headers = [
"tag_name",
"access_type",
"credential",
"credential_type"]
899 tag_name = Column(String(100), ForeignKey(fk_schema_prefix +
'TAG.name'), primary_key=
True, nullable=
False)
900 access_type = Column(Integer, nullable=
False)
901 credential = Column(String(100), primary_key=
True, nullable=
False)
902 credential_type = Column(Integer, nullable=
False)
906 Returns dictionary form of this Tag Authorization. 909 "tag_name" : self.tag_name,
910 "access_type" : self.access_type,
911 "credential" : self.credential,
912 "credential_type" : self.credential_type
916 return '<TagAuthorization %s %s %s %s>' % (self.tag_name, self.access_type, self.credential, self.credential_type)
919 return [self.tag_name, self.access_type, self.credential, self.credential_type]
921 def all(self, **kwargs):
923 Returns `amount` Records ordered by Record record. 925 query = self.session.
query(TagAuthorization)
927 amount = kwargs[
"amount"]
if "amount" in list(kwargs.keys())
else None 928 query_result = query.order_by(TagAuthorization.tag).
limit(amount).
all()
931 classes = {
"globaltag" : GlobalTag,
"iov" : IOV,
"globaltagmap" : GlobalTagMap,\
932 "payload" : Payload,
"tag" : Tag,
"TagAuthorization": TagAuthorization,
"Base" : Base}
934 if class_name ==
None:
937 return classes[class_name]
ALPAKA_FN_HOST_ACC ALPAKA_FN_INLINE constexpr float zip(ConstView const &tracks, int32_t i)
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)
void generate(uint32_t const nbins, float const *initValues, std::vector< float > &values)
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
static std::string join(char **cmd)
char data[epos_bytes_allocation]
def apply_filters(orm_query, orm_class, filters)
def status_full_name(status)
def merge_into(metrics, data, dest)