some more work on startup handler

This commit is contained in:
nemu 2008-04-03 08:49:29 +00:00
parent 83c2a0cbd3
commit 5fc7e14f3f
5 changed files with 324 additions and 32 deletions

View File

@ -77,26 +77,8 @@ GSLLIB = -lgslcblas -lgsl
# some definitions: headers (used to generate *Dict* stuff), sources, objects,...
HEADERS =
# HEADERS += PStartupHandler.h
# HEADERS += PMsrHandler.h
# HEADERS += PRunDataHandler.h
# HEADERS += PFunctionHandler.h
# HEADERS += PFunctionGrammar.h
# HEADERS += PFunction.h
# HEADERS += PRunBase.h
# HEADERS += PRunSingleHisto.h
# HEADERS += PRunAsymmetry.h
# HEADERS += PRunRRF.h
# HEADERS += PRunNonMusr.h
# HEADERS += PRunListCollection.h
# HEADERS += PTheory.h
# HEADERS += PFitterFcn.h
# HEADERS += PFitter.h
HEADERS += ../include/PMusrCanvas.h
OBJS =
OBJS += PStartupHandler.o
OBJS += PStartupHandler.o PStartupHandlerDict.o
OBJS += PMsrHandler.o
OBJS += PRunDataHandler.o
OBJS += PFunctionHandler.o
@ -112,9 +94,6 @@ OBJS += PFitterFcn.o
OBJS += PFitter.o
OBJS += PMusrCanvas.o PMusrCanvasDict.o
DICT =
DICT += PMusrCanvasDict.cpp
SHLIB = libPMusr.so
# make the shared lib:
@ -138,9 +117,13 @@ clean:; @rm -f $(OBJS) *Dict* core*
$(OBJS): %.o: %.cpp
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $<
$(DICT): $(HEADERS)
@echo "Generating dictionary files"
rootcint -f $@ -c $^
PStartupHandlerDict.cpp: ../include/PStartupHandler.h
@echo "Generating dictionary $@..."
rootcint -f $@ -c -p $^
PMusrCanvasDict.cpp: ../include/PMusrCanvas.h
@echo "Generating dictionary $@..."
rootcint -f $@ -c -p $^
install: all
@echo "Installing shared lib: libPMusr.so ( you must be root ;-) )"

View File

