diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/TGCTriggerData.h b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/TGCTriggerData.h index e423319aacce0ed8ff1861ac61bf7035b4a3d4f5..0483961af8a4751ac682d69f464dc60cf5a8acb2 100644 --- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/TGCTriggerData.h +++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/TGCTriggerData.h @@ -16,9 +16,9 @@ * =========================== * std::unordered_map<GLOBALADDR, PTVALUE> * where - * GLOBALADDR | 27 bits | unsigned int | side, octant, type, phimod2, module, roi, - * | DR(0...0x1f for -15...15)<<4 & DPhi(0...0xf for -7...7) - * PTVALUE | 3 bits | unsigned char | pT value (0x0 and 0x7 is no cand.) + * GLOBALADDR | 27 bits | uint32_t | side, octant, type, phimod2, module, roi, + * | DR(0...0x1f for -15...15)<<4 & DPhi(0...0xf for -7...7) + * PTVALUE | 3 bits | uint8_t | pT value (0x0 and 0x7 is no cand.) * * for GLOBALADDR * | 29 |28|27|26|25|24|23| 22 |21|20|19|18|17|16|15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| @@ -26,6 +26,76 @@ * where side = 0x0 (A-side), 0x1 (C-side). * octant = 0x(0...7) * type = 0x0 (HH), 0x1 (HL), 0x2 (LH), 0x3 (LL): HL means 3-station-wire and 2-station-strip. + * + * Bit information of Run-2 EIFI-LUT + * ================================= + * a) Applied pT in SSC (m_flagpt_eifi) + * std::unordered_map<ADDR, PTMASK> + * where + * ADDR | 12 bits | uint16_t | side, trigger sector, and SSC + * PTMASK | 3 bits | uint8_t | bit mask for applied pT for SSC + * + * b) Applied RoI in SSC (m_flagroi_eifi) + * std::unordered_map<ADDR, ROIMASK> + * where + * ADDR | 12 bits | uint16_t | side, trigger sector, and SSC + * ROIMASK | 8 bits | uint8_t | bit mask for applied RoI in SSC + * + * for ADDR + * | 11 |10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| + * |side| Trig. Sector | SSC | + * where side = 0x0 (A-side), 0x1 (C-side). + * trig. sector = 0x(0...2f) + * SSC = 0x(0...12) + * + * c) Trigger bit for each input (m_trigbit_eifi) + * std::unordered_map<INPUTADDR, TRIGBIT> + * where TRIGBIT is: + * | EI || FI | + * | Strip | Wire || Strip | Wire | + * | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 || 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | + * | <--L phi S--> | <--L eta S--> || <--L phi S--> | <--L eta S-->| + * where each sensor consists of 4 bits information. + * + * for INPUTADDR + * | 13 |12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| + * |side| Trig. Sector | SSC |Input| + * where side = 0x0 (A-side), 0x1 (C-side). + * trig. sector = 0x(0...2f) + * SSC = 0x(0...12) + * Input = 0x(0...3) + * + * Contents of Run-2 Tile-CW LUT + * ============================= + * a) Applied pT in SSC (m_flagpt_tile) + * std::unordered_map<ADDR, PTMASK> + * where + * ADDR | 12 bits | uint16_t | side, trigger sector, and SSC + * PTMASK | 3 bits | uint8_t | bit mask for applied pT for SSC + * + * b) Applied RoI in SSC (m_flagroi_tile) + * std::unordered_map<ADDR, ROIMASK> + * where + * ADDR | 12 bits | uint16_t | side, trigger sector, and SSC + * ROIMASK | 8 bits | uint8_t | bit mask for applied RoI in SSC + * + * c) Trigger bit for each input (m_trigbit_tile) + * std::unordered_map<ADDR, TRIGBIT> + * where TRIGBIT is: + * | Module D (Tile=3) || Module C (Tile=2) || Module B (Tile=1) || Module A (Tile=0) | + * | 15 | 14 | 13 | 12 || 11 | 10 | 9 | 8 || 7 | 6 | 5 | 4 || 3 | 2 | 1 | 0 | + * | 0 | LH | D56| D6 || 0 | LH | D56| D6 || 0 | LH | D56 | D6 || 0 | LH | D56 | D6 | + * for each Module: + * [1:0] hit with cell information: D6=0x1, D56=0x3 + * [2] Low/High threshold: 1 = H, 0=L + * e.g.) 0x7 = D5+D6 energy exceeds the high threshold + * + * for ADDR + * | 11 |10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| + * |side| Trig. Sector | SSC | + * where side = 0x0 (A-side), 0x1 (C-side). + * trig. sector = 0x(0...2f) + * SSC = 0x(0...12) */ class TGCTriggerData @@ -76,6 +146,16 @@ class TGCTriggerData static constexpr uint8_t DPHI_HIGH_RANGE = 7; /// Range of DPhi in the BW coincidence window for 2-station static constexpr uint8_t DPHI_LOW_RANGE = 3; + /// Mask for trigger sector for the (EIFI/TILE) ADDR + static constexpr uint8_t SECTOR_MASK = 0x3f; + /// Mask for SSC for the (EIFI/TILE) ADDR + static constexpr uint8_t SSC_MASK = 0x1f; + /// Bit position of the side bit in the (EIFI/TILE) ADDR + static constexpr uint8_t ADDR_SIDE_SHIFT = 11; + /// Bit position of the trigger sector bit in the (EIFI/TILE) ADDR + static constexpr uint8_t ADDR_SECTOR_SHIFT = 5; + /// Special bit shift for the EIFI Trigger bit + static constexpr uint8_t EIFI_TRIGBIT_SHIFT = 2; enum {CW_BW=0, CW_EIFI=1, CW_TILE=2, CW_NUM=3}; enum {N_PT_THRESH=6, @@ -94,12 +174,8 @@ class TGCTriggerData TGCTriggerData(); virtual ~TGCTriggerData(); - std::string getData(int cwtype, std::string file) const; - std::string getData(int cwtype, int channel) const; - std::string getFile(int cwtype, int channel) const; - std::string getVersion(int cwtype, int channel = 0) const; - std::string getType(int cwtype, int channel = 0) const; - bool isActive(int cwtype, int channel = 0) const; + std::string getType(int cwtype) const; + bool isActive(int cwtype) const; int8_t getTYPE(const int16_t lDR, const int16_t hDR, const int16_t lDPhi, const int16_t hDPhi) const; @@ -111,57 +187,29 @@ class TGCTriggerData unsigned short getTrigMaskTile(int ssc, int sectorId, int side) const; unsigned char getFlagPtTile(int ssc, int sectorId, int side) const; - unsigned char getFlagRoiTile(int ssc, int sectorId, int side) const; + uint8_t getFlagRoiTile(int ssc, int sectorId, int side) const; private: - std::map<std::string, std::string> m_datamap[CW_NUM]; - std::vector<std::string> m_data[CW_NUM]; - std::vector<std::string> m_file[CW_NUM]; - std::vector<std::string> m_version[CW_NUM]; - std::vector<std::string> m_type[CW_NUM]; - std::vector<bool> m_active[CW_NUM]; + std::string m_type[CW_NUM]; + bool m_active[CW_NUM]; /// Run-2 BW-CW LUT map std::unordered_map<uint32_t, uint8_t> m_ptmap_bw; - /** Bit information of Run-2 EIFI-LUT - * ================================= - * bits for each input - * | EI || FI | - * | Strip | Wire || Strip | Wire | - * | 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 || 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | - * | <--L phi S--> | <--L eta S--> || <--L phi S--> | <--L eta S-->| - * where each sensor consists of 4 bits information. - * - * Note: Only if fullCW option is true, the different db file per side is read. - * Therefore, the contents are stored by std::vector of side index (A=0, C=1). - */ - std::vector<unsigned short> m_trigbit_eifi[N_ENDCAP_SECTOR][N_ENDCAP_SSC][N_EIFI_INPUT]; - std::vector<unsigned char> m_flagpt_eifi[N_ENDCAP_SECTOR][N_ENDCAP_SSC]; //< bits for applied pT (N_PT_THRESH) - std::vector<unsigned char> m_flagroi_eifi[N_ENDCAP_SECTOR][N_ENDCAP_SSC]; //< bits for applied RoI in SSC (N_ROI_IN_SSC) - - /** Bit information of Run-2 Tile-LUT - * ================================= - * bits for each input - * | Module D (Tile=3) || Module C (Tile=2) || Module B (Tile=1) || Module A (Tile=0) | - * | 15 | 14 | 13 | 12 || 11 | 10 | 9 | 8 || 7 | 6 | 5 | 4 || 3 | 2 | 1 | 0 | - * | 0 | LH | D56| D6 || 0 | LH | D56| D6 || 0 | LH | D56 | D6 || 0 | LH | D56 | D6 | - * for each Module: - * [1:0] hit with cell information: D6=0x1, D56=0x3 - * [2] Low/High threshold: 1 = H, 0=L - * e.g.) 0x7 = D5+D6 energy exceeds the high threshold - * - * Note: One db file consists of whole sector information as a fullCW. - */ - unsigned short m_trigbit_tile[N_ENDCAP_SSC][N_ENDCAP_SECTOR][N_SIDE]; - unsigned char m_flagpt_tile[N_ENDCAP_SSC][N_ENDCAP_SECTOR][N_SIDE]; //< bits for applied pT (N_PT_THRESH) - unsigned char m_flagroi_tile[N_ENDCAP_SSC][N_ENDCAP_SECTOR][N_SIDE]; //< bits for applied RoI in SSC (N_ROI_IN_SSC) + // Run-2 EIFI-CW LUT map + std::unordered_map<uint16_t, uint8_t> m_flagpt_eifi; + std::unordered_map<uint16_t, uint8_t> m_flagroi_eifi; + std::unordered_map<uint16_t, uint16_t> m_trigbit_eifi; + //Run-2 Tile-CW LUT map + std::unordered_map<uint16_t, uint8_t> m_flagpt_tile; + std::unordered_map<uint16_t, uint8_t> m_flagroi_tile; + std::unordered_map<uint16_t, uint16_t> m_trigbit_tile; }; -CLASS_DEF(TGCTriggerData, 72345188, 2) +CLASS_DEF(TGCTriggerData, 72345188, 3) #include "AthenaKernel/CondCont.h" -CLASS_DEF(CondCont<TGCTriggerData>, 96649668, 2) +CLASS_DEF(CondCont<TGCTriggerData>, 96649668, 3) #endif // TGCTRIGGERDATA_H diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/TGCTriggerDbAlg.h b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/TGCTriggerDbAlg.h index dc273c4a02551787b34ad950816f75ebc39c5cd9..251c0c6debb923188548d1e418b05b241fec0f05 100644 --- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/TGCTriggerDbAlg.h +++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/MuonCondSvc/TGCTriggerDbAlg.h @@ -22,20 +22,16 @@ class TGCTriggerDbAlg: public AthAlgorithm virtual StatusCode finalize() override; private: - void loadParameters(TGCTriggerData* writeCdo, - const CondAttrListCollection* readKey, - int cw_type); - - void fillReadMapBw(TGCTriggerData* writeCdo); - void fillTrigBitEifi(TGCTriggerData* writeCdo); - void fillTrigBitTile(TGCTriggerData* writeCdo); - - SG::ReadCondHandleKey<CondAttrListCollection> m_readKey_bw; - SG::ReadCondHandleKey<CondAttrListCollection> m_readKey_eifi; - SG::ReadCondHandleKey<CondAttrListCollection> m_readKey_tile; - SG::WriteCondHandleKey<TGCTriggerData> m_writeKey; - ServiceHandle<ICondSvc> m_condSvc; + void fillReadMapBw(TGCTriggerData* writeCdo, const CondAttrListCollection* readKey); + void fillTrigBitEifi(TGCTriggerData* writeCdo, const CondAttrListCollection* readKey); + void fillTrigBitTile(TGCTriggerData* writeCdo, const CondAttrListCollection* readKey); + + SG::ReadCondHandleKey<CondAttrListCollection> m_readKey_bw{this, "ReadKeyBw", "/TGC/TRIGGER/CW_BW", "SG key for CW-BW"}; + SG::ReadCondHandleKey<CondAttrListCollection> m_readKey_eifi{this, "ReadKeyEifi", "/TGC/TRIGGER/CW_EIFI", "SG key for CW-EIFI"}; + SG::ReadCondHandleKey<CondAttrListCollection> m_readKey_tile{this, "ReadKeyTile", "/TGC/TRIGGER/CW_TILE", "SG key for CW-TILE"}; + SG::WriteCondHandleKey<TGCTriggerData> m_writeKey{this, "WriteKey", "TGCTriggerData", "SG Key of TGCTrigger LUTs"}; + ServiceHandle<ICondSvc> m_condSvc; }; #endif diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/TGCTriggerData.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/TGCTriggerData.cxx index a2780baf183c6fa156f9c3f9fb128b2c710519c9..ee634419664cae5d0e139a4bcd31c2cd57664a7d 100644 --- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/TGCTriggerData.cxx +++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/TGCTriggerData.cxx @@ -11,36 +11,14 @@ TGCTriggerData::TGCTriggerData() TGCTriggerData::~TGCTriggerData() {} -std::string TGCTriggerData::getData(int cwtype, std::string file) const { - auto itr = m_datamap[cwtype].find(file); - if (itr == m_datamap[cwtype].end()) { - return ""; - } - - return itr->second; -} - - -std::string TGCTriggerData::getData(int cwtype, int channel) const { - return m_data[cwtype][channel]; -} - - -std::string TGCTriggerData::getFile(int cwtype, int channel) const { - return m_file[cwtype][channel]; -} - -std::string TGCTriggerData::getVersion(int cwtype, int channel) const { - return m_version[cwtype][channel]; -} - -std::string TGCTriggerData::getType(int cwtype, int channel) const { - return m_type[cwtype][channel]; +std::string TGCTriggerData::getType(int cwtype) const +{ + return m_type[cwtype]; } - -bool TGCTriggerData::isActive(int cwtype, int channel) const { - return m_active[cwtype][channel]; +bool TGCTriggerData::isActive(int cwtype) const +{ + return m_active[cwtype]; } int8_t TGCTriggerData::getTYPE(const int16_t lDR, const int16_t hDR, const int16_t lDPhi, const int16_t hDPhi) const @@ -64,33 +42,65 @@ uint8_t TGCTriggerData::getBigWheelPt(const uint32_t addr) const unsigned short TGCTriggerData::getTrigBitEifi(int side, int slot, int ssc, int sectorId) const { - if(m_active[CW_EIFI][0] == false) return 0; // not required EIFI coincidence. - int sideindex = (this->getType(CW_EIFI) != "full") ? 0 : side; - return m_trigbit_eifi[sectorId][ssc][slot][sideindex]; + int sideindex = (m_type[CW_EIFI] != "full") ? 0 : side; + uint16_t addr = ((sideindex & SIDE_MASK)<<ADDR_SIDE_SHIFT) + + ((sectorId & SECTOR_MASK)<<ADDR_SECTOR_SHIFT) + + (ssc & SSC_MASK); + addr = (addr<<EIFI_TRIGBIT_SHIFT) + slot; + std::unordered_map<uint16_t, uint16_t>::const_iterator it = m_trigbit_eifi.find(addr); + if(it == m_trigbit_eifi.end()) return 0x0; // undefined sector (or active=0) + else return it->second; } unsigned char TGCTriggerData::getFlagPtEifi(int side, int ssc, int sectorId) const { - if(m_active[CW_EIFI][0] == false) return 0; // not required EIFI coincidence. - int sideindex = (this->getType(CW_EIFI) != "full") ? 0 : side; - return m_flagpt_eifi[sectorId][ssc][sideindex]; + int sideindex = (m_type[CW_EIFI] != "full") ? 0 : side; + uint16_t addr = ((sideindex & SIDE_MASK)<<ADDR_SIDE_SHIFT) + + ((sectorId & SECTOR_MASK)<<ADDR_SECTOR_SHIFT) + + (ssc & SSC_MASK); + std::unordered_map<uint16_t, uint8_t>::const_iterator it = m_flagpt_eifi.find(addr); + if(it == m_flagpt_eifi.end()) return 0x0; // undefined sector (or active=0) + else return it->second; } unsigned char TGCTriggerData::getFlagRoiEifi(int side, int ssc, int sectorId) const { - if(m_active[CW_EIFI][0] == false) return 0; // not required EIFI coincidence. - int sideindex = (this->getType(CW_EIFI) != "full") ? 0 : side; - return m_flagroi_eifi[sectorId][ssc][sideindex]; + int sideindex = (m_type[CW_EIFI] != "full") ? 0 : side; + uint16_t addr = ((sideindex & SIDE_MASK)<<ADDR_SIDE_SHIFT) + + ((sectorId & SECTOR_MASK)<<ADDR_SECTOR_SHIFT) + + (ssc & SSC_MASK); + std::unordered_map<uint16_t, uint8_t>::const_iterator it = m_flagroi_eifi.find(addr); + if(it == m_flagroi_eifi.end()) return 0x0; // undefined sector (or active=0) + else return it->second; } -unsigned short TGCTriggerData::getTrigMaskTile(int ssc, int sectorId, int side) const { - return m_trigbit_tile[ssc][sectorId][side]; +uint16_t TGCTriggerData::getTrigMaskTile(int ssc, int sectorId, int side) const +{ + uint16_t addr = ((side & SIDE_MASK)<<ADDR_SIDE_SHIFT) + + ((sectorId & SECTOR_MASK)<<ADDR_SECTOR_SHIFT) + + (ssc & SSC_MASK); + std::unordered_map<uint16_t, uint16_t>::const_iterator it = m_trigbit_tile.find(addr); + if(it == m_trigbit_tile.end()) return 0x0; // undefined sector (or active=0) + else return it->second; } -unsigned char TGCTriggerData::getFlagPtTile(int ssc, int sectorId, int side) const { - return m_flagpt_tile[ssc][sectorId][side]; +uint8_t TGCTriggerData::getFlagPtTile(int ssc, int sectorId, int side) const +{ + uint16_t addr = ((side & SIDE_MASK)<<ADDR_SIDE_SHIFT) + + ((sectorId & SECTOR_MASK)<<ADDR_SECTOR_SHIFT) + + (ssc & SSC_MASK); + std::unordered_map<uint16_t, uint8_t>::const_iterator it = m_flagpt_tile.find(addr); + if(it == m_flagpt_tile.end()) return 0x0; // undefined sector (or active=0) + else return it->second; } -unsigned char TGCTriggerData::getFlagRoiTile(int ssc, int sectorId, int side) const { - return m_flagroi_tile[ssc][sectorId][side]; +uint8_t TGCTriggerData::getFlagRoiTile(int ssc, int sectorId, int side) const +{ + uint16_t addr = ((side & SIDE_MASK)<<ADDR_SIDE_SHIFT) + + ((sectorId & SECTOR_MASK)<<ADDR_SECTOR_SHIFT) + + (ssc & SSC_MASK); + std::unordered_map<uint16_t, uint8_t>::const_iterator it = m_flagroi_tile.find(addr); + if(it == m_flagroi_tile.end()) return 0x0; // undefined sector (or active=0) + else return it->second; } + diff --git a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/TGCTriggerDbAlg.cxx b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/TGCTriggerDbAlg.cxx index a40a3adb2c7e8dd504f94a73a515219785934484..52fa501c72aaafefb3b084823e1c776f6f39ff17 100644 --- a/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/TGCTriggerDbAlg.cxx +++ b/MuonSpectrometer/MuonConditions/MuonCondGeneral/MuonCondSvc/src/TGCTriggerDbAlg.cxx @@ -8,17 +8,8 @@ TGCTriggerDbAlg::TGCTriggerDbAlg(const std::string& name, ISvcLocator* pSvcLocator) : AthAlgorithm(name, pSvcLocator), - m_readKey_bw("/TGC/TRIGGER/CW_BW"), - m_readKey_eifi("/TGC/TRIGGER/CW_EIFI"), - m_readKey_tile("/TGC/TRIGGER/CW_TILE"), - m_writeKey("TGCTriggerData"), m_condSvc("CondSvc", name) -{ - declareProperty("ReadKeyBw", m_readKey_bw); - declareProperty("ReadKeyEifi", m_readKey_eifi); - declareProperty("ReadKeyTile", m_readKey_tile); - declareProperty("WriteKey", m_writeKey); -} +{} StatusCode TGCTriggerDbAlg::initialize(){ @@ -40,10 +31,8 @@ StatusCode TGCTriggerDbAlg::initialize(){ return StatusCode::SUCCESS; } -StatusCode TGCTriggerDbAlg::execute(){ - - ATH_MSG_DEBUG( "start execute " << name() ); - +StatusCode TGCTriggerDbAlg::execute() +{ SG::WriteCondHandle<TGCTriggerData> writeHandle{m_writeKey}; if (writeHandle.isValid()) { ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid." @@ -54,7 +43,6 @@ StatusCode TGCTriggerDbAlg::execute(){ auto writeCdo = std::make_unique<TGCTriggerData>(); - // Big wheel SG::ReadCondHandle<CondAttrListCollection> readHandle_bw(m_readKey_bw); const CondAttrListCollection* readCdo_bw(*readHandle_bw); @@ -73,7 +61,7 @@ StatusCode TGCTriggerDbAlg::execute(){ } ATH_MSG_INFO("Range of input is " << rangeW_bw); - loadParameters(writeCdo.get(), readCdo_bw, TGCTriggerData::CW_BW); + fillReadMapBw(writeCdo.get(), readCdo_bw); // EIFI SG::ReadCondHandle<CondAttrListCollection> readHandle_eifi(m_readKey_eifi); @@ -93,19 +81,17 @@ StatusCode TGCTriggerDbAlg::execute(){ } ATH_MSG_INFO("Range of input is " << rangeW_eifi); - loadParameters(writeCdo.get(), readCdo_eifi, TGCTriggerData::CW_EIFI); + fillTrigBitEifi(writeCdo.get(), readCdo_eifi); // Tile SG::ReadCondHandle<CondAttrListCollection> readHandle_tile(m_readKey_tile); - const CondAttrListCollection* readCdo_tile(*readHandle_tile); - - if (readCdo_tile == 0) { + const CondAttrListCollection* readCdo_tile = *readHandle_tile; + if (readCdo_tile == nullptr) { ATH_MSG_ERROR("Null pointer to the read conditions object"); return StatusCode::FAILURE; } - ATH_MSG_INFO("Size of CondAttrListCollection " << readHandle_tile.fullKey() << " readCdo->size()= " << readCdo_tile->size()); - + EventIDRange rangeW_tile; if ( !readHandle_tile.range(rangeW_tile) ) { ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle_tile.key()); @@ -113,13 +99,7 @@ StatusCode TGCTriggerDbAlg::execute(){ } ATH_MSG_INFO("Range of input is " << rangeW_tile); - loadParameters(writeCdo.get(), readCdo_tile, TGCTriggerData::CW_TILE); - - // fill maps - fillReadMapBw(writeCdo.get()); - fillTrigBitEifi(writeCdo.get()); - fillTrigBitTile(writeCdo.get()); - + fillTrigBitTile(writeCdo.get(), readCdo_tile); // write condition object EventIDRange rangeIntersection = EventIDRange::intersect(rangeW_bw,rangeW_eifi,rangeW_tile); @@ -148,157 +128,170 @@ StatusCode TGCTriggerDbAlg::finalize(){ } -void TGCTriggerDbAlg::loadParameters(TGCTriggerData* writeCdo, - const CondAttrListCollection* readCdo, - int cw_type) { +void TGCTriggerDbAlg::fillReadMapBw(TGCTriggerData* writeCdo, + const CondAttrListCollection* readCdo) +{ + const uint8_t kNMODULETYPE = 12; + const uint8_t modulenumber[kNMODULETYPE] = {0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8}; + const std::string modulename[kNMODULETYPE] = {"0","1","2a","2b","3","4","5a","5b","6","7","8a","8b"}; + const std::string sidename[TGCTriggerData::N_SIDE] = {"A","C"}; CondAttrListCollection::const_iterator itr = readCdo->begin(); CondAttrListCollection::const_iterator itr_e = readCdo->end(); for(; itr!=itr_e; ++itr) { - const unsigned int channel = (*itr).first; const coral::AttributeList& atr = (*itr).second; + writeCdo->m_active[TGCTriggerData::CW_BW] = atr["active"].data<bool>(); + writeCdo->m_type[TGCTriggerData::CW_BW] = atr["type"].data<std::string>(); - ATH_MSG_DEBUG("channel: " << channel); - - std::string file = *(static_cast<const std::string*>((atr["file"]).addressOfData())); - std::string data = *(static_cast<const std::string*>((atr["data"]).addressOfData())); std::string version = *(static_cast<const std::string*>((atr["version"]).addressOfData())); - std::string type = *(static_cast<const std::string*>((atr["type"]).addressOfData())); - bool active = *(static_cast<const bool*>((atr["active"]).addressOfData())); - - writeCdo->m_datamap[cw_type][file] = data; - writeCdo->m_data[cw_type].push_back(data); - writeCdo->m_file[cw_type].push_back(file); - writeCdo->m_version[cw_type].push_back(version); - writeCdo->m_type[cw_type].push_back(type); - writeCdo->m_active[cw_type].push_back(active); - - ATH_MSG_INFO("active: " << active << " file: " << file); - ATH_MSG_DEBUG("data: " << data); - } -} + std::string file = *(static_cast<const std::string*>((atr["file"]).addressOfData())); + ATH_MSG_DEBUG("channel: " << (*itr).first << ", file: " << file); + ATH_MSG_INFO("type: " << writeCdo->m_type[TGCTriggerData::CW_EIFI] + << " active: " << writeCdo->m_active[TGCTriggerData::CW_EIFI] << " version: " << version); -void TGCTriggerDbAlg::fillReadMapBw(TGCTriggerData* writeCdo) -{ - if (!writeCdo->isActive(TGCTriggerData::CW_BW)) { - return; - } + if (!writeCdo->m_active[TGCTriggerData::CW_BW]) continue; - bool fullCW = (writeCdo->getType(TGCTriggerData::CW_BW) == "full"); - std::string vername = writeCdo->getVersion(TGCTriggerData::CW_BW); + bool fullCW = (writeCdo->m_type[TGCTriggerData::CW_BW] == "full"); - const uint8_t kNMODULETYPE = 12; - const uint8_t modulenumber[kNMODULETYPE] = {0, 1, 2, 2, 3, 4, 5, 5, 6, 7, 8, 8}; - const std::string modulename[kNMODULETYPE] = {"0","1","2a","2b","3","4","5a","5b","6","7","8a","8b"}; - const std::string sidename[TGCTriggerData::N_SIDE] = {"A","C"}; + uint8_t sideId = 0; // if the file is not fullCW, sideId should be zero. + if(fullCW) { + std::string side = file.substr(strlen("RPhiCoincidenceMap."), 1); + for(int id=0; id<TGCTriggerData::N_SIDE; id++) { + if(sidename[id] == side) { + sideId = id; + break; + } + } + } + + uint16_t octantId = 0; // if the file is not fullCW, octantId should be zero. + if(fullCW) { + octantId = std::stoi(file.substr(strlen("RPhiCoincidenceMap.X"), 1)); + } + + uint32_t octaddr = ((sideId & TGCTriggerData::SIDE_MASK)<<TGCTriggerData::SIDE_SHIFT) + + ((octantId & TGCTriggerData::OCTANT_MASK)<<TGCTriggerData::OCTANT_SHIFT); + + uint16_t moduleId = 0; + for(size_t iModule = 0; iModule < kNMODULETYPE; iModule++) { + std::ostringstream dbname; + dbname << "RPhiCoincidenceMap."; + if (fullCW) dbname << sidename[sideId] << octantId << "."; + dbname << "mod" << modulename[iModule] + "." + version +"._12.db"; + if(dbname.str() == file) { + moduleId = iModule; + break; + } + } - for(size_t iSide = 0; iSide < TGCTriggerData::N_SIDE; iSide++) { - for(size_t iOctant = 0; iOctant < TGCTriggerData::N_OCTANT; iOctant++) { + std::string data = *(static_cast<const std::string*>((atr["data"]).addressOfData())); + std::istringstream stream(data); - uint32_t octaddr = (iSide<<TGCTriggerData::SIDE_SHIFT) + - ((iOctant & TGCTriggerData::OCTANT_MASK)<<TGCTriggerData::OCTANT_SHIFT); + char delimiter = '\n'; + std::string field, tag; + uint32_t phimod2 = modulename[moduleId].find("b") != std::string::npos ? 1 : 0; + uint32_t modaddr = ((modulenumber[moduleId] & TGCTriggerData::MODULE_MASK)<<TGCTriggerData::MODULE_SHIFT) + + ((phimod2 & TGCTriggerData::PHIMOD2_MASK)<<TGCTriggerData::PHIMOD2_SHIFT); - for(size_t iModule = 0; iModule < kNMODULETYPE; iModule++) { + while (std::getline(stream, field, delimiter)) { - std::ostringstream dbname; - dbname << "RPhiCoincidenceMap."; - if (fullCW) dbname << sidename[iSide] << iOctant << "."; - dbname << "mod" << modulename[iModule] + "." + vername +"._12.db"; + std::istringstream header(field); + header >> tag; - std::string data = writeCdo->getData(TGCTriggerData::CW_BW, dbname.str()); - std::istringstream stream(data); + if (tag == "#") { // read header part. + uint16_t ptLevel, roi, mod; + int16_t lDR, hDR, lDPhi, hDPhi; + header >> ptLevel >> roi >> mod >> lDR >> hDR >> lDPhi >> hDPhi; - char delimiter = '\n'; - std::string field, tag; - uint32_t phimod2 = modulename[iModule].find("b") != std::string::npos ? 1 : 0; + int16_t type = writeCdo->getTYPE( lDR, hDR, lDPhi, hDPhi ); - uint32_t modaddr = ((modulenumber[iModule] & TGCTriggerData::MODULE_MASK)<<TGCTriggerData::MODULE_SHIFT) + - ((phimod2 & TGCTriggerData::PHIMOD2_MASK)<<TGCTriggerData::PHIMOD2_SHIFT); + // check moduleNumber and ptLevel + if( mod != modulenumber[moduleId] || + ptLevel > TGCTriggerData::N_PT_THRESH || type < 0 ) { + ATH_MSG_WARNING("Invalid configuration of DB file! - Nothing to load this DB file"); + break; + } - while (std::getline(stream, field, delimiter)) { + uint32_t cwaddr = ((uint8_t(type) & TGCTriggerData::TYPE_MASK)<<TGCTriggerData::TYPE_SHIFT) + + ((roi & TGCTriggerData::ROI_MASK)<<TGCTriggerData::ROI_SHIFT); - std::istringstream header(field); - header >> tag; + // get window data + std::getline(stream, field, delimiter); + std::istringstream cont(field); - if (tag == "#") { // read header part. - uint16_t ptLevel, roi, mod; - int16_t lDR, hDR, lDPhi, hDPhi; - header >> ptLevel >> roi >> mod >> lDR >> hDR >> lDPhi >> hDPhi; + for (uint8_t ir = 0; ir < 31; ir++) { // ir=0, 15 and 30 point to -15, 0 and +15 of dR, respectively. + uint32_t draddr = (ir & TGCTriggerData::DR_MASK)<<TGCTriggerData::DR_SHIFT; - int16_t type = writeCdo->getTYPE( lDR, hDR, lDPhi, hDPhi ); + uint32_t bit; + cont >> bit; + if (bit == 0) continue; // none of window is opened in this dR - // check moduleNumber and ptLevel - if( mod != modulenumber[iModule] || - ptLevel > TGCTriggerData::N_PT_THRESH || type < 0 ) { - ATH_MSG_WARNING("Invalid configuration of DB file! - Nothing to load this DB file"); - break; + for(uint8_t iphi=0; iphi<15; iphi++) { // iphi=0, 7 and 14 point to -7, 0 and +7 of dPhi, respectively. + if(bit>>iphi & 0x1) { + uint32_t theaddr = octaddr + modaddr + cwaddr + draddr + iphi; + writeCdo->m_ptmap_bw[theaddr] = (uint8_t)(ptLevel & TGCTriggerData::PT_MASK); } + } + } - uint32_t cwaddr = ((uint8_t(type) & TGCTriggerData::TYPE_MASK)<<TGCTriggerData::TYPE_SHIFT) + - ((roi & TGCTriggerData::ROI_MASK)<<TGCTriggerData::ROI_SHIFT); + } // end of if(tag)... + } // end of while(getline...) - // get window data - std::getline(stream, field, delimiter); - std::istringstream cont(field); + } // end of for(itr) - for (uint8_t ir = 0; ir < 31; ir++) { // ir=0, 15 and 30 point to -15, 0 and +15 of dR, respectively. - uint32_t draddr = (ir & TGCTriggerData::DR_MASK)<<TGCTriggerData::DR_SHIFT; + ATH_MSG_DEBUG("BW-CW LUT size: " << writeCdo->m_ptmap_bw.size()); +} - uint32_t bit; - cont >> bit; - if (bit == 0) continue; // none of window is opened in this dR +void TGCTriggerDbAlg::fillTrigBitEifi(TGCTriggerData* writeCdo, + const CondAttrListCollection* readCdo) +{ + const std::string sidename[TGCTriggerData::N_SIDE] = {"A","C"}; - for(uint8_t iphi=0; iphi<15; iphi++) { // iphi=0, 7 and 14 point to -7, 0 and +7 of dPhi, respectively. - if(bit>>iphi & 0x1) { - uint32_t theaddr = octaddr + modaddr + cwaddr + draddr + iphi; - writeCdo->m_ptmap_bw[theaddr] = (uint8_t)(ptLevel & TGCTriggerData::PT_MASK); - } - } - } + CondAttrListCollection::const_iterator itr = readCdo->begin(); + CondAttrListCollection::const_iterator itr_e = readCdo->end(); - } // end of if(tag)... - } // end of while(getline...) - } // end of for(iModule) + for(; itr!=itr_e; ++itr) { + const coral::AttributeList& atr = (*itr).second; + writeCdo->m_active[TGCTriggerData::CW_EIFI] = atr["active"].data<bool>(); + writeCdo->m_type[TGCTriggerData::CW_EIFI] = atr["type"].data<std::string>(); - if(!fullCW) break; - } // end of for(iOctant) - if(!fullCW) break; - } // end of for(iSide) -} + std::string version = *(static_cast<const std::string*>((atr["version"]).addressOfData())); + std::string file = *(static_cast<const std::string*>((atr["file"]).addressOfData())); + ATH_MSG_DEBUG("channel: " << (*itr).first << ", file: " << file); -void TGCTriggerDbAlg::fillTrigBitEifi(TGCTriggerData* writeCdo) -{ - // remove all entries - for(size_t sector=0; sector<TGCTriggerData::N_ENDCAP_SECTOR; sector++) { - for(size_t ssc=0; ssc<TGCTriggerData::N_ENDCAP_SSC; ssc++) { - for(size_t pos=0; pos<TGCTriggerData::N_EIFI_INPUT; pos++) writeCdo->m_trigbit_eifi[sector][ssc][pos].clear(); - writeCdo->m_flagpt_eifi[sector][ssc].clear(); - writeCdo->m_flagroi_eifi[sector][ssc].clear(); - } - } + ATH_MSG_INFO("type: " << writeCdo->m_type[TGCTriggerData::CW_EIFI] + << " active: " << writeCdo->m_active[TGCTriggerData::CW_EIFI] << " version: " << version); - if (!writeCdo->isActive(TGCTriggerData::CW_EIFI)) { - return; - } + if (!writeCdo->m_active[TGCTriggerData::CW_EIFI]) continue; - bool fullCW = (writeCdo->getType(TGCTriggerData::CW_EIFI) == "full"); - std::string vername = writeCdo->getVersion(TGCTriggerData::CW_EIFI); - const std::string sidename[TGCTriggerData::N_SIDE] = {"A","C"}; + bool fullCW = (writeCdo->m_type[TGCTriggerData::CW_EIFI] == "full"); - for (int iSide = 0; iSide < TGCTriggerData::N_SIDE; iSide++) { + uint8_t sideId = 0; // if the file is not fullCW, sideId should be zero. + if(fullCW) { + std::string side = file.substr(strlen("InnerCoincidenceMap."), 1); + for(int id=0; id<TGCTriggerData::N_SIDE; id++) { + if(sidename[id] == side) { + sideId = id; + break; + } + } + } std::string dbname=""; if (!fullCW) { - dbname = "InnerCoincidenceMap." + vername + "._12.db"; + dbname = "InnerCoincidenceMap." + version + "._12.db"; } else { - dbname = "InnerCoincidenceMap." + sidename[iSide] - + "." + vername + "._12.db"; + dbname = "InnerCoincidenceMap." + sidename[sideId] + + "." + version + "._12.db"; + } + if(file != dbname) { + ATH_MSG_WARNING("The file name is different. Skip to load."); + continue; } - std::string data = writeCdo->getData(TGCTriggerData::CW_EIFI, dbname); - std::istringstream stream(data); + std::istringstream stream(*(static_cast<const std::string*>((atr["data"]).addressOfData()))); char delimiter = '\n'; std::string field; @@ -320,93 +313,116 @@ void TGCTriggerDbAlg::fillTrigBitEifi(TGCTriggerData* writeCdo) return; } - unsigned char flag_pt = 0x0; + uint16_t addr = ((uint16_t(sideId) & TGCTriggerData::SIDE_MASK)<<TGCTriggerData::ADDR_SIDE_SHIFT) + + ((uint16_t(sectorId) & TGCTriggerData::SECTOR_MASK)<<TGCTriggerData::ADDR_SECTOR_SHIFT) + + (uint16_t(sscId) & TGCTriggerData::SSC_MASK); + + uint8_t flag_pt = 0x0; for (size_t pt = 0; pt < TGCTriggerData::N_PT_THRESH; pt++){ - unsigned char use; + uint8_t use; header >> use; flag_pt |= (use&0x1)<<pt; } - writeCdo->m_flagpt_eifi[sectorId][sscId].push_back(flag_pt); + writeCdo->m_flagpt_eifi[addr] = flag_pt; - unsigned char flag_roi = 0x0; + uint8_t flag_roi = 0x0; for (size_t pos = 0; pos < TGCTriggerData::N_ROI_IN_SSC; pos++){ - unsigned char use; + uint8_t use; header >> use; flag_roi |= (use&0x1)<<pos; } - writeCdo->m_flagroi_eifi[sectorId][sscId].push_back(flag_roi); + writeCdo->m_flagroi_eifi[addr] = flag_roi; std::getline(stream, field, delimiter); std::istringstream cont(field); for(size_t pos=0; pos < TGCTriggerData::N_EIFI_INPUT; pos++){ unsigned int word; cont >> word; - writeCdo->m_trigbit_eifi[sectorId][sscId][pos].push_back(word); + uint16_t inputaddr = (addr<<TGCTriggerData::EIFI_TRIGBIT_SHIFT) + pos; + writeCdo->m_trigbit_eifi[inputaddr] = word; } } // end of while(std::geline(...)) if (!fullCW) break; - } // end of for(iSide) + } // end of for(itr) + + ATH_MSG_DEBUG("EIFI-CW LUT size: " << writeCdo->m_flagpt_eifi.size() + writeCdo->m_flagroi_eifi.size() + writeCdo->m_trigbit_eifi.size()); } -void TGCTriggerDbAlg::fillTrigBitTile(TGCTriggerData* writeCdo) +void TGCTriggerDbAlg::fillTrigBitTile(TGCTriggerData* writeCdo, + const CondAttrListCollection* readCdo) { - if (!writeCdo->isActive(TGCTriggerData::CW_TILE)) { - return; - } + CondAttrListCollection::const_iterator itr = readCdo->begin(); + CondAttrListCollection::const_iterator itr_e = readCdo->end(); - std::string vername = writeCdo->getVersion(TGCTriggerData::CW_TILE); + for(; itr!=itr_e; ++itr) { + const coral::AttributeList& atr = (*itr).second; + writeCdo->m_active[TGCTriggerData::CW_TILE] = atr["active"].data<bool>(); + writeCdo->m_type[TGCTriggerData::CW_TILE] = atr["type"].data<std::string>(); - std::string dbname = "TileMuCoincidenceMap." + vername + "._12.db"; + ATH_MSG_DEBUG("channel: " << (*itr).first << ", file: " << atr["file"].data<std::string>()); + ATH_MSG_INFO("type: " << writeCdo->m_type[TGCTriggerData::CW_TILE] + << " active: " << writeCdo->m_active[TGCTriggerData::CW_TILE] + << " version: " << atr["version"].data<std::string>()); - std::string data = writeCdo->getData(TGCTriggerData::CW_TILE, dbname); - std::istringstream stream(data); + if(!writeCdo->m_active[TGCTriggerData::CW_TILE]) continue; - char delimiter = '\n'; - std::string field; - std::string tag; + std::istringstream stream(*(static_cast<const std::string*>((atr["data"]).addressOfData()))); - while (std::getline(stream, field, delimiter)) { - int sideId = -1; - int sectorId = -1; - int sscId = -1; + char delimiter = '\n'; + std::string field; - std::istringstream header(field); - header >> tag; - if (tag=="#"){ // read header part. - header >> sideId >> sectorId >> sscId; - } + while (std::getline(stream, field, delimiter)) { - if(sideId < 0 || sideId >= TGCTriggerData::N_SIDE || - sectorId < 0 || sectorId >= TGCTriggerData::N_ENDCAP_SECTOR || - sscId < 0 || sscId >= TGCTriggerData::N_ENDCAP_SSC ) { - ATH_MSG_WARNING("Invalid configuration of DB file."); - return; - } + int16_t sideId = -1; + int16_t sectorId = -1; + int16_t sscId = -1; - writeCdo->m_flagpt_tile[sscId][sectorId][sideId] = 0x0; - for (size_t pt = 0; pt < TGCTriggerData::N_PT_THRESH; pt++){ - unsigned char use; - header >> use; - writeCdo->m_flagpt_tile[sscId][sectorId][sideId] |= (use&0x1)<<pt; - } + std::istringstream header(field); + std::string tag; + header >> tag; + if (tag=="#"){ // read header part. + header >> sideId >> sectorId >> sscId; + } - writeCdo->m_flagroi_tile[sscId][sectorId][sideId] = 0x0; - for (size_t pos=0; pos< TGCTriggerData::N_ROI_IN_SSC; pos++){ - unsigned char use; - header >> use; - writeCdo->m_flagroi_tile[sscId][sectorId][sideId] |= (use&0x1)<<pos; - } + if(sideId < 0 || sideId >= TGCTriggerData::N_SIDE || + sectorId < 0 || sectorId >= TGCTriggerData::N_ENDCAP_SECTOR || + sscId < 0 || sscId >= TGCTriggerData::N_ENDCAP_SSC ) { + ATH_MSG_WARNING("Invalid configuration of DB file."); + return; + } + uint16_t addr = ((uint16_t(sideId) & TGCTriggerData::SIDE_MASK)<<TGCTriggerData::ADDR_SIDE_SHIFT) + + ((uint16_t(sectorId) & TGCTriggerData::SECTOR_MASK)<<TGCTriggerData::ADDR_SECTOR_SHIFT) + + (uint16_t(sscId) & TGCTriggerData::SSC_MASK); - std::getline(stream, field, delimiter); - std::istringstream cont(field); - writeCdo->m_trigbit_tile[sscId][sectorId][sideId] = 0x0; - for(size_t pos=0; pos < TGCTriggerData::N_TILE_INPUT; pos++){ - unsigned short word; - cont >> word; - writeCdo->m_trigbit_tile[sscId][sectorId][sideId] |= (word & 0xf)<<(pos*4); + uint8_t flagpt = 0; + for (size_t pt = 0; pt < TGCTriggerData::N_PT_THRESH; pt++){ + uint8_t use; + header >> use; + flagpt |= (use&0x1)<<pt; + } + writeCdo->m_flagpt_tile[addr] = flagpt; + + uint8_t roi = 0; + for (size_t pos=0; pos< TGCTriggerData::N_ROI_IN_SSC; pos++){ + uint8_t use; + header >> use; + roi |= (use&0x1)<<pos; + } + writeCdo->m_flagroi_tile[addr] = roi; + + std::getline(stream, field, delimiter); + std::istringstream cont(field); + uint16_t trigbit = 0x0; + for(size_t pos=0; pos < TGCTriggerData::N_TILE_INPUT; pos++){ + uint16_t word; + cont >> word; + trigbit |= (word & 0xf)<<(pos*4); + } + writeCdo->m_trigbit_tile[addr] = trigbit; } } + ATH_MSG_DEBUG("Tile-CW LUT size: " << writeCdo->m_flagpt_tile.size() + writeCdo->m_flagroi_tile.size() + writeCdo->m_trigbit_tile.size()); }