Skip to content

Commit

Permalink
add listRun and listParentTags commands
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich committed Feb 2, 2021
1 parent dc7bcc5 commit c1d18d3
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions CondCore/Utilities/scripts/conddb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import socket
import calendar
import sqlalchemy

from prettytable import PrettyTable

import CondCore.Utilities.conddblib as conddb
import CondCore.Utilities.cond2xml as cond2xml
import CondCore.Utilities.conddb_serialization_metadata as serialization_metadata
Expand Down Expand Up @@ -902,6 +904,42 @@ def listTags_(args):
return 0



def listParentTags_(args):
connection = connect(args)
session = connection.session()

IOV = session.get_dbtype(conddb.IOV)
Tag = session.get_dbtype(conddb.Tag)

query_result = session.query(IOV.tag_name).filter(IOV.payload_hash == args.hash_name).all()
tag_names = map(lambda entry : entry[0], query_result)

listOfOccur=[]

for tag in tag_names:
synchro = session.query(Tag.synchronization).filter(Tag.name == tag).all()
iovs = session.query(IOV.since).filter(IOV.tag_name == tag).filter(IOV.payload_hash == args.hash_name).all()
times = session.query(IOV.insertion_time).filter(IOV.tag_name == tag).filter(IOV.payload_hash == args.hash_name).all()

synchronization = [item[0] for item in synchro]
listOfIOVs = [item[0] for item in iovs]
listOfTimes = [str(item[0]) for item in times]

for iEntry in range(0,len(listOfIOVs)):
listOfOccur.append({"tag": tag,
"synchronization" : synchronization[0],
"since" : listOfIOVs[iEntry] ,
"insertion_time" : listOfTimes[iEntry] })

t = PrettyTable(['hash', 'since','tag','synch','insertion time'])
for element in listOfOccur:
t.add_row([args.hash_name,element['since'],element['tag'],element['synchronization'],element['insertion_time']])

print(t)



def listGTsForTag_(args):
connection = connect(args)
session = connection.session()
Expand All @@ -926,6 +964,24 @@ def listGTs_(args):
['GT_name', 'Description', 'Release', 'Snapshot_time', 'Insertion_time'],
)

def listRun_(args):
connection = connect(args)
session = connection.session()
RunInfo = session.get_dbtype(conddb.RunInfo)
table = session.query(RunInfo.run_number,RunInfo.start_time,RunInfo.end_time).\
filter(RunInfo.run_number == args.runnumber).\
order_by(RunInfo.run_number).\
all()

if(len(table)==0):
print('ERROR: No such run %s has been found in database' %args.runnumber)
else:
for i in range(len(table)):
table[i] = table[i] + ( (calendar.timegm( table[i][1].utctimetuple() ) << 32), (calendar.timegm( table[i][2].utctimetuple() ) << 32) )
output_table(args, table, ['Run_number','Start_time','End_time','Start_IOV','End_IOV'],
)


def listRuns_(args):
connection = connect(args)
session = connection.session()
Expand Down Expand Up @@ -2154,6 +2210,10 @@ def main():
parser_listTags = parser_subparsers.add_parser('listTags', description='Lists all the Tags available in the DB.')
parser_listTags.set_defaults(func=listTags_)

parser_listParentTags = parser_subparsers.add_parser('listParentTags', description='Lists all the Tags available in the DB, containing the matched payload hash.')
parser_listParentTags.add_argument('hash_name', help="Payload hash to match.")
parser_listParentTags.set_defaults(func=listParentTags_)

parser_listGTsForTag = parser_subparsers.add_parser('listGTsForTag', description='Lists the GTs which contain a given tag.')
parser_listGTsForTag.add_argument('name', help="Name of the tag.")
parser_listGTsForTag.set_defaults(func=listGTsForTag_)
Expand All @@ -2164,6 +2224,10 @@ def main():
parser_listRuns = parser_subparsers.add_parser('listRuns', description='Lists all the Runs available in the DB.')
parser_listRuns.set_defaults(func=listRuns_)

parser_listRun = parser_subparsers.add_parser('listRun', description='Lists a Run available in the DB.')
parser_listRun.add_argument('runnumber', help="Run number to match.")
parser_listRun.set_defaults(func=listRun_)

parser_diff = parser_subparsers.add_parser('diff', description='Compares the contents of two objects. For tags, their IOVs are compared to determine which ranges have different payloads. For global tags, their tag names are compared. Both objects must be of the same type. If there is more than one valid pair (ambiguity), all diffs are listed.')
parser_diff.add_argument('first', help="Name of the first object (i.e. source, old). This can be a tag's name or a global tag's name. It must exactly match -- if needed, use the search command first to look for it.")
parser_diff.add_argument('second', nargs='?', default=None, help='Name of the second object (i.e. destination, new). Ditto. Default: same as the first object (i.e. useful to compare the same object in different databases).')
Expand Down

0 comments on commit c1d18d3

Please sign in to comment.