#include <stdio.h>
#include <stdlib.h>
#include <TROOT.h>
#include <TF1.h>
#include <TH1F.h>
#include <TH1D.h>
#include <TH2D.h>
#include <TTree.h>
#include <TCanvas.h>
#include <TStyle.h>
#include <TSystem.h>
#include <TFile.h>
#include <TDirectory.h>
#include <TGraph.h>
#include <TLegend.h>
#include <TPaveText.h>
#include "TXMLEngine.h"
// const char nodes[][20]={"TMON0","TMON1", "dna", "VDD", "V2P","V2N","VSS","VTH1","VTH2","VCC12","VCC15","VCC25","V38P",0};
const char nodes[][20]={ "VDD", "V2P","V2N","VSS","VTH1","VTH2","VCC12","VCC15","VCC25","V38P",0};
const double ul[20] ={ 1.7 , 2.1, -1.85, -1.61, 3, 3, 1.31, 1.61 , 2.61 , 3.91 };
const double ll[20] ={ 1.61, 1.85, -2.09, -1.69 , 0, 0, 1.09, 1.39 , 2.39 , 3.69 };
Int_t mid=0;
void hinit( int id){
int i=0;
char name[0xFF];
sprintf(name,"title%d",id);
//printf("ime naslova=%s\n", name);
TPaveText *pt = new TPaveText(.2,.2,.7,.7);
pt->SetName(name);
gDirectory->GetList()->Add(pt);
do {
sprintf(name,"%s_%d",nodes[i],id);
printf("name=%s\n",name);
TGraph *g= new TGraph();
g->SetName(name);
g->SetLineColor(i%9+1);
g->SetLineWidth(3);
gDirectory->GetList()->Add(g);
i++;
} while (strlen(nodes[i])> 1);
}
void hplot(int id){
int i=0;
char name[0xFF];
char title[0xFF]= "Feb Test";
TLegend *leg = new TLegend(0.60,0.1,0.99,0.9);
//leg->SetHeader("Legend");
do {
sprintf(name,"%s_%d",nodes[i],id);
if (gROOT->FindObject(name) ) {
TGraph *g = (TGraph *) (gROOT->FindObject(name)) ;
if (i==0) {
TH2F *frame = new TH2F("frame",title,g->GetN(),0,g->GetN()+5,40,-2.5,4.5);
frame->SetStats(0);
frame->Draw();
}
double x, y;
g->GetPoint(g->GetN()-1,x,y);
if (y>ll[i] && y<ul[i]){
sprintf(title,"%s\t=%2.2f V",nodes[i], y);
} else {
sprintf(title,"%s\t=%2.2f V ERROR",nodes[i], y);
}
leg->AddEntry(g,title,"l");
g->Draw("ls");
} else {
printf("%s not found!\n",name);
}
i++;
} while (strlen(nodes[i])> 1);
leg->Draw();
}
void hpt( int id ){
char name[0xFF];
sprintf(name,"title%d",id);
//printf("title=%s\n", name);
TPaveText *pt = (TPaveText *) (gROOT->FindObject(name));
if (pt) pt->Draw();
}
void hend(){
TCanvas *c= new TCanvas("slowcontrol");
c->Divide(2,2);
for (int i=0;i<4;i++) {
c->cd(i+1);
hplot(i);
}
c->Modified();
c->Update();
}
void DisplayNode(TXMLEngine* xml, XMLNodePointer_t node, Int_t level)
{
// this function display all accessible information about xml node and its children
//printf("%*c node: %s\n",level,' ', xml->GetNodeName(node));
// display namespace
XMLNsPointer_t ns = xml->GetNS(node);
if (ns!=0)
printf("%*c namespace: %s refer: %s\n",level+2,' ', xml->GetNSName(ns), xml->GetNSReference(ns));
// display attributes
XMLAttrPointer_t attr = xml->GetFirstAttr(node);
while (attr!=0) {
//printf("%*c attr: %s value: %s\n",level+2,' ', xml->GetAttrName(attr), xml->GetAttrValue(attr));
attr = xml->GetNextAttr(attr);
}
// display content (if exists)
const char* content = xml->GetNodeContent(node);
if (content!=0){
//printf("%*c cont: %s\n",level+2,' ', content);
if (strcmp(xml->GetNodeName(node),"time")==0) {
// printf("Time=%s\n", content);
char name[0xFF];
//sprintf(name,"Cas kki ga hocem=\t%s",content);
//printf("Time=%s\n", name);
for (int ii=0;ii<4;ii++){
sprintf(name,"title%d",ii);
printf("title=%s\n",name);
TPaveText *pt = (TPaveText *) (gROOT->FindObject(name)) ;
if (pt) {
pt->AddText("ARICH FEB QA test");
sprintf(name,"Time= %s",content);
pt->AddText(name);
}
}
}
if (strcmp(xml->GetNodeName(node),"id")==0) {
mid=atoi(content);
//printf("ID---->%d\n",mid);
} else {
char name[0xFF];
sprintf(name,"%s_%d",xml->GetNodeName(node),mid);
TGraph *g = (TGraph *) (gROOT->FindObject(name)) ;
if (g) g->SetPoint(g->GetN(), g->GetN() ,atof(content));
else printf("%s not found!\n",name);
}
}
// display all child nodes
XMLNodePointer_t child = xml->GetChild(node);
while (child!=0) {
DisplayNode(xml, child, level+2);
child = xml->GetNext(child);
}
}
void slowcxml2root(const char* filename = "febslowc_0044.xml")
{
TTree *run = new TTree("run", "run");
// First create engine
TXMLEngine* xml = new TXMLEngine;
// Now try to parse xml file
// Only file with restricted xml syntax are supported
XMLDocPointer_t xmldoc = xml->ParseFile(filename);
if (xmldoc==0) {
delete xml;
return;
}
// take access to main node
XMLNodePointer_t mainnode = xml->DocGetRootElement(xmldoc);
// display recursively all nodes and subnodes
for (int i=0;i<4;i++) hinit(i);
DisplayNode(xml, mainnode, 1);
//hend();
// Release memory before exit
xml->FreeDoc(xmldoc);
delete xml;
}