Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:21:39

0001 #ifndef L1Trigger_RPCPacManager_h
0002 #define L1Trigger_RPCPacManager_h
0003 /** \class RPCPacManager
0004  *
0005  * The singleton object of thise class stores all PACs of L1RPC trigger.
0006  * The tempalte type TPacTypeshould be derived from RPCPacBase,
0007  * and containe the constructor:
0008  * RPCPacData(std::string patFilesDir, int m_tower, int logSector, int logSegment).
0009  * 3 configuration are suported:
0010  * ONE_PAC_PER_TOWER - the same m_PAC (set of patterns etc.) for every LogCone in a m_tower
0011  * _12_PACS_PER_TOWER - the same m_PAC in the same segment in every sector,
0012  * (i.e. 12 PACs in sector (one for LogicCone (segment)), all sectors are treat as one)
0013  * _144_PACS_PER_TOWER - one m_PAC for every LogicCone of given m_tower
0014  *
0015  * \author Karol Bunkowski (Warsaw)
0016  *
0017  */
0018 //------------------------------------------------------------------------------
0019 #include <string>
0020 #include <vector>
0021 #include "L1Trigger/RPCTrigger/interface/RPCConst.h"
0022 #include "L1Trigger/RPCTrigger/interface/RPCException.h"
0023 
0024 #include "CondFormats/L1TObjects/interface/L1RPCConfig.h"
0025 
0026 #include <cstdlib>
0027 #ifndef _STAND_ALONE
0028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0029 #endif  // _STAND_ALONE
0030 
0031 ///Suported configurations
0032 // TODO: should be moved to L1RPConfig
0033 enum L1RpcPACsCntEnum {
0034   ONE_PAC_PER_TOWER = 1,
0035   _12_PACS_PER_TOWER = 12,  //the same m_PAC in the same segment in every sector,
0036   _144_PACS_PER_TOWER = 144,
0037   TB_TESTS
0038 };
0039 
0040 template <class TPacType>
0041 class RPCPacManager {
0042 public:
0043   ~RPCPacManager() {
0044     for (unsigned int m_tower = 0; m_tower < m_PacTab.size(); m_tower++)
0045       for (unsigned int logSector = 0; logSector < m_PacTab[m_tower].size(); logSector++) {
0046         for (unsigned int logSegment = 0; logSegment < m_PacTab[m_tower][logSector].size(); logSegment++) {
0047           TPacType* pac = m_PacTab[m_tower][logSector][logSegment];
0048           delete pac;
0049         }
0050       }
0051   }
0052 
0053   /** Gets data for PACs. @param patFilesDirectory The directory where files defining
0054     * PACs are stored. The files should be named acording to special convencion.
0055     * @param  _PACsCnt The configuration version.
0056     * Should be caled once, before using PACs
0057     */
0058   void init(std::string patFilesDirectory, L1RpcPACsCntEnum _PACsCnt) {
0059     destroy();
0060     m_PACsCnt = _PACsCnt;
0061     if (m_PACsCnt == ONE_PAC_PER_TOWER) {
0062       m_SectorsCnt = 1;
0063       m_SegmentCnt = 1;
0064     } else if (m_PACsCnt == _12_PACS_PER_TOWER) {
0065       m_SectorsCnt = 1;
0066       m_SegmentCnt = 12;
0067     } else if (m_PACsCnt == _144_PACS_PER_TOWER) {
0068       m_SectorsCnt = 12;
0069       m_SegmentCnt = 12;
0070     } else if (m_PACsCnt == TB_TESTS) {
0071       m_SectorsCnt = 1;
0072       m_SegmentCnt = 4;
0073     }
0074 
0075     for (int m_tower = 0; m_tower < RPCConst::m_TOWER_COUNT; m_tower++) {
0076       m_PacTab.push_back(std::vector<std::vector<TPacType*> >());
0077       for (int logSector = 0; logSector < m_SectorsCnt; logSector++) {
0078         m_PacTab[m_tower].push_back(std::vector<TPacType*>());
0079         for (int logSegment = 0; logSegment < m_SegmentCnt; logSegment++) {
0080           TPacType* pac = new TPacType(patFilesDirectory, m_tower, logSector, logSegment);
0081           m_PacTab[m_tower][logSector].push_back(pac);
0082         }
0083       }
0084     }
0085   };
0086 
0087   void init(const L1RPCConfig* rpcconf) {
0088     destroy();
0089     switch (rpcconf->getPPT()) {
0090       case 1:
0091         m_PACsCnt = ONE_PAC_PER_TOWER;
0092         break;
0093       case 12:
0094         m_PACsCnt = _12_PACS_PER_TOWER;
0095         break;
0096       case 144:
0097         m_PACsCnt = _144_PACS_PER_TOWER;
0098         break;
0099     }
0100 
0101     if (m_PACsCnt == ONE_PAC_PER_TOWER) {
0102       m_SectorsCnt = 1;
0103       m_SegmentCnt = 1;
0104     } else if (m_PACsCnt == _12_PACS_PER_TOWER) {
0105       m_SectorsCnt = 1;
0106       m_SegmentCnt = 12;
0107     } else if (m_PACsCnt == _144_PACS_PER_TOWER) {
0108       m_SectorsCnt = 12;
0109       m_SegmentCnt = 12;
0110     } else if (m_PACsCnt == TB_TESTS) {
0111       m_SectorsCnt = 1;
0112       m_SegmentCnt = 4;
0113     }
0114 
0115     /*
0116     std::vector<std::vector<std::vector<RPCPattern::RPCPatVec> > > patvec;
0117     std::vector<std::vector<std::vector<RPCPattern::TQualityVec> > > qualvec;
0118     for (int tower = 0; tower < RPCConst::m_TOWER_COUNT; ++tower) {
0119       patvec.push_back(std::vector< std::vector< RPCPattern::RPCPatVec > >());
0120       qualvec.push_back(std::vector< std::vector< RPCPattern::TQualityVec > >());
0121       for (int logSector = 0; logSector < m_SectorsCnt; ++logSector) {
0122         patvec[tower].push_back(std::vector< RPCPattern::RPCPatVec >());
0123         qualvec[tower].push_back(std::vector< RPCPattern::TQualityVec >());
0124         for (int logSegment = 0; logSegment < m_SegmentCnt; ++logSegment) {
0125           patvec[tower][logSector].push_back(RPCPattern::RPCPatVec());
0126           qualvec[tower][logSector].push_back(RPCPattern::TQualityVec());
0127         }
0128       }
0129     }
0130 
0131     for (unsigned int ipat=0; ipat<rpcconf->m_pats.size(); ipat++)
0132       patvec[rpcconf->m_pats[ipat].getTower()][rpcconf->m_pats[ipat].getLogSector()][rpcconf->m_pats[ipat].getLogSegment()].push_back(rpcconf->m_pats[ipat]);
0133     for (unsigned int iqual=0; iqual<rpcconf->m_quals.size(); iqual++)
0134       qualvec[rpcconf->m_quals[iqual].m_tower][rpcconf->m_quals[iqual].m_logsector][rpcconf->m_quals[iqual].m_logsegment].push_back(rpcconf->m_quals[iqual]);
0135     */
0136 
0137     for (int tower = 0; tower < RPCConst::m_TOWER_COUNT; tower++) {
0138       m_PacTab.push_back(std::vector<std::vector<TPacType*> >());
0139       for (int logSector = 0; logSector < m_SectorsCnt; logSector++) {
0140         m_PacTab[tower].push_back(std::vector<TPacType*>());
0141         for (int logSegment = 0; logSegment < m_SegmentCnt; logSegment++) {
0142           /*L1RPCConfig* rpcconf1=new L1RPCConfig();
0143           rpcconf1->setPPT(rpcconf->getPPT());
0144           for (unsigned int ipat=0; ipat<patvec[tower][logSector][logSegment].size(); ipat++)
0145             rpcconf1->m_pats.push_back(patvec[tower][logSector][logSegment][ipat]);
0146           for (unsigned int iqual=0; iqual<qualvec[tower][logSector][logSegment].size(); iqual++)
0147             rpcconf1->m_quals.push_back(qualvec[tower][logSector][logSegment][iqual]);
0148           //TPacType* pac  = new TPacType(rpcconf1->m_pats,rpcconf1->m_quals);*/
0149           TPacType* pac = new TPacType(rpcconf, tower, logSector, logSegment);
0150           m_PacTab[tower][logSector].push_back(pac);
0151         }
0152       }
0153     }
0154   };
0155 
0156   /** Returns the pointer to m_PAC for given LogCone defined by m_tower, logSector, logSegment.
0157     * Here you do not have to care, what configuration is curent used.
0158     * @param m_tower -16 : 16, @param logSector 0 : 11, @param logSegment 0 : 11.
0159     */
0160   //const
0161   TPacType* getPac(int m_tower, int logSector, int logSegment) const {
0162     if (m_PacTab.size() <= (unsigned int)abs(m_tower))
0163       throw RPCException("RPCPacManager::getPac: given towerNum to big");
0164     // edm::LogError("RPCTrigger") << "RPCPacManager::getPac: given towerNum to big" << std::endl;
0165 
0166     //int curLogSector = logSector;
0167     //int curlogSegment = logSegment;
0168 
0169     if (m_PACsCnt == ONE_PAC_PER_TOWER) {
0170       logSector = 0;
0171       logSegment = 0;
0172     } else if (m_PACsCnt == _12_PACS_PER_TOWER) {
0173       logSector = 0;
0174     }
0175 
0176     //XXXX//m_PacTab[abs(m_tower)][logSector][logSegment]->setCurrentPosition(m_tower, curLogSector, curlogSegment);
0177     return m_PacTab[std::abs(m_tower)][logSector][logSegment];
0178   };
0179 
0180   //const
0181   TPacType* getPac(const RPCConst::l1RpcConeCrdnts& coneCrdnts) const {
0182     return getPac(coneCrdnts.m_Tower, coneCrdnts.m_LogSector, coneCrdnts.m_LogSegment);
0183   }
0184 
0185 private:
0186   std::vector<std::vector<std::vector<TPacType*> > > m_PacTab;  //!< m_PacTab[m_tower][logSector][m_LogSegment]
0187 
0188   int m_SectorsCnt;  //!< Count of used differnt sectors.
0189 
0190   int m_SegmentCnt;  //!< Count of used differnt segments.
0191 
0192   L1RpcPACsCntEnum m_PACsCnt;  //Used configuration version.
0193 
0194   void destroy() {
0195     for (size_t tower = 0; tower < m_PacTab.size(); ++tower) {
0196       for (size_t logSector = 0; logSector < m_PacTab.at(tower).size(); logSector++) {
0197         for (size_t logSegment = 0; logSegment < m_PacTab.at(tower).at(logSector).size(); logSegment++) {
0198           TPacType* pac = m_PacTab.at(tower).at(logSector).at(logSegment);
0199           delete pac;
0200         }
0201       }
0202     }
0203     m_PacTab.clear();
0204   }
0205 };
0206 
0207 #endif