From: Ron F. <ro...@us...> - 2006-09-28 11:16:01
|
Update of /cvsroot/nsclspectcl/SpecTcl/SpecTcl In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv32432/SpecTcl Modified Files: SpectrumPackage.cpp XamineEventHandler.cpp XamineEventHandler.h Log Message: First cut at getting 2-d sum spectra to work.. somethings work properly... others don't. Index: SpectrumPackage.cpp =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/SpecTcl/SpectrumPackage.cpp,v retrieving revision 5.6 retrieving revision 5.7 diff -C2 -d -r5.6 -r5.7 *** SpectrumPackage.cpp 22 Sep 2006 11:40:18 -0000 5.6 --- SpectrumPackage.cpp 28 Sep 2006 11:15:57 -0000 5.7 *************** *** 29,101 **** // mailto:fo...@ns... // ! // Change Log: ! // ! // May 5, 2005 - Added Support for StripChart specrtra ! // ! // July 3, 1999 - Changed the way spectra are created to take advantage ! // of CSpectrumFactory: removed New1d(), New2d() and ! // replaced them with CreateSpectrum(). ! // ! // $Log$ ! // Revision 5.6 2006/09/22 11:40:18 ron-fox ! // - SpectrumCommand - had a typo I introduced. ! // - SpectrumPackage -added lookups for m2 spectra ! // ! // Revision 5.5 2006/03/20 18:25:16 ron-fox ! // Add a bit more error detection/checking in spectrum binding/creation in ! // GUI...other changes are incidental and accidental ! // ! // Revision 5.4 2006/02/21 19:30:59 ron-fox ! // Add -showgate to spectrum -list command/subcommand ! // ! // Revision 5.3 2005/09/22 12:40:38 ron-fox ! // Port in the bitmask spectra ! // ! // Revision 5.2 2005/06/03 15:19:28 ron-fox ! // Part of breaking off /merging branch to start 3.1 development ! // ! // Revision 5.1.2.5 2005/05/27 11:07:30 thoagland ! // Added support for pseudo, parameter, clear, apply, and bind to take an optional pattern for the -list switch. ! // ! // Revision 5.1.2.4 2005/05/24 11:36:48 thoagland ! // Added support for spectrum -list [-byid] [pattern] ! // ! // Revision 5.1.2.3 2005/05/11 16:56:07 thoagland ! // dded Support for StripChart Spectra ! // ! // Revision 5.1.2.2 2005/03/15 17:28:52 ron-fox ! // Add SpecTcl Application programming interface and make use of it ! // in spots. ! // ! // Revision 5.1.2.1 2004/12/15 17:24:06 ron-fox ! // - Port to gcc/g++ 3.x ! // - Recast swrite/sread in terms of tcl[io]stream rather than ! // the kludgy thing I had done of decoding the channel fd. ! // This is both necessary due to g++ 3.x's runtime and ! // nicer too!. ! // ! // Revision 5.1 2004/11/29 16:56:12 ron-fox ! // Begin port to 3.x compilers calling this 3.0 ! // ! // Revision 4.6.2.1 2004/04/13 19:37:24 ron-fox ! // Issue 120 and related bugs: Memory leak on spectrum -delet -all ! // - Also fix up the way iteration works. ! // - Fix Issues in Xamine interface library: check for allocation failure was too late. ! // - Fix issues in Xamine allocator/free.. correct compaction algorithms. ! // ! // Revision 4.6 2004/01/31 03:48:18 ron-fox ! // Fix double deletion error on sread -replace. ! // ! // Revision 4.5.2.1 2004/01/31 03:44:13 ron-fox ! // Fix error in sread -replace : doubly deleted old spectrum and failed second time ! // around ! // ! // Revision 4.5 2003/04/15 19:25:20 ron-fox ! // To support real valued parameters, primitive gates must be internally stored as real valued coordinate pairs. Modifications support the input, listing and application information when gate coordinates are floating point. ! // ! // Revision 4.4 2003/04/01 19:55:40 ron-fox ! // Support for Real valued parameters and spectra with arbitrary binnings. ! // ! // //////////////////////////.cpp file///////////////////////////////////////////////////// --- 29,33 ---- // mailto:fo...@ns... // ! //////////////////////////.cpp file///////////////////////////////////////////////////// *************** *** 1893,1897 **** return aDataTypes[i].pName; } ! return "*uknown*"; } //////////////////////////////////////////////////////////////////////// --- 1825,1829 ---- return aDataTypes[i].pName; } ! return "*unknown*"; } //////////////////////////////////////////////////////////////////////// *************** *** 1926,1944 **** // spectrum. ! if(!pType) ! switch(st) { ! case ke1D: ! case keStrip: ! case keBitmask: ! case keG1D: ! case ke2D: ! case keSummary: ! case keG2D: ! return keLong; // All spectra default to long data types now. ! default: ! errno = EINVAL; ! throw CErrnoException("Mapping default data type for spectrum"); ! ! } // Look up pType: --- 1858,1864 ---- // spectrum. ! if(!pType) { ! return keLong; ! } // Look up pType: Index: XamineEventHandler.h =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/SpecTcl/XamineEventHandler.h,v retrieving revision 5.2 retrieving revision 5.3 diff -C2 -d -r5.2 -r5.3 *** XamineEventHandler.h 3 Jun 2005 15:19:28 -0000 5.2 --- XamineEventHandler.h 28 Sep 2006 11:15:57 -0000 5.3 *************** *** 33,36 **** --- 33,44 ---- #endif + #ifndef __GATEFACTORY_H + #include "GateFactory.h" + #endif + + #ifndef __POINT_H + #include <Point.h> + #endif + #ifndef _TK_H #include <tk.h> *************** *** 38,44 **** --- 46,66 ---- #endif + #ifndef __STL_STRING + #include <string> + #ifndef __STL_STRING + #define __STL_STRING + #endif + #endif + + #ifndef __STL_VECTOR + #include <vector> + #ifndef __STL_VECTOR + #define __STL_VECTOR + #endif + #endif class CDisplayGate; class CButtonEvent; + class CSpectrum; // XamineEventHandler class declaration: *************** *** 130,135 **** virtual UInt_t FindDisplayBinding (const STD(string)& rName); ! static void CallbackRelay(ClientData pObject); }; --- 152,170 ---- virtual UInt_t FindDisplayBinding (const STD(string)& rName); ! static void CallbackRelay(ClientData pObject); ! // Utilities: ! private: + void make2dSumgate(STD(string) gateName, + CGateFactory::GateType componentGateType, + CSpectrum* pSpectrum, + STD(vector)<CPoint> rawPoints); + STD(string) createComponentGateName(STD(string) baseName, + UInt_t p1, + UInt_t p2); + STD(vector)<FPoint> scaleSumSpectrumPoints(CSpectrum* pSpectrum, + UInt_t firstAxis, + STD(vector)<CPoint> rawPoints); + }; Index: XamineEventHandler.cpp =================================================================== RCS file: /cvsroot/nsclspectcl/SpecTcl/SpecTcl/XamineEventHandler.cpp,v retrieving revision 5.3 retrieving revision 5.4 diff -C2 -d -r5.3 -r5.4 *** XamineEventHandler.cpp 10 Mar 2006 16:04:38 -0000 5.3 --- XamineEventHandler.cpp 28 Sep 2006 11:15:57 -0000 5.4 *************** *** 41,48 **** --- 41,52 ---- #include <DisplayGate.h> #include <Spectrum.h> + #include <CSpectrum2Dm.h> + #include <SpecTcl.h> #include <XamineEvent.h> #include <Gamma2DW.h> + + #include <stdio.h> #include <vector> #include <string> *************** *** 206,209 **** --- 210,216 ---- else if((spType == keG2D)) gType = CGateFactory::gammacontour; + else if (spType == ke2Dm) { + gType = CGateFactory::contour; // will become an or of contours. + } else { cerr << "Contour gate received on a spectrum type that doesn't know" *************** *** 216,221 **** if((spType == ke2D)) // Ordinary 2d -> Band. gType = CGateFactory::band; ! else if((spType == keG2D)) // Gamma spectrum -> Gamm aband. gType = CGateFactory::gammaband; else { cerr << "Band received on a spectrum that type that doesn't know how" --- 223,231 ---- if((spType == ke2D)) // Ordinary 2d -> Band. gType = CGateFactory::band; ! else if((spType == keG2D)) // Gamma spectrum -> Gamma aband. gType = CGateFactory::gammaband; + else if (spType == ke2Dm) { + gType = CGateFactory::band; // will become an or of bands. + } else { cerr << "Band received on a spectrum that type that doesn't know how" *************** *** 235,238 **** --- 245,252 ---- switch(spType) { + case ke2Dm: + make2dSumgate(strGateName, gType, pSpec, + GatePoints); + return; case ke1D: // 1-d spectrum must be a cut.. if(gType != CGateFactory::cut) { *************** *** 472,473 **** --- 486,603 ---- pThis->operator()(); } + + /////////////////////////////////////////////////////////////////////// + ////////////////////// Private utility functions ////////////////////// + /////////////////////////////////////////////////////////////////////// + + // Create a gate on a sum spectrum. The gate type will + // be either a contour or a band. The gate will be made by + // creating individual gates for each parameter pair in the + // spectrum and then creating a gate that will or these together. + // so the gate is true whenever any pair of parameters falls in it. + // + // Parameters: + // std::string gateName - Name of the final gate to create. + // CGateFactory::GateType componentGateType - Type of component gates. + // CSpectrum* pSpectrum - Pointer to the spectrum. + // std::vector<CPoint> rawPoints - Spectrum coordinates points. + // + void + CXamineEventHandler::make2dSumgate(string gatename, + CGateFactory::GateType componentGateType, + CSpectrum* pSpectrum, + vector<CPoint> rawPoints) + { + vector<string> componentNames; // So that we can create the OR gate. + SpecTcl& api(*SpecTcl::getInstance()); // so we can call API members. + + CSpectrum2Dm* pSumSpectrum(dynamic_cast<CSpectrum2Dm*>(pSpectrum)); + vector<UInt_t> parameterIds; + pSumSpectrum->GetParameterIds(parameterIds); + + // Now we're ready to get what we need to create the component gates. + + for (int i = 0; i < parameterIds.size(); i+=2) { + UInt_t xId = parameterIds[i]; + UInt_t yId = parameterIds[i+1]; + vector<UInt_t> gateParams; + gateParams.push_back(xId); + gateParams.push_back(yId); + + vector<FPoint> points = scaleSumSpectrumPoints(pSpectrum, + i, + rawPoints); + string componentName = createComponentGateName(gatename, + xId, yId); + CGate* pGate = api.CreateGate(componentGateType, + points, gateParams); + api.AddGate(componentName, pGate); + componentNames.push_back(componentName); + } + // Now create the or gate: + + CGate* orGate = api.CreateOrGate(componentNames); + api.AddGate(gatename, orGate); + } + // Create a unique component name for a component of a + // gate accepted on a sum spectrum. + // component names are of the form basename.p1.p2.serial + // where + // basename - the final name of the or gate of which this is a component. + // p1 - First parameter id of the gate. + // p2 - Second paraemter id of the gate + // serial - Is an unsigned integer that uniquifies any conflicts. + // + // Parameters: + // std::string baseName - Name of the gate being made. + // UInt_t p1, p2 - Parameter ids of the component gate. + // + string + CXamineEventHandler::createComponentGateName(string baseName, + UInt_t p1, + UInt_t p2) + { + UInt_t serial; + SpecTcl& api(*(SpecTcl::getInstance())); + + while (true) { + char gateName[1000]; // hopefully this is large enough... + snprintf(gateName, sizeof(gateName), "_%s.%d.%d.%03d", + baseName.c_str(), p1, p2, serial); + string strName(gateName); + if (!api.FindGate(strName)) { + return strName; + } + serial++; + } + } + // Create a set of scaled points for a component gate of ta gate accepted on + // as summed 2d spectrum. + // Parameters: + // CSpectrum* pSpectrum - pointer to the spectrum in which we're + // scaling gates. + // UInt_t firstAxis - Number of the converter for the x point. + // For the y point it's firstAxis+1. + // std::vector<CPoint> rawPoints - The list of points to convert. + // Returns: + // std::vector<FPoint> - The converted points. + // + vector<FPoint> + CXamineEventHandler::scaleSumSpectrumPoints(CSpectrum* pSpectrum, + UInt_t firstAxis, + vector<CPoint> rawPoints) + { + CSpectrum2Dm* p = dynamic_cast<CSpectrum2Dm*>(pSpectrum); + assert(p); + CSpectrum2Dm::Axes a = p->getAxisMaps(); + vector<FPoint> result; + + for (int i =0; i < rawPoints.size(); i++) { + Float_t x = a[i].AxisToParameter(rawPoints[i].X()); + Float_t y = a[i+1].AxisToParameter(rawPoints[i].Y()); + + result.push_back(FPoint(x,y)); + } + return result; + + } |