Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
NomadSpecialModules
Commits
93859a03
Commit
93859a03
authored
Aug 24, 2018
by
cyclops
Browse files
Merge branch 'master' of
https://code.ill.fr/instrument-control/nomad-special-modules.git
parents
0ab69c12
54bab92b
Changes
52
Hide whitespace changes
Inline
Side-by-side
src/controllers/mantidreductiontest/Module.xml
0 → 100644
View file @
93859a03
<module
name=
"mantidreductiontest"
>
<controller
class=
"mantid::ReductionControllerTest"
/>
<include
path=
"$(NOMAD_HOME)/../NomadModules/src"
/>
</module>
src/controllers/mantidreductiontest/ReductionControllerTest.cpp
0 → 100644
View file @
93859a03
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "ReductionControllerTest.h"
#include "controllers/common/family/Families.h"
#include <boost/lexical_cast.hpp>
#include <common/base/Date.h>
#include <fstream>
#include <iostream>
#include <napi.h>
namespace
mantid
{
using
namespace
std
;
using
namespace
common
;
using
namespace
boost
;
using
namespace
cameo
;
const
std
::
string
ReductionControllerTest
::
TYPE
=
"mantid_reduction_test"
;
const
std
::
string
ReductionControllerTest
::
REMOTE_APPLICATION
=
"responder-server"
;
const
std
::
string
ReductionControllerTest
::
RESPONDER
=
"responder"
;
ReductionControllerTest
::
ReductionControllerTest
(
const
std
::
string
&
name
)
:
ExperimentController
(
name
),
controller
::
Stoppable
(
this
)
{
setFamily
(
family
::
ACQUISITION
,
family
::
COUNT
);
serverEndpoint
.
init
(
this
,
SAVE
,
"cameo_server"
);
initialized
.
init
(
this
,
NOSAVE
,
"initialized"
);
fileDirectory
.
init
(
this
,
SAVE
,
"file_directory"
);
filename
.
init
(
this
,
SAVE
,
"filename"
);
x
.
init
(
this
,
NOSAVE
,
"x"
);
data
.
init
(
this
,
NOSAVE
,
"data"
);
}
ReductionControllerTest
::
ReductionControllerTest
(
const
ReductionControllerTest
&
controller
)
:
ExperimentController
(
controller
),
controller
::
Stoppable
(
this
)
{
}
ReductionControllerTest
::~
ReductionControllerTest
()
{
if
(
m_remoteApplication
.
get
()
!=
NULL
)
{
// Stop the remote application.
m_remoteApplication
->
stop
();
// Wait for the termination
application
::
State
state
=
m_remoteApplication
->
waitFor
();
cout
<<
"Remote application "
<<
m_remoteApplication
->
getName
()
<<
" terminated with state "
<<
application
::
toString
(
state
)
<<
endl
;
}
}
void
ReductionControllerTest
::
postConfiguration
()
{
if
(
serverEndpoint
()
==
""
)
{
m_server
.
reset
(
new
Server
(
application
::
This
::
getServer
().
getEndpoint
()));
}
else
{
m_server
.
reset
(
new
Server
(
serverEndpoint
()));
}
initialized
=
initApplication
();
}
bool
ReductionControllerTest
::
initApplication
()
{
// Do not initialize if it is already done
if
(
initialized
())
{
return
true
;
}
// Start the remote server
if
(
!
m_server
->
isAvailable
(
1000
))
{
cout
<<
"Remote server is not available"
<<
endl
;
return
false
;
}
cout
<<
"Remote server is connected"
<<
endl
;
m_remoteApplication
=
m_server
->
connect
(
REMOTE_APPLICATION
);
if
(
m_remoteApplication
->
exists
())
{
// The application exists from a previous server session
m_remoteApplication
->
kill
();
application
::
State
state
=
m_remoteApplication
->
waitFor
();
cout
<<
"Terminated remote application with state "
<<
application
::
toString
(
state
)
<<
endl
;
}
m_remoteApplication
=
m_server
->
start
(
REMOTE_APPLICATION
);
if
(
!
m_remoteApplication
->
exists
())
{
cout
<<
"No remote application"
<<
endl
;
return
false
;
}
// Application initialized
initialized
=
true
;
return
true
;
}
void
ReductionControllerTest
::
readFile
(
const
std
::
string
&
nexusFileName
,
std
::
string
&
fileContent
)
{
streampos
size
;
ifstream
file
(
nexusFileName
.
c_str
(),
ios
::
in
|
ios
::
binary
|
ios
::
ate
);
if
(
file
.
is_open
())
{
size
=
file
.
tellg
();
// Reserve the string.
fileContent
.
resize
(
size
);
// Get the allocated array.
char
*
array
=
(
char
*
)
fileContent
.
data
();
file
.
seekg
(
0
,
ios
::
beg
);
file
.
read
(
array
,
size
);
file
.
close
();
}
else
{
cerr
<<
"File "
<<
nexusFileName
<<
" cannot be read."
<<
endl
;
}
}
void
ReductionControllerTest
::
writeFile
(
const
std
::
string
&
nexusFileName
,
const
std
::
string
&
fileContent
)
{
ofstream
file
;
file
.
open
(
nexusFileName
,
ios
::
binary
);
file
<<
fileContent
;
file
.
close
();
}
void
ReductionControllerTest
::
readProcessedFile
()
{
NXhandle
fileId
;
// Open the file.
int
res
=
NXopen
(
"processed.nxs"
,
NXACC_RDWR
,
&
fileId
);
if
(
res
!=
NX_OK
)
{
cerr
<<
"Cannot open processed.nxs."
<<
endl
;
return
;
}
res
=
NXopengroup
(
fileId
,
"mantid_workspace_1"
,
"NXentry"
);
if
(
res
!=
NX_OK
)
{
cerr
<<
"Cannot open group mantid_workspace_1."
<<
endl
;
return
;
}
res
=
NXopengroup
(
fileId
,
"workspace"
,
"NXdata"
);
if
(
res
!=
NX_OK
)
{
cerr
<<
"Cannot open group workspace"
<<
endl
;
return
;
}
// Read X data.
int
rank
=
1
;
int
dims
[
2
];
int
dataType
;
NXopendata
(
fileId
,
"axis1"
);
NXgetinfo
(
fileId
,
&
rank
,
dims
,
&
dataType
);
if
(
dataType
!=
NX_FLOAT64
)
{
cerr
<<
"Problem with the type of data of axis1."
<<
endl
;
return
;
}
int
xSize
=
dims
[
0
];
delete
[]
x
.
get
();
double
*
xData
=
new
double
[
xSize
];
NXgetdata
(
fileId
,
xData
);
x
.
set
(
xData
);
// We set the size - 1 to have the same size than the data.
x
.
setSize
(
xSize
-
1
);
// Close the data.
NXclosedata
(
fileId
);
// Read values data.
rank
=
2
;
NXopendata
(
fileId
,
"values"
);
NXgetinfo
(
fileId
,
&
rank
,
dims
,
&
dataType
);
if
(
dataType
!=
NX_FLOAT64
)
{
cerr
<<
"Problem with the type of data of values."
<<
endl
;
return
;
}
if
(
dims
[
1
]
+
1
!=
xSize
)
{
cerr
<<
"Problem with the size "
<<
dims
[
1
]
<<
" of values."
<<
endl
;
return
;
}
int
dataSize
=
dims
[
1
];
delete
[]
data
.
get
();
double
*
values
=
new
double
[
dataSize
];
NXgetdata
(
fileId
,
values
);
data
.
set
(
values
);
data
.
setSize
(
dataSize
);
NXclosedata
(
fileId
);
NXclosegroup
(
fileId
);
NXclosegroup
(
fileId
);
NXclose
(
&
fileId
);
// Check the data.
int
index
=
0
;
while
(
index
<
dataSize
)
{
if
(
!
isfinite
(
values
[
index
]))
{
break
;
}
++
index
;
}
cout
<<
"Forced sizes to "
<<
index
<<
endl
;
// x.setSize(index);
// data.setSize(index);
int
fixedSize
=
280
;
x
.
setSize
(
index
<
fixedSize
?
index
:
fixedSize
);
data
.
setSize
(
index
<
fixedSize
?
index
:
fixedSize
);
x
.
sendEvent
();
data
.
sendEvent
();
cout
<<
"Processing finished."
<<
endl
;
}
void
ReductionControllerTest
::
start
()
{
if
(
!
initApplication
())
{
return
;
}
// Send a simple message with the content of the Nexus data file.
string
fileContent
;
// Read the file.
readFile
(
fileDirectory
()
+
"/"
+
filename
(),
fileContent
);
// Create the requester
auto_ptr
<
application
::
Requester
>
requester
=
application
::
Requester
::
create
(
*
m_remoteApplication
,
RESPONDER
);
if
(
requester
.
get
()
==
0
)
{
cout
<<
"requester error"
<<
endl
;
return
;
}
// Start date.
Date
begin
;
// Send the file content to the server.
requester
->
sendBinary
(
fileContent
);
// Wait for the response from the server.
string
response
;
requester
->
receiveBinary
(
response
);
// Print the duration.
Date
end
;
double
ms
=
(
end
-
begin
).
getMilliseconds
();
cout
<<
"File processed in "
<<
ms
<<
" ms"
<<
endl
;
// Write the file to disc.
writeFile
(
"processed.nxs"
,
response
);
// Read the file.
readProcessedFile
();
// Remove the file.
remove
(
"processed.nxs"
);
}
void
ReductionControllerTest
::
stop
()
{
}
}
src/controllers/mantidreductiontest/ReductionControllerTest.h
0 → 100644
View file @
93859a03
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#ifndef MANTID_REDUCTIONCONTROLLERTEST_H
#define MANTID_REDUCTIONCONTROLLERTEST_H
#include <Controller.h>
#include <cameo/cameo.h>
namespace
mantid
{
class
ReductionControllerTest
:
public
ExperimentController
,
public
controller
::
Stoppable
{
public:
//! Type of controller
static
const
std
::
string
TYPE
;
ReductionControllerTest
(
const
std
::
string
&
name
);
ReductionControllerTest
(
const
ReductionControllerTest
&
controller
);
virtual
~
ReductionControllerTest
();
virtual
void
postConfiguration
();
virtual
void
start
();
virtual
void
stop
();
Property
<
std
::
string
>
serverEndpoint
;
Property
<
bool
>
initialized
;
Property
<
string
>
fileDirectory
;
Property
<
string
>
filename
;
ArrayProperty
<
float64
>
x
;
ArrayProperty
<
float64
>
data
;
private:
bool
initApplication
();
void
readFile
(
const
std
::
string
&
nexusFileName
,
std
::
string
&
fileContent
);
void
writeFile
(
const
std
::
string
&
nexusFileName
,
const
std
::
string
&
fileContent
);
void
readProcessedFile
();
static
const
std
::
string
REMOTE_APPLICATION
;
static
const
std
::
string
RESPONDER
;
std
::
auto_ptr
<
cameo
::
Server
>
m_server
;
std
::
auto_ptr
<
cameo
::
application
::
Instance
>
m_remoteApplication
;
};
}
#endif
src/controllers/mantidreductiontest/gui/mantid_reduction_testCommandView.xml
0 → 100644
View file @
93859a03
<plugin>
<controller
type=
"mantid_reduction_test"
role=
"mantid_reduction_test1"
/>
<number_of_lines
nb_lines=
"1"
/>
<text
role=
"mantid_reduction_test1"
property=
"filename"
prefix=
"Filename"
/>
</plugin>
src/controllers/mantidreductiontest/gui/mantid_reduction_testPlotDatas.xml
0 → 100644
View file @
93859a03
<plotdatas>
<plotdata
key=
"data"
color=
"1F96C0"
plugins=
"SETUP"
>
<dataX
p_role=
"mantid_reduction_test1"
p_name=
"x"
/>
<dataY
p_role=
"mantid_reduction_test1"
p_name=
"data"
/>
</plotdata>
</plotdatas>
src/controllers/mantidreductiontest/gui/mantid_reduction_testPlugin.xml
0 → 100644
View file @
93859a03
<controller_plugin_config
type=
"mantid_reduction_test"
>
<image
key=
"ACQUISITION"
/>
<settings
view=
"mantid_reduction_testView.xml"
/>
<command
view=
"mantid_reduction_testCommandView.xml"
/>
</controller_plugin_config>
src/controllers/mantidreductiontest/gui/mantid_reduction_testProperties.xml
0 → 100644
View file @
93859a03
<?xml version="1.0" encoding="ISO-8859-1" ?>
<controller
type=
"mantid_reduction_test"
>
<property
name=
"x"
type=
"doublearray"
>
</property>
<property
name=
"data"
type=
"doublearray"
>
</property>
</controller>
src/controllers/mantidreductiontest/gui/mantid_reduction_testView.xml
0 → 100644
View file @
93859a03
<plugin>
<controller
type=
"mantid_reduction_test"
role=
"mantid_reduction_test1"
/>
<text
role=
"mantid_reduction_test1"
property=
"filename"
prefix=
"Filename"
/>
<newLine/>
<plot_launcher
role=
"mantid_reduction_test1"
data=
"data"
title=
"data"
height=
"20"
/>
</plugin>
src/controllers/npp/CAENCfdController.cpp
View file @
93859a03
...
...
@@ -428,6 +428,9 @@ void CAENCfdController::updateBoardProperties() {
else
if
(
modelName
()
==
"V1730"
)
{
cardType
=
lstdpp128
::
C1730_PHA_RT
;
}
else
if
(
modelName
()
==
"V1725"
)
{
cardType
=
lstdpp128
::
C1725_PHA_RT
;
}
channels
.
update
(
m_dgtzDriver
->
channels
());
nbChannels
.
update
(
m_dgtzDriver
->
nbChannels
());
minRange
=
0
;
...
...
src/controllers/npp/CAENQdcController.cpp
0 → 100644
View file @
93859a03
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://joinup.ec.europa.eu/software/page/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include "CAENQdcController.h"
#include "drivers/global/DriversCommands.h"
#include "controllers/common/family/Families.h"
#include <boost/thread/thread.hpp>
#include <lstdpp128/lstdpp.h>
using
namespace
std
;
using
namespace
boost
;
namespace
npp
{
const
string
CAENQdcController
::
TYPE
=
"psd_controller"
;
/*
* Constructor
*/
CAENQdcController
::
CAENQdcController
(
const
string
&
name
)
:
CAENAdcController
(
name
)
{
setFamily
(
family
::
ACQUISITION
,
family
::
SETTING
);
// Register properties
triggerHoldOff
.
init
(
this
,
NOSAVE
,
"trigger_holdoff"
);
triggerThreshold
.
init
(
this
,
NOSAVE
,
"trigger_threshold"
);
selfTrigger
.
init
(
this
,
NOSAVE
,
"self_trigger"
);
chargeSensitivity
.
init
(
this
,
NOSAVE
,
"charge_sensitivity"
);
gateWidth
.
init
(
this
,
NOSAVE
,
"long_gate"
);
preGate
.
init
(
this
,
NOSAVE
,
"pre_gate"
);
baselineMean
.
init
(
this
,
NOSAVE
,
"base_mean"
);
m_dgtzDriver
.
init
(
this
,
"qdc_driver"
);
registerFunction
(
TYPE
);
}
/*
* Destructor
*/
CAENQdcController
::~
CAENQdcController
()
{
}
/*
* postConfiguration
*/
void
CAENQdcController
::
postConfiguration
()
{
registerRefresher
(
recordLength
,
&
CAENQdcController
::
refreshRecordLengthProperty
,
this
);
registerRefresher
(
nbChannels
,
&
CAENQdcController
::
refreshNbChannelsProperty
,
this
);
registerRefresher
(
dppAcqMode
,
&
CAENQdcController
::
refreshDppAcqModeProperty
,
this
);
registerRefresher
(
displayChannel
,
&
CAENQdcController
::
refreshDisplayChannelProperty
,
this
);
registerRefresher
(
triggerHoldOff
,
&
CAENQdcController
::
refreshTriggerHoldOffProperty
,
this
);
registerRefresher
(
triggerThreshold
,
&
CAENQdcController
::
refreshTriggerThresholdProperty
,
this
);
registerRefresher
(
selfTrigger
,
&
CAENQdcController
::
refreshSelfTriggerProperty
,
this
);
registerRefresher
(
chargeSensitivity
,
&
CAENQdcController
::
refreshChargeSensitivityProperty
,
this
);
registerRefresher
(
gateWidth
,
&
CAENQdcController
::
refreshGateWidthProperty
,
this
);
registerRefresher
(
preGate
,
&
CAENQdcController
::
refreshPreGateProperty
,
this
);
registerRefresher
(
baselineMean
,
&
CAENQdcController
::
refreshBaselineMean
,
this
);
registerRefresher
(
channelActive
,
&
CAENQdcController
::
refreshChannelActiveProperty
,
this
);
registerRefresher
(
dcOffset
,
&
CAENQdcController
::
refreshDcOffsetProperty
,
this
);
registerRefresher
(
preTrigger
,
&
CAENQdcController
::
refreshPreTriggerProperty
,
this
);
registerRefresher
(
pulsePolarity
,
&
CAENQdcController
::
refreshPulsePolarityProperty
,
this
);
updateBoardProperties
();
cardType
=
lstdpp128
::
C1751_PSD
;
}
void
CAENQdcController
::
refreshRecordLengthProperty
(
int32
aValue
)
throw
(
CannotSetValue
)
{
m_dgtzDriver
->
recordLength
=
aValue
;
}
void
CAENQdcController
::
refreshNbChannelsProperty
(
int32
aValue
)
throw
(
CannotSetValue
)
{
cout
<<
"CAENQdcController::refreshNbChannelsProperty : "
<<
aValue
<<
endl
;
minRange
=
0
;
maxRange
=
aValue
-
1
;
m_dgtzDriver
->
nbChannels
=
aValue
;
if
(
displayChannel
()
>=
aValue
)
displayChannel
=
aValue
-
1
;
}
void
CAENQdcController
::
refreshDppAcqModeProperty
(
int32
aValue
)
throw
(
CannotSetValue
)
{
CAENAdcController
::
refreshDppAcqModeProperty
(
aValue
);
m_dgtzDriver
->
dppAcqMode
=
aValue
;
boost
::
thread
td
(
boost
::
bind
(
&
CAENQdcController
::
initBoard
,
this
));
}
void
CAENQdcController
::
refreshDisplayChannelProperty
(
int32
aChannel
)
throw
(
CannotSetValue
)
{
cout
<<
"CAENQdcController::refreshDisplayChannelProperty : "
<<
aChannel
<<
endl
;
float64
holdOff
=
m_dgtzDriver
->
triggerHoldOff
()
/
1000.0
;
if
(
holdOff
==
0
)
holdOff
=
0.2
;
triggerHoldOff
.
update
(
holdOff
);
int32
trigTrsd
=
m_dgtzDriver
->
triggerThreshold
.
get
(
aChannel
);
if
(
trigTrsd
==
0
)
trigTrsd
=
20
;
triggerThreshold
.
update
(
trigTrsd
);
selfTrigger
.
update
(
m_dgtzDriver
->
selfTrigger
.
get
(
aChannel
));
int32
chargeSens
=
m_dgtzDriver
->
chargeSensitivity
.
get
(
aChannel
);
chargeSensitivity
.
update
(
chargeSens
);
float64
gWidth
=
m_dgtzDriver
->
gateWidth
.
get
(
aChannel
)
/
1000.0
;
if
(
gWidth
==
0.0
)
gWidth
=
1.0
;
gateWidth
.
update
(
gWidth
);
float64
pGate
=
m_dgtzDriver
->
preGate
.
get
(
aChannel
)
/
1000.0
;
if
(
pGate
==
0
)
pGate
=
0.1
;
preGate
.
update
(
pGate
);
int32
baseAvrg
=
m_dgtzDriver
->
baselineMean
.
get
(
aChannel
);
if
(
baseAvrg
==
0
)
baseAvrg
=
4
;
baselineMean
.
update
(
baseAvrg
);
channelActive
.
update
(
m_dgtzDriver
->
channelActive
.
get
(
aChannel
));
int32
offSet
=
m_dgtzDriver
->
dcOffset
.
get
(
aChannel
);
if
(
offSet
==
0
)
offSet
=
10
;
dcOffset
.
update
(
offSet
);
int32
preTrig
=
m_dgtzDriver
->
preTrigger
.
get
(
aChannel
);
if
(
preTrig
==
0
)
preTrig
=
500
;
preTrigger
.
update
(
preTrig
);
pulsePolarity
.
update
(
m_dgtzDriver
->
pulsePolarity
.
get
(
aChannel
));
initChannel
(
aChannel
);
}
void
CAENQdcController
::
refreshTriggerHoldOffProperty
(
float64
aValue
)
throw
(
CannotSetValue
)
{
m_dgtzDriver
->
triggerHoldOff
.
update
((