Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-06-13 03:23:09

0001 import re
0002 import glob
0003 import os
0004 import shutil
0005 import errno
0006 
0007 def findFiles(path, fileName):
0008     
0009     expr = fileName.format(number="*")
0010     return glob.glob(os.path.join(path,expr))
0011 
0012 
0013 shortcuts = {}
0014 # regex matching on key, replacement of groups on value
0015 # implement any other shortcuts that you want to use
0016 #sources
0017 shortcuts["mp([0-9]*)"] = "sqlite_file:/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/mp{0}/jobData/jobm/alignments_MP.db"
0018 shortcuts["mp([0-9]*)_jobm([0-9]*)"] = "sqlite_file:/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/mp{0}/jobData/jobm{1}/alignments_MP.db"
0019 shortcuts["sm([0-9]*)_iter([0-9]*)"] = "sqlite_file:/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HipPy/alignments/sm{0}/alignments_iter{1}.db"
0020 shortcuts["um([0-9]*)"] = "sqlite_file:/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/um{0}/jobData/jobm/um{0}.db"
0021 shortcuts["um([0-9]*)_jobm([0-9]*)"] = "sqlite_file:/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN/MP/MPproduction/um{0}/jobData/jobm{1}/um{0}.db"
0022 shortcuts["hp([0-9]*)_iter([0-9]*)"] = "sqlite_file:/afs/cern.ch/cms/CAF/CMSALCA/ALCA_TRACKERALIGN2/HipPy/alignments/hp{0}/alignments_iter{1}.db"
0023 shortcuts["prod"] = "frontier://FrontierProd/CMS_CONDITIONS"
0024 
0025 def replaceShortcuts(toScan):
0026     global shortcuts
0027     for key, value in shortcuts.items():
0028         match = re.search(key, toScan)
0029         if match and match.group(0) == toScan:
0030             return value.format(*match.groups())
0031     # no match
0032     return toScan
0033 
0034 def ensurePathExists(path):
0035     try:
0036         os.makedirs(path)
0037     except OSError as exception:
0038         if exception.errno != errno.EEXIST:
0039             raise
0040 
0041 # creates new folder. if folder already exists, move that one to _old, if that one already exists, delete that
0042 def newIterFolder(path, name, iteration):
0043     if os.path.isdir(os.path.join(path, name, iteration)):
0044             if os.path.isdir(os.path.join(path, name, iteration+"_old")):
0045                 shutil.rmtree(os.path.join(path, name, iteration+"_old"))
0046             os.rename(os.path.join(path, name, iteration), os.path.join(path, name, iteration+"_old"))
0047     os.makedirs(os.path.join(path, name, iteration))
0048 
0049 
0050 def parseConditions(conditions):
0051     conds = []
0052     for record in conditions:
0053         tag = conditions[record]["tag"]
0054         source = replaceShortcuts(conditions[record]["source"])
0055         conds.append( {"record":record, "source":source, "tag":tag} )
0056     return conds
0057 
0058 
0059 
0060 if __name__ == "__main__":
0061     print(findFiles(".", "test_{number}.txt"))