Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line | 
|---|---|---|---|
| 326 | f9daq | 1 | #include "TXMLEngine.h" | 
        
| 2 | |||
| 3 | // const char nodes[][20]={"TMON0","TMON1", "dna", "VDD", "V2P","V2N","VSS","VTH1","VTH2","VCC12","VCC15","VCC25","V38P",0}; | 
        ||
| 4 | |||
| 5 | const double ul[20] ={ 20, 0.25 };  | 
        ||
| 6 | const double ll[20] ={ -0.1,-0.1 };  | 
        ||
| 7 | |||
| 8 | Int_t mode=0;  | 
        ||
| 9 | Int_t mid=0;  | 
        ||
| 10 | Int_t chid=0;  | 
        ||
| 11 | const char measurement[2][0xFF]={"HV test;N,I(uA)","LV test &firmware upload;N;I(A)"};  | 
        ||
| 12 | const char smode[2][0xFF]={"n1470","pw18"};  | 
        ||
| 13 | const int nch[2]={1,4};  | 
        ||
| 14 | const char nodes[2][0xFF]={"V","I"};  | 
        ||
| 15 | const double hmax[2] ={ 20, 0.25 };  | 
        ||
| 16 | double current=0;  | 
        ||
| 17 | double voltage=0;  | 
        ||
| 18 | void hinit( int id){  | 
        ||
| 19 | char name[0xFF];  | 
        ||
| 20 | sprintf(name,"title%d",id);  | 
        ||
| 21 | TPaveText *pt = new TPaveText(.05,.4,.95,.8);  | 
        ||
| 22 | pt->SetName(name);  | 
        ||
| 23 | gDirectory->GetList()->Add(pt);  | 
        ||
| 24 | for (mode=0;mode<2;mode++){  | 
        ||
| 25 | for (chid=0;chid<nch[mode];chid++){  | 
        ||
| 26 | for (int inode=0;inode<2;inode++){  | 
        ||
| 27 | sprintf(name,"%s_%s_%d_ch%d",smode[mode],nodes[inode],id,chid);  | 
        ||
| 28 | printf("name=%s\n",name);  | 
        ||
| 29 | TGraph *g0 = (TGraph *) (gROOT->FindObject(name)) ;  | 
        ||
| 30 | if (g0) printf("%s already exists!\n",name);  | 
        ||
| 31 | |||
| 32 | TGraph *g= new TGraph();  | 
        ||
| 33 | g->SetName(name);  | 
        ||
| 34 | g->SetLineColor(chid%9+1);  | 
        ||
| 35 | g->SetLineWidth(3);  | 
        ||
| 36 | gDirectory->GetList()->Add(g);  | 
        ||
| 37 |                                 } | 
        ||
| 38 |                         } | 
        ||
| 39 |                 } | 
        ||
| 40 | |||
| 41 | mid=0;  | 
        ||
| 42 | mode=0;  | 
        ||
| 43 | chid=0;  | 
        ||
| 44 | }       | 
        ||
| 45 | |||
| 46 | void hplot(int id, int what){  | 
        ||
| 47 | int i=0;  | 
        ||
| 48 | char name[0xFF];  | 
        ||
| 49 | char title[0xFF];  | 
        ||
| 50 | |||
| 51 | leg = new TLegend(0.60,0.9-nch[what]*0.1,0.99,0.9);  | 
        ||
| 52 |    //leg->SetHeader("Legend"); | 
        ||
| 53 | for (i=0;i<nch[what];i++){  | 
        ||
| 54 | sprintf(title,"%s",measurement[what]);  | 
        ||
| 55 | sprintf(name,"%s_%s_%d_ch%d",smode[what],"I",id,i);  | 
        ||
| 56 | printf("hplot name=%s\n",name);  | 
        ||
| 57 | TGraph *g = (TGraph *) (gROOT->FindObject(name)) ;  | 
        ||
| 58 | if (g ) {  | 
        ||
| 59 | |||
| 60 | if (i==0) {  | 
        ||
| 61 | sprintf(name,"h2%s_%s_%d",smode[what],"I",id);  | 
        ||
| 62 | TH2F *frame = new TH2F(name,title,g->GetN(),0,g->GetN()+7,40,0,hmax[what]);  | 
        ||
| 63 | frame->SetStats(0);  | 
        ||
| 64 | frame->Draw();  | 
        ||
| 65 |                         } | 
        ||
| 66 | double x, y;  | 
        ||
| 67 | g->GetPoint(g->GetN()-1,x,y);  | 
        ||
| 68 | if (y>ll[what] && y<ul[what]){  | 
        ||
| 69 | sprintf(title,"CH %d\t=%2.2f A",i, y);  | 
        ||
| 70 | } else {  | 
        ||
| 71 | sprintf(title,"CH %d\t=%2.2f A ERROR",i, y);  | 
        ||
| 72 |                         } | 
        ||
| 73 | leg->AddEntry(g,title,"l");  | 
        ||
| 74 | if (g->GetN()) g->Draw("ls");  | 
        ||
| 75 | } else {  | 
        ||
| 76 | printf("%s not found!\n",name);  | 
        ||
| 77 |                 }       | 
        ||
| 78 |         } | 
        ||
| 79 | leg->Draw();  | 
        ||
| 80 | } | 
        ||
