Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:29

0001 #pragma once
0002 /**
0003 s_pmt.h
0004 ========
0005 
0006 HMM : NOW THAT THE GAPS ARE NOT SO LARGE IS TEMPTING TO DIRECTLY USE PMTID AND HAVE ZEROS IN THE GAPS
0007 
0008 
0009 Methods:
0010 
0011 s_pmt::desc
0012     dump the basis num and offsets
0013 
0014 s_pmt::check_pmtid
0015     asserts
0016 
0017 s_pmt::in_range
0018     internal
0019 
0020 s_pmt::id_CD_LPMT
0021 s_pmt::id_CD_SPMT
0022 s_pmt::id_WP_PMT
0023 s_pmt::id_WP_ATM_LPMT
0024 s_pmt::id_WP_ATM_MPMT
0025 s_pmt::id_WP_WAL_PMT
0026     return true when *id:pmtid* is within corresponding ranges of the six pmt types
0027 
0028 s_pmt::ix_CD_LPMT
0029 s_pmt::ix_CD_SPMT
0030 s_pmt::ix_WP_PMT
0031 s_pmt::ix_WP_ATM_LPMT
0032 s_pmt::ix_WP_ATM_MPMT
0033 s_pmt::ix_WP_WAL_PMT
0034     return true when *ix:oldcontiguousidx* is within corresponding ranges of the six pmt types
0035 
0036 s_pmt::oldcontiguousidx_from_pmtid
0037     return *ix:oldcontiguousidx* from *id:pmtid*
0038 
0039 s_pmt::pmtid_from_oldcontiguousidx
0040     return *id:pmtid* from *ix:oldcontiguousidx*
0041 
0042 s_pmt::contiguousidx_from_pmtid
0043     return *ix:contiguousidx* from *id:pmtid* (DIFFERS IN THE ORDERING OF PMT TYPES, WITH SPMT SHIFTED TO LAST NOT 2ND)
0044 
0045 
0046 s_pmt::lpmtidx_from_pmtid
0047     return *iy:lpmtidx* from *pmtid* (-1 for SPMT) [*iy:lpmtidx*-IS-MISNOMER-ACTUALLY-ALL-PMT-EXCLUDING-SPMT]
0048 
0049 
0050 s_pmt::iy_CD_PMT
0051 s_pmt::iy_WP_PMT
0052 s_pmt::iy_WP_ATM_LPMT
0053 s_pmt::iy_WP_ATM_MPMT
0054 s_pmt::iy_WP_WAL_PMT
0055 s_pmt::iy_CD_SPMT
0056     return true when *iy:contiguousidx* is within corresponding ranges of six pmt types, SPMT last
0057 
0058 s_pmt::pmtid_from_contiguousidx
0059     uses iy_ methods to find pmt type for *iy:contiguousidx* then uses offset and num of prior pmt types to return absolute pmtid
0060 
0061 s_pmt::pmtid_from_lpmtidx (very similar to above, just with SPMT excluded : they yield -1)
0062     uses iy_ methods to find pmt type for *iy:lpmtidx* thne uses offfset and num of prior pmt types to return absolute pmtid
0063 
0064 
0065 s_pmt::is_spmtid
0066     returns true for absolute *pmtid* within offset range of SPMT
0067 
0068 s_pmt::is_spmtidx
0069     returns true for *pmtidx* in range 0:NUM_SPMT
0070 
0071 s_pmt::pmtid_from_spmtidx
0072     returns absolute *pmtid* from *spmtidx*
0073 
0074 s_pmt::spmtidx_from_pmtid
0075     returns *spmtidx* from absolute *pmtid*
0076 
0077 
0078 
0079 
0080 Used from::
0081 
0082    qudarap/QPMT.hh
0083    qudarap/qpmt.h
0084    sysrap/SPMT.h
0085 
0086 
0087 jcv CopyNumber::
0088 
0089         014 enum PMTID_OFFSET_DETSIM {
0090          15   kOFFSET_CD_LPMT=0,     kOFFSET_CD_LPMT_END=17612, // CD-LPMT
0091          16   kOFFSET_CD_SPMT=20000, kOFFSET_CD_SPMT_END=45600,  // CD-SPMT
0092          17   kOFFSET_WP_PMT=50000,  kOFFSET_WP_PMT_END=52400,  // WP-LPMT
0093          18   kOFFSET_WP_ATM_LPMT=52400,  kOFFSET_WP_ATM_LPMT_END=52748, //WP-Atmosphere-LPMT
0094          19   kOFFSET_WP_ATM_MPMT=53000,  kOFFSET_WP_ATM_MPMT_END=53600,  //WP-Atmosphere-MPMT (Medium, 8 inch)
0095          20   kOFFSET_WP_WAL_PMT=54000,  kOFFSET_WP_WAL_PMT_END=54005 //WP-Water-attenuation-length
0096          21
0097          22 };
0098 
0099 **/
0100 
0101 
0102 #if defined(__CUDACC__) || defined(__CUDABE__)
0103 #    define SPMT_FUNCTION __host__ __device__ __forceinline__
0104 #else
0105 #    define SPMT_FUNCTION inline
0106 #endif
0107 
0108 
0109 #if defined(__CUDACC__) || defined(__CUDABE__)
0110 #else
0111 #include <cassert>
0112 #include <string>
0113 #include <iostream>
0114 #include <sstream>
0115 #include <iomanip>
0116 #endif
0117 
0118 /**
0119 NB for backward compat with an old branch, had to revert NUM_WP_ATM_MPMT to 0 from 600
0120 https://code.ihep.ac.cn/JUNO/offline/junosw/-/merge_requests/1061
0121 **/
0122 
0123 
0124 /**
0125 The below WITH_MPMT line needs to be commented for use with older branches
0126 to avoid runtime translation asserts
0127 
0128 Now that MPMT has been merged, WITH_MPMT should normally be defined, but
0129 still older branches from before MPMT was merged may need to comment it
0130 
0131 **/
0132 
0133 #define WITH_MPMT 1
0134 
0135 namespace s_pmt
0136 {
0137     enum
0138     {
0139         NUM_CAT                = 3,
0140         NUM_LAYR               = 4,
0141         NUM_PROP               = 2,
0142         NUM_CD_LPMT            = 17612,
0143         NUM_SPMT               = 25600,
0144         NUM_WP                 = 2400,
0145         NUM_WP_ATM_LPMT        = 348,
0146         NUM_WP_ATM_MPMT_ALREADY = 600,      // unfortunately some branches partially have the MPMT
0147 #ifdef WITH_MPMT
0148         NUM_WP_ATM_MPMT        = 600,      // 0:newer ones have MPMT
0149 #else
0150         NUM_WP_ATM_MPMT        = 0,        // 0:older branches lack MPMT
0151 #endif
0152         NUM_WP_WAL_PMT         = 5,
0153         OFFSET_CD_LPMT         = 0,
0154         OFFSET_CD_LPMT_END     = 17612,
0155         OFFSET_CD_SPMT         = 20000,
0156         OFFSET_CD_SPMT_END     = 45600,
0157         OFFSET_WP_PMT          = 50000,
0158         OFFSET_WP_PMT_END      = 52400,
0159         OFFSET_WP_ATM_LPMT     = 52400,
0160         OFFSET_WP_ATM_LPMT_END = 52748,
0161         OFFSET_WP_ATM_MPMT     = 53000,
0162         OFFSET_WP_ATM_MPMT_END = 53600,
0163         OFFSET_WP_WAL_PMT      = 54000,
0164         OFFSET_WP_WAL_PMT_END  = 54005
0165     };
0166 
0167 
0168     enum
0169     {
0170         NUM_CD_LPMT_AND_WP   = NUM_CD_LPMT + NUM_WP  +               0 +              0  +              0 +        0,   // 17612 + 2400 +   0 +      0  + 0  +    0 = 20012
0171         NUM_LPMTIDX          = NUM_CD_LPMT + NUM_WP  + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT + NUM_WP_WAL_PMT +        0,   // 17612 + 2400 + 348 + {0,600} + 5  +    0 = {20365,20965}
0172         NUM_ALL              = NUM_CD_LPMT + NUM_WP  + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT + NUM_WP_WAL_PMT + NUM_SPMT,   // 17612 + 2400 + 348 + {0,600} + 5 + 25600 = {45965,46565}
0173         NUM_ALL_EXCEPT_MPMT  = NUM_ALL - NUM_WP_ATM_MPMT,                                                               // 46565 - 600 = 45965
0174         NUM_CONTIGUOUSIDX    = NUM_CD_LPMT + NUM_WP  + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT         + NUM_WP_WAL_PMT + NUM_SPMT,   // 17612 + 2400 + 348 + {0,600} + 5 + 25600 = {45965,46565}
0175         NUM_OLDCONTIGUOUSIDX = NUM_CD_LPMT + NUM_WP  + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT_ALREADY + NUM_WP_WAL_PMT + NUM_SPMT,   // 17612 + 2400 + 348 + 600     + 5 + 25600 =        46565
0176     };
0177 
0178 
0179 #if defined(__CUDACC__) || defined(__CUDABE__)
0180 #else
0181    SPMT_FUNCTION std::string desc()
0182    {
0183        std::stringstream ss ;
0184        ss
0185           << "[s_pmt::desc\n"
0186 #ifdef WITH_MPMT
0187           << " WITH_MPMT\n"
0188 #else
0189           << " NOT:WITH_MPMT\n"
0190 #endif
0191           << std::setw(25) << "NUM_CAT"                   << std::setw(7) << NUM_CAT                  << "\n"
0192           << std::setw(25) << "NUM_LAYR"                  << std::setw(7) << NUM_LAYR                 << "\n"
0193           << std::setw(25) << "NUM_PROP"                  << std::setw(7) << NUM_PROP                 << "\n"
0194           << std::setw(25) << "NUM_CD_LPMT"               << std::setw(7) << NUM_CD_LPMT              << "\n"
0195           << std::setw(25) << "NUM_SPMT"                  << std::setw(7) << NUM_SPMT                 << "\n"
0196           << std::setw(25) << "NUM_WP"                    << std::setw(7) << NUM_WP                   << "\n"
0197           << std::setw(25) << "NUM_WP_ATM_LPMT"           << std::setw(7) << NUM_WP_ATM_LPMT          << "\n"
0198           << std::setw(25) << "NUM_WP_ATM_MPMT_ALREADY"   << std::setw(7) << NUM_WP_ATM_MPMT_ALREADY  << "\n"
0199           << std::setw(25) << "NUM_WP_ATM_MPMT"           << std::setw(7) << NUM_WP_ATM_MPMT          << "\n"
0200           << std::setw(25) << "NUM_WP_WAL_PMT"            << std::setw(7) << NUM_WP_WAL_PMT           << "\n"
0201           << std::setw(25) << "NUM_CD_LPMT_AND_WP"        << std::setw(7) << NUM_CD_LPMT_AND_WP       << "\n"
0202           << std::setw(25) << "NUM_ALL"                   << std::setw(7) << NUM_ALL                  << "\n"
0203           << std::setw(25) << "NUM_LPMTIDX"               << std::setw(7) << NUM_LPMTIDX              << "\n"
0204           << std::setw(25) << "NUM_CONTIGUOUSIDX"         << std::setw(7) << NUM_CONTIGUOUSIDX        << "\n"
0205           << std::setw(25) << "NUM_OLDCONTIGUOUSIDX"      << std::setw(7) << NUM_OLDCONTIGUOUSIDX     << "\n"
0206           << std::setw(25) << "OFFSET_CD_LPMT"            << std::setw(7) << OFFSET_CD_LPMT           << "\n"
0207           << std::setw(25) << "OFFSET_CD_LPMT_END"        << std::setw(7) << OFFSET_CD_LPMT_END       << "\n"
0208           << std::setw(25) << "OFFSET_CD_SPMT"            << std::setw(7) << OFFSET_CD_SPMT           << "\n"
0209           << std::setw(25) << "OFFSET_CD_SPMT_END"        << std::setw(7) << OFFSET_CD_SPMT_END       << "\n"
0210           << std::setw(25) << "OFFSET_WP_PMT"             << std::setw(7) << OFFSET_WP_PMT            << "\n"
0211           << std::setw(25) << "OFFSET_WP_PMT_END"         << std::setw(7) << OFFSET_WP_PMT_END        << "\n"
0212           << std::setw(25) << "OFFSET_WP_ATM_LPMT"        << std::setw(7) << OFFSET_WP_ATM_LPMT       << "\n"
0213           << std::setw(25) << "OFFSET_WP_ATM_LPMT_END"    << std::setw(7) << OFFSET_WP_ATM_LPMT_END   << "\n"
0214           << std::setw(25) << "OFFSET_WP_ATM_MPMT"        << std::setw(7) << OFFSET_WP_ATM_MPMT       << "\n"
0215           << std::setw(25) << "OFFSET_WP_ATM_MPMT_END"    << std::setw(7) << OFFSET_WP_ATM_MPMT_END   << "\n"
0216           << std::setw(25) << "OFFSET_WP_WAL_PMT"         << std::setw(7) << OFFSET_WP_WAL_PMT        << "\n"
0217           << std::setw(25) << "OFFSET_WP_WAL_PMT_END"     << std::setw(7) << OFFSET_WP_WAL_PMT_END    << "\n"
0218           << "]s_pmt::desc\n"
0219           ;
0220 
0221        std::string str = ss.str() ;
0222        return str ;
0223    }
0224 
0225     SPMT_FUNCTION void check_pmtid( int pmtid )
0226     {
0227         assert(  pmtid >= 0 && pmtid < OFFSET_WP_WAL_PMT_END );
0228         assert(!(pmtid >= OFFSET_CD_LPMT_END && pmtid < OFFSET_CD_SPMT ));
0229         assert(!(pmtid >= OFFSET_CD_SPMT_END && pmtid < OFFSET_WP_PMT ));
0230 
0231         assert( OFFSET_CD_LPMT_END - OFFSET_CD_LPMT == NUM_CD_LPMT );
0232         assert( OFFSET_CD_SPMT_END - OFFSET_CD_SPMT == NUM_SPMT );
0233         assert( OFFSET_WP_PMT_END  - OFFSET_WP_PMT  == NUM_WP );
0234 
0235 #ifdef WITH_MPMT
0236         assert( OFFSET_WP_ATM_MPMT_END - OFFSET_WP_ATM_MPMT == NUM_WP_ATM_MPMT ) ;
0237 #endif
0238 
0239         assert( OFFSET_WP_WAL_PMT_END - OFFSET_WP_WAL_PMT == NUM_WP_WAL_PMT ) ;
0240 
0241         assert( NUM_LPMTIDX          == NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT         + NUM_WP_WAL_PMT );
0242         assert( NUM_CONTIGUOUSIDX    == NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT         + NUM_WP_WAL_PMT + NUM_SPMT ) ;
0243         assert( NUM_ALL              == NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT         + NUM_WP_WAL_PMT + NUM_SPMT ) ;
0244 
0245         assert( NUM_OLDCONTIGUOUSIDX == NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT_ALREADY + NUM_WP_WAL_PMT + NUM_SPMT ) ;
0246         // oldcontiguousidx matches implicit pmtCat index, which includes the MPMT:600 even before fully impl 
0247 
0248 
0249     }
0250 
0251 
0252 
0253 
0254 #endif
0255 
0256 
0257 
0258 
0259 
0260     SPMT_FUNCTION bool in_range( int ix, int ix0, int ix1 ){ return ix >= ix0 && ix < ix1 ; }
0261 
0262     // returns true when id argument is within the pmtid range of that type of pmt
0263     SPMT_FUNCTION bool id_CD_LPMT(     int id ){ return in_range( id, OFFSET_CD_LPMT     , OFFSET_CD_LPMT_END     ) ; }
0264     SPMT_FUNCTION bool id_CD_SPMT(     int id ){ return in_range( id, OFFSET_CD_SPMT     , OFFSET_CD_SPMT_END     ) ; }
0265     SPMT_FUNCTION bool id_WP_PMT(      int id ){ return in_range( id, OFFSET_WP_PMT      , OFFSET_WP_PMT_END      ) ; }
0266     SPMT_FUNCTION bool id_WP_ATM_LPMT( int id ){ return in_range( id, OFFSET_WP_ATM_LPMT , OFFSET_WP_ATM_LPMT_END ) ; }
0267     SPMT_FUNCTION bool id_WP_ATM_MPMT( int id ){ return in_range( id, OFFSET_WP_ATM_MPMT , OFFSET_WP_ATM_MPMT_END ) ; }
0268     SPMT_FUNCTION bool id_WP_WAL_PMT(  int id ){ return in_range( id, OFFSET_WP_WAL_PMT  , OFFSET_WP_WAL_PMT_END  ) ; }
0269 
0270 
0271 
0272 
0273 
0274     /**
0275     s_pmt::oldcontiguousidx_from_pmtid
0276     ----------------------------------
0277 
0278     *ix:oldcontiguousidx* follows the numerical ascending order of the absolute pmtid, but without gaps.
0279 
0280     Transform non-contiguous pmtid::
0281 
0282           +------------------+      +-----------------------------+       +--------+--------------+       +-------------+          +-------------+
0283           |     CD_LPMT      |      |     SPMT                    |       |  WP    | WP_ATM_LPMT  |       | WP_ATM_MPMT |          | WP_WAL_PMT  |
0284           |     17612        |      |     25600                   |       |  2400  |   348        |       |    600      |          |     5       |
0285           +------------------+      +-----------------------------+       +--------+--------------+       +-------------+          +-------------+
0286           ^                  ^      ^                             ^       ^        ^              ^       ^             ^          ^             ^
0287           0                  17612  20000                         45600   50000    52400          52748   53000         53600      54000         54005
0288           |                  |      |                             |       |        |              |       |             |          |             |
0289           |                  |      |                             |       |        |              |       |             |          |             |
0290           |                  |      |                             |       |        |              |       |             |          |             OFFSET_WP_WAL_PMT_END
0291           |                  |      |                             |       |        |              |       |             |          OFFSET_WP_WAL_PMT
0292           |                  |      |                             |       |        |              |       |             |
0293           |                  |      |                             |       |        |              |       |             OFFSET_WP_ATM_MPMT_END
0294           |                  |      |                             |       |        |              |       OFFSET_WP_ATM_MPMT
0295           |                  |      |                             |       |        |              |
0296           |                  |      |                             |       |        |              OFFSET_WP_ATM_LPMT_END
0297           |                  |      |                             |       |        OFFSET_WP_ATM_LPMT
0298           |                  |      |                             |       |        |
0299           |                  |      |                             |       |        OFFSET_WP_PMT_END
0300           |                  |      |                             |       OFFSET_WP_PMT
0301           |                  |      |                             |
0302           |                  |      |                             OFFSET_CD_SPMT_END
0303           |                  |      OFFSET_CD_SPMT
0304           |                  |
0305           |                  OFFSET_CD_LPMT_END
0306           OFFSET_CD_LPMT
0307 
0308 
0309           pmtid >= OFFSET_CD_LPMT_END && pmtid < OFFSET_CD_SPMT    # 1st gap
0310           pmtid >= OFFSET_CD_SPMT_END && pmtid < OFFSET_WP_PMT     # 2nd gap
0311 
0312           17612+25600+2400 = 45612
0313 
0314           20000 - 17612 = 2388   # first gap
0315           50000 - 45600 = 4400   # second gap
0316           2388 + 4400   = 6788   # total gap
0317           52400 - 45612 = 6788   # diff between max pmtid kOFFSET_WP_PMT_END and NUM_ALL
0318 
0319 
0320     Into oldcontiguousidx::
0321 
0322           +------------------+-----------------------------+--------+--------------+---------------+-------------+
0323           |     CD_LPMT      |     SPMT                    |  WP    | WP_ATM_LPMT  |  WP_ATM_MPMT  |  WP_WAL_PMT |
0324           |     17612        |     25600                   |  2400  |   348        |     600       |     5       |
0325           +------------------+-----------------------------+--------+--------------+---------------+-------------+
0326           ^                  ^                             ^        ^
0327           0                17612                         43212    45612
0328 
0329          17612 + 25600 = 43212
0330 
0331 
0332     NB the oldcontiguousidx corresponds to the ordering using by pmtCat (from _PMTParamData/m_pmt_categories),
0333     even in an older branch without MPMT fully impl they are already present in the pmtCat::
0334 
0335 
0336         In [27]: np.all( f.pmtCat[17612+25600+2400+348:17612+25600+2400+348+600][:,1] == 4 )  ## MPMT all 600 are cat:4
0337         Out[27]: np.True_
0338 
0339         In [28]: f.pmtCat[17612+25600+2400+348+600:17612+25600+2400+348+600+5]
0340         Out[28]:
0341         array([[54000,     3],
0342                [54001,     0],
0343                [54002,     0],
0344                [54003,     0],
0345                [54004,     0]], dtype=int32)
0346 
0347     So the implicit contiguous index of pmtCat follows the order, and included MPMT::
0348 
0349         CD-LPMT:17612
0350         CD-SPMT:25600
0351         WP-LPMT:2400
0352         WP-Atmosphere-LPMT:348
0353         WP-Atmosphere-MPMT:600
0354         WP-Water-attenuation-length:5
0355 
0356     **/
0357 
0358 
0359     // returns true when *ix:oldcontiguousidx* argument is within the oldcontinuousidx ranges
0360     SPMT_FUNCTION bool ix_CD_LPMT(     int ix ){ return in_range(ix, 0                                                                           , NUM_CD_LPMT           ) ; }
0361     SPMT_FUNCTION bool ix_CD_SPMT(     int ix ){ return in_range(ix, NUM_CD_LPMT                                                                 , NUM_CD_LPMT + NUM_SPMT) ; }
0362     SPMT_FUNCTION bool ix_WP_PMT(      int ix ){ return in_range(ix, NUM_CD_LPMT + NUM_SPMT                                                      , NUM_CD_LPMT + NUM_SPMT + NUM_WP)  ; }
0363     SPMT_FUNCTION bool ix_WP_ATM_LPMT( int ix ){ return in_range(ix, NUM_CD_LPMT + NUM_SPMT + NUM_WP                                             , NUM_CD_LPMT + NUM_SPMT + NUM_WP + NUM_WP_ATM_LPMT)  ; }
0364     SPMT_FUNCTION bool ix_WP_ATM_MPMT( int ix ){ return in_range(ix, NUM_CD_LPMT + NUM_SPMT + NUM_WP + NUM_WP_ATM_LPMT                           , NUM_CD_LPMT + NUM_SPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT_ALREADY)  ; }
0365     SPMT_FUNCTION bool ix_WP_WAL_PMT(  int ix ){ return in_range(ix, NUM_CD_LPMT + NUM_SPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT_ALREADY , NUM_CD_LPMT + NUM_SPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT_ALREADY + NUM_WP_WAL_PMT ) ; }
0366 
0367 
0368     /**
0369     oldcontiguousidx_from_pmtid
0370     -----------------------------
0371 
0372     1. find PMT type from pmtid id_ methods
0373     2. subtract the PMT type offset to give local index within the type
0374     3. add the NUM of other types below this one in the order of PMT types
0375 
0376     **/
0377 
0378 
0379     SPMT_FUNCTION int oldcontiguousidx_from_pmtid( int id )
0380     {
0381 #if defined(__CUDACC__) || defined(__CUDABE__)
0382 #else
0383         check_pmtid(id);
0384 #endif
0385 
0386         int ix = -1 ;
0387 
0388         if(      id_CD_LPMT(id) )    ix = id ;
0389         else if( id_CD_SPMT(id) )    ix = id - OFFSET_CD_SPMT     + NUM_CD_LPMT ;
0390         else if( id_WP_PMT(id)  )    ix = id - OFFSET_WP_PMT      + NUM_CD_LPMT + NUM_SPMT ;
0391         else if( id_WP_ATM_LPMT(id)) ix = id - OFFSET_WP_ATM_LPMT + NUM_CD_LPMT + NUM_SPMT + NUM_WP ;
0392         else if( id_WP_ATM_MPMT(id)) ix = id - OFFSET_WP_ATM_MPMT + NUM_CD_LPMT + NUM_SPMT + NUM_WP + NUM_WP_ATM_LPMT ;
0393         else if( id_WP_WAL_PMT(id))  ix = id - OFFSET_WP_WAL_PMT  + NUM_CD_LPMT + NUM_SPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT_ALREADY ;
0394 
0395         return ix ;
0396     }
0397 
0398     /**
0399     pmtid_from_oldcontiguousidx
0400     ----------------------------
0401 
0402     1. find PMT type from *ix:oldcontiguousidx* using ix_ methods
0403     2. get local index within the PMT type by subtracting total NUM of PMTs for PMT types prior to this PMT type in the order of PMT types
0404     3. add the offset for this PMT type to give the absolute PMT id
0405 
0406     **/
0407 
0408     SPMT_FUNCTION int pmtid_from_oldcontiguousidx( int ix )
0409     {
0410 #if defined(__CUDACC__) || defined(__CUDABE__)
0411 #else
0412         assert( ix >= 0 && ix < NUM_OLDCONTIGUOUSIDX );
0413 #endif
0414 
0415         int id = -1 ;
0416 
0417         if(      ix_CD_LPMT(ix) )     id = OFFSET_CD_LPMT     + ix ;
0418         else if( ix_CD_SPMT(ix) )     id = OFFSET_CD_SPMT     + ix - ( NUM_CD_LPMT ) ;
0419         else if( ix_WP_PMT(ix) )      id = OFFSET_WP_PMT      + ix - ( NUM_CD_LPMT + NUM_SPMT ) ;
0420         else if( ix_WP_ATM_LPMT(ix) ) id = OFFSET_WP_ATM_LPMT + ix - ( NUM_CD_LPMT + NUM_SPMT + NUM_WP ) ;
0421         else if( ix_WP_ATM_MPMT(ix) ) id = OFFSET_WP_ATM_MPMT + ix - ( NUM_CD_LPMT + NUM_SPMT + NUM_WP + NUM_WP_ATM_LPMT )  ;
0422         else if( ix_WP_WAL_PMT(ix) )  id = OFFSET_WP_WAL_PMT  + ix - ( NUM_CD_LPMT + NUM_SPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT_ALREADY ) ;
0423 
0424         return id ;
0425     }
0426 
0427     /**
0428     s_pmt::contiguousidx_from_pmtid( int pmtid )
0429     ---------------------------------------------
0430 
0431 
0432     Transform non-contiguous pmtid::
0433 
0434           +------------------+      +-----------------------------+       +--------+--------------+       +-------------+          +-------------+
0435           |     CD_LPMT      |      |     SPMT                    |       |  WP    | WP_ATM_LPMT  |       | WP_ATM_MPMT |          | WP_WAL_PMT  |
0436           |     17612        |      |     25600                   |       |  2400  |   348        |       |    600      |          |     5       |
0437           +------------------+      +-----------------------------+       +--------+--------------+       +-------------+          +-------------+
0438           ^                  ^      ^                             ^       ^        ^              ^       ^             ^          ^             ^
0439           0                  17612  20000                         45600   50000    52400          52748   53000         53600      54000         54005
0440           |                  |      |                             |       |        |              |       |             |          |             |
0441           |                  |      |                             |       |        |              |       |             |          |             |
0442           |                  |      |                             |       |        |              |       |             |          |             OFFSET_WP_WAL_PMT_END
0443           |                  |      |                             |       |        |              |       |             |          OFFSET_WP_WAL_PMT
0444           |                  |      |                             |       |        |              |       |             |
0445           |                  |      |                             |       |        |              |       |             OFFSET_WP_ATM_MPMT_END
0446           |                  |      |                             |       |        |              |       OFFSET_WP_ATM_MPMT
0447           |                  |      |                             |       |        |              |
0448           |                  |      |                             |       |        |              OFFSET_WP_ATM_LPMT_END
0449           |                  |      |                             |       |        OFFSET_WP_ATM_LPMT
0450           |                  |      |                             |       |        |
0451           |                  |      |                             |       |        OFFSET_WP_PMT_END
0452           |                  |      |                             |       OFFSET_WP_PMT
0453           |                  |      |                             |
0454           |                  |      |                             OFFSET_CD_SPMT_END
0455           |                  |      OFFSET_CD_SPMT
0456           |                  |
0457           |                  OFFSET_CD_LPMT_END
0458           OFFSET_CD_LPMT
0459 
0460 
0461 
0462           pmtid >= OFFSET_CD_LPMT_END && pmtid < OFFSET_CD_SPMT    # 1st gap
0463           pmtid >= OFFSET_CD_SPMT_END && pmtid < OFFSET_WP_PMT     # 2nd gap
0464 
0465           17612+25600+2400 = 45612
0466 
0467           20000 - 17612 = 2388   # first gap
0468           50000 - 45600 = 4400   # second gap
0469           2388 + 4400   = 6788   # total gap
0470           52400 - 45612 = 6788   # diff between max pmtid kOFFSET_WP_PMT_END and NUM_ALL
0471 
0472 
0473     Into contiguousidx::
0474 
0475           +------------------+---------+----------------+----------------+---------------+---------------+
0476           |     CD_LPMT      |   WP    |  WP_ATM_LPMT   |   WP_ATM_MPMT  |   WP_WAL_PMT  |  SPMT         |
0477           |     17612        |   2400  |    348         |      600       |        5      |  25600        |
0478           +------------------+---------+----------------+------------------------------------------------+
0479           ^                  ^         ^
0480           0                17612     20012
0481 
0482          17612 + 2400 = 20012
0483          17612 + 2400 + 25600 = 45612
0484 
0485 
0486      The ordering CD_LPMT, WP, SPMT must match that used in::
0487 
0488          PMTSimParamSvc::init_all_pmtID_qe_scale "jcv PMTSimParamSvc"
0489          [MPMT ARE NOT INCLUDED IN THAT IN OLDER BRANCHES EG yupd_bottompipe_adjust]
0490 
0491     **/
0492 
0493 
0494     SPMT_FUNCTION int contiguousidx_from_pmtid( int id )
0495     {
0496 #if defined(__CUDACC__) || defined(__CUDABE__)
0497 #else
0498         check_pmtid(id);
0499 #endif
0500 
0501         int iy = -1 ;
0502 
0503         if(      id_CD_LPMT(id) )    iy = id ;
0504         else if( id_WP_PMT(id)  )    iy = id - OFFSET_WP_PMT      + NUM_CD_LPMT ;
0505         else if( id_WP_ATM_LPMT(id)) iy = id - OFFSET_WP_ATM_LPMT + NUM_CD_LPMT + NUM_WP ;
0506         else if( id_WP_ATM_MPMT(id)) iy = id - OFFSET_WP_ATM_MPMT + NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT ;
0507         else if( id_WP_WAL_PMT(id))  iy = id - OFFSET_WP_WAL_PMT  + NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT ;
0508         else if( id_CD_SPMT(id) )    iy = id - OFFSET_CD_SPMT     + NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT + NUM_WP_WAL_PMT ;
0509 
0510         return iy ;
0511     }
0512 
0513 
0514     /**
0515     s_pmt::lpmtidx_from_pmtid (SPMT yields -1)
0516     -------------------------------------------
0517 
0518     Rearrange the non-contiguous pmtid::
0519 
0520           +------------------+      +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+       +--------+--------------+     +-------------+     +-------------+
0521           |     CD_LPMT      |      :     SPMT                    :       |  WP    | WP_ATM_LPMT  |     | WP_ATM_MPMT |     | WP_WAL_PMT  |
0522           |     17612        |      :     25600                   :       |  2400  |    348       |     |    600      |     |     5       |
0523           +------------------+      +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+       +--------+--------------+     +-------------+     +-------------+
0524           ^                  ^      ^                             ^       ^        ^              ^     ^             ^     ^             ^
0525           0                17612  20000                         45600     50000    52400        52748  53000        53600  54000        54005
0526 
0527           |                  |      |                             |       |        |
0528           |                  |      |                             |       |        OFFSET_WP_PMT_END
0529           |                  |      |                             |       OFFSET_WP_PMT
0530           |                  |      |                             |
0531           |                  |      |                             OFFSET_CD_SPMT_END
0532           |                  |      OFFSET_CD_SPMT
0533           |                  |
0534           |                  OFFSET_CD_LPMT_END
0535           OFFSET_CD_LPMT
0536 
0537     Into a contiguous 0-based index lpmtidx with SPMT excluded::
0538 
0539           +------------------+--------+----------------+---------------+-------------+
0540           |     CD_LPMT      |  WP    |   WP_ATM_LPMT  |  WP_ATM_MPMT  | WP_WAL_PMT  |
0541           |     17612        | 2400   |       348      |     600       |     5       |
0542           +------------------+--------+----------------+---------------+-------------+
0543           ^                  ^        ^                ^               ^             ^
0544           0                 17612   20012           20360            20960         20965
0545 
0546           np.cumsum([17612, 2400, 348, 600, 5])
0547           array([17612, 20012, 20360, 20960, 20965])
0548 
0549 
0550      s_pmt::lpmtidx_from_pmtid is used for example from qpmt::get_lpmtid_stackspec_ce_acosf
0551 
0552     **/
0553 
0554 
0555     SPMT_FUNCTION int lpmtidx_from_pmtid( int id )
0556     {
0557         int iy = -1 ;
0558 
0559         if(      id_CD_LPMT(id) )    iy = id ;
0560         else if( id_WP_PMT(id)  )    iy = id - OFFSET_WP_PMT      + NUM_CD_LPMT ;
0561         else if( id_WP_ATM_LPMT(id)) iy = id - OFFSET_WP_ATM_LPMT + NUM_CD_LPMT + NUM_WP ;
0562         else if( id_WP_ATM_MPMT(id)) iy = id - OFFSET_WP_ATM_MPMT + NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT ;
0563         else if( id_WP_WAL_PMT(id))  iy = id - OFFSET_WP_WAL_PMT  + NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT ;
0564 
0565         return iy ;
0566     }
0567 
0568 
0569 
0570     /**
0571     iy_CD_LPMT/iy_WP_PMT/iy_WP_ATM_LPMT/iy_WP_ATM_MPMT/iy_WP_WAL_PMT/iy_CD_SPMT + pmtid_from_contiguousidx
0572     --------------------------------------------------------------------------------------------------------
0573 
0574     iy_methods returns true when iy "continuousidx" argument is within ranges with ordering and NUM assumptions for the six PMT types:
0575 
0576     * CD_LPMT, WP_PMT, WP_ATM_LPMT, WP_ATM_MPMT, WP_WAL_PMT, CD_SPMT
0577 
0578     *pmtid_from_contiguousidx* converts iy "continuousidx" into non-contiguous absolute standard pmtid
0579     using OFFSET for each PMT type and following the PMT type ordering and NUM assumptions
0580 
0581     **/
0582 
0583 
0584     SPMT_FUNCTION bool iy_CD_LPMT(     int iy ){ return in_range(iy, 0                                                                         , NUM_CD_LPMT ) ; }
0585     SPMT_FUNCTION bool iy_WP_PMT(      int iy ){ return in_range(iy, NUM_CD_LPMT                                                               , NUM_CD_LPMT + NUM_WP ) ; }
0586     SPMT_FUNCTION bool iy_WP_ATM_LPMT( int iy ){ return in_range(iy, NUM_CD_LPMT + NUM_WP                                                      , NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT) ; }
0587     SPMT_FUNCTION bool iy_WP_ATM_MPMT( int iy ){ return in_range(iy, NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT                                    , NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT) ; }
0588     SPMT_FUNCTION bool iy_WP_WAL_PMT(  int iy ){ return in_range(iy, NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT                  , NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT + NUM_WP_WAL_PMT ) ; }
0589     SPMT_FUNCTION bool iy_CD_SPMT(     int iy ){ return in_range(iy, NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT + NUM_WP_WAL_PMT , NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT + NUM_WP_WAL_PMT + NUM_SPMT) ; }
0590 
0591     SPMT_FUNCTION int pmtid_from_contiguousidx( int iy )
0592     {
0593 #if defined(__CUDACC__) || defined(__CUDABE__)
0594 #else
0595         assert( iy >= 0 && iy < NUM_CONTIGUOUSIDX );
0596 #endif
0597 
0598         int id = -1 ;
0599 
0600         if(      iy_CD_LPMT(iy) )     id = OFFSET_CD_LPMT     + iy ;
0601         else if( iy_WP_PMT(iy) )      id = OFFSET_WP_PMT      + iy - ( NUM_CD_LPMT ) ;
0602         else if( iy_WP_ATM_LPMT(iy) ) id = OFFSET_WP_ATM_LPMT + iy - ( NUM_CD_LPMT + NUM_WP ) ;
0603         else if( iy_WP_ATM_MPMT(iy) ) id = OFFSET_WP_ATM_MPMT + iy - ( NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT )  ;
0604         else if( iy_WP_WAL_PMT(iy) )  id = OFFSET_WP_WAL_PMT  + iy - ( NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT ) ;
0605         else if( iy_CD_SPMT(iy) )     id = OFFSET_CD_SPMT     + iy - ( NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT + NUM_WP_WAL_PMT ) ;
0606 
0607         return id ;
0608     }
0609 
0610 
0611 
0612 
0613     /**
0614     s_pmt::pmtid_from_lpmtidx   (NB very similar to s_pmt::pmtid_from_contiguousidx but with SPMT excluded)
0615     ------------------------------------------------------------------------------------------------------------
0616 
0617 
0618     Convert a contiguous 0-based index lpmtidx with SPMT excluded::
0619 
0620           +------------------+--------+----------------+----------------+--------------+~~~~~~~~~~~~~~~EXCLUDED~~~~~~
0621           |     CD_LPMT      |  WP    |   WP_ATM_LPMT  |  WP_ATM_MPMT   |   WP_WAL_PMT |      SPMT                  :
0622           |     17612        | 2400   |      348       |    600         |      5       |       25600                :
0623           +------------------+--------+----------------+----------------+--------------+~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
0624           ^                  ^        ^                ^                ^              ^                            ^
0625           0                 17612   20012            20360             20960         20965                        46565
0626 
0627                             |        |                 |                |              |
0628                             |        |                 |                |              NUM_CD_LPMT+NUM_WP+NUM_WP_ATM_PMT+NUM_WP_ATM_MPMT+NUM_WP_WAL_PMT
0629                             |        |                 |                NUM_CD_LPMT+NUM_WP+NUM_WP_ATM_PMT+NUM_WP_ATM_MPMT
0630                             |        |                NUM_CD_LPMT+NUM_WP+NUM_WP_ATM_LPMT
0631                             |       NUM_CD_LPMT+NUM_WP
0632                             NUM_CD_LPMT
0633 
0634     np.cumsum([17612,2400,348,600,5,25600])
0635     array([17612, 20012, 20360, 20960, 20965, 46565])
0636 
0637 
0638 
0639     Into the the non-contiguous lpmtid::
0640 
0641           +------------------+                                            +--------+--------------+     +-------------+     +-------------+
0642           |     CD_LPMT      |                                            |  WP    | WP_ATM_LPMT  |     | WP_ATM_MPMT |     | WP_WAL_PMT  |
0643           |     17612        |                                            |  2400  |    348       |     |    600      |     |     5       |
0644           +------------------+                                            +--------+--------------+     +-------------+     +-------------+
0645           ^                  ^      ^                             ^       ^        ^              ^     ^             ^     ^             ^
0646           0                17612  20000                         45600     50000    52400        52748  53000        53600  54000        54005
0647                                                                           |
0648                                                                           OFFSET_WP_PMT
0649 
0650 
0651    OR -1 for invalid lpmtidx arguments such as from SPMT.
0652 
0653           17612+25600+2400 = 45612
0654 
0655     This is used from SPMT::init_lcqs
0656 
0657     The assumptions made are:
0658 
0659     1. iy spans the range of expected PMT types
0660     2. ordering of PMT types for the input index is as expected
0661 
0662 
0663     **/
0664 
0665 
0666     SPMT_FUNCTION int pmtid_from_lpmtidx( int iy )
0667     {
0668 #if defined(__CUDACC__) || defined(__CUDABE__)
0669 #else
0670         assert( iy >= 0 && iy < NUM_LPMTIDX  );
0671 #endif
0672 
0673         int id = -1 ;
0674 
0675         if(      iy_CD_LPMT(iy) )     id = OFFSET_CD_LPMT     + iy ;
0676         else if( iy_WP_PMT(iy) )      id = OFFSET_WP_PMT      + iy - ( NUM_CD_LPMT ) ;
0677         else if( iy_WP_ATM_LPMT(iy) ) id = OFFSET_WP_ATM_LPMT + iy - ( NUM_CD_LPMT + NUM_WP ) ;
0678         else if( iy_WP_ATM_MPMT(iy) ) id = OFFSET_WP_ATM_MPMT + iy - ( NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT )  ;
0679         else if( iy_WP_WAL_PMT(iy) )  id = OFFSET_WP_WAL_PMT  + iy - ( NUM_CD_LPMT + NUM_WP + NUM_WP_ATM_LPMT + NUM_WP_ATM_MPMT ) ;
0680 
0681         return id ;
0682     }
0683 
0684 
0685 
0686 
0687 
0688 
0689 
0690     /**
0691     s_pmt::is_spmtid
0692      ----------------
0693 
0694     Used for example from SPMT::get_s_qescale_from_spmtid
0695 
0696     **/
0697 
0698     SPMT_FUNCTION bool is_spmtid( int pmtid )
0699     {
0700         return pmtid >= OFFSET_CD_SPMT && pmtid < OFFSET_CD_SPMT_END ;
0701     }
0702     SPMT_FUNCTION bool is_spmtidx( int pmtidx )
0703     {
0704         return pmtidx >= 0 && pmtidx < NUM_SPMT ;
0705     }
0706 
0707 
0708     SPMT_FUNCTION int pmtid_from_spmtidx( int spmtidx )
0709     {
0710 #if defined(__CUDACC__) || defined(__CUDABE__)
0711 #else
0712         assert( spmtidx >= 0 && spmtidx < NUM_SPMT );
0713 #endif
0714         return spmtidx + OFFSET_CD_SPMT ;
0715     }
0716 
0717     SPMT_FUNCTION int spmtidx_from_pmtid( int pmtid )
0718     {
0719 #if defined(__CUDACC__) || defined(__CUDABE__)
0720 #else
0721         assert( pmtid >= OFFSET_CD_SPMT && pmtid < OFFSET_CD_SPMT_END );
0722 #endif
0723         return pmtid - OFFSET_CD_SPMT ;
0724     }
0725 
0726 }
0727