ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/python/translator.py
Revision: 1.3
Committed: Tue Mar 22 02:48:51 2011 UTC (14 years, 1 month ago) by paus
Content type: text/x-python
Branch: MAIN
CVS Tags: Mit_020d, TMit_020d, Mit_020c, Mit_021pre1, Mit_020b, Mit_020a, Mit_020
Changes since 1.2: +10 -3 lines
Log Message:
Version 020 updates (64 bit architecture).

File Contents

# User Rev Content
1 paus 1.1 #---------------------------------------------------------------------------------------------------
2     # Python Module File to translate storage/computing elements into meta site names
3     #
4     # Author: C.Paus (Jun 16, 2010)
5     #---------------------------------------------------------------------------------------------------
6     import os,sys,re,string
7    
8     #---------------------------------------------------------------------------------------------------
9     """
10     Class: Translator(table)
11     Each SubTask in CRAB can be described through this class
12     """
13     #---------------------------------------------------------------------------------------------------
14     class Translator:
15     "Translator for the storage and computing elements to the "
16     # variable to be determined
17 paus 1.2 ceTable = 'undefined' # compute elements translation table
18     seTable = 'undefined' # storage elements translation table
19     allSites = 'undefined' # comma separated list of all sites
20     preferredSites = 'undefined' # comma separated list of preferred sites
21 paus 1.1 ces = {}
22     ses = {}
23     #-----------------------------------------------------------------------------------------------
24     # constructor to connect with existing setup
25     #-----------------------------------------------------------------------------------------------
26     def __init__(self,ceTable,seTable):
27     self.ceTable = ceTable
28     self.seTable = seTable
29     if os.path.exists(self.seTable):
30     self.ses = self.readTable(self.seTable)
31     else:
32     print ' WARNING -- SE table file not found.'
33     if os.path.exists(self.ceTable):
34     self.ces = self.readTable(self.ceTable)
35     else:
36     print ' WARNING -- CE table file not found.'
37    
38     #self.show()
39    
40     def readTable(self,file):
41     table = {}
42     cmd = 'grep -v ^# ' + file + ' | tr -d \' \''
43     print ' Loading table: ' + cmd
44     for line in os.popen(cmd).readlines():
45     line = line[:-1]
46     # decode the storage directory name
47     names = line.split(":")
48     if names[1] in table:
49     print ' Site already in tables %s (%s)'%(names[1],names[0])
50     table[names[1]] = names[0]
51    
52     return table
53    
54     def translateSes(self,seString):
55 paus 1.2 print ' translating SE sites: ' + seString
56 paus 1.1 sites = seString.split(",")
57     newString = ''
58     #print ' Looping through sites %s'%(seString)
59     for site in sites:
60     if site in self.ses:
61     #print ' -> %s == %s'%(site,self.ses[site])
62     if newString == '':
63     newString = self.ses[site]
64     else:
65     newString = "%s,%s"%(newString,self.ses[site])
66     else:
67     print ' dropping %s because it is not in our table'%(site)
68    
69     #print 'Translated: %s'%(newString)
70 paus 1.2 self.allSites = newString
71 paus 1.1 return newString
72    
73     def translateCes(self,ceString):
74 paus 1.2 print ' translating CE sites: ' + ceString
75 paus 1.1 sites = ceString.split(",")
76     newString = ''
77     #print ' Looping through sites %s'%(ceString)
78     for site in sites:
79     if site in self.ces:
80     #print ' -> %s == %s'%(site,self.ces[site])
81     if newString == '':
82     newString = self.ces[site]
83     else:
84     newString = "%s,%s"%(newString,self.ces[site])
85     else:
86     print ' dropping %s because it is not in our table'%(site)
87    
88     #print 'Translated: %s'%(newString)
89 paus 1.2 self.allSites = newString
90 paus 1.1 return newString
91    
92 paus 1.2 def selectPreferred(self):
93 paus 1.3 preferredSiteList = ['T2_US_MIT','T2_US_UCSD']
94     self.preferredSites = ''
95     for site in preferredSiteList:
96     if re.search(site,self.allSites):
97     if self.preferredSites != '':
98     self.preferredSites = self.preferredSites + ','
99     self.preferredSites = self.preferredSites + site
100    
101     if self.preferredSites != '':
102 paus 1.2 print ' '
103     print ' ' + self.allSites
104 paus 1.3 print ' INFO -- ' + self.preferredSites + ' found a preferred site (reducing).'
105 paus 1.2 print ' '
106     else:
107     #print ' '
108     #print ' INFO -- no preferred site in the list. Keeping all sites.'
109     #print ' '
110     self.preferredSites = self.allSites
111     return self.preferredSites
112    
113 paus 1.1 #-----------------------------------------------------------------------------------------------
114     # present the current crab subtask
115     #-----------------------------------------------------------------------------------------------
116     def show(self):
117     print ' Translator (CE Table: %s, SE Table: %s) ===='%(self.ceTable,self.seTable)
118     print ' ==== Compute Elements'
119     for name,hostname in self.ces.iteritems():
120     print ' Site: %s --> CE: %s'%(name,hostname)
121     print ' ==== Storage Elements'
122     for name,hostname in self.ses.iteritems():
123     print ' Site: %s --> SE: %s'%(name,hostname)