| 81 | |||
| 82 | void hend(){  | 
        ||
| 83 | int i=0;  | 
        ||
| 84 | char name[0xFF];  | 
        ||
| 85 | TCanvas *c[4];  | 
        ||
| 86 | |||
| 87 | for ( i=0;i<4;i++) {  | 
        ||
| 88 | sprintf(name,"cfebps%d",i);  | 
        ||
| 89 | c[i] = new TCanvas(name,name, 500,800);  | 
        ||
| 90 | c[i]->Divide(1,3);  | 
        ||
| 91 | c[i]->cd(1);  | 
        ||
| 92 | sprintf(name,"title%d",i);  | 
        ||
| 93 | TPaveText *pt = (TPaveText *) (gROOT->FindObject(name));  | 
        ||
| 94 | if (pt) pt->Draw();  | 
        ||
| 95 | c[i]->cd(2);  | 
        ||
| 96 | hplot(i,1);  | 
        ||
| 97 | c[i]->cd(3);  | 
        ||
| 98 | hplot(i,0);  | 
        ||
| 99 | c[i]->Modified();  | 
        ||
| 100 | c[i]->Update();  | 
        ||
| 101 | printf("tekst je=%s\n", pt);  | 
        ||
| 102 |         } | 
        ||
| 103 | } | 
        ||
| 104 | |||
| 105 | |||
| 106 | |||
| 107 | void DisplayNode(TXMLEngine* xml, XMLNodePointer_t node, Int_t level, const char *fname)  | 
        ||
