forked from PanDAWMS/pilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SiteInformationFactory.py
98 lines (82 loc) · 3.17 KB
/
SiteInformationFactory.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Class definition:
# SiteInformationFactory
# This class is used to generate SiteInformation class objects corresponding to a given "experiment"
# Based the on Factory Design Pattern
# Note: not compatible with Singleton Design Pattern due to the subclassing
from types import TypeType
from SiteInformation import SiteInformation
from ATLASSiteInformation import ATLASSiteInformation
from AMSTaiwanSiteInformation import AMSTaiwanSiteInformation
from CMSSiteInformation import CMSSiteInformation
from NordugridATLASSiteInformation import NordugridATLASSiteInformation
from OtherSiteInformation import OtherSiteInformation
class SiteInformationFactory(object):
def newSiteInformation(self, experiment):
""" Generate a new site information object """
# get all classes
siteInformationClasses = [j for (i,j) in globals().iteritems() if isinstance(j, TypeType) and issubclass(j, SiteInformation)]
# loop over all subclasses
for siteInformationClass in siteInformationClasses:
si = siteInformationClass()
# return the matching experiment class
if si.getExperiment() == experiment:
return siteInformationClass
# if no class was found, raise an error
raise ValueError('SiteInformationFactory: No such class: "%s"' % (experiment))
if __name__ == "__main__":
factory = SiteInformationFactory()
print "\nAttempting to get ATLAS"
try:
siteInformationClass = factory.newSiteInformation('ATLAS')
except Exception, e:
print e
else:
si = siteInformationClass()
print 'got experiment:',si.getExperiment()
del siteInformationClass
print "\nAttempting to get Nordugrid-ATLAS"
try:
from NordugridATLASSiteInformation import NordugridATLASSiteInformation
siteInformationClass = factory.newSiteInformation('Nordugrid-ATLAS')
except Exception, e:
print e
else:
si = siteInformationClass()
print 'got experiment:',si.getExperiment()
del siteInformationClass
print "\nAttempting to get CMS"
try:
siteInformationClass = factory.newSiteInformation('CMS')
except Exception, e:
print e
else:
si = siteInformationClass()
print 'got experiment:',si.getExperiment()
del siteInformationClass
print "\nAttempting to get Other"
try:
siteInformationClass = factory.newSiteInformation('Other')
except Exception, e:
print e
else:
si = siteInformationClass()
print 'got experiment:',si.getExperiment()
del siteInformationClass
print "\nAttempting to get AMSTaiwan"
try:
siteInformationClass = factory.newSiteInformation('AMSTaiwan')
except Exception, e:
print e
else:
si = siteInformationClass()
print 'got experiment:',si.getExperiment()
del siteInformationClass
print "\nAttempting to get Dummy"
try:
siteInformationClass = factory.newSiteInformation('Dummy')
except Exception, e:
print e
else:
si = siteInformationClass()
print 'got experiment:',si.getExperiment()
del siteInformationClass