1 package org.lcsim.conditions; 2 3 /** 4 * The conditions manager is the main interface to the conditions system. The 5 * conditions manager allows conditions to be stored in a hierarchical 6 * structure, but places no restrictions on the type of data provided. The 7 * conditions manager makes no assumptions about how the data is stored or 8 * retrieved. 9 */ 10 public abstract class ConditionsManager { 11 private static ConditionsManager theConditionsManager; 12 13 /** 14 * Get the default (shared) condition manager implementation. 15 * @return The default conditions manager. 16 */ 17 public static ConditionsManager defaultInstance() { 18 if (theConditionsManager == null) 19 theConditionsManager = new ConditionsManagerImplementation(); 20 return theConditionsManager; 21 } 22 23 public static void setDefaultConditionsManager(ConditionsManager manager) { 24 //System.out.println("ConditionsManager.setDefaultConditionsManager from..."); 25 //new RuntimeException().printStackTrace(); 26 theConditionsManager = manager; 27 } 28 29 /** 30 * Return true if there is a conditions manager installed. 31 * @return true if conditions managed is setup 32 */ 33 public static boolean isSetup() { 34 return theConditionsManager != null; 35 } 36 37 /** 38 * Normally called automatically by the framework to set the detector name 39 * and run number, 40 * @param name The current detector name. 41 * @param run The current run number. 42 * @throws org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException 43 * If the conditions associated with this detector/run number 44 * can not be found. 45 */ 46 public abstract void setDetector(String name, int run) throws ConditionsNotFoundException; 47 48 /** 49 * Set the current run number. Normally called automatically by the 50 * framework. 51 * @param run The current run number 52 * @throws org.lcsim.conditions.ConditionsManager.ConditionsNotFoundException 53 * If the conditions associated with the specified run number 54 * can not be found. 55 */ 56 public abstract void setRun(int run) throws ConditionsNotFoundException; 57 58 /** 59 * Get the current detector name 60 * @return The detector name. 61 */ 62 public abstract String getDetector(); 63 64 /** 65 * Get the current run number. 66 * @return The run number. 67 */ 68 public abstract int getRun(); 69 70 /** 71 * Get the conditions associated with the given name. 72 * @param name The name of the conditions to search for. 73 * @throws org.lcsim.conditions.ConditionsManager.ConditionsSetNotFoundException 74 * If the named conditions can not be found. 75 * @return The requested conditions. 76 */ 77 public abstract ConditionsSet getConditions(String name) throws ConditionsSetNotFoundException; 78 79 /** 80 * Access conditions converted to a java object using a conditions 81 * converter. The conditions are cached so that they do not need to be 82 * re-read each time the same object is requested. 83 * @param type The type of conditions requested (used to select an 84 * appropriate conditions converter). 85 * @param name The name of the conditions requested. 86 * @throws org.lcsim.conditions.ConditionsManager.ConditionsSetNotFoundException 87 * If the specified conditions can not be found. 88 * @return The converted conditions. 89 */ 90 public abstract <T> CachedConditions<T> getCachedConditions(Class<T> type, String name) throws ConditionsSetNotFoundException; 91 92 /** 93 * Get an input stream to directly read raw conditions from the database. 94 * The database makes no assumptions about the format of the data when this 95 * method is used. 96 * @param name The name of the conditions requested. 97 * @throws org.lcsim.conditions.ConditionsManager.ConditionsSetNotFoundException 98 * If the requested conditions can not be found. 99 * @return The input stream from which the data can be read. The called 100 * should close thsi input stream when they have finished using it. 101 */ 102 public abstract RawConditions getRawConditions(String name) throws ConditionsSetNotFoundException; 103 104 /** 105 * Adds a conditions converter. A conditions converter can be used to 106 * convert data requested by the user into a specific Java object. 107 * @param conv The converter to add. 108 */ 109 public abstract void registerConditionsConverter(ConditionsConverter conv); 110 111 /** 112 * Removes a conditions converter. 113 * @param conv The converter to remove. 114 */ 115 public abstract void removeConditionsConverter(ConditionsConverter conv); 116 117 /** 118 * Add a listener to be notified about changes to ANY conditions. 119 * @param listener The listener to add. 120 */ 121 public abstract void addConditionsListener(ConditionsListener listener); 122 123 /** 124 * Remove a global change listener. 125 * @param listener The listener to remove. 126 */ 127 public abstract void removeConditionsListener(ConditionsListener listener); 128 129 /** 130 * Thrown if conditions associated with a given detector can not be found. 131 */ 132 public static class ConditionsNotFoundException extends Exception { 133 public ConditionsNotFoundException(String name, int run) { 134 super("Conditions not found for detector " + name); 135 } 136 137 public ConditionsNotFoundException(String name, int run, Throwable t) { 138 super("Conditions not found for detector " + name, t); 139 } 140 } 141 142 /** 143 * Thrown if specific set of conditions can not be found. 144 */ 145 public static class ConditionsSetNotFoundException extends RuntimeException { 146 public ConditionsSetNotFoundException(String message) { 147 super(message); 148 } 149 150 public ConditionsSetNotFoundException(String message, Throwable t) { 151 super(message, t); 152 } 153 } 154 }