Numass server update

This commit is contained in:
darksnake 2017-04-11 17:01:34 +03:00
parent 3aefbd8db2
commit b5f1300c11
8 changed files with 160 additions and 109 deletions

View File

@ -1,9 +1,9 @@
apply plugin: 'application' apply plugin: 'groovy'
if (!hasProperty('mainClass')) { //if (!hasProperty('mainClass')) {
ext.mainClass = 'inr.numass.LaunchGrindShell' // ext.mainClass = 'inr.numass.LaunchGrindShell'
} //}
mainClassName = mainClass //mainClassName = mainClass
description = "Main numass project" description = "Main numass project"
@ -15,28 +15,35 @@ dependencies {
compile "hep.dataforge:grind-terminal" //project(':dataforge-grind:grind-terminal') compile "hep.dataforge:grind-terminal" //project(':dataforge-grind:grind-terminal')
} }
task listActions(dependsOn: classes, type: JavaExec) { //task listActions(dependsOn: classes, type: JavaExec) {
main mainClass // main "inr.numass.LaunchGrindShell"
args "-lc" // args "-lc"
classpath = sourceSets.main.runtimeClasspath // classpath = sourceSets.main.runtimeClasspath
description "print a list of available actions as via -lc command line parameter" // description "print a list of available actions as via -lc command line parameter"
group "numass" // group "numass"
} //}
task workspace(dependsOn: classes, type: JavaExec) {
main 'inr.numass.workspace.NumassGrindLauncher'
classpath = sourceSets.main.runtimeClasspath
args "-c \"D:\\Work\\Numass\\sterile2016\\workspace.groovy\" numass.fitsum sum_down".split()
description "Run workspace task"
group "numass"
}
task repl(dependsOn: classes, type: JavaExec) { task repl(dependsOn: classes, type: JavaExec) {
group "numass"
main 'inr.numass.LaunchGrindShell' main 'inr.numass.LaunchGrindShell'
classpath = sourceSets.main.runtimeClasspath classpath = sourceSets.main.runtimeClasspath
description "Start Grind repl" description "Start Grind repl"
standardInput = System.in standardInput = System.in
standardOutput = System.out standardOutput = System.out
args["--config",] if (project.hasProperty("cmd")) {
args = cmd.split().toList()
}
}
task simulate(dependsOn: classes, type: JavaExec) {
group "numass" group "numass"
main 'inr.numass.scripts.Simulate'
classpath = sourceSets.main.runtimeClasspath
description "Simulate spectrum"
}
task underflow(dependsOn: classes, type: JavaExec) {
group "numass"
main 'inr.numass.scripts.Underflow'
classpath = sourceSets.main.runtimeClasspath
} }

View File

@ -18,7 +18,10 @@ package inr.numass.scripts
import hep.dataforge.context.Global import hep.dataforge.context.Global
import hep.dataforge.io.ColumnedDataWriter import hep.dataforge.io.ColumnedDataWriter
import hep.dataforge.meta.Meta import hep.dataforge.meta.Meta
import hep.dataforge.stat.fit.* import hep.dataforge.stat.fit.FitManager
import hep.dataforge.stat.fit.FitStage
import hep.dataforge.stat.fit.FitState
import hep.dataforge.stat.fit.ParamSet
import hep.dataforge.stat.models.XYModel import hep.dataforge.stat.models.XYModel
import hep.dataforge.tables.ListTable import hep.dataforge.tables.ListTable
import inr.numass.NumassPlugin import inr.numass.NumassPlugin
@ -38,10 +41,9 @@ import static java.util.Locale.setDefault
*/ */
setDefault(Locale.US); setDefault(Locale.US);
new MINUITPlugin().startGlobal();
new NumassPlugin().startGlobal() new NumassPlugin().startGlobal()
FitManager fm = Global.instance().getFeature(FitManager)
FitManager fm = new FitManager();
SterileNeutrinoSpectrum sp = new SterileNeutrinoSpectrum(Global.instance(), Meta.empty()); SterileNeutrinoSpectrum sp = new SterileNeutrinoSpectrum(Global.instance(), Meta.empty());
//beta.setCaching(false); //beta.setCaching(false);
@ -79,7 +81,7 @@ allPars.setParDomain("trap", 0d, Double.POSITIVE_INFINITY);
// ListTable config = OldDataReader.readConfig(configName); // ListTable config = OldDataReader.readConfig(configName);
SpectrumGenerator generator = new SpectrumGenerator(model, allPars, 12316); SpectrumGenerator generator = new SpectrumGenerator(model, allPars, 12316);
ListTable data = generator.generateData(DataModelUtils.getUniformSpectrumConfiguration(5000d, 18500, 604800/100*100, 100)); ListTable data = generator.generateData(DataModelUtils.getUniformSpectrumConfiguration(14000, 18500, 604800 / 100 * 100, 100));
data = TritiumUtils.correctForDeadTime(data, new SpectrumDataAdapter(), 10e-9); data = TritiumUtils.correctForDeadTime(data, new SpectrumDataAdapter(), 10e-9);
// data = data.filter("X", Value.of(15510.0), Value.of(18610.0)); // data = data.filter("X", Value.of(15510.0), Value.of(18610.0));