@ -29,12 +29,21 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
using namespace std;
#include <TObjArray.h>
#include <TObjString.h>
#include <TColor.h>
#include "PStartupHandler.h"
ClassImpQ(PStartupHandler)
//--------------------------------------------------------------------------
// Constructor
//--------------------------------------------------------------------------
/*!
/**
* <p>
*/
PStartupHandler::PStartupHandler()
@ -44,11 +53,246 @@ PStartupHandler::PStartupHandler()
//--------------------------------------------------------------------------
// Destructor
//--------------------------------------------------------------------------
/*!
/**
* <p>
*/
PStartupHandler::~PStartupHandler()
{
// clean up
fDataPathList.empty();
fMarkerList.empty();
fColorList.empty();
}
//--------------------------------------------------------------------------
// OnStartDocument
//--------------------------------------------------------------------------
/**
* <p>
*/
void PStartupHandler::OnStartDocument()
{
fKey = eEmpty;
}
//--------------------------------------------------------------------------
// OnEndDocument
//--------------------------------------------------------------------------
/**
* <p>
*/
void PStartupHandler::OnEndDocument()
{
// check if anything was set, and if not set some default stuff
// check if any data path is given
if (fDataPathList.size() == 0) {
fDataPathList.push_back(TString("/mnt/data/nemu/his"));
fDataPathList.push_back(TString("/mnt/data/nemu/wkm"));
}
// check if any markers are given
if (fMarkerList.size() == 0) {
// to be done yet
}
// check if any colors are given
if (fColorList.size() == 0) {
// to be done yet
}
}
//--------------------------------------------------------------------------
// OnStartElement
//--------------------------------------------------------------------------
/**
* <p>
*
* \param str
* \param attributes
*/
void PStartupHandler::OnStartElement(const char *str, const TList *attributes)
{
if (!strcmp(str, "data_path")) {
fKey = eDataPath;
} else if (!strcmp(str, "marker")) {
fKey = eMarker;
} else if (!strcmp(str, "color")) {
fKey = eColor;
}
}
//--------------------------------------------------------------------------
// OnEndElement
//--------------------------------------------------------------------------
/**
* <p>
*
* \param str
*/
void PStartupHandler::OnEndElement(const char *str)
{
fKey = eEmpty;
}
//--------------------------------------------------------------------------
// OnCharacters
//--------------------------------------------------------------------------
/**
* <p>
*
* \param str
*/
void PStartupHandler::OnCharacters(const char *str)
{
TObjArray *tokens;
TObjString *ostr;
TString tstr;
Int_t color, r, g, b;
switch (fKey) {
case eDataPath:
// check that str is a valid path
// add str to the path list
break;
case eMarker:
// check that str is a number
tstr = TString(str);
if (tstr.IsDigit()) {
// add converted str to the marker list
fMarkerList.push_back(tstr.Atoi());
} else {
cout << endl << "PStartupHandler **WARNING** '" << str << "' is not a number, will ignore it";
cout << endl;
}
break;
case eColor:
// check that str is a rbg code
tstr = TString(str);
tokens = tstr.Tokenize(",");
// check that there any tokens
if (!tokens) {
cout << endl << "PStartupHandler **WARNING** '" << str << "' is not a rbg code, will ignore it";
cout << endl;
return;
}
// check there is the right number of tokens
if (tokens->GetEntries() != 3) {
cout << endl << "PStartupHandler **WARNING** '" << str << "' is not a rbg code, will ignore it";
cout << endl;
return;
}
// get r
ostr = dynamic_cast<TObjString*>(tokens->At(0));
tstr = ostr->GetString();
if (tstr.IsDigit()) {
r = tstr.Atoi();
} else {
cout << endl << "PStartupHandler **WARNING** r within the rgb code is not a number, will ignore it";
cout << endl;
return;
}
// get g
ostr = dynamic_cast<TObjString*>(tokens->At(1));
tstr = ostr->GetString();
if (tstr.IsDigit()) {
g = tstr.Atoi();
} else {
cout << endl << "PStartupHandler **WARNING** g within the rgb code is not a number, will ignore it";
cout << endl;
return;
}
// get b
ostr = dynamic_cast<TObjString*>(tokens->At(2));
tstr = ostr->GetString();
if (tstr.IsDigit()) {
b = tstr.Atoi();
} else {
cout << endl << "PStartupHandler **WARNING** b within the rgb code is not a number, will ignore it";
cout << endl;
return;
}
// clean up tokens
if (tokens) {
delete tokens;
tokens = 0;
}
// generate the ROOT color code based on str
color = TColor::GetColor(r,g,b);
// add the color code to the color list
fColorList.push_back(color);
break;
default:
break;
}
}
//--------------------------------------------------------------------------
// OnComment
//--------------------------------------------------------------------------
/**
* <p>
*
* \param str
*/
void PStartupHandler::OnComment(const char *str)
{
// nothing to be done for now
}
//--------------------------------------------------------------------------
// OnWarning
//--------------------------------------------------------------------------
/**
* <p>
*
* \param str
*/
void PStartupHandler::OnWarning(const char *str)
{
cout << endl << "PStartupHandler **WARNING** " << str;
cout << endl;
}
//--------------------------------------------------------------------------
// OnError
//--------------------------------------------------------------------------
/**
* <p>
*
* \param str
*/
void PStartupHandler::OnError(const char *str)
{
cout << endl << "PStartupHandler **ERROR** " << str;
cout << endl;
}
//--------------------------------------------------------------------------
// OnFatalError
//--------------------------------------------------------------------------
/**
* <p>
*
* \param str
*/
void PStartupHandler::OnFatalError(const char *str)
{
cout << endl << "PStartupHandler **FATAL ERROR** " << str;
cout << endl;
}
//--------------------------------------------------------------------------
// OnCdataBlock
//--------------------------------------------------------------------------
/**
* <p>
*
* \param str
*/
void PStartupHandler::OnCdataBlock(const char *str, Int_t len)
{
// nothing to be done for now
}
// end ---------------------------------------------------------------------

