Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:54

0001 #!/usr/bin/env python
0002 from __future__ import print_function
0003 import os
0004 import json
0005 
0006 
0007 # documentation: https://twiki.cern.ch/twiki/bin/view/CMS/AlCaDBPCL#Drop_box_metadata_management
0008 if __name__ == "__main__":
0009     # the input file is in text format, formatted as the outout of cmsRun ProduceDropBoxMetadata.py
0010     # the inoput file holds metadata for a list of workflows, prod/prep for each
0011     filenameinput = "last-iov-DropBoxMetadata_v5.1_express.db-f422b9d9589e65175b255acc01700f9103842a6e.log"
0012 
0013     # the .json files will be produced inside the specified directory
0014     # each .json file is the complete metadata for either prod or prep
0015     dirnameoutput = 'last-iov-DropBoxMetadata_v5.1_express'
0016     
0017     filehandler = open(filenameinput, 'r')
0018     lines = filehandler.readlines()
0019 
0020     
0021     try:
0022         os.stat(dirnameoutput)
0023     except:
0024         os.mkdir(dirnameoutput)
0025                 
0026     recordname = None
0027     
0028 
0029     for line in lines:
0030 
0031         
0032         if '--- record' in line:
0033             recordname = line.split()[2]
0034             print('-----------------------------------------------------------------')
0035             print('record: ',recordname)
0036             
0037         if 'prepMetaData' in line:
0038             dict_text = line.split('value: ')[1]
0039             prep_metadata = json.loads(dict_text.replace('"','"'))
0040             prep_metadata_dump = json.dumps(prep_metadata, sort_keys = True, indent = 4)
0041             print('----- prepMetaData:')
0042             print(prep_metadata_dump)
0043             outFilePrep = open('%s/%s_prep.json'%(dirnameoutput,recordname), 'w')
0044             outFilePrep.write(prep_metadata_dump+'\n')
0045             outFilePrep.close()
0046             
0047         if 'prodMetaData' in line:
0048             dict_text = line.split('value: ')[1]
0049             prod_metadata = json.loads(dict_text.replace('"','"'))
0050             prod_metadata_dump = json.dumps(prod_metadata, sort_keys = True, indent = 4)
0051             print('----- prodMetaData:')
0052             print(prod_metadata_dump)
0053             outFileProd = open('%s/%s_prod.json'%(dirnameoutput,recordname), 'w')
0054             outFileProd.write(prod_metadata_dump+'\n')
0055             outFileProd.close()
0056         
0057 
0058     filehandler.close()
0059         #print line