CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/L1Trigger/RPCTrigger/interface/RPCPacManager.h

Go to the documentation of this file.
00001 #ifndef L1Trigger_RPCPacManager_h
00002 #define L1Trigger_RPCPacManager_h
00003 
00018 //------------------------------------------------------------------------------
00019 #include <string>
00020 #include <vector>
00021 #include "L1Trigger/RPCTrigger/interface/RPCConst.h"
00022 #include "L1Trigger/RPCTrigger/interface/RPCException.h"
00023 
00024 #include "CondFormats/L1TObjects/interface/L1RPCConfig.h"
00025 
00026 #include <xercesc/util/PlatformUtils.hpp>
00027 #include <cstdlib>
00028 #ifndef _STAND_ALONE
00029 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00030 #endif // _STAND_ALONE
00031 
00033 // TODO: should be moved to L1RPConfig
00034 enum L1RpcPACsCntEnum {
00035   ONE_PAC_PER_TOWER = 1,
00036   _12_PACS_PER_TOWER = 12, //the same m_PAC in the same segment in every sector,
00037   _144_PACS_PER_TOWER =144,
00038   TB_TESTS
00039 };
00040 
00041 
00042 template<class TPacType> class RPCPacManager {
00043 public:
00044   ~RPCPacManager() {
00045     for (unsigned int m_tower = 0; m_tower < m_PacTab.size(); m_tower++)
00046       for (unsigned int logSector = 0; logSector < m_PacTab[m_tower].size(); logSector++) {
00047         for (unsigned int logSegment = 0; logSegment < m_PacTab[m_tower][logSector].size(); logSegment++) {
00048           TPacType* pac = m_PacTab[m_tower][logSector][logSegment];
00049           delete pac;
00050         }
00051       }
00052   }
00053 
00054 
00055 
00061   void init(std::string patFilesDirectory, L1RpcPACsCntEnum _PACsCnt)  {
00062     destroy(); 
00063     m_PACsCnt = _PACsCnt;
00064     if(m_PACsCnt == ONE_PAC_PER_TOWER) {
00065       m_SectorsCnt = 1;
00066       m_SegmentCnt = 1;
00067     }
00068     else if(m_PACsCnt == _12_PACS_PER_TOWER) {
00069       m_SectorsCnt = 1;
00070       m_SegmentCnt = 12;
00071     }
00072     else if(m_PACsCnt == _144_PACS_PER_TOWER) {
00073       m_SectorsCnt = 12;
00074       m_SegmentCnt = 12;
00075     }
00076     else if(m_PACsCnt == TB_TESTS) {
00077       m_SectorsCnt = 1;
00078       m_SegmentCnt = 4;
00079     }
00080 
00081     for (int m_tower = 0; m_tower < RPCConst::m_TOWER_COUNT; m_tower++) {
00082       m_PacTab.push_back(std::vector<std::vector<TPacType*> >());
00083       for (int logSector = 0; logSector < m_SectorsCnt; logSector++) {
00084         m_PacTab[m_tower].push_back(std::vector<TPacType*>());
00085         for (int logSegment = 0; logSegment < m_SegmentCnt; logSegment++) {
00086           TPacType* pac  = new TPacType(patFilesDirectory, m_tower, logSector, logSegment); 
00087           m_PacTab[m_tower][logSector].push_back(pac);                   
00088         }
00089       } 
00090     } 
00091     xercesc::XMLPlatformUtils::Terminate();
00092   };
00093 
00094   
00095   void init(const L1RPCConfig *rpcconf)  {
00096     destroy(); 
00097     switch (rpcconf->getPPT()){
00098       case 1:
00099         m_PACsCnt = ONE_PAC_PER_TOWER;
00100         break;
00101       case 12:
00102         m_PACsCnt = _12_PACS_PER_TOWER;
00103         break;
00104       case 144:
00105         m_PACsCnt = _144_PACS_PER_TOWER;
00106         break;
00107     
00108     }
00109     
00110     if(m_PACsCnt == ONE_PAC_PER_TOWER) {
00111       m_SectorsCnt = 1;
00112       m_SegmentCnt = 1;
00113     }
00114     else if(m_PACsCnt == _12_PACS_PER_TOWER) {
00115       m_SectorsCnt = 1;
00116       m_SegmentCnt = 12;
00117     }
00118     else if(m_PACsCnt == _144_PACS_PER_TOWER) {
00119       m_SectorsCnt = 12;
00120       m_SegmentCnt = 12;
00121     }
00122     else if(m_PACsCnt == TB_TESTS) {
00123       m_SectorsCnt = 1;
00124       m_SegmentCnt = 4;
00125     }
00126 
00127     /*
00128     std::vector<std::vector<std::vector<RPCPattern::RPCPatVec> > > patvec;
00129     std::vector<std::vector<std::vector<RPCPattern::TQualityVec> > > qualvec;
00130     for (int tower = 0; tower < RPCConst::m_TOWER_COUNT; ++tower) {
00131       patvec.push_back(std::vector< std::vector< RPCPattern::RPCPatVec > >());
00132       qualvec.push_back(std::vector< std::vector< RPCPattern::TQualityVec > >());
00133       for (int logSector = 0; logSector < m_SectorsCnt; ++logSector) {
00134         patvec[tower].push_back(std::vector< RPCPattern::RPCPatVec >());
00135         qualvec[tower].push_back(std::vector< RPCPattern::TQualityVec >());
00136         for (int logSegment = 0; logSegment < m_SegmentCnt; ++logSegment) {
00137           patvec[tower][logSector].push_back(RPCPattern::RPCPatVec());
00138           qualvec[tower][logSector].push_back(RPCPattern::TQualityVec());
00139         }
00140       }
00141     }
00142 
00143     for (unsigned int ipat=0; ipat<rpcconf->m_pats.size(); ipat++)
00144       patvec[rpcconf->m_pats[ipat].getTower()][rpcconf->m_pats[ipat].getLogSector()][rpcconf->m_pats[ipat].getLogSegment()].push_back(rpcconf->m_pats[ipat]);
00145     for (unsigned int iqual=0; iqual<rpcconf->m_quals.size(); iqual++)
00146       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]);
00147     */
00148 
00149 
00150     for (int tower = 0; tower < RPCConst::m_TOWER_COUNT; tower++) {
00151       m_PacTab.push_back(std::vector<std::vector<TPacType*> >());
00152       for (int logSector = 0; logSector < m_SectorsCnt; logSector++) {
00153         m_PacTab[tower].push_back(std::vector<TPacType*>());
00154         for (int logSegment = 0; logSegment < m_SegmentCnt; logSegment++) {
00155           /*L1RPCConfig* rpcconf1=new L1RPCConfig();
00156           rpcconf1->setPPT(rpcconf->getPPT());
00157           for (unsigned int ipat=0; ipat<patvec[tower][logSector][logSegment].size(); ipat++)
00158             rpcconf1->m_pats.push_back(patvec[tower][logSector][logSegment][ipat]);
00159           for (unsigned int iqual=0; iqual<qualvec[tower][logSector][logSegment].size(); iqual++)
00160             rpcconf1->m_quals.push_back(qualvec[tower][logSector][logSegment][iqual]);
00161           //TPacType* pac  = new TPacType(rpcconf1->m_pats,rpcconf1->m_quals);*/
00162           TPacType* pac  = new TPacType(rpcconf, tower, logSector, logSegment);
00163           m_PacTab[tower][logSector].push_back(pac);
00164         }
00165       } 
00166     } 
00167     xercesc::XMLPlatformUtils::Terminate();
00168   };
00169   
00174   //const
00175   TPacType* getPac(int m_tower, int logSector, int logSegment) const {
00176     if (m_PacTab.size() <= (unsigned int) abs(m_tower))
00177      throw RPCException("RPCPacManager::getPac: given towerNum to big");
00178      // edm::LogError("RPCTrigger") << "RPCPacManager::getPac: given towerNum to big" << std::endl;
00179 
00180     //int curLogSector = logSector;
00181     //int curlogSegment = logSegment;
00182 
00183     if(m_PACsCnt == ONE_PAC_PER_TOWER) {
00184       logSector = 0;
00185       logSegment = 0;
00186     }
00187     else if(m_PACsCnt == _12_PACS_PER_TOWER) {
00188       logSector = 0;
00189     }
00190 
00191     //XXXX//m_PacTab[abs(m_tower)][logSector][logSegment]->setCurrentPosition(m_tower, curLogSector, curlogSegment);
00192     return  m_PacTab[std::abs(m_tower)][logSector][logSegment];
00193   };
00194   
00195   //const 
00196   TPacType* getPac(const RPCConst::l1RpcConeCrdnts& coneCrdnts) const {
00197     return getPac(coneCrdnts.m_Tower, coneCrdnts.m_LogSector, coneCrdnts.m_LogSegment);
00198   }
00199   
00200   private:
00201     std::vector<std::vector<std::vector<TPacType*> > > m_PacTab; 
00202 
00203     int m_SectorsCnt; 
00204 
00205     int m_SegmentCnt; 
00206 
00207     L1RpcPACsCntEnum m_PACsCnt; //Used configuration version.
00208 
00209     void destroy(){
00210       for (size_t tower = 0; tower < m_PacTab.size() ; ++tower) {
00211         for (size_t logSector = 0; logSector < m_PacTab.at(tower).size(); logSector++) {
00212           for (size_t logSegment = 0; logSegment < m_PacTab.at(tower).at(logSector).size() ; logSegment++) {
00213             TPacType* pac = m_PacTab.at(tower).at(logSector).at(logSegment);
00214             delete pac;
00215           }
00216         }
00217       }
00218       m_PacTab.clear();
00219     }
00220 };
00221 
00222 #endif