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

CCAENV830.cpp

Go to the documentation of this file.
00001 /*
00002                     GNU GENERAL PUBLIC LICENSE
00003                        Version 2, June 1991
00004 
00005  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
00006                        59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00007  Everyone is permitted to copy and distribute verbatim copies
00008  of this license document, but changing it is not allowed.
00009 
00010                             Preamble
00011 
00012   The licenses for most software are designed to take away your
00013 freedom to share and change it.  By contrast, the GNU General Public
00014 License is intended to guarantee your freedom to share and change free
00015 software--to make sure the software is free for all its users.  This
00016 General Public License applies to most of the Free Software
00017 Foundation's software and to any other program whose authors commit to
00018 using it.  (Some other Free Software Foundation software is covered by
00019 the GNU Library General Public License instead.)  You can apply it to
00020 your programs, too.
00021 
00022   When we speak of free software, we are referring to freedom, not
00023 price.  Our General Public Licenses are designed to make sure that you
00024 have the freedom to distribute copies of free software (and charge for
00025 this service if you wish), that you receive source code or can get it
00026 if you want it, that you can change the software or use pieces of it
00027 in new free programs; and that you know you can do these things.
00028 
00029   To protect your rights, we need to make restrictions that forbid
00030 anyone to deny you these rights or to ask you to surrender the rights.
00031 These restrictions translate to certain responsibilities for you if you
00032 distribute copies of the software, or if you modify it.
00033 
00034   For example, if you distribute copies of such a program, whether
00035 gratis or for a fee, you must give the recipients all the rights that
00036 you have.  You must make sure that they, too, receive or can get the
00037 source code.  And you must show them these terms so they know their
00038 rights.
00039 
00040   We protect your rights with two steps: (1) copyright the software, and
00041 (2) offer you this license which gives you legal permission to copy,
00042 distribute and/or modify the software.
00043 
00044   Also, for each author's protection and ours, we want to make certain
00045 that everyone understands that there is no warranty for this free
00046 software.  If the software is modified by someone else and passed on, we
00047 want its recipients to know that what they have is not the original, so
00048 that any problems introduced by others will not reflect on the original
00049 authors' reputations.
00050 
00051   Finally, any free program is threatened constantly by software
00052 patents.  We wish to avoid the danger that redistributors of a free
00053 program will individually obtain patent licenses, in effect making the
00054 program proprietary.  To prevent this, we have made it clear that any
00055 patent must be licensed for everyone's free use or not licensed at all.
00056 
00057   The precise terms and conditions for copying, distribution and
00058 modification follow.
00059 
00060                     GNU GENERAL PUBLIC LICENSE
00061    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
00062 
00063   0. This License applies to any program or other work which contains
00064 a notice placed by the copyright holder saying it may be distributed
00065 under the terms of this General Public License.  The "Program", below,
00066 refers to any such program or work, and a "work based on the Program"
00067 means either the Program or any derivative work under copyright law:
00068 that is to say, a work containing the Program or a portion of it,
00069 either verbatim or with modifications and/or translated into another
00070 language.  (Hereinafter, translation is included without limitation in
00071 the term "modification".)  Each licensee is addressed as "you".
00072 
00073 Activities other than copying, distribution and modification are not
00074 covered by this License; they are outside its scope.  The act of
00075 running the Program is not restricted, and the output from the Program
00076 is covered only if its contents constitute a work based on the
00077 Program (independent of having been made by running the Program).
00078 Whether that is true depends on what the Program does.
00079 
00080   1. You may copy and distribute verbatim copies of the Program's
00081 source code as you receive it, in any medium, provided that you
00082 conspicuously and appropriately publish on each copy an appropriate
00083 copyright notice and disclaimer of warranty; keep intact all the
00084 notices that refer to this License and to the absence of any warranty;
00085 and give any other recipients of the Program a copy of this License
00086 along with the Program.
00087 
00088 You may charge a fee for the physical act of transferring a copy, and
00089 you may at your option offer warranty protection in exchange for a fee.
00090 
00091   2. You may modify your copy or copies of the Program or any portion
00092 of it, thus forming a work based on the Program, and copy and
00093 distribute such modifications or work under the terms of Section 1
00094 above, provided that you also meet all of these conditions:
00095 
00096     a) You must cause the modified files to carry prominent notices
00097     stating that you changed the files and the date of any change.
00098 
00099     b) You must cause any work that you distribute or publish, that in
00100     whole or in part contains or is derived from the Program or any
00101     part thereof, to be licensed as a whole at no charge to all third
00102     parties under the terms of this License.
00103 
00104     c) If the modified program normally reads commands interactively
00105     when run, you must cause it, when started running for such
00106     interactive use in the most ordinary way, to print or display an
00107     announcement including an appropriate copyright notice and a
00108     notice that there is no warranty (or else, saying that you provide
00109     a warranty) and that users may redistribute the program under
00110     these conditions, and telling the user how to view a copy of this
00111     License.  (Exception: if the Program itself is interactive but
00112     does not normally print such an announcement, your work based on
00113     the Program is not required to print an announcement.)
00114 
00115 These requirements apply to the modified work as a whole.  If
00116 identifiable sections of that work are not derived from the Program,
00117 and can be reasonably considered independent and separate works in
00118 themselves, then this License, and its terms, do not apply to those
00119 sections when you distribute them as separate works.  But when you
00120 distribute the same sections as part of a whole which is a work based
00121 on the Program, the distribution of the whole must be on the terms of
00122 this License, whose permissions for other licensees extend to the
00123 entire whole, and thus to each and every part regardless of who wrote it.
00124 
00125 Thus, it is not the intent of this section to claim rights or contest
00126 your rights to work written entirely by you; rather, the intent is to
00127 exercise the right to control the distribution of derivative or
00128 collective works based on the Program.
00129 
00130 In addition, mere aggregation of another work not based on the Program
00131 with the Program (or with a work based on the Program) on a volume of
00132 a storage or distribution medium does not bring the other work under
00133 the scope of this License.
00134 
00135   3. You may copy and distribute the Program (or a work based on it,
00136 under Section 2) in object code or executable form under the terms of
00137 Sections 1 and 2 above provided that you also do one of the following:
00138 
00139     a) Accompany it with the complete corresponding machine-readable
00140     source code, which must be distributed under the terms of Sections
00141     1 and 2 above on a medium customarily used for software interchange; or,
00142 
00143     b) Accompany it with a written offer, valid for at least three
00144     years, to give any third party, for a charge no more than your
00145     cost of physically performing source distribution, a complete
00146     machine-readable copy of the corresponding source code, to be
00147     distributed under the terms of Sections 1 and 2 above on a medium
00148     customarily used for software interchange; or,
00149 
00150     c) Accompany it with the information you received as to the offer
00151     to distribute corresponding source code.  (This alternative is
00152     allowed only for noncommercial distribution and only if you
00153     received the program in object code or executable form with such
00154     an offer, in accord with Subsection b above.)
00155 
00156 The source code for a work means the preferred form of the work for
00157 making modifications to it.  For an executable work, complete source
00158 code means all the source code for all modules it contains, plus any
00159 associated interface definition files, plus the scripts used to
00160 control compilation and installation of the executable.  However, as a
00161 special exception, the source code distributed need not include
00162 anything that is normally distributed (in either source or binary
00163 form) with the major components (compiler, kernel, and so on) of the
00164 operating system on which the executable runs, unless that component
00165 itself accompanies the executable.
00166 
00167 If distribution of executable or object code is made by offering
00168 access to copy from a designated place, then offering equivalent
00169 access to copy the source code from the same place counts as
00170 distribution of the source code, even though third parties are not
00171 compelled to copy the source along with the object code.
00172 
00173   4. You may not copy, modify, sublicense, or distribute the Program
00174 except as expressly provided under this License.  Any attempt
00175 otherwise to copy, modify, sublicense or distribute the Program is
00176 void, and will automatically terminate your rights under this License.
00177 However, parties who have received copies, or rights, from you under
00178 this License will not have their licenses terminated so long as such
00179 parties remain in full compliance.
00180 
00181   5. You are not required to accept this License, since you have not
00182 signed it.  However, nothing else grants you permission to modify or
00183 distribute the Program or its derivative works.  These actions are
00184 prohibited by law if you do not accept this License.  Therefore, by
00185 modifying or distributing the Program (or any work based on the
00186 Program), you indicate your acceptance of this License to do so, and
00187 all its terms and conditions for copying, distributing or modifying
00188 the Program or works based on it.
00189 
00190   6. Each time you redistribute the Program (or any work based on the
00191 Program), the recipient automatically receives a license from the
00192 original licensor to copy, distribute or modify the Program subject to
00193 these terms and conditions.  You may not impose any further
00194 restrictions on the recipients' exercise of the rights granted herein.
00195 You are not responsible for enforcing compliance by third parties to
00196 this License.
00197 
00198   7. If, as a consequence of a court judgment or allegation of patent
00199 infringement or for any other reason (not limited to patent issues),
00200 conditions are imposed on you (whether by court order, agreement or
00201 otherwise) that contradict the conditions of this License, they do not
00202 excuse you from the conditions of this License.  If you cannot
00203 distribute so as to satisfy simultaneously your obligations under this
00204 License and any other pertinent obligations, then as a consequence you
00205 may not distribute the Program at all.  For example, if a patent
00206 license would not permit royalty-free redistribution of the Program by
00207 all those who receive copies directly or indirectly through you, then
00208 the only way you could satisfy both it and this License would be to
00209 refrain entirely from distribution of the Program.
00210 
00211 If any portion of this section is held invalid or unenforceable under
00212 any particular circumstance, the balance of the section is intended to
00213 apply and the section as a whole is intended to apply in other
00214 circumstances.
00215 
00216 It is not the purpose of this section to induce you to infringe any
00217 patents or other property right claims or to contest validity of any
00218 such claims; this section has the sole purpose of protecting the
00219 integrity of the free software distribution system, which is
00220 implemented by public license practices.  Many people have made
00221 generous contributions to the wide range of software distributed
00222 through that system in reliance on consistent application of that
00223 system; it is up to the author/donor to decide if he or she is willing
00224 to distribute software through any other system and a licensee cannot
00225 impose that choice.
00226 
00227 This section is intended to make thoroughly clear what is believed to
00228 be a consequence of the rest of this License.
00229 
00230   8. If the distribution and/or use of the Program is restricted in
00231 certain countries either by patents or by copyrighted interfaces, the
00232 original copyright holder who places the Program under this License
00233 may add an explicit geographical distribution limitation excluding
00234 those countries, so that distribution is permitted only in or among
00235 countries not thus excluded.  In such case, this License incorporates
00236 the limitation as if written in the body of this License.
00237 
00238   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.
00239 
00240 Each version is given a distinguishing version number.  If the Program
00241 specifies a version number of this License which applies to it and "any
00242 later version", you have the option of following the terms and conditions 
00243 either of that version or of any later version published by the Free Software 
00244 Foundation.  If the Program does not specify a version number of this License,
00245  you may choose any version ever published by the Free Software Foundation.
00246 
00247   10. If you wish to incorporate parts of the Program into other free
00248 programs whose distribution conditions are different, write to the author to 
00249 ask for permission.  For software which is copyrighted by the Free Software 
00250 Foundation, write to the Free Software Foundation; we sometimes make 
00251 exceptions for this.  Our decision will be guided by the two goals of 
00252 preserving the free status of all derivatives of our free software and of 
00253 promoting the sharing and reuse of software generally.
00254 
00255                             NO WARRANTY
00256 
00257   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR
00258 THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN 
00259 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE 
00260 THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, 
00261 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
00262 FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND 
00263 PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, 
00264 YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
00265 
00266   12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 
00267 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 
00268 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 
00269 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 
00270 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO 
00271 LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR 
00272 THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 
00273 EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 
00274 DAMAGES.
00275 
00276                      END OF TERMS AND CONDITIONS
00277 */
00278 
00279 #include "CCAENV830.h"
00280 #include "CCAENV820Registers.h"
00281 #include <CVMEInterface.h>
00282 #include <string>
00283 #include <stdio.h>
00284 #include <string.h>
00285 
00286 // The 'macros' below are used to do structure like offsets
00287 // using the register structure through VmeModule:
00288 //
00289 #define SOffset(s,field) (((unsigned int)&(((s*)0)->field))/sizeof(short))
00290 #define LOffset(s,field) (((unsigned int)&(((s*)0)->field))/sizeof(long))
00291 #define GetShort(field) (m_pModule->peekw(SOffset(CAENV830Registers,field)))
00292 #define GetLong(field)  (m_pModule->peekl(LOffset(CAENV830Registers,field)))
00293 #define PutShort(field,value) (m_pModule->pokew((value),  \
00294                                   SOffset(CAENV830Registers,field)))
00295 #define PutLong(field,value)  (m_pModule->pokel((value), \
00296                                   LOffset(CAENV830Registers,field)))
00297 #define GetProm(m,field) (m.peekw(SOffset(CAENV830ROM,field)))
00298  
00299 static inline void ThrowIntString(char* formatstring, int value) 
00300   throw (string)
00301 {
00302   char msg[strlen(formatstring) + 100];
00303   sprintf(msg, formatstring, value);
00304   throw string(msg);
00305 }
00306 static inline void ThrowIfBadChannel(const char* pFunction,
00307                                    int nChannel)  throw (string)
00308 {
00309   char* pFmtString=
00310     "CCAENV830::%s Invalid channel must be in [0,31] %d";
00311   if( (nChannel < 0) || (nChannel > 31)) {
00312     char msg[100 + strlen(pFunction) + strlen(pFmtString)];
00313     sprintf(msg, pFmtString, pFunction, nChannel);
00314     throw string(msg);
00315   }
00316 }
00338 CCAENV830::CCAENV830(int slot,
00339                      int crate,
00340                      bool geo,
00341                      unsigned long base) throw (string) :
00342   m_nCrate(crate),
00343   m_nSlot(slot),
00344   m_nBase(base),
00345   m_pModule(0),
00346   m_fGeo(geo)
00347 {
00348   try {
00349     MapModule();                // Access the module.
00350     InitModule();               // Setup initial module state.
00351   } catch (...) {
00352     delete m_pModule;           // Prevent leakage...
00353     throw;                      // But let the exception propagate.
00354   }
00355 
00356 }
00360 CCAENV830::~CCAENV830()
00361 {
00362   UnmapModule();                // Destroy mapping info.
00363 }
00364 
00365 // Functions that operate on the module:
00366 
00367 
00368 
00369 // Utility functions:
00370 
00376 void
00377 CCAENV830::Enable(int nChannel) throw (string)
00378 {
00379   ThrowIfBadChannel("Enable", nChannel);
00380   int nMask  = GetLong(Enables);
00381   nMask     |= 1 << nChannel;
00382   SetEnableMask(nMask);
00383 }
00384 
00390 void
00391 CCAENV830::Disable(int nChannel) throw (string)
00392 {
00393   ThrowIfBadChannel("Disable", nChannel);
00394   int nMask = GetLong(Enables);
00395   nMask    &= ~(1 << nChannel); 
00396   SetEnableMask(nMask);
00397 }
00398 
00405 void
00406 CCAENV830::SetEnableMask(int nMask)
00407 {
00408   PutLong(Enables, nMask);
00409   ComputeEventSize();           // Update the event size.
00410 }
00411 
00424 void
00425 CCAENV830::SetDwellTime(int n400ns) 
00426 {
00427   PutLong(DwellTime, n400ns);
00428 }
00429 
00442 void
00443 CCAENV830::SetTriggerMode(CCAENV830::TriggerMode mode) throw (string)
00444 {
00445   short csr = GetShort(Csr);
00446   csr      &= ~CSRAcqMode;
00447   switch (mode) {
00448   case Disabled:
00449     csr |= CSRAcqDisable;
00450     break;
00451   case Random:
00452     csr |= CSRAcqRandom;
00453     break;
00454   case Periodic:
00455     csr |= CSRAcqPeriodic;
00456     break;
00457   default:
00458     ThrowIntString("CCAENV830::SetTriggerMode invalid trigger mode %d",
00459                 mode);
00460                 
00461   }
00462   PutShort(Csr, csr);
00463 }
00464 
00465 
00474 void CCAENV830::SetWide()
00475 {
00476   PutShort(Bitclear1, CSRFormat);
00477 }
00486 void CCAENV830::SetNarrow()
00487 {
00488   PutShort(Bitset1, CSRFormat);
00489 }
00499 void
00500 CCAENV830::EnableHeader()
00501 {
00502   PutShort(Bitset1, CSRHeader);
00503   ComputeEventSize();           // Update event size.
00504 }
00509 void
00510 CCAENV830::DisableHeader()
00511 {
00512   PutShort(Bitclear1, CSRHeader);
00513   ComputeEventSize();           // Update the event size.
00514 }
00524 void
00525 CCAENV830::FPClearsMEB(bool state)
00526 {
00527   if(state) {
00528     PutShort(Bitset1, CSRFPClear);
00529   }
00530   else {
00531     PutShort(Bitclear1, CSRFPClear);
00532   }
00533 }
00540 void
00541 CCAENV830::EnableAutoReset()
00542 {
00543   PutShort(Bitset1, CSRAutoClr);
00544 }
00550 void
00551 CCAENV830::DisableAutoReset()
00552 {
00553   PutShort(Bitclear1, CSRAutoClr);
00554 }
00571 bool
00572 CCAENV830::isDataReady()
00573 {
00574   short stat = GetShort(Status);
00575   return ((stat & STATUSDready) != 0);
00576 }
00588 bool
00589 CCAENV830::isAlmostFull()
00590 {
00591   short stat = GetShort(Status);
00592   return ((stat & STATUSAFull) != 0);
00593 }
00606 bool
00607 CCAENV830::isFull()
00608 {
00609   short stat = GetShort(Status);
00610   return ((stat & STATUSFull) != 0);
00611 }
00623 bool
00624 CCAENV830::isGlobalDready()
00625 {
00626   short stat = GetShort(Status);
00627   return ((stat & STATUSGDready) != 0);
00628 }
00640 bool
00641 CCAENV830::isGlobalBusy()
00642 {
00643   short stat = GetShort(Status);
00644   return ((stat & STATUSGBusy) & 1);
00645 
00646 }
00647 
00656 void
00657 CCAENV830::Reset()
00658 {
00659   PutShort(SwReset, 0);         // That I write is all that matters
00660 }
00668 void
00669 CCAENV830::Clear()
00670 {
00671   PutShort(SwClear, 0);
00672 }
00677 void
00678 CCAENV830::Trigger()
00679 {
00680   PutShort(SwTrigger, 0);
00681 }
00689 void
00690 CCAENV830::SetTriggerCounter(int n)
00691 {
00692   PutLong(TriggerCounter, n);
00693 }
00700 void
00701 CCAENV830::SetAlmostFullLevel(int n)
00702 {
00703   PutShort(AlmostFull, (n & 0xffff));
00704 }
00709 int
00710 CCAENV830::GetMEBEventCount()
00711 {
00712   return GetShort(MEBCount);
00713 }
00714 
00730 void
00731 CCAENV830::MapModule() throw (string)
00732 {
00733   // Validate the member data:
00734 
00735   if(m_nCrate < 0) {
00736     ThrowIntString("CCAENV820::MapCard - invalid crate %d",
00737                    m_nCrate);
00738   }
00739   if((m_nSlot < 2) || (m_nSlot > 24)) { // Can't be controller !
00740     ThrowIntString("CCAENV820::MapCard - invalid slot %d",
00741                    m_nSlot);
00742   }
00743   
00744 
00745   // If geographically addressed,  First access in geo mode and 
00746   // then re-program.  We're going to check the module's
00747   // validity later... hopefully this won't harm anything
00748   // if this is not a V820/V830:
00749   //
00750   if(m_fGeo) {
00751     m_pModule = new CVmeModule(CVmeModule::geo,
00752                                m_nSlot << 19,
00753                                sizeof(CAENV830Registers),
00754                                m_nCrate);
00755     
00756     PutShort(Ader_24, 0);       // Set the new base address.
00757     PutShort(Ader_32, m_nSlot); 
00758     PutShort(EnableAder,ADEREnable); // Turn on the new address.
00759     m_nBase = m_nSlot << 24;    // Let remaining code know it.
00760     delete m_pModule;
00761     m_pModule = 0;
00762     
00763   } 
00764   // At this point, the module is supposed to be set up to respond
00765   // to the address at m_nBase, either because that's what it's
00766   // rotaries were set to or that's where the module was programmed
00767   // to be.  Now we create the 'permanent' CVmeModule for the
00768   // registers and a temporary one for the prom.  Pull the prom
00769   // characteristics and take a bit of time to ensure that 
00770   // this module is what we think it is...
00771 
00772   CVmeModule prom(CVmeModule::a32d32,
00773                   m_nBase + CAENV830_PROMBASE,
00774                   sizeof(CAENV830ROM), 
00775                   m_nCrate);
00776   m_nModuleType = ((GetProm(prom, ModelH) & 0xff) << 16 ) |
00777                   ((GetProm(prom, ModelM) & 0xff) <<  8 ) |
00778                    (GetProm(prom, ModelL) & 0xff);
00779   m_nSerialno   = ((GetProm(prom, SerialH) & 0xff)  << 8)  |
00780                    (GetProm(prom, SerialL) & 0xff);
00781   if((m_nModuleType  != 820) && 
00782      (m_nModuleType  != 830)) {
00783     ThrowIntString("CCAENV830::MapModule Module type invalid %d",
00784              m_nModuleType);
00785   }
00786   // Now create the 'permanent' register map.
00787   
00788   m_pModule = new CVmeModule(CVmeModule::a32d32,
00789                              m_nBase,
00790                              sizeof(CAENV830Registers),
00791                              m_nCrate);
00792 
00793   // We attempt to set the module's slot number:
00794   // If this module accepts geo addressing, the slot will already
00795   // match the slot param.  If not, then this will set the
00796   // slot address for the data.  It is considered an error to 
00797   // use base addressing on a non geo accessed slot.. so we'll
00798   // throw an error if the slot address reg. doesn't match after
00799   // all this is done:
00800 
00801   PutShort(Slot, m_nSlot);
00802   if((GetShort(Slot) & 0x1f) != m_nSlot) {
00803     ThrowIntString("CCAENV830::MapModule - Module's slot register \
00804 doesn't match requested slot %d",
00805              m_nSlot);
00806   }
00807   m_nFirmware = GetShort(FirmwareRev) & 0xff;
00808   
00809 }
00820 void
00821 CCAENV830::InitModule()
00822 {
00823   // Set module to power up settings, and clear the data
00824   Reset();
00825   Clear();
00826 
00827   //Setup the module to the default config:
00828 
00829   SetEnableMask(0xffffffff);    // All channels on.
00830   SetTriggerMode(Random);
00831   SetNarrow();
00832   EnableHeader();
00833   FPClearsMEB(true);
00834   EnableAutoReset();
00835 
00836 }
00846 void
00847 CCAENV830::ComputeEventSize()
00848 {
00849   m_nEventLength = 0;
00850   if((GetShort(Csr) & CSRHeader) != 0) m_nEventLength++;
00851   
00852   long nEnables = GetLong(Enables);
00853   for(int i =0; i < 32; i++) {
00854     if( ((1 << i) & nEnables) != 0) m_nEventLength++;
00855   }
00856 
00857 }
00861 void
00862 CCAENV830::UnmapModule()
00863 {
00864   delete m_pModule;
00865   m_pModule = 0;
00866 }
00887 int
00888 CCAENV830::ReadEvent(void * pBuffer) 
00889 {
00890   if(isDataReady()) {
00891 #ifdef WienerVME
00892     void* pHandle = m_pModule->getDriver();
00893     ReadLongs(pHandle, m_nBase, pBuffer, m_nEventLength);
00894 #else
00895     unsigned long* p((unsigned long*) pBuffer);
00896     for(int i = 0; i < m_nEventLength; i++) {
00897       *p++ = GetLong(MEB[i]);
00898     }
00899 #endif
00900     return m_nEventLength * sizeof(long)/sizeof(short);
00901   }
00902   else {
00903     return 0;
00904   }
00905 }
00917 int
00918 CCAENV830::ReadEvent(DAQWordBufferPtr& rBufferPtr)
00919 {
00920   unsigned long localBuffer[m_nEventLength];
00921   int nSize = ReadEvent(localBuffer);
00922   if(nSize) {
00923     unsigned short* pLocal = (unsigned short*)localBuffer;
00924     for(int i =0; i < nSize; i++) {
00925       *rBufferPtr = *pLocal++;
00926       ++rBufferPtr;             // This is faster than post incr.
00927     }
00928   }
00929   return nSize;
00930   
00931 }
00947 int
00948 CCAENV830::ReadEvent(DAQWordBuffer& rBuffer, int offset)
00949 {
00950   unsigned long localBuffer[m_nEventLength];
00951   int nSize = ReadEvent(localBuffer);
00952   if(nSize) {
00953     unsigned short* pBuf = (unsigned short*)localBuffer;
00954     for(int i =0; i < nSize; i++) {
00955       rBuffer[offset++] = *pBuf++;
00956     }
00957   }
00958   return nSize;
00959 }
00960 
00971 int
00972 CCAENV830::ReadCounter(int nChannel)
00973 {
00974   if((nChannel < 0) || (nChannel > 31)) {
00975     char text[1000];
00976     string msg;
00977     sprintf(text, "Invalid channel %d (must be in [0,31] in %s\n",
00978             nChannel, "CCAENV830::ReadCounter");
00979     msg = text;
00980     throw msg;
00981   }
00982   return GetLong(Counters[nChannel]);
00983 }

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