Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

MyExperiment.cpp

Go to the documentation of this file.
00001 //  This file contains a test readout system.
00002 //   It derives from the CReadoutMain class
00003 //   to setup our experiment specific requirements
00004 //   creates an instance of it and lets the base classes
00005 //  do most of the work:
00006 #include <CReadoutMain.h>
00007 #include <CExperiment.h>
00008 #include <CInterpreterStartup.h>
00009 #include <CInterpreterCore.h>
00010 #include <CRunVariableCommand.h>
00011 #include <CRunVariable.h>
00012 #include <CStateVariableCommand.h>
00013 #include <CStateVariable.h>
00014 #include <TCLInterpreter.h>
00015 #include <CDAQTCLProcessor.h>
00016 #include <CVMEScalerLRS1151.h>
00017 #include <CTraditionalEventSegment.h>
00018 #include <CEventSegment.h>
00019 #include <CDocumentedPacket.h>
00020 #include "Hierarchy.h"
00021 //
00022 //   This declaration makes possible the use of the 'old style skelton'.
00023 //
00024 CTraditionalEventSegment oldstyle;
00025 
00026 //  The class below implements a counting pattern event segment.
00027 //  The number of items in the pattern is a constructor parameter.
00028 //  The class also constructs a Documented packet as described in the
00029 //  constructor so that the event segment is tagged appropriately.
00030 //
00031 class CCountingEventSegment : public CEventSegment {
00032 private:
00033   unsigned int      m_nPatternLength;
00034   CDocumentedPacket m_PacketId;
00035 
00036   // Constructors and canonical operations.
00037 
00038 public:
00039   CCountingEventSegment(unsigned int nLength,
00040                         unsigned short nTag,
00041                 const string& rName, const string& rDescription,
00042                         const string& rVersion);
00043   virtual ~CCountingEventSegment() {}
00044 private:
00045   CCountingEventSegment(const CCountingEventSegment& rhs);
00046   CCountingEventSegment& operator= (const CEventSegment& rhs);
00047   int                    operator==(const CEventSegment& rhs) const;
00048   int                    operator!=(const CEventSegment& rhs) const;
00049 public:
00050 
00051   // Class attribute selectors:
00052 public:
00053   int                getPatternLenth() const { return m_nPatternLength; }
00054   const CDocumentedPacket& getPacket() const { return m_PacketId; }
00055   
00056   // Class has no mutators.
00057 protected:
00058 
00059   // Overrides of the interface pure virtual methods:
00060 
00061 public:
00062   virtual   void Initialize () {}
00063   virtual   DAQWordBufferPtr& Read (DAQWordBufferPtr& rBuffer);
00064   virtual   void Clear () {}
00065   virtual   unsigned int MaxSize () { return m_nPatternLength + 2;} // not needed.
00066   
00067 
00068 protected:
00069 
00070   
00071 };
00072 
00073 
00074 /* Implementation of the CCountingEventSegment. */
00075 
00079 CCountingEventSegment::CCountingEventSegment(unsigned int nLength,
00080                                              unsigned short nTag,
00081                                              const string& rName,
00082                                              const string& rDescription,
00083                                              const string& rVersion) :
00084   CEventSegment(),
00085   m_nPatternLength(nLength),
00086   m_PacketId(nTag, rName, rDescription, rVersion)
00087 {}
00088 
00089 
00095 DAQWordBufferPtr&
00096 CCountingEventSegment::Read(DAQWordBufferPtr& rBuffer)
00097 {
00098   rBuffer = m_PacketId.Begin(rBuffer);  //  Open the packet.
00099 
00100   for(int i =0; i < m_nPatternLength; i++) {
00101     *rBuffer = i;
00102     ++rBuffer;                  // Preincrement is faster than post.
00103   }
00104   rBuffer =  m_PacketId.End(rBuffer);   // close the packet.
00105   return rBuffer;
00106 }
00107 
00108 // The variables below create event segments that can will be registered
00109 // for readout.  Note that if they don't get registered, because of the way
00110 // CDocumentedPackets work their packets will still appear in the documentation
00111 // buffer.
00112 
00113 CCountingEventSegment seg1(10, 
00114                            0x1, 
00115                            string("Ten"), 
00116                            string("Segment with 10 size counting pattern"),
00117                            string("1.1"));
00118 CCountingEventSegment seg2(20,
00119                            0x2, 
00120                            string("Twenty"), 
00121                            string("Segment with 20 consecutive shorts"),
00122                            string("0.1"));
00123 
00124 // Build the objects needed for a two level hierarchy:
00125 
00126 CCountingEventSegment seg3(10, 0x3, string("Hierarchy.Ten"),
00127                            string("Nested segment with 10 consec. shorts"),
00128                            string("1.1"));
00129 
00130 CCountingEventSegment seg4(20, 0x4, string("Hierarchy.Twenty"),
00131                            string("Nested segment with 20 consec shorts"),
00132                            string("0.1"));
00133 
00134 Hierarchy hier(0xaaaa, string("Hierarchy"),
00135                string("Top level of the hierarchy"),
00136                string("2.5"));
00142 class CMyExperiment : public CReadoutMain
00143 {
00144 public:
00145    // Constructors and other canonical operations:
00146 
00147    CMyExperiment() {
00148    }
00149    virtual ~CMyExperiment() {
00150    }
00151    // Copy construction, assignment and comparison 
00152    // make no sense and are therefore disallowed:
00153 private:
00154    CMyExperiment(const CMyExperiment& rhs);
00155    CMyExperiment& operator=(const CMyExperiment& rhs);
00156    int            operator==(const CMyExperiment& rhs);
00157    int            operator!=(const CMyExperiment& rhs);
00158 public:
00159    // The member functions below allow us to override/extend base
00160    // class behavior for experiment specific stuff.
00161    
00162 protected:
00163    virtual void SetupReadout(CExperiment& rExperiment);
00164    virtual void SetupScalers(CExperiment& rExperiment);
00165 
00166 public:
00167    virtual void SetupRunVariables(CExperiment& rExperiment,
00168                                   CInterpreterStartup& rStartup,
00169                                   CInterpreterCore&    rCore);
00170    virtual void SetupStateVariables(CExperiment& rExperiment,
00171                                   CInterpreterStartup& rStartup,
00172                                   CInterpreterCore&    rCore);
00173    virtual void AddUserCommands(CExperiment& rExperiment,
00174                                   CInterpreterStartup& rStartup,
00175                                   CInterpreterCore&    rCore);
00176    
00177 };
00178 
00179 // The system relies on a globally accessible instsance of a CReadoutMain 
00180 // derived object called MyApp so here it is:
00181 
00182 CMyExperiment MyApp;
00183 
00207 void
00208 CMyExperiment::SetupReadout(CExperiment& rExperiment)
00209 {
00210    CReadoutMain::SetupReadout(rExperiment);
00211    
00212    // Insert your code below this comment.
00213 
00214    rExperiment.AddEventSegment(&oldstyle);
00215    rExperiment.AddEventSegment(&seg1);
00216    rExperiment.AddEventSegment(&seg2);
00217    hier.AddSegment(&seg3);
00218    hier.AddSegment(&seg4);
00219    rExperiment.AddEventSegment(&hier);
00220 
00221 }
00236 void
00237 CMyExperiment::SetupScalers(CExperiment& rExperiment)
00238 {
00239    CReadoutMain::SetupScalers(rExperiment);
00240 
00241    // Insert your code below this comment.
00242 
00243    // For test,setup an LRS 1151 at 0x200c00
00244 
00245    //   CScaler* pScaler = new CVMEScalerLRS1151(0xc00200);
00246    //   rExperiment.AddScalerModule(pScaler);
00247 
00248 }
00273 void
00274 CMyExperiment::SetupRunVariables(CExperiment& rExperiment,
00275                                   CInterpreterStartup& rStartup,
00276                                  CInterpreterCore&   rCore)
00277 {
00278    CReadoutMain::SetupRunVariables(rExperiment, rStartup, rCore);
00279    
00280    CRunVariableCommand& rCommand(*(rCore.getRunVariables()));
00281    
00282    // Add your code below this commet. rCommand is a reference to the run variable
00283    // commands object.
00284 }
00285 /*
00286     This function allows you to create run state variables.  Run state
00287    variables are TCL variables that are write locked during a run.  Their
00288    values are logged to run state variable buffers at run state transitions.
00289 
00290    An example of a run state variable is the run number; created by the
00291    base class.  An example of run variables you might like to create are
00292    fixed run conditions, such as beam species, energy, target species,
00293    trigger conditions etc.
00294 
00295    The Tcl command statevar can also be used to create list and delete
00296    state variables.
00297 
00298    \param rExperiment - CExperiment& the experiment object.
00299    \param rStartup   - CInterpreterStartup& the interpreter startup
00300                                             object.
00301     \param rCore  - CInterpreterCore& the core TCL interpreter
00302          add on functionality.  Normally you will obtain the 
00303          state variable command object and do CStateVariableCommand::Create
00304          calls to add your run variables.
00305 
00306    \note The base class creates key run variables.  It is therefore 
00307    very important to be sure the base class version of this function is
00308    called.
00309 */
00310 void
00311 CMyExperiment::SetupStateVariables(CExperiment& rExperiment,
00312                                    CInterpreterStartup& rStartup,
00313                                    CInterpreterCore&    rCore)
00314 {
00315    CReadoutMain::SetupStateVariables(rExperiment, rStartup, rCore);
00316    
00317    CStateVariableCommand& rCommand(*(rCore.getStateVariables()));
00318    
00319    // Insert your code below this comment.  Note that rCommand is the 
00320    // state variable command object.
00321 
00322 }
00340 void
00341 CMyExperiment::AddUserCommands(CExperiment& rExperiment, 
00342                                    CInterpreterStartup& rStartup,
00343                                    CInterpreterCore&    rCore)
00344 {
00345    CReadoutMain::AddUserCommands(rExperiment, rStartup, rCore);
00346    
00347    CTCLInterpreter& rInterp(rStartup.Interp());
00348    
00349    // Add your command definitions after this comment.  rInterp
00350    // is a reference to the interpreter.
00351 }

Generated on Fri Nov 8 13:36:50 2002 for Event Readout system. by doxygen1.2.16