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 "CPacketCreator.h"
00354 #include "CAENcard.h"
00355 
00356 #include "CCAENV830.h"
00357 #include "CCAENV830Creator.h"
00358 #include "CCAENV830Module.h"
00359 
00360 #ifndef __unix__
00361 #include "cpus.h"
00362 #endif
00363 
00364 #ifdef __unix__
00365 #include <stdlib.h>
00366 #include <daqinterface.h>
00367 #include <spectrodaq.h>
00368 #endif
00369 
00370 #include <daqdatatypes.h>
00371 #include <camac.h>
00372 #include <macros.h>
00373 
00374 #ifdef VME16
00375 #undef VME16
00376 #endif
00377 #if CPU == MICROPROJECT
00378 #define VME16 0 
00379 #endif
00380 
00381 #ifndef __unix__
00382 #include <vme.h>
00383 #endif
00384 #include <buftypes.h>
00385 
00386 /* Short circuit run time evaluation of constant BCNAF's */
00387 
00388 #ifdef __unix__
00389 #include <camac.h>
00390 #else
00391 #if CPU == IRONICS
00392 #undef CAMBAS
00393 #define CAMBAS(b)       0xFA800000
00394 #endif
00395 
00396 #if CPU == MICROPROJECT
00397 #undef CAMBAS
00398 #define CAMBAS(b)       0xFE800000
00399 #endif
00400 #endif
00401 
00402 #include <iostream.h>
00403 #include <CAENcard.h>
00404 
00405 #define SEE_PACKETID   0x8000     // SEE Packet id from Bazin.
00406 
00407 
00408 /*
00409 **  INSTRUCTIONS:
00410 **  -------------
00411 **                          Introduction
00412 **
00413 **      There are several functions that the user is supposed to fill in
00414 **      to tailor this skeleton for a particular experiment.  While the
00415 **      skeleton is written in C, several extensions to the C language have
00416 **      been defined to bring the syntax closer to FORTRAN.  One thing you must
00417 **      be aware of, however is that C is case sensitive, that is, 'if' and
00418 **      'IF' are completely different from each other and 'If'.
00419 **
00420 **                          Functions to fill in:
00421 **
00422 **      The following are the set of functions that need to be filled in:
00423 **
00424 **      Function    Meaning             When Called
00425 **      initevt     Init event readout  Power up Begin run and Resume Run.
00426 **      clrtrig1    Clr trig1 readout   Power up, Begin, resume, end of trig1.
00427 **      iniscl      Init scalers.       Power up Begin run and Resume Run.
00428 **      clearevt    Clear evt readout   Power up, Begin, Resume, end of event.
00429 **      clrtrig1    Clr trig1 readout   Power up, Begin, resume, end of trig1.
00430 **      clrscl      Clear scaler readout Power up, Begin, Resume, end of scaler
00431 **      readevt     Read an event       Event trigger.
00432 **      readscl     REad scaler event   Scaler time.
00433 **      trig1ena    Enable trigger 1    Begin run, resume run.
00434 **      trig1dis    Disable trigger1    End run
00435 **      rdtrig1     Readout for trig 1  User trigger 1 fires.
00436 **      evtmax      Max size of event   Begin run time.
00437 **      trig1max    Max words in trig1  Begin run time.
00438 **
00439 **                      Language elements:
00440 **          Statements:
00441 **      Statements can occur anywhere on a line there can even be multiple
00442 **      statements on a single line. The end of a statement is flagged with
00443 **      a semicolon.  The following are legal statements:
00444 **
00445 **              a = b;
00446 **              camwrite16(0,1,29,0,16,1234);
00447 **
00448 **          Variables:
00449 **      Variables must be declared at the beginning of a function.
00450 **      C variables are the native type, however, the following FORTRAN
00451 **      style variable declarations are supported via definitions in 
00452 **      macros.h
00453 **
00454 **          LOGICAL     - Takes the values TRUE or FALSE
00455 **          WORD        - INTEGER*2 sized word.
00456 **          INTEGER     - INTEGER*4 sized lognword.
00457 **          REAL        - REAL*4 sized real.
00458 **
00459 **      Arrays may be declared, subscripts always go from 0:size-1. In C
00460 **      subscripts are in square brackets not rounded ones. The following
00461 **      are legal variable declarations:
00462 **
00463 **          LOGICAL flag;
00464 **          INTEGER i,j,k[10];
00465 **      Note in the above, the declaration of k is identical to the FORTRAN
00466 **      declaration:
00467 **
00468 **          INTEGER*4 k(0:9)
00469 **
00470 **      Multidimensional arrays are also allowed, but the syntax is a bit
00471 **      different:
00472 **          IINTEGER twod[5][6];
00473 **
00474 **      In C, the last dimension runs sequentially in memory rather than
00475 **      the first (reverse of fortran), and array references require both
00476 **      dimensions to be used as in the declaration e.g., to fill the
00477 **      array above:
00478 **         
00479 **               for(j = 0; j < 5; j++) 
00480 **                  for(i = 0; i < 6; i++)
00481 **                     twod[j][i] = i+j;
00482 **         
00483 **          Expressions:
00484 **      The only FORTRAN operators not allowed are exponentiation (**).
00485 **      the following is a subset of the operators supported:
00486 **          + - * / AND OR EQ NE GT GE LT LE
00487 **      The following assignment statement is an example of an expression:
00488 **          LOGICAL   flag;
00489 **          INTEGER   i1,i2,i3,i4;
00490 **              ...
00491 **          flag = (i1)/(i1+i2) LT (i3+i4)
00492 **
00493 **      Note that operators (e.g. LT above) are case sensitive.
00494 **      Bitwise operator functions IAND, IOR, ISHIFT are defined like in FORTRAN
00495 **      Hexadecimal constants are allowed and the syntax is 0xNNN where NNN is
00496 **      the constant.
00497 **
00498 **          Flow of control:
00499 **
00500 **      The following statements can control the flow of a program.
00501 **              IF
00502 **
00503 **      IF(expresson) <statement>;
00504 **
00505 **              BLOCK IF with optional ELSE clause:
00506 **
00507 **      IF(expression) THEN
00508 **          <statements with trailing ';'s>
00509 **      [ELSE 
00510 **          <statements with trailing ';'s>
00511 **      ]ENDIF
00512 **
00513 **              Top tested DO WHILE loop:
00514 **
00515 **      DO WHILE(expression)
00516 **          <statements>;
00517 **      ENDDO
00518 **
00519 **                  Buffer manipulation:
00520 **      The following functions manipulate the buffer:
00521 **
00522 **      putbufw(w)      - Put w, a 16 bit word to buffer.
00523 **      putbufl(l)      - Put l, a 32 bit longword to the buffer in VAX word 
00524 **                        order.
00525 **
00526 **                  CAMAC operations:
00527 **
00528 **      In the discussion below, b= branch number 0-7, c = crate number 1-7,
00529 **      n = CAMAC slot, a = CAMAC subaddress, f = CAMAC function code.
00530 **      d = CAMAC data transfered.
00531 **      CAMAC operations are implemented as 'pseudo functions' which are
00532 **      expanded in line and hence quite fast (~3usec per transaction).
00533 **
00534 **      camread16(b,c,n,a,f)    - Returns a 16 bit value read from CAMAC
00535 **      camread24(b,c,n,a,f)    - Returns a 24 bit value read from CAMAC format
00536 **                                is 68K format.
00537 **      camwrite16(b,c,n,a,f,d) - Write least significant 16 bits of d to CAMAC
00538 **      camwrite24(b,c,n,a,f,d) - Write least significate 24 bits of d to CAMAC
00539 **      camctl(b,c,n,a,f)       - Perform non data transfer CAMAC cycle.
00540 **      rdtobuf16(b,c,n,a,f)    - Do 16 bit CAMAC read into buffer.
00541 **      rdtobuf24(b,c,n,a,f)    - Do 24 bit CAMAC read into buffer (VAX format).
00542 **      qtst(b)                 - TRUE if most recent CAMAC operation on 
00543 **                                given branch set Q
00544 **      xtst(b)                 - Same as qtst, but tests X status.
00545 **
00546 **              More complex pseudo functions:
00547 **
00548 **      qstop(b,c,n,a,f)        - Performs a Q stop block read into buffer.
00549 **      branchinit(b)           - Initialize branch controller.
00550 **      crateinit(b,c)          - C/Z/Uninhibit crate.
00551 **
00552 **              LAM waiting:
00553 **
00554 **      The Pseudo functions below set up to do LAM busy waiting on a bit
00555 **      register decode:
00556 **
00557 **      BEGINLAM(numbr, numcr)  - Begin LAM mask buildup:
00558 **                                      numbr   - Number of branches involved
00559 **                                                in LAM wait process.
00560 **                                      numcr   - Highest crate number involved
00561 **                                                in LAM wait process.
00562 **      ENDLAM                  - End LAM mask processing.
00563 **      READBIT(b,c,n,a,f,d)    - Read a pattern register pattern register
00564 **                                is put in buffer and in WORD variable
00565 **                                d
00566 **      NEEDLAM(b,c,n)          - Indicate that LAM from given slot is needed.
00567 **      IFTIMEOUT(maxloop)      - Loops maxloop times (>10us/pass) waiting for
00568 **                                lams.  THen looks like IF statment, but
00569 **                                condition is that a timeout has occured.
00570 **      Example use of bit register functions:
00571 **
00572 **      LOGICAL timeout;
00573 **      WORD    brg;
00574 **      ..
00575 **      READDBIT(0,1,20,0,0,brg);
00576 **          ..
00577 **      BEGINLAM
00578 **        IF(IAND(brg, 0x1))NEEDLAM(0,2,3);
00579 **        IF(IAND(brg, 0x2))NEEDLAM(0,2,4);
00580 **        if(IAND(brg, 0x3))NEEDLAM(0,2,5);
00581 **        IFTIMEOUT(100) THEN
00582 **          timeout = TRUE;
00583 **          ENDDO
00584 **        ELSE
00585 **          timeout = FALSE;
00586 **        ENDIF
00587 **      ENDLAM
00588 **
00589 **                  Device specific pseudoroutines:
00590 **      Several device specific in-line routines are defined to make the
00591 **  handling of more common devices easier.  Devices not supported in this set
00592 **  can be managed with the primitive CAMAC operations. NOTE: clear functions
00593 **  are provided for modules which can be front panel cleared just in case 
00594 **  there is the need to clear them from CAMAC as well.
00595 **
00596 **    See the header macros.h for more information.
00597 **
00598 **          User parameters:
00599 **
00600 **      The front end includes three pre-defined arrays:
00601 **
00602 **          INTEGER userints[]  - Front end integer parameters.
00603 **          LOGICAL userflags[] - Front end flag parameters
00604 **          REAL    userreals[] - Front end real paraemters.
00605 **
00606 ** End of instructions... but look for more later in the file.
00607 */
00608 extern INT16 second;
00609 extern ReadoutStateMachine* gpStateMachine;
00610 
00611 // The following objects constitute the configurable readout engine:
00612 
00613 CTCLInterpreter*      pInterp(0);       // TCL interpreter.
00614 CDigitizerDictionary* pDictionary(0);   // Dictionary of modules.
00615 CReadOrder*           pReader(0);       // The readout engine.
00616 CModuleCommand*       pCreator(0);      // Module creational. 
00617 CCAENV775Creator*     p775(0);          // Creator for V775.
00618 CCAENV785Creator*     p785(0);          // Creator for V785.
00619 CCAENV792Creator*     p792(0);          // Creator for V792.
00620 CPacketCreator*       pPacket(0);       // Creator for subpackets.
00621 
00622 // The following constitute the configurable scaler readout engine.
00623 
00624 CDigitizerDictionary* pScalers(0);      // Dictionary of scaler modules
00625 CReadOrder*           pScalerRead(0);   // Reader for scalers.
00626 CModuleCommand*       pScalerCreator(0); // Creates scaler modules.
00627 CCAENV830Creator*     p830(0);          // Creates CAEN V830 scalers.
00632 void DestroyConfigurator()
00633 {
00634   // Clean up prior incarnations.
00635 
00636   // The Event readout infrastructure...
00637 
00639   //  a minor memory leak so they can run.
00640 
00641   // if(pInterp)     delete pInterp; // Causes deletion of objects too.
00642   // if(pCreator)    delete pCreator;
00643   // if(pReader)     delete pReader;
00644   // if(pDictionary) delete pDictionary;
00645   // if(p775)        delete p775;
00646   // if(p785)        delete p785;
00647   // if(p792)        delete p792;
00648 
00649 
00650   pCreator    = 0;
00651   pReader     = 0;
00652   pDictionary = 0;
00653   pInterp     = 0;
00654   p775        = 0;
00655   p785        = 0;
00656   p792        = 0;
00657   pPacket     = 0;
00658 
00659 
00660   // The Scaler readout infrastructure
00661 
00662   //  if(pScalers)        delete pScalers;
00663   //  if(pScalerRead)     delete pScalerRead;
00664   //  if(pScalerCreator)  delete pScalerCreator;
00665   //   if(p830)            delete p830;
00666 
00667   pScalers       = 0;
00668   pScalerRead    = 0;
00669   pScalerCreator = 0;
00670   p830           = 0;
00671 
00672 }
00673 
00683 void InitializeConfigurator()
00684 {
00685   DestroyConfigurator();
00686 
00687   // Instantiate and link together new config system.
00688 
00689   // Make a new interpreter:
00690 
00691   pInterp = new CTCLInterpreter();
00692   Tcl_Init(pInterp->getInterpreter());
00693   pInterp->Eval("set Readout true"); // Indicate this is readout.
00694 
00695   // Create the readout module creation/readout infrastructure:
00696 
00697   pDictionary = new CDigitizerDictionary;
00698   pReader     = new CReadOrder(pInterp, pDictionary);
00699   pCreator    = new CModuleCommand(pInterp,
00700                                    pDictionary);
00701 
00702   // Register the event module creators with the module command:
00703 
00704   pCreator->AddCreator(p775 = new CCAENV775Creator);
00705   pCreator->AddCreator(p785 = new CCAENV785Creator);
00706   pCreator->AddCreator(p792 = new CCAENV792Creator);
00707   pCreator->AddCreator(pPacket = new CPacketCreator("packet",pDictionary));
00708 
00709   // Create the scaler module creation/readout infrastructure:
00710 
00711   pScalers       = new CDigitizerDictionary;
00712   pScalerRead    = new CReadOrder(pInterp, pScalers, 
00713                                   string("scalerbank"));
00714   pScalerCreator = new CModuleCommand(pInterp,
00715                                       pScalers,
00716                                       string("scaler"));
00717 
00718   // Register the scaler modules with the scaler command.
00719 
00720   pScalerCreator->AddCreator(p830 = new CCAENV830Creator);
00721 
00722 }
00723 
00728 void SourceScript(CTCLInterpreter* pInterp, const string& rPath)
00729 {
00730   pInterp->EvalFile(rPath);
00731 }
00732 
00733 
00734 
00735 /*
00736 **++
00737 **  FUNCTIONAL DESCRIPTION:
00738 **
00739 **      initevt - This function contains code which indicates how to initialize
00740 **                the CAMAC system for event readout.
00741 **
00742 **
00743 **--
00744 */
00745 extern string    SetupFile;
00746 CNullBusy*       pBusy(0);
00747 
00748 void
00749 initevt ()
00750 {
00751 /*
00752 **  INSTRUCTIONS:
00753 **  -------------
00754 **
00755 **      Fill in the area below the end of these instructions, but before the
00756 **      curly bracket with code that initializes devices in the event readout
00757 **      section of the device.  Typically what's needed here is to first
00758 **      put all crates on-line and initialize them, and then to clear all
00759 **      digitizers and initialize any programmable devices.  If you have
00760 **      more than one branh highway (not just branch 0), you should initialize
00761 **      that as well before touching crates on that branch. The routine provided
00762 **      shows how to initialize two empty crates on branch 0.  This initializer
00763 **      is the first of the initializers called so it's not a bad idea to do
00764 **      all crate initializations here, unless the crates are functionally
00765 **      broken up.  A bit register is also initialized.  See the #define
00766 **      statments below to tailor the location of that bit register.
00767 **  End instructions... but watch for more further down */
00768 
00769   cerr << "Initializing Readout Engine\n";
00770   InitializeConfigurator();
00771 
00772                            
00773 
00774   try {
00775     cerr << "Processing setup file: " << SetupFile << endl;
00776     SourceScript(pInterp, SetupFile);
00777 
00778     pReader->Initialize();      // config modules.
00779     pReader->Clear();           // Always clear at start.
00780 
00781   }
00782   catch (CTCLException except) {
00783     CTCLVariable traceback(pInterp,
00784                            string("errorInfo"),
00785                            false);
00786     cerr << "Error in configuration script: ";
00787     cerr << except.ReasonText() << endl;
00788     cerr << traceback.Get(TCL_GLOBAL_ONLY) << endl;
00789     cerr << "1. Stop the run\n";
00790     cerr << "2. Fix the setup file\n";
00791     cerr << "3. Start the run again\n";
00792     DestroyConfigurator();
00793     return;
00794   }
00795   catch (string except) {
00796     cerr << "An exception was caught probably while";
00797     cerr << "Initalizing a module:\n";
00798     cerr << "   " << except << endl;
00799     cerr << "1.   Stop the run\n";
00800     cerr << "2.   Correct the setup file\n";
00801     cerr << "3.   Start the run again\n";
00802     DestroyConfigurator();
00803     return;
00804   }
00805   catch (...) {
00806     cerr << "An unexpected exception was caught in ";
00807     cerr << "initevt().  Probably there's an unforeseen ";
00808     cerr << "problem in your configuration script.\n";
00809     cerr << "Sorry I can't be more specific.\n";
00810     cerr << "   1. Stop the run\n";
00811     cerr << "   2. Examine the configuration script carefully\n";
00812     cerr << "   3. Fix any errors you find.\n";
00813     cerr << "   4. Start the run again.\n";
00814     DestroyConfigurator();
00815     return;
00816 
00817   }
00818 
00819 }
00820 
00821 
00822 
00823 /*
00824 /*
00825 **++
00826 **  FUNCTIONAL DESCRIPTION:
00827 **
00828 **      initrig1    - This section should be filled in to initialize CAMAC
00829 **                    modules associated with user trigger 1.
00830 **
00831 **--
00832 */
00833 void
00834 initrig1 ()
00835 {
00836 
00837 /*
00838 **  Instructions:
00839 **  -------------
00840 **
00841 **      The section of code between the end of this comment and the the }
00842 **      should be filled in with code that initializes all hardware associated
00843 **      with user trigger1.  This trigger SHOULD NOT BE ENABLED AT THIS TIME
00844 **      since this routine is called at power up as well as at run start.
00845 **      The trigger should only be enabled in trig1ena().
00846 **      The sample provided takes no action to initialize trigger 1.
00847 ** End of instructions, but there's more later...                   */
00848 
00849     
00850 }
00851 
00852 
00853 
00854 /*
00855 **++
00856 **  FUNCTIONAL DESCRIPTION:
00857 **
00858 **      iniscl  - Initialize scaler readout.
00859 **
00860 **
00861 **  IMPLICIT INPUTS:
00862 **
00863 **      The special variable numscalers is the number of scalers.
00864 **
00865 **--
00866 */
00867 void
00868 iniscl ()
00869 {
00870 /*
00871 **  Instructions:
00872 **  -------------
00873 **      This function is called to intialize all scaler modules in the
00874 **      system.  There is a pre-declared variable 'numscalers' which 
00875 **      contains the number of scalers in the system.  The sample code below
00876 **      is written to deal with either a block of 12 channel scalers (LRS2551)
00877 **      or a block of 32 channel scalers (LRS4434), depedning on the definition
00878 **      of the constant SCALER_CHANNELS.  If SCALER_CHANNELS is 12, then
00879 **      code is generated for LRS2551, if SCALER_CHANNELS is 32, then for
00880 **      LRS4434.  Several notes:
00881 **          1. The code below demonstrates the use of C's #define statement
00882 **             for generating symbolic constants (like FORTRAN parameters).
00883 **             Note that #defines must start in column 1.
00884 **          2. The code below demonstrates the use of C's #if statement to
00885 **             do conditional compilation.  There is a big difference between
00886 **            #if and IF. #if controls what code is generated, while
00887 **            IF controls what code is executed.  The false side of the
00888 **            #if statement doesn't exist and therefore cannot be used
00889 **            to do run time control flow.
00890 **          3. If all the user wants to do is modify the starting scaler,
00891 **            or the type of scaler, then the definitions below are all
00892 **            that need to be changed.  More complex changes require coding.
00893 **          4.The % operator is the modulus operator, that is (a % b) is the
00894 **            same as FORTRAN's MOD(A,B).
00895 **          5. Advanced note. #define creates things called MACRO's a MACRO
00896 **             is a stored series of text which is expanded in line when it
00897 **             is invoked.  MACROs can have parameters just like functions
00898 **             and this is how the psuedo functions and FORTRAN like syntax
00899 **             has been layered on to C.  For example, if you would like
00900 **             to define a FORTRAN like MOD pseudo function, then:
00901 **             12345678901234567890123456789012345678901234567890 <- Column
00902 **             #define MOD(a,b)  ((a) % (b))
00903 **  End of instructions for now...                                  */
00904 
00905 
00906 
00907   try {
00908     if(pScalerRead) {
00909       pScalerRead->Initialize();
00910       pScalerRead->Clear();
00911       
00912       // Figure out how many scalers we have and set the scaler count.
00913       
00914       char buffer[8192];
00915       int nWords = pScalerRead->Read(buffer); //  do a test read.
00916       daq_SetScalerCount(nWords*sizeof(short)/sizeof(long));
00917       pScalerRead->Clear();
00918     }
00919   }
00920   catch (CTCLException except) {
00921     CTCLVariable traceback(pInterp,
00922                            string("errorInfo"),
00923                            false);
00924     cerr << "Error in configuration script: ";
00925     cerr << except.ReasonText() << endl;
00926     cerr << traceback.Get(TCL_GLOBAL_ONLY) << endl;
00927     cerr << "1. Stop the run\n";
00928     cerr << "2. Fix the setup file\n";
00929     cerr << "3. Start the run again\n";
00930     DestroyConfigurator();
00931     return;
00932   }
00933   catch (string except) {
00934     cerr << "An exception was caught probably while";
00935     cerr << "Initalizing a module:\n";
00936     cerr << "   " << except << endl;
00937     cerr << "1.   Stop the run\n";
00938     cerr << "2.   Correct the setup file\n";
00939     cerr << "3.   Start the run again\n";
00940   }
00941   catch (...) {
00942     cerr << "An unexpected exception was caught in ";
00943     cerr << "initevt().  Probably there's an unforeseen ";
00944     cerr << "problem in your configuration script.\n";
00945     cerr << "Sorry I can't be more specific.\n";
00946     cerr << "   1. Stop the run\n";
00947     cerr << "   2. Examine the configuration script carefully\n";
00948     cerr << "   3. Fix any errors you find.\n";
00949     cerr << "   4. Start the run again.\n";
00950     DestroyConfigurator();    
00951   }
00952 
00953 
00954 }
00955 
00956 
00957 /*
00958 **++
00959 **  FUNCTIONAL DESCRIPTION:
00960 **
00961 **      clearevt    - Clear user events.
00962 **
00963 **
00964 **--
00965 */
00966 void
00967 clearevt ()
00968 {
00969 /*
00970 **  Instructions:
00971 **  -------------
00972 **      This routine should be filled in with the actions needed to clear
00973 **      all digitizers associated with the primary event.  Note that after
00974 **      the readout, of an event, a standard NIM-out is written to with all
00975 **      1's.  This is done in time suitable for clearing devices with front
00976 **      panel clears.  The user need not clear devices which are cleared via
00977 **      this signal.
00978 **      The sample code does nothing.
00979 **  End of instructions... but there's more.                */
00980     
00981   if(pReader)
00982     pReader->Prepare();
00983 }
00984 
00985 
00986 
00987 /*
00988 **++
00989 **  FUNCTIONAL DESCRIPTION:
00990 **
00991 **      clrtrig1    - This function is called when a user 1 trigger read out is 
00992 **                    complete.
00993 **
00994 **
00995 **--
00996 */
00997 void
00998 clrtrig1 ()
00999 {
01000 /*
01001 **  Instructions:
01002 **  -------------
01003 **      This function is called to clear the user1 trigger devices.  This
01004 **      should not be used to disable triggers, since we are called at the end
01005 **      of every trigger 1 event.  The entry trig1dis should be used instead.
01006 **      Note when clearing trigger 1 devices, it is assumed that there need not
01007 **      be any connection between trigger 1 and the 'event' trigger.  Therefore,
01008 **      the front panel NIM out clear register is not written to by the uppler
01009 **      levels of the system and must be written to by the user if that's 
01010 **      desired.
01011 **          The sample code below does nothing.
01012 **      End of Instructions for now...                                      */ 
01013     
01014 }
01015 
01016 
01017 
01018 /*
01019 **++
01020 **  FUNCTIONAL DESCRIPTION:
01021 **
01022 **      clrscl  - Clear scalers
01023 **
01024 **
01025 **--
01026 */
01027 void
01028 clrscl ()
01029 {
01030 /*
01031 **  Instructions:
01032 **  -------------
01033 **      This function is called to clear the scalers following readout, on 
01034 **      run start and on run resume.  The sample code below is intended for 
01035 **      use with the sample code given in iniscl(), that is we can deal
01036 **      with either a contiguous block of 32 or 12 channel scalers.
01037 **  End of instructions for now....                             */
01038 
01039   if(pScalerRead) {
01040     pScalerRead->Prepare();
01041   }
01042     
01043 }
01044 
01045 
01046 /*
01047 **++
01048 **  FUNCTIONAL DESCRIPTION:
01049 **
01050 **      readevt - This function is called to read an event.
01051 **
01052 **  FORMAL PARAMETERS:
01053 **
01054 **      INT16 *bufpt    - Pointer to buffer to fill.
01055 **
01056 **
01057 **  FUNCTION VALUE:
01058 **
01059 **      Number of words read.
01060 **
01061 **--
01062 */
01063 WORD
01064 #ifdef __unix__
01065 readevt (DAQWordBufferPtr& bufpt)
01066 #else 
01067 readevt (WORD* bufpt)
01068 #endif
01069 {
01070 #ifdef __unix__
01071     DAQWordBufferPtr _sbufpt = bufpt;
01072 #else
01073     WORD *_sbufpt = bufpt;
01074 #endif
01075     LOGICAL reject;
01076 
01077     reject   = FALSE;
01078     {    
01079 /*------------------------- Begin user code. ----------------------------*/
01080 /*
01081 **  Instructions:
01082 **  -------------
01083 **      This routine must be filled in with code that indicates how to perform
01084 **      the event readout.  Digitizers need not be cleared after readout,
01085 **      that's done by a call back down here to clearevt().  Some points of
01086 **      interest:
01087 **          1. the predefined array _sbufpt can be used to reference the
01088 **             buffer after words have been read, that is, _sbufpt[0] is
01089 **             the first word you read.
01090 **          2. The predefined logical variable reject can be set to TRUE to
01091 **             inform the system that the event is to be thrown away.
01092 **          3. The data the user reads will be prefaced by the system with
01093 **             a word count.
01094 **          The sample code below is a skeleton which cracks a single 16
01095 **          bit register, waits for indicated lams for each bit and then
01096 **          does the read out on the set bits in the register.  If a LAM timeout
01097 **          occured, then the top bit of the bit register is set in the buffer
01098 **          and the readout procedes.  Note the use of #defines to tailor
01099 **          the location of the bit register, the LAM's expected for each bit,
01100 **          and the bits that are actually used in the register.
01101 **          Note how conditional compilation is used to remove tests for bits
01102 **          which are not used by the experiment.
01103 **          Note the use of the pre-defined 2-d array _lammsk in the LAM
01104 **          decoding code below.  Setting the bits all at once is faster
01105 **          than one at a a time (via NEEDLAM).  Note also the difference
01106 **          in the way C addresses 2-d arrays.  The predefined array _lammsk
01107 **          is an array of branch/crate lam masks.
01108 **  End of instructions for now...                              */
01109 
01110       if(pReader) {
01111 
01112         // If he wants to he can turn on packetization in the reader!!
01113 
01114         pReader->Read(bufpt);
01115       }
01116 
01117 
01118 /*-------------------------  End of user code. ---------------------------*/
01119 }
01120     IF(reject) return 0;
01121 #ifdef __unix__
01122     return bufpt.GetIndex() - _sbufpt.GetIndex();
01123 #else
01124     return (bufpt - _sbufpt);
01125 #endif
01126 }
01127 
01128 
01129 
01130 /*
01131 **++
01132 **  FUNCTIONAL DESCRIPTION:
01133 **
01134 **      readscl  - Read out scalers.
01135 **
01136 **  FORMAL PARAMETERS:
01137 **
01138 **      UINT32 *bufpt           - buffer pointer.
01139 **      int numscalers          - Number of scalers to read out.
01140 **
01141 
01142 **
01143 **
01144 **--
01145 */
01146 UINT16
01147 readscl (UINT32* buffer,int numscalers)
01148 {
01149     UINT32* _sbufpt = buffer;
01150     UINT16*  bufpt  = (UINT16*)buffer;
01151 
01152 
01153 
01154     {
01155 /*
01156 **  Instructions:
01157 **  -------------
01158 **
01159 **      This section of code must be filled in to read out scalers into a buffer
01160 **      provided by the caller.  The special predeclared array INTEGER _sbufpt[]
01161 **      allows access to the buffer contents by longword number.
01162 **      The sample code below continues the examples of scaler handling shown
01163 **      so far.  If 12 channel scalers are used, we read them out assuming
01164 **      that we've got a contiguous block of them.
01165 **      If 32 channel scalers are used, then we use them instead.
01166 **      The predefined INTEGER numscalers is the number of scaler channels
01167 **      to be read out (set by SET SCALERS command).
01168 **        NOTES:
01169 **          1. After the scalers have been read out, the upper levels of code
01170 **              will call the scaler clear routine so it is not necessary
01171 **              to clear scalers at this level.
01172 **          2.  Do not molest the code below the dashed line as it is necessary
01173 **              to the correct operation of the system.
01174 ** End of instructions for now:                         */
01175 
01176  
01177       if(pScalerRead) {
01178         int nWords = pScalerRead->Read(buffer);
01179         bufpt +=  nWords;
01180       }
01181 
01182 
01183 /*-------------------------------END USER CODE ---------------------------*/
01184     }
01185 
01186 
01187 
01188     
01189      
01190     return (UINT16)((UINT32)bufpt - (UINT32)_sbufpt);
01191 }
01192 
01193 
01194 
01195 /*
01196 **++
01197 **  FUNCTIONAL DESCRIPTION:
01198 **
01199 **      trig1dis    - Disable trigger 1 triggers.
01200 **
01201 **
01202 **--
01203 */
01204 void
01205 trig1dis ()
01206 {
01207 
01208 /*
01209 ** NOTE:
01210 **    >>>>User triggers are not supported in the UNIX readout system<<<<
01211 **  Instructions:
01212 **  -------------
01213 **      The code below is used to turn off user triggers.  At present, the only
01214 **      sort of user triggers supported are time periodic user triggers for
01215 **      user trigger 1.  User triggers are intended to trigger readout events
01216 **      that are not necessarily part of the normal set of event triggers.
01217 **      These might be triggers to readout calibration systems or other
01218 **      monitoring systems.
01219 **        The sample code below is compiled if the #define for USERTRIG1_ENABLE
01220 **      is set to be true.  In that case, the frequency and eventy type produced
01221 **      for user triggers is controlled by the #define statements for
01222 **      USER1_PERIOD    (INTEGER seconds between triggers) and:
01223 **
01224 **  End of instructions for now:    */
01225 
01226 #ifndef __unix__
01227 #define USERTRIG1_ENABLE        FALSE           /* TRUE if triggers desired */
01228 #define USERTRIG1_PERIOD        -1              /* Seconds between triggers */
01229 
01230 #if USERTRIG1_ENABLE
01231 
01232     STOPUSR1TRIG();
01233     
01234 #endif
01235 #endif
01236 }
01237 
01238 
01239 
01240 /*
01241 **++
01242 **  FUNCTIONAL DESCRIPTION:
01243 **
01244 **      trig1ena    - This function is called when user triggers are to be
01245 **                    enabled.
01246 **
01247 **
01248 **--
01249 */
01250 void
01251 trig1ena ()
01252 {
01253 /*
01254 **  NOTE:
01255 **     >>>>User triggers are not supported in the UNIX environment<<<<
01256 **  Instructions:
01257 **  -------------
01258 **      This section of code should be filled in to enable user triggers.
01259 **  The sample code continues the example begun for trig1dis.
01260 **  End of instructions for now:        */
01261 #ifndef __unix__
01262 INTEGER period;
01263 
01264 
01265 #if USERTRIG1_ENABLE
01266     IF(USERTRIG1_PERIOD LE 0) THEN
01267         msg("FATAL - Trigger frequency less than zero in trig1ena()");
01268         newline; newline;
01269         die();
01270     ENDIF
01271 
01272     STARTUSR1TRIG(USERTRIG1_PERIOD);
01273 
01274 #endif
01275 #endif
01276 }
01277 
01278 
01279 
01280 /*
01281 **++
01282 **  FUNCTIONAL DESCRIPTION:
01283 **
01284 **      rdtrig1 - Read out a user trigger.
01285 **
01286 **  FORMAL PARAMETERS:
01287 **
01288 **      INT16 *buffer   - Pointer to buffer to readout.
01289 **
01290 */
01291 int 
01292 rdtrig1 (WORD* bufpt)
01293 {
01294     WORD *_sbufpt;
01295 
01296     _sbufpt = bufpt;
01297     {
01298 /*
01299 **  NOTE:
01300 **    >>>>The UNIX environment does not support user triggers <<<<
01301 **  Instructions:
01302 **  -------------
01303 **      This area should be filled in with code that manages the readout of a
01304 **      user 1 trigger.  The sample code below assumes that if user triggers are
01305 **      enabled, you will want to trigger an action via setting a bit in a NIM
01306 **      out register. 
01307 **        The default event type of the event being read out
01308 **      is USERBUF1 (32).  If not data is read into the buffer, then no event
01309 **      is generated.  Similarly, if the function returns the value zero, then
01310 **      no event is generated.
01311 **      NOTE:
01312 **          1.  The special variable bufpt is a 'pointer' to the event buffer.
01313 **          2.  As before, the predeclared variable WORD _sbufpt[] gives
01314 **              you a way to modify the buffer after readout (e.g. put in
01315 **              a special bit in the bit register.
01316 **          3.  The defines for NIMOUT_xxx allow the CAMAC location of the
01317 **              nimout to be defined, as well as the bit that's actually
01318 **              fired off.
01319 **  End of instructions for now...                  */
01320 #ifndef __unix__
01321 #define NIMOUT_BRANCH   0                           /* Branch nimout is in */
01322 #define NIMOUT_CRATE    2                           /* Crate nimout is in. */
01323 #define NIMOUT_SLOT     20                          /* Slot nimout lives in */
01324 #define NIMOUT_TRIG1    0x800                       /* Bit to set. */
01325 
01326 #if USERTRIG1_ENABLE
01327         NIMOUT(NIMOUT_BRANCH, NIMOUT_CRATE, NIMOUT_SLOT, NIMOUT_TRIG1);
01328 
01329 /* -------------------------- End user code. ----------------------- */
01330 #endif
01331 #endif
01332 
01333     }
01334     return (bufpt - _sbufpt);
01335 }
01336 
01337 
01338 
01339 /*
01340 **++
01341 **  FUNCTIONAL DESCRIPTION:
01342 **
01343 **      evtmax  - Returns the size of the largest physics event.
01344 **
01345 **  FUNCTION VALUE:
01346 **
01347 **      Largest number of words that can be read out by a physics trigger.
01348 ****--
01349 */
01350 WORD 
01351 evtmax ()
01352 {
01353 
01354 /*
01355 **  Instructions:
01356 **  -------------
01357 **      Fill in the #define below to indicate the size of the largest
01358 **      possible physics event in words.
01359 **  End of instructions for now...          */
01360 
01361 #define EVENT_MAXWORDS  40      /* Fill with correct size */
01362 
01363 /*------------------------------ end of user code  -----------------------*/
01364 
01365     IF (EVENT_MAXWORDS LE 0) THEN           /* We crash the program if the */
01366                                             /* user didn't set the size */
01367         fprintf (stderr, "EVENT_MAXWORDS was not properly defined\n");
01368         fprintf (stderr, "Must be .GT. 0 was %d \n", EVENT_MAXWORDS);
01369 #ifdef __unix__
01370         abort();
01371 #else
01372         panic("BUGCHECK");
01373 #endif
01374     ENDIF;
01375     return (EVENT_MAXWORDS);
01376 }
01377 
01378 
01379 
01380 /*
01381 **++
01382 **  FUNCTIONAL DESCRIPTION:
01383 **
01384 **      trig1max    - Returns the number of words readout in a user1 trigger.
01385 **
01386 **  FUNCTION VALUE:
01387 **
01388 **      Number of  words read out.
01389 **
01390 **
01391 **--
01392 */
01393 WORD 
01394 trig1max ()
01395 {
01396 /*
01397 ** NOTE:
01398 **    >>>>The UNIX environment does not support user triggers <<<<
01399 **
01400 **  Instructions:
01401 **  -------------
01402 **      This function should be filled in to indicate the maximum number
01403 **      of words to be read out on a user trigger 1.  The sample code operates
01404 **      as follows, if the #define'd constant USERTRIG1_ENABLE is FALSE, then
01405 **      the value 0 is generated (no words read out), If USERTRIG1_ENABLE is
01406 **      true, then the user should edit the definition of USERTRIG1_MAXWORDS
01407 **      to reflect the largest number of words that can be read out in a
01408 **      user1 trigger.  
01409 **  End of all Instructions for now....                         */
01410 
01411 #define USERTRIG1_MAXWORDS      0           /* Edit to reflect actual count */
01412 
01413 #if USERTRIG1_ENABLE && (!defined(__unix__))
01414     IF (USERTRIG1_MAXWORDS LT 0) THEN
01415         fprintf (stderr, "USERTRIG1_MAXWORDS incorrectly initialized\n");
01416         fprintf (stderr, "Must be GE 0 was %d\n", USERTRIG1_MAXWORDS);
01417         die();
01418         return USERTRIG1_MAXWORDS;
01419     ENDIF;
01420 #else
01421     return 0;
01422 #endif    
01423 
01424 }

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