| 108 | { | 
        ||
| 109 |    // this function display all accessible information about xml node and its children | 
        ||
| 110 | |||
| 111 | printf("%*c node: %s\n",level,' ', xml->GetNodeName(node));  | 
        ||
| 112 | |||
| 113 |    // display namespace | 
        ||
| 114 | XMLNsPointer_t ns = xml->GetNS(node);  | 
        ||
| 115 | if (ns!=0)  | 
        ||
| 116 | printf("%*c namespace: %s refer: %s\n",level+2,' ', xml->GetNSName(ns), xml->GetNSReference(ns));  | 
        ||
| 117 | |||
| 118 |    // display attributes | 
        ||
| 119 | XMLAttrPointer_t attr = xml->GetFirstAttr(node);  | 
        ||
| 120 | while (attr!=0) {  | 
        ||
| 121 | printf("%*c attr: %s value: %s\n",level+2,' ', xml->GetAttrName(attr), xml->GetAttrValue(attr));  | 
        ||
| 122 | if (strcmp(xml->GetNodeName(node),"feb")==0 && strcmp(xml->GetAttrName(attr),"id")==0 ) {  | 
        ||
| 123 | mid=atoi( xml->GetAttrValue(attr) );  | 
        ||
| 124 | printf("ID---->%d\n",mid);  | 
        ||
| 125 |        } | 
        ||
| 126 | if (strcmp(xml->GetNodeName(node),"pw18")==0 && strcmp(xml->GetAttrName(attr),"id")==0 ) {  | 
        ||
| 127 | chid=atoi( xml->GetAttrValue(attr) );  | 
        ||
| 128 |        } | 
        ||
| 129 | if (strcmp(xml->GetNodeName(node),"n1470")==0 && strcmp(xml->GetAttrName(attr),"id")==0 ) {  | 
        ||
| 130 | chid=atoi( xml->GetAttrValue(attr) );  | 
        ||
| 131 |        } | 
        ||
| 132 | attr = xml->GetNextAttr(attr);  | 
        ||
| 133 |    } | 
        ||
| 134 | |||
| 135 |    // display content (if exists) | 
        ||
| 136 | const char* content = xml->GetNodeContent(node);  | 
        ||
| 137 | if (strcmp(xml->GetNodeName(node),"n1470")==0) {  | 
        ||
| 138 | printf("mode %s\n",smode[mode]);  | 
        ||
| 139 | mode=0;  | 
        ||
| 140 | printf("N1470 Channel ID---->%d\n",chid);  | 
        ||
| 141 |    }      | 
        ||
| 142 | if (strcmp(xml->GetNodeName(node),"pw18")==0) {  | 
        ||
| 143 | mode=1;  | 
        ||
| 144 | printf("PW18 Channel ID---->%d\n",chid);  | 
        ||
| 145 |    } | 
        ||
| 146 | |||
| 147 | if (content!=0){  | 
        ||
| 148 | printf("%*c cont: %s\n",level+2,' ', content);  | 
        ||
| 149 | if (strcmp(xml->GetNodeName(node),"dna")==0) {  | 
        ||
| 150 | |||
| 151 | char name[0xFF];  | 
        ||
| 152 | sprintf(name,"title%d",mid);  | 
        ||
| 153 | TPaveText *pt = (TPaveText *) (gROOT->FindObject(name)) ;  | 
        ||
| 154 | if (pt) {  | 
        ||
| 155 | sprintf(name,"DNA=%s",content);  | 
        ||
| 156 | pt->AddText(name);  | 
        ||
| 157 |                   } | 
        ||
| 158 |           } | 
        ||
| 159 | if (strcmp(xml->GetNodeName(node),"sn")==0 && mode==0) {  | 
        ||
| 160 | char name[0xFF];  | 
        ||
| 161 | sprintf(name,"title%d",mid);  | 
        ||
| 162 | TPaveText *pt = (TPaveText *) (gROOT->FindObject(name)) ;  | 
        ||
| 163 | if (pt) {  | 
        ||
| 164 | sprintf(name,"SN = %s",content);  | 
        ||
| 165 | pt->AddText(fname);  | 
        ||
| 166 | pt->AddText(name);  | 
        ||
| 167 |                   } | 
        ||
| 168 |           }     | 
        ||
| 169 | if (strcmp(xml->GetNodeName(node),"time")==0) {  | 
        ||
| 170 | char name[0xFF];  | 
        ||
| 171 | for (int ii=0;ii<4;ii++){  | 
        ||
| 172 | sprintf(name,"title%d",ii);  | 
        ||
| 173 | TPaveText *pt = (TPaveText *) (gROOT->FindObject(name)) ;  | 
        ||
| 174 | if (pt) {  | 
        ||
| 175 | sprintf(name,"Time=\t%s",content);  | 
        ||
| 176 | pt->AddText("ARICH FEB QA test");  | 
        ||
| 177 | pt->AddText(name);  | 
        ||
| 178 |                     } | 
        ||
| 179 |               } | 
        ||
| 180 |           }               | 
        ||
| 181 | if (strcmp(xml->GetNodeName(node),"V")==0) {  | 
        ||
| 182 | voltage =atof( content );  | 
        ||
| 183 | char name[0xFF];  | 
        ||
| 184 | sprintf(name,"%s_%s_%d_ch%d",smode[mode],xml->GetNodeName(node),mid,chid);  | 
        ||
| 185 | TGraph *g = (TGraph *) (gROOT->FindObject(name)) ;  | 
        ||
| 186 | if (g) g->SetPoint(g->GetN(), g->GetN(), voltage );  | 
        ||
| 187 | else printf("%s not found!\n",name);  | 
        ||
| 188 |       } | 
        ||
| 189 | if (strcmp(xml->GetNodeName(node),"I")==0) {  | 
        ||
| 190 | current =atof( content );  | 
        ||
| 191 | char name[0xFF];  | 
        ||
| 192 | sprintf(name,"%s_%s_%d_ch%d",smode[mode],xml->GetNodeName(node),mid,chid);  | 
        ||
| 193 | TGraph *g = (TGraph *) (gROOT->FindObject(name)) ;  | 
        ||
| 194 | if (g) g->SetPoint(g->GetN(), g->GetN(), current );  | 
        ||
| 195 | else printf("%s not found!\n",name);  | 
        ||
| 196 |       } | 
        ||
| 197 | |||
| 198 |    }   | 
        ||
| 199 |    // display all child nodes    | 
        ||
| 200 | XMLNodePointer_t child = xml->GetChild(node);  | 
        ||
| 201 | while (child!=0) {  | 
        ||
| 202 | DisplayNode(xml, child, level+2, fname);  | 
        ||
| 203 | child = xml->GetNext(child);  | 
        ||
| 204 |    } | 
        ||
| 205 | } | 
        ||
| 206 | |||
| 207 | |||
| 208 | void febpsxml2root(const char* filename = "febps_0001.xml")  | 
        ||
| 209 | { | 
        ||
| 210 | |||
| 211 |    // First create engine | 
        ||
| 212 | TXMLEngine* xml = new TXMLEngine;  | 
        ||
| 213 | |||
| 214 |    // Now try to parse xml file | 
        ||
| 215 |    // Only file with restricted xml syntax are supported | 
        ||
| 216 | XMLDocPointer_t xmldoc = xml->ParseFile(filename);  | 
        ||
| 217 | if (xmldoc==0) {  | 
        ||
| 218 | delete xml;  | 
        ||
| 219 | return;  | 
        ||
| 220 |    } | 
        ||
| 221 | |||
| 222 |    // take access to main node    | 
        ||
| 223 | XMLNodePointer_t mainnode = xml->DocGetRootElement(xmldoc);  | 
        ||
| 224 | |||
| 225 |    // display recursively all nodes and subnodes | 
        ||
| 226 | for (int i=0;i<4;i++) hinit(i);  | 
        ||
| 227 | |||
| 228 | DisplayNode(xml, mainnode, 1, filename);  | 
        ||
| 229 | hend();  | 
        ||
| 230 |    // Release memory before exit | 
        ||
| 231 | xml->FreeDoc(xmldoc);  | 
        ||
| 232 | delete xml;  | 
        ||
| 233 | } | 
        ||
| 234 |