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 \class CVMEptr 00280 \file CVMEptr.h 00281 00282 Encapsulates a CVMEptr object. CVMEptrs are the lowest level of the 00283 vme module memory mapping hierarchy. They perform the actual mapping 00284 via the CVMEInterface class. They directly manipulate the registers 00285 and scale the pointer offsets. 00286 00287 Author: 00288 Jason Venema 00289 NSCL 00290 Michigan State University 00291 East Lansing, MI 48824-1321 00292 mailto: venemaja@msu.edu 00293 */ 00294 00295 #ifndef __CVMEPTR_H 00296 #define __CVMEPTR_H 00297 00298 #ifndef __SYS_MMAN_H 00299 #include <sys/mman.h> 00300 #endif 00301 00302 #ifndef __UNISTD_H 00303 #include <unistd.h> 00304 #endif 00305 00306 #ifndef __TYPES_H 00307 #include <sys/types.h> 00308 #endif 00309 00310 00311 #ifndef __HISTOTYPES_H 00312 #include <histotypes.h> 00313 #endif 00314 00315 #ifndef __RANGEERROR_H 00316 #include <RangeError.h> 00317 #endif 00318 00319 #ifndef __CVMEINTERFACE_H 00320 #include <CVMEInterface.h> 00321 #endif 00322 00323 #ifndef __STRING 00324 #include <string> 00325 #endif 00326 00327 #ifndef __MMAPERROR_H 00328 #include <MmapError.h> 00329 #endif 00330 00331 template<class T> 00332 class CVMEptr 00333 { 00334 UInt_t m_nLength; // the length of the mmap 00335 volatile Address_t m_pStart; // the starting address of the mmap 00336 void* m_pHandle; // Handle to VME interface device. 00337 Int_t m_nOffset; 00338 public: 00339 // Default constructor and Copy Constructor 00340 CVMEptr<T>(UInt_t space, UInt_t base, UInt_t length); 00341 CVMEptr<T>(const CVMEptr& aCVMEptr); 00342 CVMEptr<T>(); 00343 00344 // operator= Assignment operator 00345 CVMEptr<T>& operator= (const CVMEptr& aCVMEptr); 00346 00347 // Operator== equality operator 00348 int operator== (const CVMEptr<T>& aCVMEptr) 00349 { 00350 return ((m_nOffset == aCVMEptr.m_nOffset) && 00351 (m_nLength == aCVMEptr.m_nLength) && 00352 (m_pStart == aCVMEptr.m_pStart) && 00353 (m_pActualBase == aCVMEptr.m_pActualBase)); 00354 } 00355 00356 // Destructor 00357 ~CVMEptr<T>(); 00358 00359 protected: 00360 00361 // Protected function member: 00362 // This does the actual mmapping of the VME module 00363 void CreateMap(UInt_t space, UInt_t base, UInt_t length); 00364 00365 // Public accessor functions to data members 00366 public: 00367 00368 UInt_t getLength() const { 00369 return m_nLength; 00370 } 00371 Address_t getStart() const { 00372 return m_pStart; 00373 } 00374 Address_t getActualBase() const { 00375 return m_pActualBase; 00376 } 00377 Address_t getgenptr(UInt_t nOffset); 00378 00379 // Protected mutator functions to data members 00380 public: 00381 void setLength(UInt_t am_nLength) { 00382 m_nLength = am_nLength; 00383 } 00384 void setStart(Address_t pStart) { 00385 m_pStart = pStart; 00386 } 00387 00388 // Public member functions 00389 public: 00390 // Pointer dereference 00391 T& operator*(); 00392 T* operator->(); 00393 00394 // Indexing 00395 T& operator[] (UInt_t nOffset); 00396 00397 // Pointer addition/subtraction 00398 CVMEptr<T> operator+(UInt_t nOffset); 00399 CVMEptr<T> operator-(UInt_t nOffset); 00400 CVMEptr<T>& operator+=(UInt_t nOffset); 00401 CVMEptr<T>& operator-=(UInt_t nOffset); 00402 00403 // Pointer pre-increment/decrement 00404 CVMEptr<T>& operator++(); 00405 CVMEptr<T>& operator--(); 00406 00407 // Pointer post-increment/decrement 00408 CVMEptr<T> operator++(Int_t); 00409 CVMEptr<T> operator--(Int_t); 00410 00411 // Type conversion operators 00412 public: 00413 CVMEptr<UChar_t> asChar(); 00414 CVMEptr<UShort_t> asShort(); 00415 CVMEptr<ULong_t> asLong(); 00416 }; 00417 00418 #endif 00419 00420 /* 00421 \fn CVMEptr(VmeSpace space, UInt_t base, UInt_t length) 00422 00423 Operation Type: 00424 Construction 00425 00426 \param VmeSpace space - enumeration indicating which vme address space 00427 to use 00428 UInt_t base - the base (offset) into the mapping 00429 UInt_t length - the length of the mapping 00430 */ 00431 00432 template<class T> 00433 CVMEptr<T>::CVMEptr<T>(UInt_t space, UInt_t base, UInt_t length) : 00434 m_nOffset(0), 00435 m_nLength(length) 00436 { 00437 CreateMap(space, base, length); 00438 00439 } 00440 00441 /* 00442 \fn CVMEptr<T>::CVMEptr<T>() 00443 00444 Operation Type: 00445 Constructor 00446 00447 Purpose: 00448 Construct an object of this type. Note that no mapping is 00449 performed, and m_nOffset and m_nLength are both set to 0. 00450 */ 00451 template<class T> 00452 CVMEptr<T>::CVMEptr<T>() 00453 { 00454 m_nOffset = 0; 00455 m_nLength = 0; 00456 } 00457 00458 /* 00459 \fn CVMEptr(const CVMEptr& aCVMEptr) 00460 00461 Operation Type: 00462 Copy construction 00463 00464 \param CVMEptr aCVMEptr - the CVMEptr to copy 00465 */ 00466 template<class T> 00467 CVMEptr<T>::CVMEptr<T>(const CVMEptr& aCVMEptr) 00468 { 00469 m_nOffset = aCVMEptr.m_nOffset; 00470 m_nLength = aCVMEptr.m_nLength; 00471 m_pStart = aCVMEptr.m_pStart; 00472 } 00473 00474 /* 00475 \fn CVMEptr& operator= (const CVMEptr& aCVMEptr) 00476 00477 Operation type: 00478 operator= Assignment operator 00479 00480 \param CVMEptr& aCVMEptr - reference to the CVMEptr to assign this to 00481 */ 00482 template<class T> 00483 CVMEptr<T>& 00484 CVMEptr<T>::operator= (const CVMEptr& aCVMEptr) 00485 { 00486 if(this == &aCVMEptr) return *this; 00487 00488 m_nOffset = aCVMEptr.m_nOffset; 00489 m_nLength = aCVMEptr.m_nLength; 00490 m_pStart = aCVMEptr.m_pStart; 00491 00492 return *this; 00493 } 00494 00495 /* 00496 \fn CVMEptr<T>::~CVMEptr<T>() 00497 00498 Operation type: 00499 Destructor 00500 00501 Purpose: Destructor is responsible for munmapping the module 00502 */ 00503 template<class T> 00504 CVMEptr<T>::~CVMEptr<T>() 00505 { 00506 00507 CVMEInterface::Unmap(m_pHandle, m_pStart, m_nLength); 00508 CVMEInterface::Close(m_pHandle); 00509 } 00510 00511 /* 00512 \fn void CVMEptr<T>::CreateMap(UInt_t space, UInt_t base, UInt_t length) 00513 00514 Operation Type: 00515 Map 00516 00517 \param UInt_t space - indicates which vme device to open 00518 (a16d16, a24d32 or a32d32) 00519 UInt_t base - the base address of the module which we're mapping to 00520 UInt_t lenght - the length (bytes) of the map 00521 */ 00522 template<class T> 00523 void 00524 CVMEptr<T>::CreateMap(UInt_t space, UInt_t base, UInt_t length) 00525 { 00526 00527 m_nOffset = 0; 00528 00529 // First open the specified vme device 00530 00531 try { 00532 switch(space) { 00533 case 0: 00534 m_pHandle = CVMEInterface::Open(CVMEInterface::A16); 00535 break; 00536 case 1: 00537 m_pHandle = CVMEInterface::Open(CVMEInterface::A24); 00538 break; 00539 case 2: 00540 m_pHandle = CVMEInterface::Open(CVMEInterface::A24); 00541 break; 00542 case 3: 00543 m_pHandle = CVMEInterface::Open(CVMEInterface::A32); 00544 break; 00545 default: 00546 cerr << "Default condition in CVMEptr<T> CreateMap switch " << space 00547 << endl; 00548 cerr.flush(); 00549 00550 break; 00551 } 00552 } 00553 catch(string& err) { 00554 string merr = "CVMEptr<T>::CreateMap - Opening connection to vme device"; 00555 merr += '\n'; 00556 merr += err; 00557 merr += "\n"; 00558 CMmapError me(err.c_str()); 00559 throw me; 00560 } 00561 00562 00563 // Determine the page size and page offset 00564 00565 m_nLength = length; 00566 try { 00567 m_pStart = CVMEInterface::Map(m_pHandle, base, length); 00568 } 00569 catch (string& err) { 00570 string merr("CVMEptr<T>::CreateMap - Unable to perform CVMEInterface::Map"); 00571 merr += '\n'; 00572 merr += err; 00573 merr += "/n"; 00574 throw CMmapError(merr.c_str()); 00575 00576 } 00577 00578 00579 } 00580 00581 00582 /* 00583 \fn T& CVMEptr<T>::operator*() 00584 00585 Operation Type: 00586 Pointer dereference 00587 00588 Purpose: 00589 Return the value stored at location m_nOffset in the mapped 00590 address space. Throws an exception if the value is out of range. 00591 */ 00592 template<class T> 00593 T& 00594 CVMEptr<T>::operator*() 00595 { 00596 if( (m_nOffset < 0) || (m_nOffset >= m_nLength)) { 00597 throw CRangeError (0, m_nLength, m_nOffset, 00598 "CVMEptr<T>::operator*() - outside of address window"); 00599 00600 } 00601 00602 Address_t pVa = (Address_t)(m_nOffset*sizeof(T) + (UInt_t)m_pStart); 00603 return (*(T*)pVa); 00604 } 00605 00606 /* 00607 \fn T* CVMEptr<T>::operator->() 00608 00609 Operation Type: 00610 Pointer dereference 00611 00612 Purpose: 00613 Return a pointer to the value at location m_nOffset 00614 into the mapped address space. Throws an exception if the value is 00615 out of range. 00616 */ 00617 template<class T> 00618 T* 00619 CVMEptr<T>::operator->() 00620 { 00621 if((m_nOffset < 0) || (m_nOffset >= m_nLength)) { 00622 throw CRangeError(0, m_nLength, m_nOffset, 00623 "CVMEptr<T>::operator->() - outside of address window"); 00624 } 00625 Address_t pVa = (Address_t)(m_nOffset*sizeof(T) + (UInt_t)m_pStart); 00626 00627 return (T*)pVa; 00628 } 00629 00630 /* 00631 \fn T& CVMEptr<T>::operator[] (UInt_t nOffset) 00632 00633 Operation Type: 00634 Index read/write 00635 00636 Purpose: 00637 Return the value stored at locaton nOffset into the mapped address 00638 space. Throws an exception if the value is out of range. 00639 00640 \param UInt_t nOffset - the offset into the address space from which to read. 00641 */ 00642 template <class T> 00643 T& 00644 CVMEptr<T>::operator[] (UInt_t nOffset) 00645 { 00646 if((m_nOffset < 0) || (m_nOffset >= m_nLength)) { 00647 throw CRangeError(0, m_nLength, m_nOffset, 00648 "CVMEptr<T>::operator[]() - outside of address window"); 00649 } 00650 Address_t pVa = (Address_t)(nOffset*sizeof(T) + (UInt_t)m_pStart); 00651 00652 return (*(T*)pVa); 00653 } 00654 00655 /* 00656 \fn CVMEptr<T>& CVMEptr<T>::operator+(UInt_t nOffset) 00657 00658 Operation Type: 00659 Mutator 00660 00661 Purpose: 00662 Add an offset to the current offset. Throws an exception if this 00663 puts us out of range of the memory map. 00664 00665 \param UInt_t nOffset - the integer to add to the current offset 00666 */ 00667 template<class T> 00668 CVMEptr<T> 00669 CVMEptr<T>::operator+(UInt_t nOffset) 00670 { 00671 if(nOffset+m_nOffset <= m_nLength) { // make sure we're in bounds 00672 CVMEptr<T> temp = *this; 00673 temp += nOffset; 00674 return temp; 00675 } 00676 else { 00677 CRangeError re(0, m_nOffset, nOffset, 00678 "CVMEptr<T>::operator+() - outside of mapped address window"); 00679 throw re; 00680 } 00681 } 00682 00683 /* 00684 \fn CVMEptr<T>& CVMEptr<T>::operator-(UInt_t nOffset) 00685 00686 Operation Type: 00687 Mutator 00688 00689 Purpose: 00690 Subtracts an offset to the current offset. Throws an exception if this 00691 puts us out of range of the memory map. 00692 00693 \param UInt_t nOffset - the integer to subtract from the current offset 00694 */ 00695 template<class T> 00696 CVMEptr<T> 00697 CVMEptr<T>::operator-(UInt_t nOffset) 00698 { 00699 if(nOffset <= m_nOffset) { // make sure we're in bounds 00700 CVMEptr<T> temp = *this; 00701 temp -= nOffset; 00702 return temp; 00703 } 00704 else { 00705 CRangeError re(0, m_nOffset, nOffset, 00706 "CVMEptr<T>::operator-() - outside of mapped addressed window"); 00707 throw re; 00708 } 00709 } 00710 00711 /* 00712 \fn CVMEptr<T>& CVMEptr<T>::operator+=(UInt_t nOffset) 00713 00714 Operation Type: 00715 Mutator 00716 00717 Purpose: 00718 Add an offset to the current offset. Throws an exception if this 00719 puts us out of range of the memory map. 00720 00721 \param UInt_t nOffset - the integer to add to the current offset 00722 */ 00723 template<class T> 00724 CVMEptr<T>& 00725 CVMEptr<T>::operator+=(UInt_t nOffset) 00726 { 00727 if(m_nOffset+nOffset <= m_nLength) { 00728 m_nOffset += nOffset; 00729 return *this; 00730 } 00731 else { 00732 CRangeError re(0, m_nOffset, nOffset, 00733 "CVMEptr<T>::operator+=() - outside of mapped address window"); 00734 throw re; 00735 } 00736 } 00737 00738 /* 00739 \fn CVMEptr<T>& CVMEptr<T>::operator-=(UInt_t nOffset) 00740 00741 Operation Type: 00742 Mutator 00743 00744 Purpose: 00745 Subtract an offset to the current offset. Throws an exception if this 00746 puts us out of range of the memory map. 00747 00748 \param UInt_t nOffset - the integer to subtract from the current offset 00749 */ 00750 template<class T> 00751 CVMEptr<T>& 00752 CVMEptr<T>::operator-=(UInt_t nOffset) 00753 { 00754 if(m_nOffset-nOffset > 0) { 00755 m_nOffset -= nOffset; 00756 return *this; 00757 } 00758 else { 00759 CRangeError re(0, m_nOffset, nOffset, 00760 "CVMEptr<T>::operator-=() - outside of mapped address window"); 00761 } 00762 } 00763 00764 /* 00765 \fn CVMEptr<T>& CVMEptr<T>::operator++() 00766 00767 Operation Type: 00768 Mutator 00769 00770 Purpose: 00771 (Pre)Increment the current offset. Throws an exception if this puts 00772 m_nOffset past the length of the memory map. 00773 */ 00774 template<class T> 00775 CVMEptr<T>& 00776 CVMEptr<T>::operator++() 00777 { 00778 if(m_nOffset < m_nLength) { 00779 m_nOffset++; 00780 return *this; 00781 } 00782 else { 00783 string reason = "CVMEptr<T>::operator++() - reference to address which\n"; 00784 reason += "is greater than map size"; 00785 CRangeError re(0, m_nOffset, m_nOffset+1, reason); 00786 throw re; 00787 } 00788 } 00789 00790 /* 00791 \fn CVMEptr<T>& CVMEptr<T>::operator--() 00792 00793 Operation Type: 00794 Mutator 00795 00796 Purpose: 00797 (Pre)Decrement the current offset. Throws an exception if this puts 00798 m_nOffset less than 0. 00799 */ 00800 template<class T> 00801 CVMEptr<T>& 00802 CVMEptr<T>::operator--() 00803 { 00804 if(m_nOffset > 0) { 00805 m_nOffset--; 00806 return *this; 00807 } 00808 else { 00809 string reason = "CVMEptr<T>::operator--() - reference to address which\n"; 00810 reason += "is less than map size"; 00811 CRangeError re(0, m_nOffset, m_nOffset-1, reason); 00812 throw re; 00813 } 00814 } 00815 00816 /* 00817 \fn CVMEptr<T>& CVMEptr<T>::operator++(Int_t) 00818 00819 Operation type: 00820 Mutator 00821 00822 Purpose: 00823 (Post)Increment the current offset. Throws an exception if this puts 00824 us past the length of the map. 00825 00826 \param Int_t - dummy parameter indicates this is a 00827 post-increment operator 00828 */ 00829 template<class T> 00830 CVMEptr<T> 00831 CVMEptr<T>::operator++(Int_t) 00832 { 00833 if(m_nOffset < m_nLength) { 00834 CVMEptr<T> p(*this); 00835 operator++(); 00836 return p; 00837 } 00838 else { 00839 string reason = "CVMEptr<T>::operator++() - reference to memory address\n"; 00840 reason += "which is greater than the size of the map"; 00841 CRangeError re(0, m_nOffset, m_nOffset+1, reason); 00842 throw re; 00843 } 00844 } 00845 00846 /* 00847 \fn CVMEptr<T>& CVMEptr<T>::operator--(Int_t) 00848 00849 Operation type: 00850 Mutator 00851 00852 Purpose: 00853 (Post)Decrement the current offset. Throws an exception if this puts 00854 us before the beginning of the memory map. 00855 00856 \param Int_t - dummy parameter indicates this is a 00857 post-decrement operator 00858 */ 00859 template<class T> 00860 CVMEptr<T> 00861 CVMEptr<T>::operator--(Int_t) 00862 { 00863 if(m_nOffset > 0) { 00864 CVMEptr<T> p(*this); 00865 operator--(); 00866 return p; 00867 } 00868 else { 00869 string reason = "CVMEptr<T>::operator--() reference to memory address\n"; 00870 reason += "which is less than the start address of the map"; 00871 CRangeError re(0, m_nOffset, m_nOffset-1, reason); 00872 throw re; 00873 } 00874 } 00875 00876 /* 00877 \fn Address_t CVMEptr<T>::getgenptr(UInt_t nOffset) 00878 00879 Operation type: 00880 Selector 00881 00882 Purpose: 00883 Return a pointer to the current address+offset into the module 00884 00885 \param UInt_t nOffset - an offset to use to determine the pointer 00886 */ 00887 template<class T> 00888 Address_t 00889 CVMEptr<T>::getgenptr(UInt_t nOffset) 00890 { 00891 Address_t p = (Address_t)(nOffset*sizeof(T) + (UInt_t)m_pStart); 00892 if(p) return p; 00893 else return (Address_t)kpNULL; 00894 } 00895 00896 /* 00897 \fn CVMEptr<UChar_t> CVMEptr<T>::asChar() 00898 00899 Operation Type: 00900 Type conversion operator 00901 00902 Purpose: 00903 Returns this as a CVMEptr which maps m_pStart to an address space 00904 containing data of type UChar_t. 00905 */ 00906 template<class T> 00907 CVMEptr<UChar_t> 00908 CVMEptr<T>::asChar() 00909 { 00910 //if(sizeof(T) == sizeof(UChar_t)) return *this; 00911 00912 CVMEptr<UChar_t> temp; 00913 temp.setOffset(m_nOffset); 00914 temp.setLength(m_nLength); 00915 temp.setStart(m_pStart); 00916 temp.setActualBase(m_pActualBase); 00917 return temp; 00918 } 00919 00920 /* 00921 \fn CVMEptr<UShort_t> CVMEptr<T>::asShort() 00922 00923 Operation Type: 00924 Type conversion operator 00925 00926 Purpose: 00927 Returns this as a CVMEptr which maps m_pStart to an address space 00928 containing data of type UShort_t. 00929 */ 00930 template<class T> 00931 CVMEptr<UShort_t> 00932 CVMEptr<T>::asShort() 00933 { 00934 if(sizeof(T) == sizeof(UShort_t)) return *this; 00935 00936 CVMEptr<UShort_t> temp; 00937 temp.setOffset(m_nOffset); 00938 temp.setLength(m_nLength); 00939 temp.setStart(m_pStart); 00940 00941 return temp; 00942 } 00943 00944 /* 00945 \fn CVMEptr<ULong_t> CVMEptr<T>::asLong() 00946 00947 Operation Type: 00948 Type conversion operator 00949 00950 Purpose: 00951 Returns this as a CVMEptr which maps m_pStart to an address space 00952 containing data of type ULong_t. 00953 */ 00954 template<class T> 00955 CVMEptr<ULong_t> 00956 CVMEptr<T>::asLong() 00957 { 00958 if(sizeof(T) == sizeof(ULong_t)) return *this; 00959 00960 CVMEptr<ULong_t> temp; 00961 temp.setOffset(m_nOffset); 00962 temp.setLength(m_nLength); 00963 temp.setStart(m_pStart); 00964 00965 return temp; 00966 }