Skip to content
Snippets Groups Projects
Commit 695a5517 authored by Adrien Matta's avatar Adrien Matta :skull_crossbones:
Browse files

* Addind missing file for Elog support

parent 176eb23e
No related branches found
No related tags found
No related merge requests found
...@@ -2,4 +2,4 @@ add_custom_command(OUTPUT TAsciiFileDict.cxx COMMAND ../scripts/build_dict.sh T ...@@ -2,4 +2,4 @@ add_custom_command(OUTPUT TAsciiFileDict.cxx COMMAND ../scripts/build_dict.sh T
add_custom_command(OUTPUT NPVDetectorDict.cxx COMMAND ../scripts/build_dict.sh NPVDetector.h NPVDetectorDict.cxx NPVDetector.rootmap libNPCore.so NPCoreLinkdef.h) add_custom_command(OUTPUT NPVDetectorDict.cxx COMMAND ../scripts/build_dict.sh NPVDetector.h NPVDetectorDict.cxx NPVDetector.rootmap libNPCore.so NPCoreLinkdef.h)
add_library(NPCore SHARED NPCore.cxx NPVAnalysis.cxx NPAnalysisFactory.cxx NPCalibrationManager.cxx NPOptionManager.cxx RootOutput.cxx RootInput.cxx TAsciiFile.cxx TAsciiFileDict.cxx NPDetectorManager.cxx NPVDetector.cxx NPVDetectorDict.cxx NPVSpectra.cxx NPDetectorFactory.cxx NPSpectraServer.cxx NPInputParser.cxx NPImage.cxx NPElog.cxx) add_library(NPCore SHARED NPCore.cxx NPVAnalysis.cxx NPAnalysisFactory.cxx NPCalibrationManager.cxx NPOptionManager.cxx RootOutput.cxx RootInput.cxx TAsciiFile.cxx TAsciiFileDict.cxx NPDetectorManager.cxx NPVDetector.cxx NPVDetectorDict.cxx NPVSpectra.cxx NPDetectorFactory.cxx NPSpectraServer.cxx NPInputParser.cxx NPImage.cxx NPElog.cxx)
target_link_libraries(NPCore ${ROOT_LIBRARIES}) target_link_libraries(NPCore ${ROOT_LIBRARIES})
install(FILES NPCore.h NPVAnalysis.h NPAnalysisFactory.h NPCalibrationManager.h NPOptionManager.h RootInput.h RootOutput.h TAsciiFile.h NPDetectorManager.h NPVDetector.h NPGlobalSystemOfUnits.h NPPhysicalConstants.h NPSystemOfUnits.h NPVSpectra.h NPDetectorFactory.h NPSpectraServer.h NPInputParser.h NPImage.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY}) install(FILES NPCore.h NPVAnalysis.h NPAnalysisFactory.h NPCalibrationManager.h NPOptionManager.h RootInput.h RootOutput.h TAsciiFile.h NPDetectorManager.h NPVDetector.h NPGlobalSystemOfUnits.h NPPhysicalConstants.h NPSystemOfUnits.h NPVSpectra.h NPDetectorFactory.h NPSpectraServer.h NPInputParser.h NPImage.h NPElog.h DESTINATION ${CMAKE_INCLUDE_OUTPUT_DIRECTORY})
/*****************************************************************************
* Copyright (C) 2009-2016 this file is part of the NPTool Project *
* *
* For the licensing terms see $NPTOOL/Licence/NPTool_Licence *
* For the list of contributors see $NPTOOL/Licence/Contributors *
*****************************************************************************/
/*****************************************************************************
* Original Author: Adrien Matta contact address: matta@lpccaen.in2p3.fr *
* *
* Creation Date : 9 May 2017 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class make an interface to the elog command line *
* The elog CLI must be installed on the system for this class to work *
* The interface is designed to help create elog entry from within nptool *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
*****************************************************************************/
#include <iostream>
#include "NPElog.h"
#include "NPCore.h"
#include "NPInputParser.h"
#include "NPOptionManager.h"
////////////////////////////////////////////////////////////////////////////////
NPL::Elog::Elog(){
}
////////////////////////////////////////////////////////////////////////////////
NPL::Elog::~Elog(){
}
////////////////////////////////////////////////////////////////////////////////
void NPL::Elog::ReadConfiguration(std::string filename){
int verbose = NPOptionManager::getInstance()->GetVerboseLevel();
NPL::InputParser parser(filename);
std::vector<NPL::InputBlock*> block = parser.GetAllBlocksWithToken("elog");
if(block.size()!=1){
NPL::SendWarning("NPL::Elog","Elog configuration file has wrong formatting");
return;
}
std::vector<std::string> token = {"host","port","port","ssl","logbook","username","password"};
if(!block[0]->HasTokenList(token)){
NPL::SendWarning("NPL::Elog","Elog configuration file has wrong formatting");
return;
}
if(verbose)
std::cout << "//// Elog Configuration " << std::endl;
m_host = block[0]->GetString("host");
m_port = block[0]->GetString("port");
m_ssl = block[0]->GetString("ssl");
m_logbook = block[0]->GetString("logbook");
m_username = block[0]->GetString("username");
m_password = block[0]->GetString("password");
std::vector<NPL::InputBlock*> attributes = parser.GetAllBlocksWithToken("attribute");
unsigned int size = attributes.size();
for(unsigned int i = 0 ; i < size ; i++){
if(attributes[i]->HasToken("values"))
m_AttributesValues[attributes[i]->GetMainValue()]=attributes[i]->GetVectorString("values");
}
}
////////////////////////////////////////////////////////////////////////////////
bool NPL::Elog::CheckServer(){
// to be done
return true;
}
////////////////////////////////////////////////////////////////////////////////
bool NPL::Elog::CheckEntry(std::vector<std::string>& attributes, std::vector<std::string>& val){
return true;
}
////////////////////////////////////////////////////////////////////////////////
bool NPL::Elog::CreateEntry(std::vector<std::string>& attributes, std::vector<std::string>& val,std::string message, std::vector<std::string> attachement){
if(CheckEntry(attributes,val)){
std::string cmd = "elog -h " + m_host + " -p " + m_port + " -s " + m_ssl;
cmd += " -u " + m_username + " " + m_password;
cmd += " -l " + m_logbook;
unsigned int size = attributes.size();
for(unsigned int i = 0 ; i < size ; i++)
cmd += " -a " + attributes[i] + "=" + val[i];
cmd += " \""+message+"\"";
size = attachement.size();
for(unsigned int i = 0 ; i < size ; i++){
cmd += " -f " + attachement[i];
}
int code = system(cmd.c_str());
}
return true;
}
#ifndef NPELOG_H
#define NPELOG_H
/*****************************************************************************
* Copyright (C) 2009-2016 this file is part of the NPTool Project *
* *
* For the licensing terms see $NPTOOL/Licence/NPTool_Licence *
* For the list of contributors see $NPTOOL/Licence/Contributors *
*****************************************************************************/
/*****************************************************************************
* Original Author: Adrien Matta contact address: matta@lpccaen.in2p3.fr *
* *
* Creation Date : 9 May 2017 *
* Last update : *
*---------------------------------------------------------------------------*
* Decription: *
* This class make an interface to the elog command line *
* The elog CLI must be installed on the system for this class to work *
* The interface is designed to help create elog entry from within nptool *
*---------------------------------------------------------------------------*
* Comment: *
* *
* *
*****************************************************************************/
#include <string>
#include <vector>
#include <map>
namespace NPL{
class Elog{
public:
Elog();
~Elog();
public:
// Read the elog configuration file in nptool format
void ReadConfiguration(std::string filename);
// check if the server is reachable
bool CheckServer();
// Check the submitted entry match the required grammar (all attribute filled correctly)
bool CheckEntry(std::vector<std::string>& attributes, std::vector<std::string>& val);
// Submit the entry
bool CreateEntry(std::vector<std::string>& attributes, std::vector<std::string>& val, std::string message , std::vector<std::string> attachement=std::vector<std::string>());
private: // Login configuration
std::string m_host;
std::string m_port;
std::string m_ssl;
std::string m_logbook;
std::string m_username;
std::string m_password;
private: // attribute and their possible values
std::map<std::string, std::vector<std::string> > m_AttributesValues;
public: // Accessort to the define attributes and their default value
inline std::map<std::string, std::vector<std::string> > GetAttributesValues() { return m_AttributesValues;};
};
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment