Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ROOTR: check if R interface is running in the thread of event loop, to
avoid segfault in scientific linux.
  • Loading branch information
omazapa committed Mar 20, 2017
commit 3214c75cddf0737deadacbf9a726d013924030e5
4 changes: 2 additions & 2 deletions bindings/r/inc/RExports.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ namespace ROOT {
extern VARIABLE_IS_NOT_USED SEXP ModuleSymRef;
template<class T> class class_: public Rcpp::class_<T> {
public:
class_(const char *name_, const char *doc = 0): Rcpp::class_<T>(name_, doc) {}
class_(const Char_t *name_, const Char_t *doc = 0): Rcpp::class_<T>(name_, doc) {}
};

//________________________________________________________________________________________________________
template<class T> void function(const char *name_, T fun, const char *docstring = 0)
template<class T> void function(const Char_t *name_, T fun, const Char_t *docstring = 0)
{
//template function required to create modules using the macro ROOTR_MODULE
Rcpp::function(name_, fun, docstring);
Expand Down
20 changes: 10 additions & 10 deletions bindings/r/inc/TRDataFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ namespace ROOT {
*/
template <class T> Binding operator=(T var)
{
int size = fDf.size(), i = 0 ;
Int_t size = fDf.size(), i = 0 ;
Rcpp::CharacterVector names = fDf.attr("names");
bool found = false;
Bool_t found = false;
while (i < size) {
if (names[i] == fName.Data()) {
found = true;
Expand Down Expand Up @@ -238,9 +238,9 @@ namespace ROOT {
*/
Binding operator=(Binding obj)
{
int size = fDf.size(), i = 0 ;
Int_t size = fDf.size(), i = 0 ;
Rcpp::CharacterVector names = fDf.attr("names");
bool found = false;
Bool_t found = false;
while (i < size) {
if (names[i] == fName.Data()) {
found = true;
Expand Down Expand Up @@ -291,9 +291,9 @@ namespace ROOT {
*/
template <class T> Binding &operator <<(T var)
{
int size = fDf.size(), i = 0 ;
Int_t size = fDf.size(), i = 0 ;
Rcpp::CharacterVector names = fDf.attr("names");
bool found = false;
Bool_t found = false;
while (i < size) {
if (names[i] == fName.Data()) {
found = true;
Expand Down Expand Up @@ -392,15 +392,15 @@ namespace ROOT {
Method to get the number of colunms
\return number of cols
*/
int GetNcols()
Int_t GetNcols()
{
return df.size();
}
/**
Method to get the number of rows
\return number of rows
*/
int GetNrows()
Int_t GetNrows()
{
return df.nrows();
}
Expand All @@ -412,7 +412,7 @@ namespace ROOT {
{
Rcpp::CharacterVector names = df.attr("names");
TVectorString rnames(GetNcols());
for (int i = 0; i < GetNcols(); i++)rnames[i] = names[i];
for (Int_t i = 0; i < GetNcols(); i++)rnames[i] = names[i];
return rnames;
}

Expand All @@ -431,7 +431,7 @@ namespace ROOT {
Method to print the dataframe in stdout or a column given the label
\param label nomber of the column to print
*/
void Print(const char* label = "")
void Print(const Char_t *label = "")
{
TRFunctionImport print("print");
if (label && !label[0]) {
Expand Down
8 changes: 4 additions & 4 deletions bindings/r/inc/TRFunctionExport.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ namespace ROOT {
Default TRFunctionExport constructor
*/
TRFunctionExport();

/**
Default TRFunctionExport destructor
*/
~TRFunctionExport()
{
if(f) delete f;
}
{
if (f) delete f;
}
/**
TRFunctionExport copy constructor
\param fun other TRFunctionExport
Expand Down
2 changes: 1 addition & 1 deletion bindings/r/inc/TRInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace ROOT {
\param verbose default false
\param interactive default true
*/
TRInterface(const int argc = 0, const char *argv[] = NULL, const bool loadRcpp = true, const bool verbose = false, const bool interactive = true);
TRInterface(const Int_t argc = 0, const Char_t *argv[] = NULL, const Bool_t loadRcpp = true, const Bool_t verbose = false, const Bool_t interactive = true);
public:
~TRInterface();

Expand Down
2 changes: 1 addition & 1 deletion bindings/r/src/RExports.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace Rcpp {
template<> TMatrixT<Float_t> as(SEXP m)
{
NumericMatrix mat =::Rcpp::as<NumericMatrix>(m);
std::vector<float> dat = Rcpp::as<std::vector<float> >(mat);
std::vector<Float_t> dat = Rcpp::as<std::vector<Float_t> >(mat);
return TMatrixT<Float_t>(mat.rows(), mat.cols(), &dat[0], "F");
}

Expand Down
2 changes: 0 additions & 2 deletions bindings/r/src/TRDataFrame.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@


using namespace ROOT::R;
ClassImp(TRDataFrame)


//______________________________________________________________________________
TRDataFrame::TRDataFrame(): TObject()
Expand Down
20 changes: 11 additions & 9 deletions bindings/r/src/TRInterface.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ClassImp(TRInterface)
static ROOT::R::TRInterface *gR = NULL;
static Bool_t statusEventLoop;

TRInterface::TRInterface(const int argc, const char *argv[], const bool loadRcpp, const bool verbose, const bool interactive): TObject()
TRInterface::TRInterface(const Int_t argc, const Char_t *argv[], const Bool_t loadRcpp, const Bool_t verbose, const Bool_t interactive): TObject()
{
if (RInside::instancePtr()) throw std::runtime_error("Can only have one TRInterface instance");
fR = new RInside(argc, argv, loadRcpp, verbose, interactive);
Expand Down Expand Up @@ -105,7 +105,7 @@ TRObject TRInterface::Eval(const TString &code)
Error("Eval", "Can execute the requested code: %s", code.Data());
}

return TRObject(ans , (rc == 0) ? kTRUE : kFALSE);
return TRObject(ans, (rc == 0) ? kTRUE : kFALSE);
}


Expand Down Expand Up @@ -139,7 +139,7 @@ void TRInterface::Assign(const TRDataFrame &obj, const TString &name)
void TRInterface::Interactive()
{
while (kTRUE) {
char *line = readline("[r]:");
Char_t *line = readline("[r]:");
if (!line) continue;
if (std::string(line) == ".q") break;
Execute(line);
Expand All @@ -153,7 +153,7 @@ void TRInterface::Interactive()
TRInterface *TRInterface::InstancePtr()
{
if (!gR) {
const char *R_argv[] = {"rootr", "--gui=none", "--no-save", "--no-readline", "--silent", "--vanilla", "--slave"};
const Char_t *R_argv[] = {"rootr", "--gui=none", "--no-save", "--no-readline", "--silent", "--vanilla", "--slave"};
gR = new TRInterface(7, R_argv, true, false, false);
}
gR->ProcessEventsLoop();
Expand Down Expand Up @@ -198,11 +198,13 @@ void TRInterface::ProcessEventsLoop()
if (!statusEventLoop) {
th = new TThread([](void *args) {
while (kTRUE) {
fd_set *fd;
int usec = 10000;
fd = R_checkActivity(usec, 0);
R_runHandlers(R_InputHandlers, fd);
gSystem->Sleep(100);
if (gR) {//in case global object was freed
fd_set *fd;
Int_t usec = 10000;
fd = R_checkActivity(usec, 0);
R_runHandlers(R_InputHandlers, fd);
if (gSystem) gSystem->Sleep(100);
}
}
});
th->Run();
Expand Down