Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-06-24 22:51:38

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