Changeset 3441 in Sophya for trunk/SophyaLib/Manual
- Timestamp:
- Dec 13, 2007, 4:12:03 PM (18 years ago)
- Location:
- trunk/SophyaLib/Manual
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/Manual/piapp.tex
r3439 r3441 132 132 133 133 We thank also the persons who have helped us by useful suggestions, among others : \\ 134 S. Bargot, S. Du, S.Plasczczynski, C. Renault and D. Yvon.134 S. Bargot, S. Plasczczynski, C. Renault and D. Yvon. 135 135 136 136 %%% … … 1501 1501 \section{On the fly C++ execution} 1502 1502 \label{flycplusplus} 1503 and the option window activated by the menu: 1504 {\bf Special/CxxExecOption}. 1503 Piapp operates on the underlying SOPHYA class library objects. 1504 Obviously, only a small fraction of functionalities in the libraries 1505 are directly available through the commands. On the fly C++ compilation 1506 and execution in piapp provides an easy access to the whole class library. 1507 1508 The {\bf NamedObjMgr} class handles most of the communication between different 1509 component of the application, including user c++ code. 1510 The NamedObjMgr class implements a singleton scheme, where all instances of the 1511 class operate on the same data. 1512 Most operations, in particular directory and object management are thread-safe. 1513 The most usefull NamedObjMgr methods in user code are: 1514 \begin{itemize} 1515 \item Adding an object using its pointer. The object should be created using new. \\ 1516 {\tt \small bool NamedObjMgr::AddObj(AnyDataObj* obj, string \& nom, bool crd=false) } 1517 \item Adding an object using its reference. The Object Adapter is used to Clone 1518 the object. For classes like TArray or Spherical maps, implementing reference sharing, 1519 the cloned object shares its data with the original object. 1520 The Cloned object is then added to the list. \\ 1521 {\tt \small bool NamedObjMgr::AddObj(AnyDataObj\& obj, string \& nom, bool crd=false)} 1522 \item Object display methods : \\ 1523 {\tt \small NamedObjMgr::DisplayObj(string \& nom, string dopt="") \\ 1524 NamedObjMgr::DisplayImage(string \& nom, \ldots ) \\ 1525 NamedObjMgr::DisplayNT(string \& nom, \ldots )} \\ 1526 \ldots 1527 \item Access to other parts of the piapp application : \\ 1528 {\tt \small PIStdImgApp* NamedObjMgr::GetImgApp() \\ 1529 PIACmd* PIStdImgApp::CmdInterpreter() } 1530 \end{itemize} 1531 1532 \subsection{How does it work ?} 1533 When one the {\bf CxxExecutorCmd} \myppageref{CxxExecutorCmd} commands 1534 ({\tt c++exec} or {\tt c++execfrf}) is invoked, piapp performs the 1535 following operations: 1536 \begin{itemize} 1537 \item Create a c++ file, and includes the usual libstc++ and SOPHYA header files 1538 (file named PIATmp\_xxx/cxx\_spiapp.cc) 1539 \item The user code is put in a c++ function: \\ 1540 {\small \tt int usercxx( vector<string> \& args ) } 1541 \item References to all objects present in the current working NamedObjMgr directory 1542 (default=/home) are declared and initialized. Objects in the current directory can 1543 thus be easily accessed through variables bearing the corresponding object name 1544 in piapp. 1545 \item The c++ source file is compiled and linked with SOPHYA libraries, 1546 and any additional library, specified through {\tt c++mylibs} \myppageref{cZZmylibs}). 1547 The compilation and link steps are carried by the SOPHYA class {\b CxxCompilerLinker}. 1548 \item The resulting shared object is loaded by piapp and the function 1549 {\tt usercxx()} is called. 1550 \end{itemize} 1551 1552 To facilitate communication with piapp/NamedObjMgr, two CPP macros are defined: 1553 \begin{itemize} 1554 \item[\rond] {\bf KeepObj(VarName) } where VarName is a user declared 1555 c++ variable, corresponding to an object inheriting from AnyDataObj. 1556 When this macro is called, the corresponding object is cloned by the object 1557 Adapter and added to the list managed by NamedObjMgr, 1558 with VarName as the object name. 1559 \item[\rond] {\bf DisplayObj(VarName, graphic\_att) } adds the object and 1560 request its display. 1561 \end{itemize} 1562 1563 \subsection{Examples} 1564 1565 \begin{enumerate} 1566 \item Computation using TimeStamp object. \\[1mm] 1567 %% 1568 $\longrightarrow$ File compdate.cc : 1569 \begin{verbatim} 1570 TimeStamp now; // Current date 1571 TimeStamp y2000(2000,1,1,12,0,0.); // 1 jan 2000, 12:00 1572 cout << " Y2000=" << y2000 << " --> Now: " << now << endl; 1573 cout << " From Y2000 to Now= " << now.ToDays() - y2000.ToDays() << " days" << endl; 1574 \end{verbatim} 1575 $\longrightarrow$ piapp commands : \\ 1576 {\tt piapp> c++execfrf compdate.cc} \\ 1577 $\longrightarrow$ The result : \\ 1578 \begin{verbatim} 1579 PIABaseExecutor: Call usercxx( ... ) 1580 Y2000= 01/01/2000 12:00:0.0 UT --> Now: 13/12/2007 14:20:50.0 UT 1581 From Y2000 to Now= 2903.1 days 1582 \end{verbatim} 1583 %%%% 1584 \item Working with objects in piapp: \\[1mm] 1585 \begin{verbatim} 1586 # We create three vectors 1587 newvec va 256 sin(x/5.) 1588 newvec vb 256 cos(x/18.)*exp(-x/150.) 1589 newvec vc 256 1590 # We call c++exec to make an operation on these vectors 1591 c++exec vc=va+3.*vb; 1592 # Display the resulting vector 1593 disp vc 1594 \end{verbatim} 1595 %%% 1596 \item Creating and adding new objects \\[1mm] 1597 $\longrightarrow$ File myf\_fft.h : 1598 \begin{verbatim} 1599 inline double myf(double x) 1600 { 1601 return(3*sin(0.2*x)+4*cos(x)+5*sin(4*x+0.25) 1602 +3.5*cos(9*x+0.45) + 0.05*x); 1603 } 1604 \end{verbatim} 1605 $\longrightarrow$ File myf\_fft.h : 1606 \begin{verbatim} 1607 TVector<r_8> in(4048); 1608 TVector<r_8> noise(4048); 1609 TVector< complex<r_8> > out; 1610 in = RegularSequence(0., 0.05); 1611 noise = RandomSequence(RandomSequence::Gaussian, 0., 4.); 1612 MathArray<r_8> ma; 1613 ma.ApplyFunctionInPlace(in, myf); 1614 in += noise; 1615 FFTPackServer FFTServ; 1616 cout << " Calling FFT " << endl; 1617 FFTServ.FFTForward(in, out); 1618 DisplayObj(in, ""); 1619 DisplayObj(out, "red"); 1620 \end{verbatim} 1621 $\longrightarrow$ piapp commands : 1622 \begin{verbatim} 1623 # Remove existing in/out objects 1624 rm in out 1625 # Divide then graphic window in two regions 1626 zone 1 2 1627 # Compile and execute the c++ code 1628 c++execfrf fft.icc myf_fft.h 1629 listobjs 1630 \end{verbatim} 1631 \end{enumerate} 1632 1633 \subsection{Include files, libraries \ldots} 1634 \begin{itemize} 1635 \item[\rond] The different steps of c++exec or c++execfrf 1636 can be performed by the following commands: {\tt c++create , c++createfrf, 1637 c++compile, c++link, call}. This is useful when the same code 1638 has to be executed multiple times. 1639 \item[\rond] An interactive editing / c++ execution window can be 1640 displayed through the menu-bar, \menubar{Tools/CxxExecutorWindow} 1641 \item[\rond] The {\tt c++import} \myppageref{cZZimport} 1642 activate inclusion of header files for additional SOPHYA modules, 1643 such as Samba SkyMap SkyT FitsIOServe \ldots. 1644 \item[\rond] The inclusion of additional header files and libraries 1645 can be specified using the {\tt c++include} \myppageref{cZZinclude} 1646 and {\tt c++mylibs} \myppageref{cZZmylibs}. 1647 \item[\rond] A dialog window for changing various c++ compile and link 1648 options can be displayed by through the menu-bar 1649 \menubar{Special/CxxExecOption} 1650 \end{itemize} 1651 1505 1652 1506 1653 %%%%%%%%%%%%%%% Section 8 : command reference -
trunk/SophyaLib/Manual/sophya.tex
r3438 r3441 122 122 123 123 We thank also the persons who have helped us by useful suggestions, among others : \\ 124 S. Bargot, S. Du, S.Plasczczynski, C. Renault and D. Yvon.124 S. Bargot, S. Plasczczynski, C. Renault and D. Yvon. 125 125 126 126 \subsection{SOPHYA modules}
Note:
See TracChangeset
for help on using the changeset viewer.