View File

@ -14,15 +14,15 @@ import inr.numass.storage.NumassDataUtils
import inr.numass.storage.NumassStorage import inr.numass.storage.NumassStorage
import inr.numass.utils.UnderflowCorrection import inr.numass.utils.UnderflowCorrection
File rootDir = new File("D:\\Work\\Numass\\data\\2016_10\\Fill_1") //File rootDir = new File("D:\\Work\\Numass\\data\\2016_10\\Fill_1")
//File rootDir = new File("D:\\Work\\Numass\\data\\2016_10\\Fill_2_wide") //File rootDir = new File("D:\\Work\\Numass\\data\\2016_10\\Fill_2_wide")
//File rootDir = new File("D:\\Work\\Numass\\data\\2017_01\\Fill_2_wide") File rootDir = new File("D:\\Work\\Numass\\data\\2017_01\\Fill_2_wide")
NumassStorage storage = NumassStorage.buildLocalNumassRoot(rootDir, true); NumassStorage storage = NumassStorage.buildLocalNumassRoot(rootDir, true);
Collection<NMPoint> data = NumassDataUtils.joinSpectra( Collection<NMPoint> data = NumassDataUtils.joinSpectra(
StorageUtils.loaderStream(storage) StorageUtils.loaderStream(storage)
.filter { it.key.matches("set_.{2,3}") } .filter { it.key.matches("set_.{1,3}") }
.map { .map {
println "loading ${it.key}" println "loading ${it.key}"
it.value it.value
@ -60,12 +60,10 @@ def printPoint(Iterable<NMPoint> data, List us, int binning = 20, normalize = tr
}; };
points.eachWithIndex { it, index -> points.eachWithIndex { it, index ->
if (index > 0) {
print "\t${it.uset}" print "\t${it.uset}"
it.getMapWithBinning(binning, normalize).each { k, v -> it.getMapWithBinning(binning, normalize).each { k, v ->
spectra[k].add(v) spectra[k].add(v)
} }
}
} }
println() println()
@ -81,7 +79,8 @@ def printPoint(Iterable<NMPoint> data, List us, int binning = 20, normalize = tr
println "\n# spectra\n" println "\n# spectra\n"
printPoint(data, [16200d, 16400d, 16800d, 17000d, 17200d, 17700d]) //printPoint(data, [16200d, 16400d, 16800d, 17000d, 17200d, 17700d])
printPoint(data, [14000d, 14500d, 15000d, 15500d, 16500d])
println() println()

View File

@ -43,7 +43,7 @@ import org.apache.commons.math3.util.FastMath;
* @author Alexander Nozik * @author Alexander Nozik
*/ */
@PluginDef(group = "inr.numass", name = "numass", @PluginDef(group = "inr.numass", name = "numass",
dependsOn = {"hep.dataforge:actions", "hep.dataforge:math", "hep.dataforge:MINUIT"}, dependsOn = {"hep.dataforge:math", "hep.dataforge:MINUIT"},
description = "Numass data analysis tools") description = "Numass data analysis tools")
public class NumassPlugin extends BasicPlugin { public class NumassPlugin extends BasicPlugin {

View File

@ -11,3 +11,12 @@ dependencies {
//} //}
task runServer(dependsOn: classes, type: JavaExec){
group "numass"
description "Run numass server in current directory"
main 'inr.numass.server.ServerRunner'
classpath = sourceSets.main.runtimeClasspath
workingDir "D:\\Temp\\test\\"
standardInput = System.in
standardOutput = System.out
}

View File

@ -82,6 +82,7 @@ public class NumassServer extends AbstractNetworkListener {
int port = meta().getInt("ratpack.port", 8336); int port = meta().getInt("ratpack.port", 8336);
ratpack = RatpackServer.start((RatpackServerSpec server) -> server ratpack = RatpackServer.start((RatpackServerSpec server) -> server
.serverConfig((ServerConfigBuilder config) -> config .serverConfig((ServerConfigBuilder config) -> config
// .baseDir(Paths.get(getClass().getResource("/ratpack/.ratpack").toURI()))
.findBaseDir() .findBaseDir()
.address(InetAddress.getLocalHost()) .address(InetAddress.getLocalHost())
.port(port)) .port(port))

View File

@ -15,102 +15,36 @@
*/ */
package inr.numass.server; package inr.numass.server;
import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.Annotated;
import hep.dataforge.meta.Meta;
import hep.dataforge.storage.commons.StorageManager;
import hep.dataforge.storage.filestorage.FileStorage;
import org.apache.commons.daemon.Daemon; import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext; import org.apache.commons.daemon.DaemonContext;
import org.slf4j.Logger; import org.apache.commons.daemon.DaemonInitException;
import org.slf4j.LoggerFactory;
import java.io.File;
/** /**
* A daemon wrapper for numass server * A daemon wrapper for numass server
* *
* @author darksnake * @author darksnake
*/ */
public class NumassServerDaemon implements Daemon, Annotated { public class NumassServerDaemon implements Daemon {
private ServerRunner server;
private final Logger logger = LoggerFactory.getLogger("NUMASS-SERVER");
public static final String SERVER_CONFIG_PATH = "numass-server.xml";
private static final String NUMASS_REPO_ELEMENT = "numass.repository";
private static final String LISTENER_ELEMENT = "listener";
private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path";
Meta serverConfig;
FileStorage root;
NumassServer listener;
@Override @Override
public void destroy() { public void init(DaemonContext context) throws DaemonInitException, Exception {
if (root != null) { server = new ServerRunner();
try {
root.close();
} catch (Exception ex) {
logger.error("Error while closing storage", ex);
}
}
}
@Override
public Meta meta() {
if (serverConfig != null) {
return serverConfig;
} else {
return Meta.buildEmpty("numass-server");
}
}
@Override
public void init(DaemonContext dc) throws Exception {
logger.info("Starting numass server daemon");
logger.info("Starting storage plugin");
new StorageManager().startGlobal();
File configFile = new File(SERVER_CONFIG_PATH);
if (configFile.exists()) {
logger.info("Trying to read server configuration from {}", SERVER_CONFIG_PATH);
serverConfig = MetaFileReader.read(configFile);
}
String repoPath = meta().getString(NUMASS_REPO_PATH_PROPERTY, "/home/numass-storage/");
Meta repoConfig = null;
if (meta().hasMeta(NUMASS_REPO_ELEMENT)) {
repoConfig = meta().getMeta(NUMASS_REPO_ELEMENT);
}
logger.info("Initializing file storage in {}", repoPath);
root = FileStorage.in(new File(repoPath), repoConfig);
// root.toggleMonitor(true);
} }
@Override @Override
public void start() throws Exception { public void start() throws Exception {
logger.info("Starting numass server daemon"); server.start();
if (root != null) {
root.open();
Meta listenerConfig = null;
if (meta().hasMeta(LISTENER_ELEMENT)) {
listenerConfig = meta().getMeta(LISTENER_ELEMENT);
}
listener = new NumassServer(root, listenerConfig);
listener.open();
logger.info("Sucessfully started numass server");
} else {
logger.error("Root storage not initialized");
}
} }
@Override @Override
public void stop() throws Exception { public void stop() throws Exception {
logger.info("Stoping numass server daemon"); server.close();
if (listener != null) {
listener.close();
}
} }
@Override
public void destroy() {
server.close();
}
} }

View File

@ -0,0 +1,99 @@
package inr.numass.server;
import hep.dataforge.io.MetaFileReader;
import hep.dataforge.meta.Meta;
import hep.dataforge.meta.SimpleConfigurable;
import hep.dataforge.storage.filestorage.FileStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.util.Objects;
/**
* Created by darksnake on 11-Apr-17.
*/
public class ServerRunner extends SimpleConfigurable implements AutoCloseable {
public static final String SERVER_CONFIG_PATH = "numass-server.xml";
private static final String NUMASS_REPO_ELEMENT = "numass.repository";
private static final String LISTENER_ELEMENT = "listener";
private static final String NUMASS_REPO_PATH_PROPERTY = "numass.repository.path";
private final Logger logger = LoggerFactory.getLogger("NUMASS-SERVER");
FileStorage root;
NumassServer listener;
public ServerRunner() throws IOException, ParseException {
// Global.instance().pluginManager().load(StorageManager.class);
File configFile = new File(SERVER_CONFIG_PATH);
if (configFile.exists()) {
logger.info("Trying to read server configuration from {}", SERVER_CONFIG_PATH);
configure(MetaFileReader.read(configFile));
}
}
public static void main(String[] args) {
try (ServerRunner r = new ServerRunner()) {
r.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String in = null;
while (!Objects.equals(in, "exit")) {
in = reader.readLine();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public ServerRunner start() throws Exception {
String repoPath = meta().getString(NUMASS_REPO_PATH_PROPERTY, ".");
Meta repoConfig = null;
if (meta().hasMeta(NUMASS_REPO_ELEMENT)) {
repoConfig = meta().getMeta(NUMASS_REPO_ELEMENT);
}
logger.info("Initializing file storage in {}", repoPath);
root = FileStorage.in(new File(repoPath), repoConfig);
logger.info("Starting numass server");
if (root != null) {
root.open();
Meta listenerConfig = null;
if (meta().hasMeta(LISTENER_ELEMENT)) {
listenerConfig = meta().getMeta(LISTENER_ELEMENT);
}
listener = new NumassServer(root, listenerConfig);
listener.open();
logger.info("Successfully started numass server");
} else {
logger.error("Root storage not initialized");
}
return this;
}
@Override
public void close() {
logger.info("Stopping numass server");
if (listener != null) {
try {
listener.close();
} catch (Exception e) {
logger.error("Failed to close listener", e);
}
}
if (root != null) {
try {
root.close();
} catch (Exception ex) {
logger.error("Error while closing storage", ex);
}
}
}
}