41 Base = declarative_base()
44 __tablename__ =
'GLOBAL_TAG'
46 headers = [
"name",
"validity",
"description",
"release",
"insertion_time",
"snapshot_time",
"scenario",
"workflow",
"type"]
48 name = Column(String(100), unique=
True, nullable=
False, primary_key=
True)
49 validity = Column(Integer, nullable=
False)
50 description = Column(String(4000), nullable=
False)
51 release = Column(String(100), nullable=
False)
52 insertion_time = Column(DateTime, nullable=
False)
53 snapshot_time = Column(DateTime, nullable=
False)
54 scenario = Column(String(100))
55 workflow = Column(String(100))
56 type = Column(String(1))
57 tag_map = relationship(
'GlobalTagMap', backref=
'global_tag')
59 def __init__(self, dictionary={}, convert_timestamps=True):
61 for key
in dictionary:
63 if convert_timestamps:
66 self.__dict__[key] = dictionary[key]
71 return '<GlobalTag %r>' % self.name
76 'validity': self.validity,
77 'description': self.description,
78 'release': self.release,
79 'insertion_time': self.insertion_time,
80 'snapshot_time': self.snapshot_time,
81 'scenario': self.scenario,
82 'workflow': self.workflow,
88 return [self.name, self.release,
to_timestamp(self.insertion_time),
to_timestamp(self.snapshot_time), self.description]
93 'headers': [
'Global Tag',
'Release',
'Insertion Time',
'Snapshot Time',
'Description'],
94 'data': [ g.to_array()
for g
in global_tags ],
99 def all(self, amount=10):
103 def tags(self, amount=10):
104 """gt_maps = self.session.query(GlobalTagMap).filter(GlobalTagMap.global_tag_name == self.name).limit(amount).subquery()
105 all_tags = self.session.query(gt_maps.c.record, gt_maps.c.label,\
106 Tag.name, Tag.time_type, Tag.object_type,\
107 Tag.synchronization, Tag.end_of_validity, Tag.description,\
108 Tag.last_validated_time, Tag.insertion_time,\
109 Tag.modification_time)\
110 .join(gt_maps, Tag.name == gt_maps.c.tag_name).order_by(Tag.name.asc()).limit(amount).all()"""
111 all_tags = self.session.query(GlobalTagMap.global_tag_name, GlobalTagMap.record, GlobalTagMap.label, GlobalTagMap.tag_name)\
112 .
filter(GlobalTagMap.global_tag_name == self.name)\
113 .order_by(GlobalTagMap.tag_name).
limit(amount).
all()
114 column_names = [
"global_tag_name",
"record",
"label",
"tag_name"]
115 all_tags = map(
lambda row :
dict(
zip(column_names, map(to_timestamp, row))), all_tags)
120 def tags_full(self, amount=10):
121 tags = self.session.query(Tag).order_by(Tag.name).subquery()
122 all_tags = self.session.query(GlobalTagMap.global_tag_name,\
123 GlobalTagMap.record,\
125 tags.c.name, tags.c.time_type, tags.c.object_type,\
126 tags.c.synchronization, tags.c.end_of_validity, tags.c.description,\
127 tags.c.last_validated_time, tags.c.insertion_time,\
128 tags.c.modification_time)\
129 .
join(tags, GlobalTagMap.tag_name == tags.c.name).
filter(GlobalTagMap.global_tag_name == self.name)
131 all_tags = all_tags.limit(amount)
132 all_tags = all_tags.all()
133 column_names = [
"global_tag_name",
"record",
"label",
"name",
"time_type",
"object_type",
"synchronization",\
134 "end_of_validity",
"description",
"last_validated_time",
"insertion_time",
"modification_time"]
135 all_tags = map(
lambda row :
dict(
zip(column_names, map(to_timestamp, row))), all_tags)
141 def insertion_time_interval(self, insertion_time, **radius):
145 minus = insertion_time - datetime.timedelta(days=days)
146 plus = insertion_time + datetime.timedelta(days=days)
147 gts = self.session.query(GlobalTag).
filter(and_(GlobalTag.insertion_time >= minus, GlobalTag.insertion_time <= plus)).order_by(GlobalTag.name).
all()
150 def snapshot_time_interval(self, snapshot_time, **radius):
152 minus = snapshot_time - datetime.timedelta(days=days)
153 plus = snapshot_time + datetime.timedelta(days=days)
154 gts = self.session.query(GlobalTag).
filter(and_(GlobalTag.snapshot_time >= minus, GlobalTag.snapshot_time <= plus)).order_by(GlobalTag.name).
all()
158 def iovs(self, amount=10, valid=False):
160 valid_iovs_all_tags = self.session.query(IOV)
162 valid_iovs_all_tags = valid_iovs_all_tags.filter(IOV.insertion_time < self.snapshot_time)
163 valid_iovs_all_tags = valid_iovs_all_tags.subquery()
164 valid_iovs_gt_tags = self.session.query(GlobalTagMap.tag_name, valid_iovs_all_tags.c.since,\
165 valid_iovs_all_tags.c.payload_hash, valid_iovs_all_tags.c.insertion_time)\
166 .
join(valid_iovs_all_tags, GlobalTagMap.tag_name == valid_iovs_all_tags.c.tag_name)\
167 .
filter(GlobalTagMap.global_tag_name == self.name)\
168 .order_by(valid_iovs_all_tags.c.insertion_time).
limit(amount).
all()
169 column_names = [
"tag_name",
"since",
"payload_hash",
"insertion_time"]
170 all_iovs = map(
lambda row :
dict(
zip(column_names, map(to_timestamp, row))), valid_iovs_gt_tags)
174 def pending_tag_requests(self):
178 gt_map_requests = self.session.query(GlobalTagMapRequest.queue, GlobalTagMapRequest.record, GlobalTagMapRequest.label,\
179 GlobalTagMapRequest.tag, GlobalTagMapRequest.status)\
180 .
filter(and_(GlobalTagMapRequest.queue == self.name, GlobalTagMapRequest.status.in_([
"P",
"R"]))).all()
182 column_names = [
"queue",
"record",
"label",
"tag",
"status"]
183 gt_map_requests = map(
lambda row :
dict(
zip(column_names, map(to_timestamp, row))), gt_map_requests)
188 def candidate(self, gt_map_requests):
191 new_candidate =
Candidate(self, gt_map_requests)
196 global_tag_object =
None
198 authentication =
None
200 def __init__(self, queue, gt_map_requests):
202 self.session = queue.session
203 self.authentication = queue.authentication
206 if queue.type !=
"Q":
209 self.global_tag_object = queue
212 found_record_label_pairs = []
214 for gt_map
in gt_map_requests:
215 if (gt_map.record, gt_map.label)
in found_record_label_pairs:
217 if gt_map_requests.__class__.__name__ ==
"json_list":
218 gt_map_requests.reset()
221 found_record_label_pairs.append((gt_map.record, gt_map.label))
223 if gt_map_requests.__class__.__name__ ==
"json_list":
224 gt_map_requests.reset()
227 self.tags_to_use = gt_map_requests
232 CANDIDATE_TIME_FORMAT =
"%Y_%m_%d_%H_%M_%S"
233 TIME_FORMAT =
"%Y-%m-%d %H:%M:%S"
235 candidate_name = self.global_tag_object.name.replace(
"Queue",
"Candidate")
236 candidate_name +=
"_%s" % datetime.datetime.now().strftime(CANDIDATE_TIME_FORMAT)
237 time_now = datetime.datetime.now().strftime(TIME_FORMAT)
238 candidate_release = self.global_tag_object.release
239 candidate_description =
"Candidate created from the queue: '%s' at: '%s'" % (self.global_tag_object.name, time_now)
241 extra_records = data_formats._objects_as_dicts(self.tags_to_use)
242 for record
in extra_records:
243 for key
in [
"submitter_id",
"description",
"time_submitted",
"last_edited"]:
247 "c_name" : candidate_name,
248 "snapshot_time" : time_now,
249 "from_gt" : self.global_tag_object.name,
250 "release" : candidate_release,
251 "desc" : candidate_description,
252 "validity" : 18446744073709551615,
253 "extra_records" : json.dumps(extra_records.data())
258 credentials = self.authentication.authenticators(
"dbAccess")
262 auth = base64.encodestring(
"%s:%s" % (credentials[0], credentials[1])).
replace(
'\n',
'')
265 params = urllib.urlencode(params)
270 class GlobalTagMap(
Base):
271 __tablename__ =
'GLOBAL_TAG_MAP'
273 headers = [
"global_tag_name",
"record",
"label",
"tag_name"]
275 global_tag_name = Column(String(100), ForeignKey(
'GLOBAL_TAG.name'), primary_key=
True, nullable=
False)
276 record = Column(String(100), ForeignKey(
'RECORDS.record'), primary_key=
True, nullable=
False)
277 label = Column(String(100), primary_key=
True, nullable=
False)
278 tag_name = Column(String(100), ForeignKey(
'TAG.name'), nullable=
False)
280 def __init__(self, dictionary={}, convert_timestamps=True):
282 for key
in dictionary:
284 if convert_timestamps:
287 self.__dict__[key] = dictionary[key]
288 except KeyError
as k:
292 return '<GlobalTagMap %r>' % self.global_tag_name
296 "global_tag_name" : str(self.global_tag_name),
297 "record" : str(self.record),
298 "label" : str(self.label),
299 "tag_name" : str(self.tag_name)
304 class GlobalTagMapRequest(
Base):
305 __tablename__ =
'GLOBAL_TAG_MAP_REQUEST'
307 queue = Column(String(100), primary_key=
True, nullable=
False)
308 tag = Column(String(100), ForeignKey(
'TAG.name'), primary_key=
True, nullable=
False)
309 record = Column(String(100), ForeignKey(
'RECORDS.record'), primary_key=
True, nullable=
False)
310 label = Column(String(100), primary_key=
True, nullable=
False)
311 status = Column(String(1), nullable=
False)
312 description = Column(String(4000), nullable=
False)
313 submitter_id = Column(Integer, nullable=
False)
314 time_submitted = Column(DateTime, nullable=
False)
315 last_edited = Column(DateTime, nullable=
False)
317 def __init__(self, dictionary={}, convert_timestamps=True):
319 for key
in dictionary:
321 if convert_timestamps:
324 self.__dict__[key] = dictionary[key]
325 except KeyError
as k:
328 headers = [
"queue",
"tag",
"record",
"label",
"status",
"description",
"submitter_id",
"time_submitted",
"last_edited"]
332 "queue" : self.queue,
334 "record" : self.record,
335 "label" : self.label,
336 "status" : self.status,
337 "description" : self.description,
338 "submitter_id" : self.submitter_id,
339 "time_submitted" : self.time_submitted,
340 "last_edited" : self.last_edited
344 return '<GlobalTagMapRequest %r>' % self.queue
352 'headers': [
'Queue',
'Tag',
'Record',
'Label',
'Status',
'Submitted',
'Modified'],
353 'data': [ r.to_array()
for r
in requests ],
358 __tablename__ =
'IOV'
360 headers = [
"tag_name",
"since",
"payload_hash",
"insertion_time"]
362 tag_name = Column(String(4000), ForeignKey(
'TAG.name'), primary_key=
True, nullable=
False)
363 since = Column(Integer, primary_key=
True, nullable=
False)
364 payload_hash = Column(String(40), ForeignKey(
'PAYLOAD.hash'), primary_key=
True, nullable=
False)
365 insertion_time = Column(DateTime, nullable=
False)
367 def __init__(self, dictionary={}, convert_timestamps=True):
369 for key
in dictionary:
371 if convert_timestamps:
374 self.__dict__[key] = dictionary[key]
375 except KeyError
as k:
380 "tag_name" : self.tag_name,
381 "since" : self.since,
382 "payload_hash" : self.payload_hash,
383 "insertion_time" : self.insertion_time
387 return '<IOV %r>' % self.tag_name
390 return [self.since,
to_timestamp(self.insertion_time), self.payload_hash]
395 'headers': [
'Since',
'Insertion Time',
'Payload'],
396 'data': [ i.to_array()
for i
in iovs ],
400 def all(self, amount=10):
405 __tablename__ =
'PAYLOAD'
407 headers = [
"hash",
"object_type",
"version",
"insertion_time"]
409 hash = Column(String(40), primary_key=
True, nullable=
False)
410 object_type = Column(String(4000), nullable=
False)
411 version = Column(String(4000), nullable=
False)
412 insertion_time = Column(DateTime, nullable=
False)
414 def __init__(self, dictionary={}, convert_timestamps=True):
416 for key
in dictionary:
418 if convert_timestamps:
421 self.__dict__[key] = dictionary[key]
422 except KeyError
as k:
428 "object_type" : self.object_type,
429 "version" : self.version,
430 "insertion_time" : self.insertion_time
434 return '<Payload %r>' % self.hash
437 return [self.hash, self.object_type, self.version,
to_timestamp(self.insertion_time)]
442 'headers': [
"Payload",
"Object Type",
"Version",
"Insertion Time"],
443 'data': [ p.to_array()
for p
in payloads ],
447 def parent_tags(self):
452 tag_names = map(
lambda entry : entry[0],\
453 self.session.query(IOV.tag_name).
filter(IOV.payload_hash == self.hash).
all())
454 tags = self.session.query(Tag).
filter(Tag.name.in_(tag_names)).order_by(Tag.name).
all()
457 def all(self, amount=10):
462 __tablename__ =
'RECORDS'
464 headers = [
"record",
"object",
"type"]
466 record = Column(String(100), primary_key=
True, nullable=
False)
467 object = Column(String(200), nullable=
False)
468 type = Column(String(20), nullable=
False)
472 "record" : self.record,
473 "object" : self.object,
478 return '<Record %r>' % self.record
481 return [self.record, self.object]
486 'headers': [
"Record",
"Object"],
487 'data': [ r.to_array()
for r
in records ],
491 def all(self, amount=10):
495 class RecordReleases(
Base):
496 __tablename__ =
'RECORD_RELEASES'
498 record = Column(String(100), ForeignKey(
'RECORDS.record'), nullable=
False)
499 release_cycle = Column(String(100), primary_key=
True, nullable=
False)
500 release = Column(String(100), nullable=
False)
501 release_int = Column(String(100), nullable=
False)
505 "release_cycle" : self.release_cycle,
506 "release" : self.release,
507 "release_int" : self.release_int
511 return '<RecordReleases %r>' % self.record
514 return [self.release_cycle, self.release, self.release_int]
518 record_releases_data = {
519 'headers': [
"Release Cycle",
"Starting Release",
"Starting Release Number"],
520 'data': [ r.to_array()
for r
in recordReleases ],
522 return record_releases_data
525 class ParsedReleases(
Base):
526 __tablename__ =
'PARSED_RELEASES'
528 release_cycle = Column(String(100), primary_key=
True, nullable=
False)
529 release = Column(String(100), nullable=
False)
530 release_int = Column(String(100), nullable=
False)
534 "release_cycle" : self.release_cycle,
535 "release" : self.release,
536 "release_int" : self.release_int
540 return '<ParsedReleases %r>' % self.release_cycle
543 return [self.release_cycle, self.release, self.release_int]
547 parsed_releases_data = {
548 'headers': [
"Release Cycle",
"Starting Release",
"Starting Release Number"],
549 'data': [ p.to_array()
for p
in parsedReleases ],
551 return parsed_releases_data
555 __tablename__ =
'TAG'
557 headers = [
"name",
"time_type",
"object_type",
"synchronization",
"end_of_validity",\
558 "description",
"last_validated_time",
"insertion_time",
"modification_time"]
560 name = Column(String(4000), primary_key=
True, nullable=
False)
561 time_type = Column(String(4000), nullable=
False)
562 object_type = Column(String(4000), nullable=
False)
563 synchronization = Column(String(4000), nullable=
False)
564 end_of_validity = Column(Integer, nullable=
False)
565 description = Column(String(4000), nullable=
False)
566 last_validated_time = Column(Integer, nullable=
False)
567 insertion_time = Column(DateTime, nullable=
False)
568 modification_time = Column(DateTime, nullable=
False)
573 def __init__(self, dictionary={}, convert_timestamps=True):
575 for key
in dictionary:
577 if convert_timestamps:
580 self.__dict__[key] = dictionary[key]
581 except KeyError
as k:
587 "time_type" : self.time_type,
588 "object_type" : self.object_type,
589 "synchronization" : self.synchronization,
590 "end_of_validity" : self.end_of_validity,
591 "description" : self.description,
592 "last_validated_time" : self.last_validated_time,
593 "insertion_time" : self.insertion_time,
594 "modification_time" : self.modification_time,
595 "record" : self.record,
600 return '<Tag %r>' % self.name
603 return [self.name, self.time_type, self.object_type, self.synchronization,
to_timestamp(self.insertion_time), self.description]
608 'headers': [
"Tag",
"Time Type",
"Object Type",
"Synchronization",
"Insertion Time",
"Description"],
609 'data': [ t.to_array()
for t
in tags ],
613 def parent_global_tags(self):
617 global_tag_names = map(
lambda entry : entry[0], self.session.query(GlobalTagMap.global_tag_name).
filter(GlobalTagMap.tag_name == self.name).
all())
618 if len(global_tag_names) != 0:
619 global_tags = self.session.query(GlobalTag).
filter(GlobalTag.name.in_(global_tag_names)).order_by(GlobalTag.name).
all()
624 def all(self, amount=10):
627 def insertion_time_interval(self, insertion_time, **radius):
629 minus = insertion_time - datetime.timedelta(days=days)
630 plus = insertion_time + datetime.timedelta(days=days)
631 tags = self.session.query(Tag).
filter(and_(Tag.insertion_time >= minus, Tag.insertion_time <= plus)).order_by(Tag.name).
all()
634 def modification_time_interval(self, modification_time, **radius):
636 minus = modification_time - datetime.timedelta(days=days)
637 plus = modification_time + datetime.timedelta(days=days)
638 tags = self.session.query(Tag).
filter(and_(Tag.modification_time >= minus, Tag.modification_time <= plus)).order_by(Tag.name).
all()
642 def iovs(self, pretty=False):
644 iovs = self.session.query(IOV).
filter(IOV.tag_name == self.name).
all()
647 for n
in range(0, len(iovs)):
648 iovs[n][
"since"] =
"{:>6}".
format(str(iovs[n][
"since"])) +
" - " + (
"{:<6}".
format(str(iovs[n+1][
"since"]-1))
if n != len(iovs)-1
else "")
652 return {
"globaltag" : GlobalTag,
"candidate" : Candidate,
"globaltagmap" : GlobalTagMap,
"globaltagmaprequest" : GlobalTagMapRequest,
"iov" : IOV,\
"payload" : Payload,
"record" : Record,
"recordreleases" : RecordReleases,
"parsedreleases" : ParsedReleases,
"tag" : Tag,
"Base" : Base}
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
static std::string join(char **cmd)
char data[epos_bytes_allocation]