source: Sophya/trunk/SophyaPI/PIext/servnobjm.cc@ 295

Last change on this file since 295 was 295, checked in by ercodmgr, 26 years ago

Mise aux "normes" version DPC/Planck - Gestion des objets a travers

un adaptateur/interface NTuple par NamedObjMgr.
Enregistrement d'objets et de l'adaptateur (I/O PPersist, display, ...)
par ServNobjMgr .... Reza 13/05/99

File size: 12.0 KB
RevLine 
[165]1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
[295]5#include <typeinfo>
[165]6#include <iostream.h>
7#include <string>
8#include <list>
9#include <map>
10#if defined(__KCC__)
11using std::string ;
12#include <list.h>
13#include <map.h>
14#endif
15
16#include "strutil.h"
17
18#include "nobjmgr.h"
19#include "servnobjm.h"
20#include "pistdimgapp.h"
21
22#include "histos.h"
23#include "histos2.h"
24#include "ntuple.h"
25#include "hisprof.h"
26
27
28
29/* --Methode-- */
30Services2NObjMgr::Services2NObjMgr(PIStdImgApp* app, string& tmpdir)
31{
32TmpDir = tmpdir;
[171]33PDynLinkMgr::SetTmpDir(tmpdir);
[165]34mImgapp = app;
[171]35dynlink = NULL;
[165]36InitGrAttNames();
37}
38
39/* --Methode-- */
40Services2NObjMgr::~Services2NObjMgr()
41{
42CloseDLL();
43}
44
45/* --Methode-- */
[295]46void Services2NObjMgr::RegisterClass(AnyDataObj* o, NObjMgrAdapter* oa)
[165]47{
[295]48ObjAdaptList::iterator it;
49for(it = objadaplist.begin(); it != objadaplist.end(); it++)
50 if (typeid(*o) == typeid(*((*it).obj))) THROW(dupIdErr);
[165]51
[295]52dataobj_adapter oba;
53oba.obj = o;
54oba.obja = oa;
55objadaplist.push_back(oba);
56}
[165]57
[295]58/* --Methode-- */
59NObjMgrAdapter* Services2NObjMgr::GetAdapter(AnyDataObj* o)
60{
61ObjAdaptList::iterator it;
62for(it = objadaplist.begin(); it != objadaplist.end(); it++)
63 if (typeid(*o) == typeid(*((*it).obj))) return((*it).obja->Clone(o));
64return(new NObjMgrAdapter(o));
65}
[165]66
[295]67/* --Methode-- */
68void Services2NObjMgr::Nobj_ComputeExpressions(NObjMgrAdapter* obja, string& expx, string& expy, string& expz,
69 string& expwt, string& expcut, NTuple* nt, Histo* h1, Histo2D* h2, HProf* hp)
70{
71if (obja == NULL) return;
72NTupleInterface* objnt = obja->GetNTupleInterface();
73if (objnt == NULL) return;
74string vardec = objnt->VarList_C("_zz61qq_");
[165]75
76PlotExprFunc f = LinkExprFunc(vardec, expx, expy, expz, expwt, expcut);
77if (!f) {
78 cerr << "NamedObjMgr_ComputeExpressions() Error Creation PlotExprFunc " << endl;
79 return;
80 }
81
[295]82double xnt[10];
83float fxnt[10];
[165]84
85int i,j,k;
[295]86for(i=0; i<10; i++) xnt[i] = 0.;
[165]87
[295]88TRY {
89 double* xn;
90 for(k=0; k<objnt->NbLines(); k++) {
91 xn = objnt->GetLineD(k);
92 if (f(xn, xnt, xnt+1, xnt+2, xnt+3) != 0) {
93 if (nt) {
94 for(i=0; i<4; i++) fxnt[i] = xnt[i];
95 nt->Fill(fxnt);
96 }
97 if (h1) h1->Add(xnt[0], xnt[3]);
98 if (h2) h2->Add(xnt[0], xnt[1], xnt[3]);
99 if (hp) hp->Add(xnt[0], xnt[1], xnt[3]);
[165]100 }
101 }
[295]102 }
103CATCH(merr) {
[165]104 fflush(stdout);
105 cout << endl;
106 cerr << endl;
107 string es = PeidaExc(merr);
108 cerr << "NamedObjMgr_ComputeExpressions() Exception :" << merr << es;
109 } ENDTRY;
110
111
112// Fermeture du fichier .so
113CloseDLL();
114return;
115}
116
117
118/* --Methode-- */
119PlotExprFunc Services2NObjMgr::LinkExprFunc(string& vardec, string& expx, string& expy, string& expz,
120 string& expwt, string& cut)
121{
122FILE *fip;
123string fname = TmpDir + "expf_pia_dl.c";
124string fnamer = TmpDir + "expf_pia_dl";
125string cmd;
126int rc;
127
[293]128cmd = "rm -f " + fname;
[165]129rc = system(cmd.c_str());
130//DBG printf("LinkExprFunc_Do> %s (Rc=%d)\n", cmd.c_str(), rc);
131
132if ((fip = fopen(fname.c_str(), "w")) == NULL) {
133 string sn = fname;
134 cout << "NamedObjMgr/LinkExprFunc_Erreur: Pb. Ouverture " << sn << endl;
135 return(NULL);
136 }
137
138// constitution du fichier a compiler
139fputs("#include <math.h> \n", fip);
[295]140fputs("int expf_pia_dl_func(double* _zz61qq_, double* _rx_61qq_, double* _ry_61qq_, double* _rz_61qq_, double* _wt_61qq_) \n{\n", fip);
[165]141fprintf(fip,"%s \n", vardec.c_str());
142fprintf(fip, "if (!(%s)) { *_rx_61qq_ = *_ry_61qq_ = *_rz_61qq_ = *_wt_61qq_ = 0.; return(0); } \n", cut.c_str());
143fprintf(fip, "*_rx_61qq_ = %s ; \n", expx.c_str());
144fprintf(fip, "*_ry_61qq_ = %s ; \n", expy.c_str());
145fprintf(fip, "*_rz_61qq_ = %s ; \n", expz.c_str());
146fprintf(fip, "*_wt_61qq_ = %s ; \n", expwt.c_str());
147fputs("return(1); \n} \n", fip);
148fclose(fip);
149
150return((PlotExprFunc)LinkFunctionFromFile(fnamer, "expf_pia_dl_func"));
151}
152
153
154/* --Methode-- */
155DlFunction Services2NObjMgr::LinkFunctionFromFile(string& fnamer, char* funcname)
156{
157string fname = fnamer + ".c" ;
158string fnameobj = fnamer + ".o" ;
159string fnameso = fnamer + ".so";
160
161// Le link dynamique
162CloseDLL();
[171]163dynlink = PDynLinkMgr::BuildFromCFile(fname);
164if (dynlink == NULL) {
165 cerr << "NamedObjMgr/LinkFunctionFromFile_Erreur: Erreur ouverture SO " << endl;
[165]166 return(NULL);
167 }
168
[171]169DlFunction retfunc = dynlink->GetFunction(funcname);
[165]170if (retfunc == NULL) {
171 string sn = funcname;
172 cerr << "NamedObjMgr/LinkExprFunc_Erreur: Erreur linking " << sn << endl;
173 CloseDLL();
174 return(NULL);
175 }
176else return(retfunc);
177}
178
179/* --Methode-- */
180void Services2NObjMgr::CloseDLL()
181{
[171]182if (dynlink) delete dynlink; dynlink = NULL;
[165]183}
184
185/* --Methode-- */
186string Services2NObjMgr::FileName2Name(string const & fn)
187{
188
189char fsep[2] = {FILESEP, '\0'};
190char tsep[2] = {'.', '\0'};
191size_t p = fn.find_last_of(fsep);
[194]192size_t l = fn.length();
193if (p >= l) p = 0;
194else p++;
195size_t q = fn.find_first_of(tsep,p);
196if (q < p) q = l;
[165]197return(fn.substr(p,q-p));
198}
199
200
201typedef vector<string> GraTok;
202
203/* --Methode-- */
204int Services2NObjMgr::DecodeDispOption(string& gratt, bool& fgsrgr)
205{
206int ropt = Disp_Next;
207if (!mImgapp) return(ropt);
208
209for(int i=0; i<gratt.length(); i++) gratt[i] = tolower(gratt[i]);
210
211if (fgsrgr) mImgapp->SaveGraphicAtt();
212
213if (gratt.substr(0,3) == "def") { // Remise aux valeurs par defaut = non defini
214 mImgapp->SetColAtt();
215 mImgapp->SetLineAtt();
216 mImgapp->SetFontAtt();
217 mImgapp->SetMarkerAtt();
218 mImgapp->SetColMapId();
219 mImgapp->SetZoomAtt();
220 return(ropt);
221 }
222
223// On separe en mots separes par des virgules
224gratt = ","+gratt;
225size_t p = 0;
226size_t q = 0;
227size_t l = gratt.length();
228string token;
229
230GraTok grt;
231
232while (q < l) {
233 p = gratt.find_first_not_of(" ,",q+1); // au debut d'un token
234 if (p>=l) break;
235 q = gratt.find_first_of(" ,",p); // la fin du token;
236 token = gratt.substr(p,q-p);
237 grt.push_back(token);
238 }
239
240
241static GrAttNames::iterator it;
242
243int k;
244bool fgcont = true;
245fgsrgr = false;
246
247for(k=0; k<grt.size(); k++) {
248// cout << "--DBG--SetGraphicAttributes() " << grt[k] << endl;
249
250 // Decodage option affichage (win, next, etc
251 fgcont = true;
252 if ( (grt[k] == "win") || (grt[k] == "w") ) ropt = Disp_Win;
253 else if ( (grt[k] == "same") || (grt[k] == "s") ) ropt = Disp_Same;
254 else if ( (grt[k] == "stack") || (grt[k] == "st") ) ropt = Disp_Stack;
255 else fgcont = false;
256 if (fgcont) continue;
257
258 // Si c'est une couleur
259 it = GrAcolors.find(grt[k]);
260 if (it != GrAcolors.end()) { mImgapp->SetColAtt((PIColors)((*it).second.a1)); fgsrgr = true; continue; }
261 // Si c'est un attribut de lignes
262 it = GrAlines.find(grt[k]);
263 if (it != GrAlines.end()) { mImgapp->SetLineAtt((PILineAtt)((*it).second.a1)); fgsrgr = true; continue; }
264 // Si c'est un attribut de fontes
265 it = GrAfonts.find(grt[k]);
266 if (it != GrAfonts.end()) { mImgapp->SetFontAtt((PIFontSize)((*it).second.a2), (PIFontAtt)((*it).second.a1) );
267 fgsrgr = true; continue; }
268 // Si c'est un attribut de markers
269 it = GrAmarkers.find(grt[k]);
270 if (it != GrAmarkers.end()) { mImgapp->SetMarkerAtt((*it).second.a2, (PIMarker)((*it).second.a1) );
271 fgsrgr = true; continue; }
272 // Si c'est un colormap
273 it = GrAcmap.find(grt[k]);
274 if (it != GrAcmap.end()) { mImgapp->SetColMapId( (CMapId)((*it).second.a1) ); fgsrgr = true; continue; }
275 // Si c'est un facteur de zoom
276 it = GrAzoom.find(grt[k]);
277 if (it != GrAzoom.end()) { mImgapp->SetZoomAtt( (*it).second.a1 ); fgsrgr = true; continue; }
[203]278 // Si c'est un attribut d'axe
279 it = GrAaxes.find(grt[k]);
280 if (it != GrAaxes.end()) { mImgapp->SetAxesAtt( (*it).second.a1 ); fgsrgr = true; continue; }
[165]281
282 }
283
284return(ropt);
285}
286
287
288
289// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
290// Initialisation des chaines de caracteres designant les attributs graphiques
291
292/* --Methode-- */
293void Services2NObjMgr::InitGrAttNames()
294{
295gratt_item gi;
296// Les couleurs
297gi.a2 = 0;
298gi.a1 = PI_NotDefColor;
299GrAcolors["defcol"] = gi;
300gi.a1 = PI_Black;
301GrAcolors["black"] = gi;
302gi.a1 = PI_White;
303GrAcolors["white"] = gi;
304gi.a1 = PI_Grey;
305GrAcolors["grey"] = gi;
306gi.a1 = PI_Red;
307GrAcolors["red"] = gi;
308gi.a1 = PI_Blue;
309GrAcolors["blue"] = gi;
310gi.a1 = PI_Green;
311GrAcolors["green"] = gi;
312gi.a1 = PI_Yellow;
313GrAcolors["yellow"] = gi;
314gi.a1 = PI_Magenta;
315GrAcolors["magenta"] = gi;
316
317gi.a1 = PI_Cyan;
318GrAcolors["cyan"] = gi;
319gi.a1 = PI_Turquoise;
320GrAcolors["turquoise"] = gi;
321gi.a1 = PI_NavyBlue;
322GrAcolors["navyblue"] = gi;
323gi.a1 = PI_Orange;
324GrAcolors["orange"] = gi;
325gi.a1 = PI_SiennaRed;
326GrAcolors["siennared"] = gi;
327gi.a1 = PI_Purple;
328GrAcolors["purple"] = gi;
329gi.a1 = PI_LimeGreen;
330GrAcolors["limegreen"] = gi;
331gi.a1 = PI_Gold;
332GrAcolors["gold"] = gi;
333
334// Les attributs de lignes
335gi.a2 = 0;
336gi.a1 = PI_NotDefLineAtt;
337GrAlines["defline"] = gi;
338gi.a1 = PI_NormalLine;
339GrAlines["normalline"] = gi;
340gi.a1 = PI_ThinLine;
341GrAlines["thinline"] = gi;
342gi.a1 = PI_ThickLine;
343GrAlines["thickline"] = gi;
344gi.a1 = PI_DashedLine;
345GrAlines["dashedline"] = gi;
346gi.a1 = PI_ThinDashedLine;
347GrAlines["thindashedline"] = gi;
348gi.a1 = PI_ThickDashedLine;
349GrAlines["thickdashedline"] = gi;
[192]350gi.a1 = PI_DottedLine;
351GrAlines["dottedline"] = gi;
352gi.a1 = PI_ThinDottedLine;
353GrAlines["thindottedline"] = gi;
354gi.a1 = PI_ThickDottedLine;
355GrAlines["thickdottedline"] = gi;
[165]356
[293]357// Les fontes
[165]358gi.a2 = PI_NotDefFontSize;
359gi.a1 = PI_NotDefFontAtt;
360GrAlines["deffont"] = gi;
361
362gi.a2 = PI_NormalSizeFont;
363gi.a1 = PI_RomanFont;
364GrAlines["normalfont"] = gi;
365gi.a1 = PI_BoldFont;
366GrAlines["boldfont"] = gi;
367gi.a1 = PI_ItalicFont;
368GrAlines["italicfont"] = gi;
369gi.a2 = PI_SmallSizeFont;
370gi.a1 = PI_RomanFont;
371GrAlines["smallfont"] = gi;
372gi.a1 = PI_BoldFont;
373GrAlines["smallboldfont"] = gi;
374gi.a1 = PI_ItalicFont;
375GrAlines["smallitalicfont"] = gi;
376gi.a2 = PI_BigSizeFont;
377gi.a1 = PI_RomanFont;
378GrAlines["bigfont"] = gi;
379gi.a1 = PI_BoldFont;
380GrAlines["bigboldfont"] = gi;
381gi.a1 = PI_ItalicFont;
382GrAlines["bigitalicfont"] = gi;
[192]383gi.a2 = PI_HugeSizeFont;
384gi.a1 = PI_RomanFont;
385GrAlines["hugefont"] = gi;
386gi.a1 = PI_BoldFont;
387GrAlines["hugeboldfont"] = gi;
388gi.a1 = PI_ItalicFont;
389GrAlines["hugeitalicfont"] = gi;
[165]390
391
392// Les markers
[176]393const char* mrkn[11] = { "dotmarker", "plusmarker", "crossmarker",
394 "circlemarker", "fcirclemarker", "boxmarker", "fboxmarker",
395 "trianglemarker", "ftrianglemarker", "starmarker", "fstarmarker"};
[165]396PIMarker mrk[11] = { PI_DotMarker, PI_PlusMarker, PI_CrossMarker,
397 PI_CircleMarker, PI_FCircleMarker, PI_BoxMarker, PI_FBoxMarker,
398 PI_TriangleMarker, PI_FTriangleMarker, PI_StarMarker, PI_FStarMarker};
399
400gi.a2 = 0;
401gi.a1 = PI_NotDefMarker;
402GrAmarkers["defmarker"] = gi;
403
404for(int j=0; j<11; j++) {
405 string smrk;
406 char buff[16];
407 for(int m=1; m<10; m+=2) {
408 sprintf(buff,"%d",m);
409 smrk = (string)mrkn[j] + (string)buff;
410 gi.a1 = mrk[j]; gi.a2 = m;
411 GrAmarkers[smrk] = gi;
412 }
413 }
414
415// Les tables de couleurs
416gi.a2 = 0;
417gi.a1 = CMAP_OTHER;
418GrAcmap["defcmap"] = gi;
419gi.a1 = CMAP_GREY32;
420GrAcmap["grey32"] = gi;
421gi.a1 = CMAP_GREYINV32;
422GrAcmap["greyinv32"] = gi;
423gi.a1 = CMAP_COLRJ32;
424GrAcmap["colrj32"] = gi;
425gi.a1 = CMAP_COLBR32;
426GrAcmap["colbr32"] = gi;
427gi.a1 = CMAP_GREY128;
428GrAcmap["grey128"] = gi;
429gi.a1 = CMAP_GREYINV128;
430GrAcmap["greyinv128"] = gi;
431gi.a1 = CMAP_COLRJ128;
432GrAcmap["colrj128"] = gi;
433gi.a1 = CMAP_COLBR128;
434GrAcmap["colbr128"] = gi;
435
[203]436// La valeur de zoom
[165]437gi.a2 = 0;
438gi.a1 = 0;
439GrAzoom["defzoom"] = gi;
440gi.a1 = 1;
441GrAzoom["zoomx1"] = gi;
442gi.a1 = 2;
443GrAzoom["zoomx2"] = gi;
444gi.a1 = 3;
445GrAzoom["zoomx3"] = gi;
446gi.a1 = 4;
447GrAzoom["zoomx4"] = gi;
448gi.a1 = 5;
449GrAzoom["zoomx5"] = gi;
450gi.a1 = -2;
451GrAzoom["zoom/2"] = gi;
452gi.a1 = -3;
453GrAzoom["zoom/3"] = gi;
454gi.a1 = -4;
455GrAzoom["zoom/4"] = gi;
456gi.a1 = -5;
457GrAzoom["zoom/5"] = gi;
[203]458
459// Attributs d'axes
460gi.a2 = 0;
461gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels);
462GrAaxes["stdaxes"] = gi;
463GrAaxes["defaxes"] = gi;
464GrAaxes["boxaxes"] = gi;
465gi.a1 = (int)kAxesDflt;
466GrAaxes["simpleaxes"] = gi;
467gi.a1 = (int)(kBoxAxes | kExtTicks | kLabels | kGridOn);
468GrAaxes["boxaxesgrid"] = gi;
469
470gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks);
471GrAaxes["fineaxes"] = gi;
472 gi.a1 = (int)(kBoxAxes | kTicks | kLabels | kMinTicks | kMajTicks | kGridOn);
473GrAaxes["grid"] = gi;
474GrAaxes["fineaxesgrid"] = gi;
475
[165]476}
Note: See TracBrowser for help on using the repository browser.