Initial commit

This commit is contained in:
ebner
2011-10-12 13:53:32 +02:00
commit de7d1d9200
20 changed files with 1289 additions and 0 deletions

View File

@@ -0,0 +1,158 @@
/**
*
* Copyright 2010 Paul Scherrer Institute. All rights reserved.
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This code is distributed in the hope that it will be useful,
* but without any warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this code. If not, see <http://www.gnu.org/licenses/>.
*
*/
package ch.psi.cdump;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author ebner
*
*/
public class CdumpConfiguration {
private static final CdumpConfiguration instance = new CdumpConfiguration();
private String dataChannel;
private int nelements = 65536;
private String controlChannel;
private String samplingRateChannel;
private String filePrefix = "${yyyy_MM}/${yyyyMMdd}/${yyyyMMddHHmmss}_${name}/${yyyyMMddHHmm}_";
private String dataDirectory;
/**
* Singleton - Private constructor
*/
private CdumpConfiguration(){
loadConfiguration();
}
public static CdumpConfiguration getInstance(){
return instance;
}
private void loadConfiguration() {
String config = System.getProperty(CdumpService.APP_HOME);
if(config == null){
throw new RuntimeException("No configuration file specified via -D"+CdumpService.APP_HOME+"=...");
}
Properties properties = new Properties();
try {
properties.load(new FileReader(config+"/config/cdump.properties"));
} catch (FileNotFoundException e) {
throw new RuntimeException("Configuration file "+config+" not found", e);
} catch (IOException e) {
throw new RuntimeException("Cannot read configuration file "+config, e);
}
dataChannel = properties.getProperty(CdumpConfiguration.class.getPackage().getName()+".dataChannel", "");
controlChannel = properties.getProperty(CdumpConfiguration.class.getPackage().getName()+".controlChannel", "");
samplingRateChannel = properties.getProperty(CdumpConfiguration.class.getPackage().getName()+".samplingRateChannel", "");
dataDirectory = config+"/data";
}
/**
* @return the dataChannel
*/
public String getDataChannel() {
return dataChannel;
}
/**
* @param dataChannel the dataChannel to set
*/
public void setDataChannel(String dataChannel) {
this.dataChannel = dataChannel;
}
/**
* @return the controlChannel
*/
public String getControlChannel() {
return controlChannel;
}
/**
* @param controlChannel the controlChannel to set
*/
public void setControlChannel(String controlChannel) {
this.controlChannel = controlChannel;
}
/**
* @return the samplingRateChannel
*/
public String getSamplingRateChannel() {
return samplingRateChannel;
}
/**
* @param samplingRateChannel the samplingRateChannel to set
*/
public void setSamplingRateChannel(String samplingRateChannel) {
this.samplingRateChannel = samplingRateChannel;
}
/**
* @return the nelements
*/
public int getNelements() {
return nelements;
}
/**
* @return the filePrefix
*/
public String getFilePrefix() {
return filePrefix;
}
/**
* @return the dataDirectory
*/
public String getDataDirectory() {
return dataDirectory;
}
public String replaceMacros(String string, Date date, String name){
String newString = string;
// Replace scan name macros
newString = newString.replaceAll("\\$\\{name\\}", name);
// Replace date macros
Pattern pattern = Pattern.compile("\\$\\{[a-z,A-Z,-,_,:]*\\}");
Matcher matcher = pattern.matcher(newString);
while(matcher.find()){
String datePattern = matcher.group();
datePattern = datePattern.replaceAll("\\$\\{", "");
datePattern = datePattern.replaceAll("\\}", "");
SimpleDateFormat datef = new SimpleDateFormat(datePattern);
newString = matcher.replaceFirst(datef.format(date));
matcher = pattern.matcher(newString);
}
return newString;
}
}