1 package org.lcsim.conditions.readers;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5
6 import org.lcsim.conditions.ConditionsManager;
7 import org.lcsim.conditions.ConditionsReader;
8
9
10
11
12
13 public class BaseClasspathConditionsReader extends ConditionsReader {
14
15 private String _resourcePath;
16 String propFileName = "detector.properties";
17
18 int _runNumber = -1;
19 String _detectorName;
20
21 public BaseClasspathConditionsReader() {
22 }
23
24 public BaseClasspathConditionsReader(String resourcePath) throws IOException {
25 _resourcePath = resourcePath;
26
27
28 if (getClass().getResourceAsStream("/" + _resourcePath + "/" + propFileName) == null) {
29 throw new IOException("Unable to find " + _resourcePath + "/" + propFileName + " on the classpath.");
30 }
31 }
32
33
34
35
36
37
38
39
40
41
42
43
44 public InputStream open(String name, String type) throws IOException {
45 InputStream in = getClass().getResourceAsStream("/" + _resourcePath + "/" + name + "." + type);
46 if (in == null) {
47 throw new IOException("The conditions " + name + " of type " + type + " do not exist at path " + _resourcePath);
48 }
49 return in;
50 }
51
52
53
54
55
56 public void setResourcePath(String resourcePath) {
57 _resourcePath = resourcePath;
58 }
59
60
61
62
63
64
65
66 public boolean update(ConditionsManager manager, String detectorName, int run) throws IOException {
67
68 boolean update = false;
69
70
71 if (_detectorName == null || _detectorName != detectorName) {
72 _detectorName = detectorName;
73 update = true;
74 }
75
76
77 if (run != _runNumber) {
78 update = true;
79 }
80
81 return update;
82 }
83
84
85
86
87
88 public void close() throws IOException {
89 }
90 }