Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:27

0001 from __future__ import print_function
0002 import xml.etree.ElementTree as ET
0003 import sys
0004 
0005 ## declare all constants here
0006 TARGET_LIST_OF_TAGS=['BeamSpotObject_ByLumi',           # beamspot
0007                      'BeamSpotObject_ByRun', 
0008                      'BeamSpotObjectHP_ByLumi', 
0009                      'BeamSpotObjectHP_ByRun',
0010                      'SiPixelLA_pcl',                   # SiPixel
0011                      'SiPixelLAMCS_pcl',
0012                      'SiPixelQualityFromDbRcd_other', 
0013                      'SiPixelQualityFromDbRcd_prompt', 
0014                      'SiPixelQualityFromDbRcd_stuckTBM',
0015                      'SiStripApvGain_pcl',              # SiStrip
0016                      'SiStripApvGainAAG_pcl', 
0017                      'SiStripBadStrip_pcl', 
0018                      'SiStripBadStripRcdHitEff_pcl',
0019                      'SiStripLA_pcl',
0020                      'SiPixelAli_pcl',                  # Alignment
0021                      'SiPixelAliHG_pcl',
0022                      'SiPixelAliHGCombined_pcl']
0023 TARGET_DQM_FILES=1
0024 TARGET_DQM_FILENAME='./DQM_V0001_R000325022__Express__PCLTest__ALCAPROMPT.root'
0025 TARGET_DB_FILES=len(TARGET_LIST_OF_TAGS)
0026 TARGET_DB_FILENAME='sqlite_file:testPCLAlCaHarvesting.db'
0027 TARGET_XML_FILENAME='testPCLAlCaHarvesting.xml'
0028 TOTAL_TARGET_FILES=TARGET_DQM_FILES+TARGET_DB_FILES
0029 
0030 #_____________________________________________________
0031 def parseXML(xmlfile):
0032   
0033     # create element tree object
0034     tree = ET.parse(xmlfile)
0035   
0036     # get root element
0037     root = tree.getroot()
0038 
0039     totAnaEntries=len(root.findall('AnalysisFile'))
0040 
0041     if(totAnaEntries!=TOTAL_TARGET_FILES):
0042         print("ERROR: found a not expected number (",totAnaEntries,") of AnalysisFile entries in the FrameworkJobReport.xml, expecting",TOTAL_TARGET_FILES)
0043         return -1
0044 
0045     listOfInputTags=[]
0046 
0047     countDBfiles=0
0048     countDQMfiles=0
0049 
0050     # iterate news items
0051     for item in root.findall('AnalysisFile'):
0052         # iterate child elements of item
0053         for child in item:
0054             if(child.tag == 'FileName'):
0055                 if(child.text==TARGET_DB_FILENAME):
0056                     countDBfiles+=1
0057                 elif(child.text==TARGET_DQM_FILENAME):
0058                     countDQMfiles+=1
0059                 else:
0060                     pass
0061             if(child.tag == 'inputtag'):
0062                 listOfInputTags.append(child.attrib['Value'])
0063 
0064     if(countDBfiles!=TARGET_DB_FILES):
0065         print("ERROR! Found an unexpected number of DB files (",countDBfiles,")")
0066         return -1
0067 
0068     if(countDQMfiles!=TARGET_DQM_FILES):
0069         print("ERROR! Found an uexpected number of DQM files (",countDQMfiles,")")
0070         return -1
0071 
0072     ## first sort to avoid spurious false positives
0073     listOfInputTags.sort()
0074     TARGET_LIST_OF_TAGS.sort()
0075 
0076     ## That's strict! 
0077     if(listOfInputTags!=TARGET_LIST_OF_TAGS):
0078         print(" list of input tags found in file:",listOfInputTags)
0079         print(" target list of tags:",TARGET_LIST_OF_TAGS)
0080 
0081         if (listOfInputTags>TARGET_LIST_OF_TAGS):
0082             print("ERROR!\n This ",[x for x in TARGET_LIST_OF_TAGS if x not in listOfInputTags]," is the set of expected tags not found in the FwdJobReport!")
0083         else:
0084             print("ERROR!\n This ",[x for x in listOfInputTags if x not in TARGET_LIST_OF_TAGS]," is the set of tags found in the FwkJobReport, but not expected!")
0085         return -1
0086     
0087     return 0
0088 
0089 #_____________________________________________________
0090 def main():
0091     try:
0092         f = open(TARGET_XML_FILENAME)
0093     except IOError:
0094         print("%s is not accessible" % TARGET_XML_FILENAME)
0095         sys.exit(1)
0096 
0097     # parse xml file
0098     result = parseXML(TARGET_XML_FILENAME)
0099     if(result==0):
0100         print("All is fine with the world!")
0101         sys.exit(0)
0102     else:
0103         print("Parsing the FwkJobReport results in failure!")
0104         sys.exit(1)
0105 
0106 #_____________________________________________________
0107 if __name__ == "__main__":
0108   
0109     # calling main function
0110     main()