View File

@ -32,15 +32,54 @@
#ifndef _PSTARTUPHANDLER_H_
#define _PSTARTUPHANDLER_H_
#include <TSAXParser.h>
#include <TObject.h>
#include <TQObject.h>
#include <TList.h>
#include <TString.h>
class PStartupHandler : public TSAXParser
#include "PMusr.h"
class PStartupHandler : public TObject, public TQObject
{
public:
PStartupHandler();
virtual ~PStartupHandler();
virtual void OnStartDocument(); // SLOT
virtual void OnEndDocument(); // SLOT
virtual void OnStartElement(const char*, const TList*); // SLOT
virtual void OnEndElement(const char*); // SLOT
virtual void OnCharacters(const char*); // SLOT
virtual void OnComment(const char*); // SLOT
virtual void OnWarning(const char*); // SLOT
virtual void OnError(const char*); // SLOT
virtual void OnFatalError(const char*); // SLOT
virtual void OnCdataBlock(const char*, Int_t); // SLOT
private:
enum EKeyWords {eEmpty, eComment, eDataPath,
eRootSettings, eMarkerList, eMarker,
eColorList, eColor};
EKeyWords fKey;
vector<TString> fDataPathList;
PIntVector fMarkerList;
PIntVector fColorList;
ClassDef(PStartupHandler, 1)
};
// root dictionary stuff --------------------------------------------------
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class PStartupHandler+;
#endif
// root dictionary stuff --------------------------------------------------
#endif // _PSTARTUPHANDLER_H_

View File

@ -26,8 +26,10 @@
</marker_list>
<color_list>
<!-- Color as RGB coded string -->
<color>"0,0,0"</color>
<color>"1,0,0"</color>
<color>0,0,0</color>
<color>255,0,0</color>
<color>0,255,0</color>
<color>0,0,255</color>
</color_list>
</root_settings>
</musrfit>

View File

@ -33,6 +33,7 @@
using namespace std;
#include <TApplication.h>
#include <TSAXParser.h>
#include "PMusr.h"
#include "PStartupHandler.h"
@ -62,6 +63,7 @@ int main(int argc, char *argv[])
{
bool show_syntax = false;
int status;
bool success = true;
switch (argc) {
case 1:
@ -92,7 +94,25 @@ int main(int argc, char *argv[])
}
// read startup file
TSAXParser *saxParser = new TSAXParser();
PStartupHandler *startupHandler = new PStartupHandler();
saxParser->ConnectToHandler("PStartupHandler", startupHandler);
status = saxParser->ParseFile("musrfit_startup.xml");
// check for parse errors
if (status) { // error
cout << endl << "**ERROR** reading/parsing musrfit_startup.xml. Fix it.";
cout << endl;
// clean up
if (saxParser) {
delete saxParser;
saxParser = 0;
}
if (startupHandler) {
delete startupHandler;
startupHandler = 0;
}
return PMUSR_WRONG_STARTUP_SYNTAX;
}
// read msr-file
PMsrHandler *msrHandler = new PMsrHandler(argv[1]);
@ -113,7 +133,7 @@ int main(int argc, char *argv[])
// read all the necessary runs (raw data)
PRunDataHandler *dataHandler = new PRunDataHandler(msrHandler);
bool success = dataHandler->IsAllDataAvailable();
success = dataHandler->IsAllDataAvailable();
if (!success) {
cout << endl << "**ERROR** Couldn't read all data files, will quit ..." << endl;
}
@ -160,6 +180,10 @@ int main(int argc, char *argv[])
}
// clean up
if (saxParser) {
delete saxParser;
saxParser = 0;
}
if (startupHandler) {
delete startupHandler;
startupHandler = 0;