Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

skeleton.cpp

Go to the documentation of this file.
00001 /* Change the line below if we ever move out of CES branch drivers:
00002 
00003  */
00004 #ifndef CESCAMAC
00005 #define CESCAMAC
00006 #endif
00007 
00008 /*
00009                     GNU GENERAL PUBLIC LICENSE
00010                        Version 2, June 1991
00011 
00012  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
00013                        59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00014  Everyone is permitted to copy and distribute verbatim copies
00015  of this license document, but changing it is not allowed.
00016 
00017                             Preamble
00018 
00019   The licenses for most software are designed to take away your
00020 freedom to share and change it.  By contrast, the GNU General Public
00021 License is intended to guarantee your freedom to share and change free
00022 software--to make sure the software is free for all its users.  This
00023 General Public License applies to most of the Free Software
00024 Foundation's software and to any other program whose authors commit to
00025 using it.  (Some other Free Software Foundation software is covered by
00026 the GNU Library General Public License instead.)  You can apply it to
00027 your programs, too.
00028 
00029   When we speak of free software, we are referring to freedom, not
00030 price.  Our General Public Licenses are designed to make sure that you
00031 have the freedom to distribute copies of free software (and charge for
00032 this service if you wish), that you receive source code or can get it
00033 if you want it, that you can change the software or use pieces of it
00034 in new free programs; and that you know you can do these things.
00035 
00036   To protect your rights, we need to make restrictions that forbid
00037 anyone to deny you these rights or to ask you to surrender the rights.
00038 These restrictions translate to certain responsibilities for you if you
00039 distribute copies of the software, or if you modify it.
00040 
00041   For example, if you distribute copies of such a program, whether
00042 gratis or for a fee, you must give the recipients all the rights that
00043 you have.  You must make sure that they, too, receive or can get the
00044 source code.  And you must show them these terms so they know their
00045 rights.
00046 
00047   We protect your rights with two steps: (1) copyright the software, and
00048 (2) offer you this license which gives you legal permission to copy,
00049 distribute and/or modify the software.
00050 
00051   Also, for each author's protection and ours, we want to make certain
00052 that everyone understands that there is no warranty for this free
00053 software.  If the software is modified by someone else and passed on, we
00054 want its recipients to know that what they have is not the original, so
00055 that any problems introduced by others will not reflect on the original
00056 authors' reputations.
00057 
00058   Finally, any free program is threatened constantly by software
00059 patents.  We wish to avoid the danger that redistributors of a free
00060 program will individually obtain patent licenses, in effect making the
00061 program proprietary.  To prevent this, we have made it clear that any
00062 patent must be licensed for everyone's free use or not licensed at all.
00063 
00064   The precise terms and conditions for copying, distribution and
00065 modification follow.
00066 
00067                     GNU GENERAL PUBLIC LICENSE
00068    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
00069 
00070   0. This License applies to any program or other work which contains
00071 a notice placed by the copyright holder saying it may be distributed
00072 under the terms of this General Public License.  The "Program", below,
00073 refers to any such program or work, and a "work based on the Program"
00074 means either the Program or any derivative work under copyright law:
00075 that is to say, a work containing the Program or a portion of it,
00076 either verbatim or with modifications and/or translated into another
00077 language.  (Hereinafter, translation is included without limitation in
00078 the term "modification".)  Each licensee is addressed as "you".
00079 
00080 Activities other than copying, distribution and modification are not
00081 covered by this License; they are outside its scope.  The act of
00082 running the Program is not restricted, and the output from the Program
00083 is covered only if its contents constitute a work based on the
00084 Program (independent of having been made by running the Program).
00085 Whether that is true depends on what the Program does.
00086 
00087   1. You may copy and distribute verbatim copies of the Program's
00088 source code as you receive it, in any medium, provided that you
00089 conspicuously and appropriately publish on each copy an appropriate
00090 copyright notice and disclaimer of warranty; keep intact all the
00091 notices that refer to this License and to the absence of any warranty;
00092 and give any other recipients of the Program a copy of this License
00093 along with the Program.
00094 
00095 You may charge a fee for the physical act of transferring a copy, and
00096 you may at your option offer warranty protection in exchange for a fee.
00097 
00098   2. You may modify your copy or copies of the Program or any portion
00099 of it, thus forming a work based on the Program, and copy and
00100 distribute such modifications or work under the terms of Section 1
00101 above, provided that you also meet all of these conditions:
00102 
00103     a) You must cause the modified files to carry prominent notices
00104     stating that you changed the files and the date of any change.
00105 
00106     b) You must cause any work that you distribute or publish, that in
00107     whole or in part contains or is derived from the Program or any
00108     part thereof, to be licensed as a whole at no charge to all third
00109     parties under the terms of this License.
00110 
00111     c) If the modified program normally reads commands interactively
00112     when run, you must cause it, when started running for such
00113     interactive use in the most ordinary way, to print or display an
00114     announcement including an appropriate copyright notice and a
00115     notice that there is no warranty (or else, saying that you provide
00116     a warranty) and that users may redistribute the program under
00117     these conditions, and telling the user how to view a copy of this
00118     License.  (Exception: if the Program itself is interactive but
00119     does not normally print such an announcement, your work based on
00120     the Program is not required to print an announcement.)
00121 
00122 These requirements apply to the modified work as a whole.  If
00123 identifiable sections of that work are not derived from the Program,
00124 and can be reasonably considered independent and separate works in
00125 themselves, then this License, and its terms, do not apply to those
00126 sections when you distribute them as separate works.  But when you
00127 distribute the same sections as part of a whole which is a work based
00128 on the Program, the distribution of the whole must be on the terms of
00129 this License, whose permissions for other licensees extend to the
00130 entire whole, and thus to each and every part regardless of who wrote it.
00131 
00132 Thus, it is not the intent of this section to claim rights or contest
00133 your rights to work written entirely by you; rather, the intent is to
00134 exercise the right to control the distribution of derivative or
00135 collective works based on the Program.
00136 
00137 In addition, mere aggregation of another work not based on the Program
00138 with the Program (or with a work based on the Program) on a volume of
00139 a storage or distribution medium does not bring the other work under
00140 the scope of this License.
00141 
00142   3. You may copy and distribute the Program (or a work based on it,
00143 under Section 2) in object code or executable form under the terms of
00144 Sections 1 and 2 above provided that you also do one of the following:
00145 
00146     a) Accompany it with the complete corresponding machine-readable
00147     source code, which must be distributed under the terms of Sections
00148     1 and 2 above on a medium customarily used for software interchange; or,
00149 
00150     b) Accompany it with a written offer, valid for at least three
00151     years, to give any third party, for a charge no more than your
00152     cost of physically performing source distribution, a complete
00153     machine-readable copy of the corresponding source code, to be
00154     distributed under the terms of Sections 1 and 2 above on a medium
00155     customarily used for software interchange; or,
00156 
00157     c) Accompany it with the information you received as to the offer
00158     to distribute corresponding source code.  (This alternative is
00159     allowed only for noncommercial distribution and only if you
00160     received the program in object code or executable form with such
00161     an offer, in accord with Subsection b above.)
00162 
00163 The source code for a work means the preferred form of the work for
00164 making modifications to it.  For an executable work, complete source
00165 code means all the source code for all modules it contains, plus any
00166 associated interface definition files, plus the scripts used to
00167 control compilation and installation of the executable.  However, as a
00168 special exception, the source code distributed need not include
00169 anything that is normally distributed (in either source or binary
00170 form) with the major components (compiler, kernel, and so on) of the
00171 operating system on which the executable runs, unless that component
00172 itself accompanies the executable.
00173 
00174 If distribution of executable or object code is made by offering
00175 access to copy from a designated place, then offering equivalent
00176 access to copy the source code from the same place counts as
00177 distribution of the source code, even though third parties are not
00178 compelled to copy the source along with the object code.
00179 
00180   4. You may not copy, modify, sublicense, or distribute the Program
00181 except as expressly provided under this License.  Any attempt
00182 otherwise to copy, modify, sublicense or distribute the Program is
00183 void, and will automatically terminate your rights under this License.
00184 However, parties who have received copies, or rights, from you under
00185 this License will not have their licenses terminated so long as such
00186 parties remain in full compliance.
00187 
00188   5. You are not required to accept this License, since you have not
00189 signed it.  However, nothing else grants you permission to modify or
00190 distribute the Program or its derivative works.  These actions are
00191 prohibited by law if you do not accept this License.  Therefore, by
00192 modifying or distributing the Program (or any work based on the
00193 Program), you indicate your acceptance of this License to do so, and
00194 all its terms and conditions for copying, distributing or modifying
00195 the Program or works based on it.
00196 
00197   6. Each time you redistribute the Program (or any work based on the
00198 Program), the recipient automatically receives a license from the
00199 original licensor to copy, distribute or modify the Program subject to
00200 these terms and conditions.  You may not impose any further
00201 restrictions on the recipients' exercise of the rights granted herein.
00202 You are not responsible for enforcing compliance by third parties to
00203 this License.
00204 
00205   7. If, as a consequence of a court judgment or allegation of patent
00206 infringement or for any other reason (not limited to patent issues),
00207 conditions are imposed on you (whether by court order, agreement or
00208 otherwise) that contradict the conditions of this License, they do not
00209 excuse you from the conditions of this License.  If you cannot
00210 distribute so as to satisfy simultaneously your obligations under this
00211 License and any other pertinent obligations, then as a consequence you
00212 may not distribute the Program at all.  For example, if a patent
00213 license would not permit royalty-free redistribution of the Program by
00214 all those who receive copies directly or indirectly through you, then
00215 the only way you could satisfy both it and this License would be to
00216 refrain entirely from distribution of the Program.
00217 
00218 If any portion of this section is held invalid or unenforceable under
00219 any particular circumstance, the balance of the section is intended to
00220 apply and the section as a whole is intended to apply in other
00221 circumstances.
00222 
00223 It is not the purpose of this section to induce you to infringe any
00224 patents or other property right claims or to contest validity of any
00225 such claims; this section has the sole purpose of protecting the
00226 integrity of the free software distribution system, which is
00227 implemented by public license practices.  Many people have made
00228 generous contributions to the wide range of software distributed
00229 through that system in reliance on consistent application of that
00230 system; it is up to the author/donor to decide if he or she is willing
00231 to distribute software through any other system and a licensee cannot
00232 impose that choice.
00233 
00234 This section is intended to make thoroughly clear what is believed to
00235 be a consequence of the rest of this License.
00236 
00237   8. If the distribution and/or use of the Program is restricted in
00238 certain countries either by patents or by copyrighted interfaces, the
00239 original copyright holder who places the Program under this License
00240 may add an explicit geographical distribution limitation excluding
00241 those countries, so that distribution is permitted only in or among
00242 countries not thus excluded.  In such case, this License incorporates
00243 the limitation as if written in the body of this License.
00244 
00245   9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time.  Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
00246 
00247 Each version is given a distinguishing version number.  If the Program
00248 specifies a version number of this License which applies to it and "any
00249 later version", you have the option of following the terms and conditions 
00250 either of that version or of any later version published by the Free Software 
00251 Foundation.  If the Program does not specify a version number of this License,
00252  you may choose any version ever published by the Free Software Foundation.
00253 
00254   10. If you wish to incorporate parts of the Program into other free
00255 programs whose distribution conditions are different, write to the author to 
00256 ask for permission.  For software which is copyrighted by the Free Software 
00257 Foundation, write to the Free Software Foundation; we sometimes make 
00258 exceptions for this.  Our decision will be guided by the two goals of 
00259 preserving the free status of all derivatives of our free software and of 
00260 promoting the sharing and reuse of software generally.
00261 
00262                             NO WARRANTY
00263 
00264   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
00265 THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN 
00266 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE 
00267 THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, 
00268 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
00269 FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND 
00270 PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, 
00271 YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
00272 
00273   12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 
00274 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 
00275 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 
00276 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 
00277 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO 
00278 LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR 
00279 THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 
00280 EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
00281 DAMAGES.
00282 
00283                      END OF TERMS AND CONDITIONS
00284 */
00285 static const char* Copyright= "(C) Copyright Michigan State University 2002, All rights reserved";/*
00286 ** Ported to Linux and CES/CBD 8210 device driver.
00287 ** At present, the preprocessor symbol __unix__ is used to switch on/off
00288 ** Linux/unix specific  code. #ifndef for it is used to switch off VME 
00289 ** 68K specific code.
00290 **   >>>>This module must be compiled without optimization<<<<
00291 **      Ron Fox
00292 **      January 28, 1999
00293 */
00294 
00295 
00296 /*
00297 **++
00298 **  FACILITY:
00299 **
00300 **      Data acquisition system.
00301 **
00302 **  ABSTRACT:
00303 **
00304 **      skeleton.c  - This file contains an upper level readout skeleton.
00305 **                      This skeleton is called from the evtuser.c skeleton
00306 **                      at even more confined locations than evtuser.c  The
00307 **                      user here is providing routines that tyipcally just do
00308 **                      CAMAC operations and not much else.
00309 **                      Users performing tailoring should read carefully
00310 **                      the areas which begin with the text:
00311 **
00312 **                      INSTRUCTIONS:
00313 **                      -------------
00314 **
00315 **  AUTHORS:
00316 **
00317 **      Ron Fox
00318 **
00319 **
00320 **  CREATION DATE:      6-Mar-1990
00321 **
00322 **  MODIFICATION HISTORY:
00323 **
00324 **--
00325 */
00326 
00327 
00328 /*
00329 **
00330 **  
00331 INCLUDE FILES
00332 **
00333 */
00334 
00335 
00336 #include <stdio.h>
00337 #include <string>
00338 #include <tcl.h>
00339 
00340 #include <TCLInterpreter.h>
00341 #include <TCLVariable.h>
00342 #include <TCLException.h>
00343 #include <CNullBusy.h>
00344 #include <ReadoutStateMachine.h>
00345 #include <Active.h>
00346 
00347 #include "CDigitizerDictionary.h"
00348 #include "CReadOrder.h"
00349 #include "CModuleCommand.h"
00350 #include "CCAENV785Creator.h"
00351 #include "CCAENV792Creator.h"
00352 #include "CCAENV775Creator.h"
00353 #include "CAENcard.h"
00354 
00355 #include "CCAENV830.h"
00356 #include "CCAENV830Creator.h"
00357 #include "CCAENV830Module.h"
00358 
00359 #ifndef __unix__
00360 #include "cpus.h"
00361 #endif
00362 
00363 #ifdef __unix__
00364 #include <stdlib.h>
00365 #include <daqinterface.h>
00366 #include <spectrodaq.h>
00367 #endif
00368 
00369 #include <daqdatatypes.h>
00370 #include <camac.h>
00371 #include <macros.h>
00372 
00373 #ifdef VME16
00374 #undef VME16
00375 #endif
00376 #if CPU == MICROPROJECT
00377 #define VME16 0 
00378 #endif
00379 
00380 #ifndef __unix__
00381 #include <vme.h>
00382 #endif
00383 #include <buftypes.h>
00384 
00385 /* Short circuit run time evaluation of constant BCNAF's */
00386 
00387 #ifdef __unix__
00388 #include <camac.h>
00389 #else
00390 #if CPU == IRONICS
00391 #undef CAMBAS
00392 #define CAMBAS(b)       0xFA800000
00393 #endif
00394 
00395 #if CPU == MICROPROJECT
00396 #undef CAMBAS
00397 #define CAMBAS(b)       0xFE800000
00398 #endif
00399 #endif
00400 
00401 #include <iostream.h>
00402 #include <CAENcard.h>
00403 
00404 #define SEE_PACKETID   0x8000     // SEE Packet id from Bazin.
00405 
00406 
00407 /*
00408 **  INSTRUCTIONS:
00409 **  -------------
00410 **                          Introduction
00411 **
00412 **      There are several functions that the user is supposed to fill in
00413 **      to tailor this skeleton for a particular experiment.  While the
00414 **      skeleton is written in C, several extensions to the C language have
00415 **      been defined to bring the syntax closer to FORTRAN.  One thing you must
00416 **      be aware of, however is that C is case sensitive, that is, 'if' and
00417 **      'IF' are completely different from each other and 'If'.
00418 **
00419 **                          Functions to fill in:
00420 **
00421 **      The following are the set of functions that need to be filled in:
00422 **
00423 **      Function    Meaning             When Called
00424 **      initevt     Init event readout  Power up Begin run and Resume Run.
00425 **      clrtrig1    Clr trig1 readout   Power up, Begin, resume, end of trig1.
00426 **      iniscl      Init scalers.       Power up Begin run and Resume Run.
00427 **      clearevt    Clear evt readout   Power up, Begin, Resume, end of event.
00428 **      clrtrig1    Clr trig1 readout   Power up, Begin, resume, end of trig1.
00429 **      clrscl      Clear scaler readout Power up, Begin, Resume, end of scaler
00430 **      readevt     Read an event       Event trigger.
00431 **      readscl     REad scaler event   Scaler time.
00432 **      trig1ena    Enable trigger 1    Begin run, resume run.
00433 **      trig1dis    Disable trigger1    End run
00434 **      rdtrig1     Readout for trig 1  User trigger 1 fires.
00435 **      evtmax      Max size of event   Begin run time.
00436 **      trig1max    Max words in trig1  Begin run time.
00437 **
00438 **                      Language elements:
00439 **          Statements:
00440 **      Statements can occur anywhere on a line there can even be multiple
00441 **      statements on a single line. The end of a statement is flagged with
00442 **      a semicolon.  The following are legal statements:
00443 **
00444 **              a = b;
00445 **              camwrite16(0,1,29,0,16,1234);
00446 **
00447 **          Variables:
00448 **      Variables must be declared at the beginning of a function.
00449 **      C variables are the native type, however, the following FORTRAN
00450 **      style variable declarations are supported via definitions in 
00451 **      macros.h
00452 **
00453 **          LOGICAL     - Takes the values TRUE or FALSE
00454 **          WORD        - INTEGER*2 sized word.
00455 **          INTEGER     - INTEGER*4 sized lognword.
00456 **          REAL        - REAL*4 sized real.
00457 **
00458 **      Arrays may be declared, subscripts always go from 0:size-1. In C
00459 **      subscripts are in square brackets not rounded ones. The following
00460 **      are legal variable declarations:
00461 **
00462 **          LOGICAL flag;
00463 **          INTEGER i,j,k[10];
00464 **      Note in the above, the declaration of k is identical to the FORTRAN
00465 **      declaration:
00466 **
00467 **          INTEGER*4 k(0:9)
00468 **
00469 **      Multidimensional arrays are also allowed, but the syntax is a bit
00470 **      different:
00471 **          IINTEGER twod[5][6];
00472 **
00473 **      In C, the last dimension runs sequentially in memory rather than
00474 **      the first (reverse of fortran), and array references require both
00475 **      dimensions to be used as in the declaration e.g., to fill the
00476 **      array above:
00477 **         
00478 **               for(j = 0; j < 5; j++) 
00479 **                  for(i = 0; i < 6; i++)
00480 **                     twod[j][i] = i+j;
00481 **         
00482 **          Expressions:
00483 **      The only FORTRAN operators not allowed are exponentiation (**).
00484 **      the following is a subset of the operators supported:
00485 **          + - * / AND OR EQ NE GT GE LT LE
00486 **      The following assignment statement is an example of an expression:
00487 **          LOGICAL   flag;
00488 **          INTEGER   i1,i2,i3,i4;
00489 **              ...
00490 **          flag = (i1)/(i1+i2) LT (i3+i4)
00491 **
00492 **      Note that operators (e.g. LT above) are case sensitive.
00493 **      Bitwise operator functions IAND, IOR, ISHIFT are defined like in FORTRAN
00494 **      Hexadecimal constants are allowed and the syntax is 0xNNN where NNN is
00495 **      the constant.
00496 **
00497 **          Flow of control:
00498 **
00499 **      The following statements can control the flow of a program.
00500 **              IF
00501 **
00502 **      IF(expresson) <statement>;
00503 **
00504 **              BLOCK IF with optional ELSE clause:
00505 **
00506 **      IF(expression) THEN
00507 **          <statements with trailing ';'s>
00508 **      [ELSE 
00509 **          <statements with trailing ';'s>
00510 **      ]ENDIF
00511 **
00512 **              Top tested DO WHILE loop:
00513 **
00514 **      DO WHILE(expression)
00515 **          <statements>;
00516 **      ENDDO
00517 **
00518 **                  Buffer manipulation:
00519 **      The following functions manipulate the buffer:
00520 **
00521 **      putbufw(w)      - Put w, a 16 bit word to buffer.
00522 **      putbufl(l)      - Put l, a 32 bit longword to the buffer in VAX word 
00523 **                        order.
00524 **
00525 **                  CAMAC operations:
00526 **
00527 **      In the discussion below, b= branch number 0-7, c = crate number 1-7,
00528 **      n = CAMAC slot, a = CAMAC subaddress, f = CAMAC function code.
00529 **      d = CAMAC data transfered.
00530 **      CAMAC operations are implemented as 'pseudo functions' which are
00531 **      expanded in line and hence quite fast (~3usec per transaction).
00532 **
00533 **      camread16(b,c,n,a,f)    - Returns a 16 bit value read from CAMAC
00534 **      camread24(b,c,n,a,f)    - Returns a 24 bit value read from CAMAC format
00535 **                                is 68K format.
00536 **      camwrite16(b,c,n,a,f,d) - Write least significant 16 bits of d to CAMAC
00537 **      camwrite24(b,c,n,a,f,d) - Write least significate 24 bits of d to CAMAC
00538 **      camctl(b,c,n,a,f)       - Perform non data transfer CAMAC cycle.
00539 **      rdtobuf16(b,c,n,a,f)    - Do 16 bit CAMAC read into buffer.
00540 **      rdtobuf24(b,c,n,a,f)    - Do 24 bit CAMAC read into buffer (VAX format).
00541 **      qtst(b)                 - TRUE if most recent CAMAC operation on 
00542 **                                given branch set Q
00543 **      xtst(b)                 - Same as qtst, but tests X status.
00544 **
00545 **              More complex pseudo functions:
00546 **
00547 **      qstop(b,c,n,a,f)        - Performs a Q stop block read into buffer.
00548 **      branchinit(b)           - Initialize branch controller.
00549 **      crateinit(b,c)          - C/Z/Uninhibit crate.
00550 **
00551 **              LAM waiting:
00552 **
00553 **      The Pseudo functions below set up to do LAM busy waiting on a bit
00554 **      register decode:
00555 **
00556 **      BEGINLAM(numbr, numcr)  - Begin LAM mask buildup:
00557 **                                      numbr   - Number of branches involved
00558 **                                                in LAM wait process.
00559 **                                      numcr   - Highest crate number involved
00560 **                                                in LAM wait process.
00561 **      ENDLAM                  - End LAM mask processing.
00562 **      READBIT(b,c,n,a,f,d)    - Read a pattern register pattern register
00563 **                                is put in buffer and in WORD variable
00564 **                                d
00565 **      NEEDLAM(b,c,n)          - Indicate that LAM from given slot is needed.
00566 **      IFTIMEOUT(maxloop)      - Loops maxloop times (>10us/pass) waiting for
00567 **                                lams.  THen looks like IF statment, but
00568 **                                condition is that a timeout has occured.
00569 **      Example use of bit register functions:
00570 **
00571 **      LOGICAL timeout;
00572 **      WORD    brg;
00573 **      ..
00574 **      READDBIT(0,1,20,0,0,brg);
00575 **          ..
00576 **      BEGINLAM
00577 **        IF(IAND(brg, 0x1))NEEDLAM(0,2,3);
00578 **        IF(IAND(brg, 0x2))NEEDLAM(0,2,4);
00579 **        if(IAND(brg, 0x3))NEEDLAM(0,2,5);
00580 **        IFTIMEOUT(100) THEN
00581 **          timeout = TRUE;
00582 **          ENDDO
00583 **        ELSE
00584 **          timeout = FALSE;
00585 **        ENDIF
00586 **      ENDLAM
00587 **
00588 **                  Device specific pseudoroutines:
00589 **      Several device specific in-line routines are defined to make the
00590 **  handling of more common devices easier.  Devices not supported in this set
00591 **  can be managed with the primitive CAMAC operations. NOTE: clear functions
00592 **  are provided for modules which can be front panel cleared just in case 
00593 **  there is the need to clear them from CAMAC as well.
00594 **
00595 **    See the header macros.h for more information.
00596 **
00597 **          User parameters:
00598 **
00599 **      The front end includes three pre-defined arrays:
00600 **
00601 **          INTEGER userints[]  - Front end integer parameters.
00602 **          LOGICAL userflags[] - Front end flag parameters
00603 **          REAL    userreals[] - Front end real paraemters.
00604 **
00605 ** End of instructions... but look for more later in the file.
00606 */
00607 extern INT16 second;
00608 extern ReadoutStateMachine* gpStateMachine;
00609 
00610 // The following objects constitute the configurable readout engine:
00611 
00612 CTCLInterpreter*      pInterp(0);       // TCL interpreter.
00613 CDigitizerDictionary* pDictionary(0);   // Dictionary of modules.
00614 CReadOrder*           pReader(0);       // The readout engine.
00615 CModuleCommand*       pCreator(0);      // Module creational. 
00616 CCAENV775Creator*     p775(0);          // Creator for V775.
00617 CCAENV785Creator*     p785(0);          // Creator for V785.
00618 CCAENV792Creator*     p792(0);          // Creator for V792.
00619 
00620 // The following constitute the configurable scaler readout engine.
00621 
00622 CDigitizerDictionary* pScalers(0);      // Dictionary of scaler modules
00623 CReadOrder*           pScalerRead(0);   // Reader for scalers.
00624 CModuleCommand*       pScalerCreator(0); // Creates scaler modules.
00625 CCAENV830Creator*     p830(0);          // Creates CAEN V830 scalers.
00630 void DestroyConfigurator()
00631 {
00632   // Clean up prior incarnations.
00633 
00634   // The Event readout infrastructure...
00635 
00637   //  a minor memory leak so they can run.
00638 
00639   // if(pInterp)     delete pInterp; // Causes deletion of objects too.
00640   // if(pCreator)    delete pCreator;
00641   // if(pReader)     delete pReader;
00642   // if(pDictionary) delete pDictionary;
00643   // if(p775)        delete p775;
00644   // if(p785)        delete p785;
00645   // if(p792)        delete p792;
00646 
00647 
00648   pCreator    = 0;
00649   pReader     = 0;
00650   pDictionary = 0;
00651   pInterp     = 0;
00652   p775        = 0;
00653   p785        = 0;
00654   p792        = 0;
00655 
00656 
00657   // The Scaler readout infrastructure
00658 
00659   //  if(pScalers)        delete pScalers;
00660   //  if(pScalerRead)     delete pScalerRead;
00661   //  if(pScalerCreator)  delete pScalerCreator;
00662   //   if(p830)            delete p830;
00663 
00664   pScalers       = 0;
00665   pScalerRead    = 0;
00666   pScalerCreator = 0;
00667   p830           = 0;
00668 
00669 }
00670 
00680 void InitializeConfigurator()
00681 {
00682   DestroyConfigurator();
00683 
00684   // Instantiate and link together new config system.
00685 
00686   // Make a new interpreter:
00687 
00688   pInterp = new CTCLInterpreter();
00689   Tcl_Init(pInterp->getInterpreter());
00690   pInterp->Eval("set Readout true"); // Indicate this is readout.
00691 
00692   // Create the readout module creation/readout infrastructure:
00693 
00694   pDictionary = new CDigitizerDictionary;
00695   pReader     = new CReadOrder(pInterp, pDictionary);
00696   pCreator    = new CModuleCommand(pInterp,
00697                                    pDictionary,
00698                                    pReader);
00699 
00700   // Register the event module creators with the module command:
00701 
00702   pCreator->AddCreator(p775 = new CCAENV775Creator);
00703   pCreator->AddCreator(p785 = new CCAENV785Creator);
00704   pCreator->AddCreator(p792 = new CCAENV792Creator);
00705   
00706 
00707   // Create the scaler module creation/readout infrastructure:
00708 
00709   pScalers       = new CDigitizerDictionary;
00710   pScalerRead    = new CReadOrder(pInterp, pScalers, 
00711                                   string("scalerbank"));
00712   pScalerCreator = new CModuleCommand(pInterp,
00713                                       pScalers,
00714                                       pScalerRead,
00715                                       string("scaler"));
00716 
00717   // Register the scaler modules with the scaler command.
00718 
00719   pScalerCreator->AddCreator(p830 = new CCAENV830Creator);
00720 
00721 }
00722 
00727 void SourceScript(CTCLInterpreter* pInterp, const string& rPath)
00728 {
00729   pInterp->EvalFile(rPath);
00730 }
00731 
00732 
00733 
00734 /*
00735 **++
00736 **  FUNCTIONAL DESCRIPTION:
00737 **
00738 **      initevt - This function contains code which indicates how to initialize
00739 **                the CAMAC system for event readout.
00740 **
00741 **
00742 **--
00743 */
00744 extern string    SetupFile;
00745 CNullBusy*       pBusy(0);
00746 
00747 void
00748 initevt ()
00749 {
00750 /*
00751 **  INSTRUCTIONS:
00752 **  -------------
00753 **
00754 **      Fill in the area below the end of these instructions, but before the
00755 **      curly bracket with code that initializes devices in the event readout
00756 **      section of the device.  Typically what's needed here is to first
00757 **      put all crates on-line and initialize them, and then to clear all
00758 **      digitizers and initialize any programmable devices.  If you have
00759 **      more than one branh highway (not just branch 0), you should initialize
00760 **      that as well before touching crates on that branch. The routine provided
00761 **      shows how to initialize two empty crates on branch 0.  This initializer
00762 **      is the first of the initializers called so it's not a bad idea to do
00763 **      all crate initializations here, unless the crates are functionally
00764 **      broken up.  A bit register is also initialized.  See the #define
00765 **      statments below to tailor the location of that bit register.
00766 **  End instructions... but watch for more further down */
00767 
00768   cerr << "Initializing Readout Engine\n";
00769   InitializeConfigurator();
00770 
00771                            
00772 
00773   try {
00774     cerr << "Processing setup file: " << SetupFile << endl;
00775     SourceScript(pInterp, SetupFile);
00776 
00777     pReader->Initialize();      // config modules.
00778     pReader->Clear();           // Always clear at start.
00779 
00780   }
00781   catch (CTCLException except) {
00782     CTCLVariable traceback(pInterp,
00783                            string("errorInfo"),
00784                            false);
00785     cerr << "Error in configuration script: ";
00786     cerr << except.ReasonText() << endl;
00787     cerr << traceback.Get(TCL_GLOBAL_ONLY) << endl;
00788     cerr << "1. Stop the run\n";
00789     cerr << "2. Fix the setup file\n";
00790     cerr << "3. Start the run again\n";
00791     DestroyConfigurator();
00792     return;
00793   }
00794   catch (string except) {
00795     cerr << "An exception was caught probably while";
00796     cerr << "Initalizing a module:\n";
00797     cerr << "   " << except << endl;
00798     cerr << "1.   Stop the run\n";
00799     cerr << "2.   Correct the setup file\n";
00800     cerr << "3.   Start the run again\n";
00801     DestroyConfigurator();
00802     return;
00803   }
00804   catch (...) {
00805     cerr << "An unexpected exception was caught in ";
00806     cerr << "initevt().  Probably there's an unforeseen ";
00807     cerr << "problem in your configuration script.\n";
00808     cerr << "Sorry I can't be more specific.\n";
00809     cerr << "   1. Stop the run\n";
00810     cerr << "   2. Examine the configuration script carefully\n";
00811     cerr << "   3. Fix any errors you find.\n";
00812     cerr << "   4. Start the run again.\n";
00813     DestroyConfigurator();
00814     return;
00815 
00816   }
00817 
00818 }
00819 
00820 
00821 
00822 /*
00823 /*
00824 **++
00825 **  FUNCTIONAL DESCRIPTION:
00826 **
00827 **      initrig1    - This section should be filled in to initialize CAMAC
00828 **                    modules associated with user trigger 1.
00829 **
00830 **--
00831 */
00832 void
00833 initrig1 ()
00834 {
00835 
00836 /*
00837 **  Instructions:
00838 **  -------------
00839 **
00840 **      The section of code between the end of this comment and the the }
00841 **      should be filled in with code that initializes all hardware associated
00842 **      with user trigger1.  This trigger SHOULD NOT BE ENABLED AT THIS TIME
00843 **      since this routine is called at power up as well as at run start.
00844 **      The trigger should only be enabled in trig1ena().
00845 **      The sample provided takes no action to initialize trigger 1.
00846 ** End of instructions, but there's more later...                   */
00847 
00848     
00849 }
00850 
00851 
00852 
00853 /*
00854 **++
00855 **  FUNCTIONAL DESCRIPTION:
00856 **
00857 **      iniscl  - Initialize scaler readout.
00858 **
00859 **
00860 **  IMPLICIT INPUTS:
00861 **
00862 **      The special variable numscalers is the number of scalers.
00863 **
00864 **--
00865 */
00866 void
00867 iniscl ()
00868 {
00869 /*
00870 **  Instructions:
00871 **  -------------
00872 **      This function is called to intialize all scaler modules in the
00873 **      system.  There is a pre-declared variable 'numscalers' which 
00874 **      contains the number of scalers in the system.  The sample code below
00875 **      is written to deal with either a block of 12 channel scalers (LRS2551)
00876 **      or a block of 32 channel scalers (LRS4434), depedning on the definition
00877 **      of the constant SCALER_CHANNELS.  If SCALER_CHANNELS is 12, then
00878 **      code is generated for LRS2551, if SCALER_CHANNELS is 32, then for
00879 **      LRS4434.  Several notes:
00880 **          1. The code below demonstrates the use of C's #define statement
00881 **             for generating symbolic constants (like FORTRAN parameters).
00882 **             Note that #defines must start in column 1.
00883 **          2. The code below demonstrates the use of C's #if statement to
00884 **             do conditional compilation.  There is a big difference between
00885 **            #if and IF. #if controls what code is generated, while
00886 **            IF controls what code is executed.  The false side of the
00887 **            #if statement doesn't exist and therefore cannot be used
00888 **            to do run time control flow.
00889 **          3. If all the user wants to do is modify the starting scaler,
00890 **            or the type of scaler, then the definitions below are all
00891 **            that need to be changed.  More complex changes require coding.
00892 **          4.The % operator is the modulus operator, that is (a % b) is the
00893 **            same as FORTRAN's MOD(A,B).
00894 **          5. Advanced note. #define creates things called MACRO's a MACRO
00895 **             is a stored series of text which is expanded in line when it
00896 **             is invoked.  MACROs can have parameters just like functions
00897 **             and this is how the psuedo functions and FORTRAN like syntax
00898 **             has been layered on to C.  For example, if you would like
00899 **             to define a FORTRAN like MOD pseudo function, then:
00900 **             12345678901234567890123456789012345678901234567890 <- Column
00901 **             #define MOD(a,b)  ((a) % (b))
00902 **  End of instructions for now...                                  */
00903 
00904 
00905 
00906   try {
00907     if(pScalerRead) {
00908       pScalerRead->Initialize();
00909       pScalerRead->Clear();
00910       
00911       // Figure out how many scalers we have and set the scaler count.
00912       
00913       char buffer[8192];
00914       int nWords = pScalerRead->Read(buffer); //  do a test read.
00915       daq_SetScalerCount(nWords*sizeof(short)/sizeof(long));
00916       pScalerRead->Clear();
00917     }
00918   }
00919   catch (CTCLException except) {
00920     CTCLVariable traceback(pInterp,
00921                            string("errorInfo"),
00922                            false);
00923     cerr << "Error in configuration script: ";
00924     cerr << except.ReasonText() << endl;
00925     cerr << traceback.Get(TCL_GLOBAL_ONLY) << endl;
00926     cerr << "1. Stop the run\n";
00927     cerr << "2. Fix the setup file\n";
00928     cerr << "3. Start the run again\n";
00929     DestroyConfigurator();
00930     return;
00931   }
00932   catch (string except) {
00933     cerr << "An exception was caught probably while";
00934     cerr << "Initalizing a module:\n";
00935     cerr << "   " << except << endl;
00936     cerr << "1.   Stop the run\n";
00937     cerr << "2.   Correct the setup file\n";
00938     cerr << "3.   Start the run again\n";
00939   }
00940   catch (...) {
00941     cerr << "An unexpected exception was caught in ";
00942     cerr << "initevt().  Probably there's an unforeseen ";
00943     cerr << "problem in your configuration script.\n";
00944     cerr << "Sorry I can't be more specific.\n";
00945     cerr << "   1. Stop the run\n";
00946     cerr << "   2. Examine the configuration script carefully\n";
00947     cerr << "   3. Fix any errors you find.\n";
00948     cerr << "   4. Start the run again.\n";
00949     DestroyConfigurator();    
00950   }
00951 
00952 
00953 }
00954 
00955 
00956 /*
00957 **++
00958 **  FUNCTIONAL DESCRIPTION:
00959 **
00960 **      clearevt    - Clear user events.
00961 **
00962 **
00963 **--
00964 */
00965 void
00966 clearevt ()
00967 {
00968 /*
00969 **  Instructions:
00970 **  -------------
00971 **      This routine should be filled in with the actions needed to clear
00972 **      all digitizers associated with the primary event.  Note that after
00973 **      the readout, of an event, a standard NIM-out is written to with all
00974 **      1's.  This is done in time suitable for clearing devices with front
00975 **      panel clears.  The user need not clear devices which are cleared via
00976 **      this signal.
00977 **      The sample code does nothing.
00978 **  End of instructions... but there's more.                */
00979     
00980   if(pReader)
00981     pReader->Prepare();
00982 }
00983 
00984 
00985 
00986 /*
00987 **++
00988 **  FUNCTIONAL DESCRIPTION:
00989 **
00990 **      clrtrig1    - This function is called when a user 1 trigger read out is 
00991 **                    complete.
00992 **
00993 **
00994 **--
00995 */
00996 void
00997 clrtrig1 ()
00998 {
00999 /*
01000 **  Instructions:
01001 **  -------------
01002 **      This function is called to clear the user1 trigger devices.  This
01003 **      should not be used to disable triggers, since we are called at the end
01004 **      of every trigger 1 event.  The entry trig1dis should be used instead.
01005 **      Note when clearing trigger 1 devices, it is assumed that there need not
01006 **      be any connection between trigger 1 and the 'event' trigger.  Therefore,
01007 **      the front panel NIM out clear register is not written to by the uppler
01008 **      levels of the system and must be written to by the user if that's 
01009 **      desired.
01010 **          The sample code below does nothing.
01011 **      End of Instructions for now...                                      */ 
01012     
01013 }
01014 
01015 
01016 
01017 /*
01018 **++
01019 **  FUNCTIONAL DESCRIPTION:
01020 **
01021 **      clrscl  - Clear scalers
01022 **
01023 **
01024 **--
01025 */
01026 void
01027 clrscl ()
01028 {
01029 /*
01030 **  Instructions:
01031 **  -------------
01032 **      This function is called to clear the scalers following readout, on 
01033 **      run start and on run resume.  The sample code below is intended for 
01034 **      use with the sample code given in iniscl(), that is we can deal
01035 **      with either a contiguous block of 32 or 12 channel scalers.
01036 **  End of instructions for now....                             */
01037 
01038   if(pScalerRead) {
01039     pScalerRead->Prepare();
01040   }
01041     
01042 }
01043 
01044 
01045 /*
01046 **++
01047 **  FUNCTIONAL DESCRIPTION:
01048 **
01049 **      readevt - This function is called to read an event.
01050 **
01051 **  FORMAL PARAMETERS:
01052 **
01053 **      INT16 *bufpt    - Pointer to buffer to fill.
01054 **
01055 **
01056 **  FUNCTION VALUE:
01057 **
01058 **      Number of words read.
01059 **
01060 **--
01061 */
01062 WORD
01063 #ifdef __unix__
01064 readevt (DAQWordBufferPtr& bufpt)
01065 #else 
01066 readevt (WORD* bufpt)
01067 #endif
01068 {
01069 #ifdef __unix__
01070     DAQWordBufferPtr _sbufpt = bufpt;
01071 #else
01072     WORD *_sbufpt = bufpt;
01073 #endif
01074     LOGICAL reject;
01075 
01076     reject   = FALSE;
01077     {    
01078 /*------------------------- Begin user code. ----------------------------*/
01079 /*
01080 **  Instructions:
01081 **  -------------
01082 **      This routine must be filled in with code that indicates how to perform
01083 **      the event readout.  Digitizers need not be cleared after readout,
01084 **      that's done by a call back down here to clearevt().  Some points of
01085 **      interest:
01086 **          1. the predefined array _sbufpt can be used to reference the
01087 **             buffer after words have been read, that is, _sbufpt[0] is
01088 **             the first word you read.
01089 **          2. The predefined logical variable reject can be set to TRUE to
01090 **             inform the system that the event is to be thrown away.
01091 **          3. The data the user reads will be prefaced by the system with
01092 **             a word count.
01093 **          The sample code below is a skeleton which cracks a single 16
01094 **          bit register, waits for indicated lams for each bit and then
01095 **          does the read out on the set bits in the register.  If a LAM timeout
01096 **          occured, then the top bit of the bit register is set in the buffer
01097 **          and the readout procedes.  Note the use of #defines to tailor
01098 **          the location of the bit register, the LAM's expected for each bit,
01099 **          and the bits that are actually used in the register.
01100 **          Note how conditional compilation is used to remove tests for bits
01101 **          which are not used by the experiment.
01102 **          Note the use of the pre-defined 2-d array _lammsk in the LAM
01103 **          decoding code below.  Setting the bits all at once is faster
01104 **          than one at a a time (via NEEDLAM).  Note also the difference
01105 **          in the way C addresses 2-d arrays.  The predefined array _lammsk
01106 **          is an array of branch/crate lam masks.
01107 **  End of instructions for now...                              */
01108 
01109       if(pReader) {
01110         VPacket(SEE_PACKETID);
01111         bufpt = pReader->Read(bufpt);
01112         EndVPacket;
01113       }
01114 
01115 
01116 /*-------------------------  End of user code. ---------------------------*/
01117 }
01118     IF(reject) return 0;
01119 #ifdef __unix__
01120     return bufpt.GetIndex() - _sbufpt.GetIndex();
01121 #else
01122     return (bufpt - _sbufpt);
01123 #endif
01124 }
01125 
01126 
01127 
01128 /*
01129 **++
01130 **  FUNCTIONAL DESCRIPTION:
01131 **
01132 **      readscl  - Read out scalers.
01133 **
01134 **  FORMAL PARAMETERS:
01135 **
01136 **      UINT32 *bufpt           - buffer pointer.
01137 **      int numscalers          - Number of scalers to read out.
01138 **
01139 
01140 **
01141 **
01142 **--
01143 */
01144 UINT16
01145 readscl (UINT32* buffer,int numscalers)
01146 {
01147     UINT32* _sbufpt = buffer;
01148     UINT16*  bufpt  = (UINT16*)buffer;
01149 
01150 
01151 
01152     {
01153 /*
01154 **  Instructions:
01155 **  -------------
01156 **
01157 **      This section of code must be filled in to read out scalers into a buffer
01158 **      provided by the caller.  The special predeclared array INTEGER _sbufpt[]
01159 **      allows access to the buffer contents by longword number.
01160 **      The sample code below continues the examples of scaler handling shown
01161 **      so far.  If 12 channel scalers are used, we read them out assuming
01162 **      that we've got a contiguous block of them.
01163 **      If 32 channel scalers are used, then we use them instead.
01164 **      The predefined INTEGER numscalers is the number of scaler channels
01165 **      to be read out (set by SET SCALERS command).
01166 **        NOTES:
01167 **          1. After the scalers have been read out, the upper levels of code
01168 **              will call the scaler clear routine so it is not necessary
01169 **              to clear scalers at this level.
01170 **          2.  Do not molest the code below the dashed line as it is necessary
01171 **              to the correct operation of the system.
01172 ** End of instructions for now:                         */
01173 
01174  
01175       if(pScalerRead) {
01176         int nWords = pScalerRead->Read(buffer);
01177         bufpt +=  nWords;
01178       }
01179 
01180 
01181 /*-------------------------------END USER CODE ---------------------------*/
01182     }
01183 
01184 
01185 
01186     
01187      
01188     return (UINT16)((UINT32)bufpt - (UINT32)_sbufpt);
01189 }
01190 
01191 
01192 
01193 /*
01194 **++
01195 **  FUNCTIONAL DESCRIPTION:
01196 **
01197 **      trig1dis    - Disable trigger 1 triggers.
01198 **
01199 **
01200 **--
01201 */
01202 void
01203 trig1dis ()
01204 {
01205 
01206 /*
01207 ** NOTE:
01208 **    >>>>User triggers are not supported in the UNIX readout system<<<<
01209 **  Instructions:
01210 **  -------------
01211 **      The code below is used to turn off user triggers.  At present, the only
01212 **      sort of user triggers supported are time periodic user triggers for
01213 **      user trigger 1.  User triggers are intended to trigger readout events
01214 **      that are not necessarily part of the normal set of event triggers.
01215 **      These might be triggers to readout calibration systems or other
01216 **      monitoring systems.
01217 **        The sample code below is compiled if the #define for USERTRIG1_ENABLE
01218 **      is set to be true.  In that case, the frequency and eventy type produced
01219 **      for user triggers is controlled by the #define statements for
01220 **      USER1_PERIOD    (INTEGER seconds between triggers) and:
01221 **
01222 **  End of instructions for now:    */
01223 
01224 #ifndef __unix__
01225 #define USERTRIG1_ENABLE        FALSE           /* TRUE if triggers desired */
01226 #define USERTRIG1_PERIOD        -1              /* Seconds between triggers */
01227 
01228 #if USERTRIG1_ENABLE
01229 
01230     STOPUSR1TRIG();
01231     
01232 #endif
01233 #endif
01234 }
01235 
01236 
01237 
01238 /*
01239 **++
01240 **  FUNCTIONAL DESCRIPTION:
01241 **
01242 **      trig1ena    - This function is called when user triggers are to be
01243 **                    enabled.
01244 **
01245 **
01246 **--
01247 */
01248 void
01249 trig1ena ()
01250 {
01251 /*
01252 **  NOTE:
01253 **     >>>>User triggers are not supported in the UNIX environment<<<<
01254 **  Instructions:
01255 **  -------------
01256 **      This section of code should be filled in to enable user triggers.
01257 **  The sample code continues the example begun for trig1dis.
01258 **  End of instructions for now:        */
01259 #ifndef __unix__
01260 INTEGER period;
01261 
01262 
01263 #if USERTRIG1_ENABLE
01264     IF(USERTRIG1_PERIOD LE 0) THEN
01265         msg("FATAL - Trigger frequency less than zero in trig1ena()");
01266         newline; newline;
01267         die();
01268     ENDIF
01269 
01270     STARTUSR1TRIG(USERTRIG1_PERIOD);
01271 
01272 #endif
01273 #endif
01274 }
01275 
01276 
01277 
01278 /*
01279 **++
01280 **  FUNCTIONAL DESCRIPTION:
01281 **
01282 **      rdtrig1 - Read out a user trigger.
01283 **
01284 **  FORMAL PARAMETERS:
01285 **
01286 **      INT16 *buffer   - Pointer to buffer to readout.
01287 **
01288 */
01289 int 
01290 rdtrig1 (WORD* bufpt)
01291 {
01292     WORD *_sbufpt;
01293 
01294     _sbufpt = bufpt;
01295     {
01296 /*
01297 **  NOTE:
01298 **    >>>>The UNIX environment does not support user triggers <<<<
01299 **  Instructions:
01300 **  -------------
01301 **      This area should be filled in with code that manages the readout of a
01302 **      user 1 trigger.  The sample code below assumes that if user triggers are
01303 **      enabled, you will want to trigger an action via setting a bit in a NIM
01304 **      out register. 
01305 **        The default event type of the event being read out
01306 **      is USERBUF1 (32).  If not data is read into the buffer, then no event
01307 **      is generated.  Similarly, if the function returns the value zero, then
01308 **      no event is generated.
01309 **      NOTE:
01310 **          1.  The special variable bufpt is a 'pointer' to the event buffer.
01311 **          2.  As before, the predeclared variable WORD _sbufpt[] gives
01312 **              you a way to modify the buffer after readout (e.g. put in
01313 **              a special bit in the bit register.
01314 **          3.  The defines for NIMOUT_xxx allow the CAMAC location of the
01315 **              nimout to be defined, as well as the bit that's actually
01316 **              fired off.
01317 **  End of instructions for now...                  */
01318 #ifndef __unix__
01319 #define NIMOUT_BRANCH   0                           /* Branch nimout is in */
01320 #define NIMOUT_CRATE    2                           /* Crate nimout is in. */
01321 #define NIMOUT_SLOT     20                          /* Slot nimout lives in */
01322 #define NIMOUT_TRIG1    0x800                       /* Bit to set. */
01323 
01324 #if USERTRIG1_ENABLE
01325         NIMOUT(NIMOUT_BRANCH, NIMOUT_CRATE, NIMOUT_SLOT, NIMOUT_TRIG1);
01326 
01327 /* -------------------------- End user code. ----------------------- */
01328 #endif
01329 #endif
01330 
01331     }
01332     return (bufpt - _sbufpt);
01333 }
01334 
01335 
01336 
01337 /*
01338 **++
01339 **  FUNCTIONAL DESCRIPTION:
01340 **
01341 **      evtmax  - Returns the size of the largest physics event.
01342 **
01343 **  FUNCTION VALUE:
01344 **
01345 **      Largest number of words that can be read out by a physics trigger.
01346 ****--
01347 */
01348 WORD 
01349 evtmax ()
01350 {
01351 
01352 /*
01353 **  Instructions:
01354 **  -------------
01355 **      Fill in the #define below to indicate the size of the largest
01356 **      possible physics event in words.
01357 **  End of instructions for now...          */
01358 
01359 #define EVENT_MAXWORDS  40      /* Fill with correct size */
01360 
01361 /*------------------------------ end of user code  -----------------------*/
01362 
01363     IF (EVENT_MAXWORDS LE 0) THEN           /* We crash the program if the */
01364                                             /* user didn't set the size */
01365         fprintf (stderr, "EVENT_MAXWORDS was not properly defined\n");
01366         fprintf (stderr, "Must be .GT. 0 was %d \n", EVENT_MAXWORDS);
01367 #ifdef __unix__
01368         abort();
01369 #else
01370         panic("BUGCHECK");
01371 #endif
01372     ENDIF;
01373     return (EVENT_MAXWORDS);
01374 }
01375 
01376 
01377 
01378 /*
01379 **++
01380 **  FUNCTIONAL DESCRIPTION:
01381 **
01382 **      trig1max    - Returns the number of words readout in a user1 trigger.
01383 **
01384 **  FUNCTION VALUE:
01385 **
01386 **      Number of  words read out.
01387 **
01388 **
01389 **--
01390 */
01391 WORD 
01392 trig1max ()
01393 {
01394 /*
01395 ** NOTE:
01396 **    >>>>The UNIX environment does not support user triggers <<<<
01397 **
01398 **  Instructions:
01399 **  -------------
01400 **      This function should be filled in to indicate the maximum number
01401 **      of words to be read out on a user trigger 1.  The sample code operates
01402 **      as follows, if the #define'd constant USERTRIG1_ENABLE is FALSE, then
01403 **      the value 0 is generated (no words read out), If USERTRIG1_ENABLE is
01404 **      true, then the user should edit the definition of USERTRIG1_MAXWORDS
01405 **      to reflect the largest number of words that can be read out in a
01406 **      user1 trigger.  
01407 **  End of all Instructions for now....                         */
01408 
01409 #define USERTRIG1_MAXWORDS      0           /* Edit to reflect actual count */
01410 
01411 #if USERTRIG1_ENABLE && (!defined(__unix__))
01412     IF (USERTRIG1_MAXWORDS LT 0) THEN
01413         fprintf (stderr, "USERTRIG1_MAXWORDS incorrectly initialized\n");
01414         fprintf (stderr, "Must be GE 0 was %d\n", USERTRIG1_MAXWORDS);
01415         die();
01416         return USERTRIG1_MAXWORDS;
01417     ENDIF;
01418 #else
01419     return 0;
01420 #endif    
01421 
01422 }

Generated on Fri Mar 12 13:04:04 2004 for Scripted Readout by doxygen 1.3.4