Skip to content
Snippets Groups Projects
Commit 4e58db81 authored by Sarah Louise Barnes's avatar Sarah Louise Barnes Committed by Graeme Stewart
Browse files

Added functions to return the list of chambers associated with either a single...

Added functions to return the list of chambers associated with either a single or list of ROBs (MuonMDT_Cabling-00-04-09)
parent eb0bd56f
No related branches found
No related tags found
No related merge requests found
Showing
with 1158 additions and 0 deletions
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MUONMDT_CABLING_MDTTESTCABLING_H
#define MUONMDT_CABLING_MDTTESTCABLING_H
/***********************************************
*
* @class MdtTestCabling
*
* Testing algorithm for the Muon MDT mapping class
*
* @author Stefano Rosati Stefano.Rosati@roma1.infn.it
*
***********************************************/
#include "GaudiKernel/Algorithm.h"
#include "GaudiKernel/MsgStream.h"
#include "GaudiKernel/IChronoStatSvc.h"
#include "MuonMDT_Cabling/MuonMDT_CablingSvc.h"
// old cabling service
#include "MDTcabling/IMDTcablingSvc.h"
class MdtTestCabling : public Algorithm {
public:
MdtTestCabling(const std::string& name, ISvcLocator* pSvcLocator);
~MdtTestCabling();
virtual StatusCode initialize();
virtual StatusCode finalize();
virtual StatusCode execute();
private:
MuonMDT_CablingSvc* m_cablingSvc;
MsgStream* m_log;
IMDTcablingSvc* m_oldCablingSvc;
const MdtIdHelper* m_mdtIdHelper;
// test initialize function
bool initTestMap();
bool testMapTiming();
bool testMap();
// the chrono service
IChronoStatSvc* m_chronoSvc;
std::string m_chrono1;
std::string m_chrono2;
std::string m_chrono3;
std::string m_chrono4;
};
#endif // MUONMDT_CABLING_MDTTESTCABLING_H
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#ifndef MUONMDT_CABLING_MUONMDT_CABLINGSVC_H
#define MUONMDT_CABLING_MUONMDT_CABLINGSVC_H
#include "AthenaKernel/IOVSvcDefs.h"
#include "AthenaBaseComps/AthService.h"
#include "GaudiKernel/IInterface.h"
//#include "GaudiKernel/IIncidentListener.h"
#include "GaudiKernel/ToolHandle.h"
#include "GaudiKernel/ServiceHandle.h"
#include "StoreGate/DataHandle.h"
#include "AthenaKernel/IOVSvcDefs.h"
class MuonMDT_CablingMap;
class MdtMezzanineType;
class StoreGateSvc;
class IMDTcablingSvc;
class IMDTCablingDbTool;
class ITagInfoMgr;
class IdentifierHash;
static const InterfaceID IID_IMuonMDT_CablingSvc("MuonMDT_CablingSvc", 1, 0);
class MuonMDT_CablingSvc : public AthService
// virtual public IInterface,
// virtual public IIncidentListener
{
public:
MuonMDT_CablingSvc(const std::string& name,ISvcLocator* sl);
virtual ~MuonMDT_CablingSvc();
virtual StatusCode initialize();
virtual StatusCode finalize();
/** methods called at trigger stop/start */
// virtual StatusCode start();
// virtual StatusCode stop();
/** method for begin run transition */
// virtual void handle(const Incident&);
static const InterfaceID& interfaceID() { return IID_IMuonMDT_CablingSvc; }
virtual StatusCode queryInterface(const InterfaceID & riid, void** ppvInterface );
// IOV service callback
StatusCode initMappingModel(IOVSVC_CALLBACK_ARGS_P(I,keys));
// MuonMDT_CablingMap* getCablingMap() {return m_cablingMap;}
DataHandle<MuonMDT_CablingMap> getCablingMap();
/*
* get the id of the ROD to which a chamber is connected;
* this function is needed by the bytestream converters
*/
uint32_t getROBId(int stationName, int stationEta, int stationPhi);
/*
* Get the ROB id from the hashId
*/
uint32_t getROBId(const IdentifierHash mdtHashId);
/*
* get the robs corresponding to a vector of hashIds
*/
std::vector<uint32_t> getROBId(const std::vector<IdentifierHash>& mdtHashVector);
/*
* get all rob Ids
*/
std::vector<uint32_t> getAllROBId();
/** return a vector of HashId lists for a given list of ROD's */
const std::vector<IdentifierHash> getChamberHashVec(const std::vector< uint32_t> &ROBId_list);
/** return a HashId list for a given ROD */
const std::vector<IdentifierHash>& getChamberHashVec(const uint32_t ROBId);
/*
* get the offline id for a given online id
*
*/
bool getOfflineId(uint8_t subdetectorId,
uint8_t rodId,
uint8_t csmId,
uint8_t tdcId,
uint8_t channelId,
int& stationName, int& stationEta, int& stationPhi,
int& multiLayer, int& layer, int& tube);
/** return the online id given the offline id */
bool getOnlineId(int stationName, int stationEta, int stationPhi,
int multiLayer, int layer, int tube,
uint8_t& subdetectorId, uint8_t& rodId, uint8_t& csmId,
uint8_t& tdcId, uint8_t& channelId);
virtual StatusCode compareTags(IOVSVC_CALLBACK_ARGS);
/** Returns true if we're using the old (non-DB) cabling*/
bool usingOldCabling() const;
private:
/** pointer to the class holding the cabling map */
// MuonMDT_CablingMap* m_cablingMap;
DataHandle<MuonMDT_CablingMap> m_cablingMap;
/** flag to use the old cabling service.
To be activated only when reading old simulated data */
bool m_useOldCabling;
/** pointer to the db access tool */
ToolHandle<IMDTCablingDbTool> m_dbTool;
/** flag to indicate the first access to the map (to be fixed) */
bool m_firstAccess;
/** pointer to the old cabling service: added for backwards compatibility to read
old simulated data */
ServiceHandle<IMDTcablingSvc> m_oldCablingSvc;
ServiceHandle<ITagInfoMgr> m_tagInfoMgr; // Tag Info Manager
mutable bool m_tagsCompared;
StoreGateSvc* m_detStore;
/**Set to true, to override callback and take original setting of m_useOldCabling*/
bool m_forceUse;
};
inline bool MuonMDT_CablingSvc::usingOldCabling() const {
return m_useOldCabling;
}
#endif // MUONMDT_CABLING_MUONMDT_CABLINGSVC_H
package MuonMDT_Cabling
public
use AtlasPolicy AtlasPolicy-*
use AthenaBaseComps AthenaBaseComps-* Control
use AthenaKernel AthenaKernel-* Control
use StoreGate StoreGate-* Control
use GaudiInterface GaudiInterface-* External
#use GaudiPython v*
use MDTcabling MDTcabling-* MuonSpectrometer/MuonCablings
private
use AthenaPoolUtilities AthenaPoolUtilities-* Database/AthenaPOOL
use EventInfo EventInfo-* Event
use EventInfoMgt EventInfoMgt-* Event
use MuonCablingData MuonCablingData-* MuonSpectrometer/MuonCablings
use MuonCondInterface MuonCondInterface-* MuonSpectrometer/MuonConditions/MuonCondGeneral
public
#library MuonMDT_Cabling *.cxx components/*.cxx
#apply_pattern component_library
apply_pattern dual_use_library files=*.cxx
apply_pattern declare_python_modules files="*.py"
# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
# template __init__.py defined in the GaudiPolicy package.
from AthenaCommon.GlobalFlags import globalflags
from AthenaCommon.AppMgr import ServiceMgr
from AthenaCommon.AppMgr import ToolSvc
from AthenaCommon.AlgSequence import AlgSequence
#initialize the detector description
include("RecExCond/AllDet_detDescr.py")
from MuonByteStream.MuonByteStreamFlags import muonByteStreamFlags
muonByteStreamFlags.MdtDataType = "atlas"
#initialize correctly the old cabling service
from MDTcabling.MDTcablingConfig import *
topSequence=AlgSequence()
import AthenaPoolCnvSvc.ReadAthenaPool
ServiceMgr.EventSelector.InputCollections = ["testfile.pool.root"]
from MuonMDT_Cabling.MuonMDT_CablingConf import MdtTestCabling
topSequence += MdtTestCabling()
from MDT_CondCabling.MDT_CondCablingConf import MDTCablingDbTool
#from MuonCondTool.MuonCondToolConf import MDTCablingDbTool
MDTCablingDbTool = MDTCablingDbTool("MDTCablingDbTool")
#MDTCablingDbTool.OutputLevel = DEBUG
MessageSvc.OutputLevel = INFO
#MDTCablingDbTool.MezzanineFolders = ["/MDT/CABLING/MEZZANINE_SCHEMA"]
#MDTCablingDbTool.MapFolders = ["/MDT/CABLING/MAP_SCHEMA"]
ToolSvc += MDTCablingDbTool
#dbConn="oracle://intr;schema=ATLAS_COOL_MDTDQ;dbname=MDT_DQA;user=ATLAS_COOL_MDTDQ"
dbConn="oracle://ATLAS_COOLPROD;schema=ATLAS_COOLONL_MDT;dbname=COMP200;user=ATLAS_COOLONL_MDT"
folder="/MDT/CABLING/MAP_SCHEMA"
folder2="/MDT/CABLING/MEZZANINE_SCHEMA"
from IOVDbSvc.IOVDbSvcConf import IOVDbSvc
from IOVDbSvc.CondDB import conddb
include("RegistrationServices/IOVRegistrationSvc_jobOptions.py")
ServiceMgr.IOVDbSvc.dbConnection=dbConn
ServiceMgr.IOVDbSvc.Folders+=[folder+" <tag>HEAD</tag> <dbConnection>"+dbConn+"</dbConnection>"]
ServiceMgr.IOVDbSvc.Folders+=[folder2+" <tag>HEAD</tag> <dbConnection>"+dbConn+"</dbConnection>"]
#configure the chrono service
ServiceMgr.ChronoStatSvc.PrintUserTime = True
ServiceMgr.ChronoStatSvc.PrintSystemTime = True
ServiceMgr.ChronoStatSvc.PrintEllapsedTime = True
theApp.EvtMax = 10
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "MuonMDT_Cabling/MdtTestCabling.h"
#include "MuonCablingData/MuonMDT_CablingMap.h"
#include "StoreGate/StoreGateSvc.h"
#include "StoreGate/DataHandle.h"
MdtTestCabling::MdtTestCabling(const std::string& name, ISvcLocator* pSvcLocator) :
Algorithm(name,pSvcLocator)
{
// m_log = new MsgStream(msgSvc(),name());
m_log = new MsgStream(msgSvc(),"MdtTestCabling");
}
MdtTestCabling::~MdtTestCabling() { }
StatusCode MdtTestCabling::initialize()
{
// initialize the chrono service
StatusCode sc = service("ChronoStatSvc",m_chronoSvc);
if (sc != StatusCode::SUCCESS) {
*m_log << MSG::ERROR << "Could not find the ChronoSvc" << endreq;
return sc;
}
// initialize the cabling service
sc = service("MuonMDT_CablingSvc",m_cablingSvc);
if (sc != StatusCode::SUCCESS) {
*m_log << MSG::ERROR << "Could not find the MuonMDT_CablingSvc" << endreq;
return sc;
}
sc = service("MDTcablingSvc",m_oldCablingSvc);
if (sc != StatusCode::SUCCESS) {
*m_log << MSG::ERROR << "Could not find the MDTcablingSvc" << endreq;
return sc;
}
// bool init = initTestMap();
//if (!init) {
// *m_log << MSG::FATAL << "could not initialize the test map " << endreq;
// return StatusCode::FAILURE;
//}
// initialize the pointer to the MdtIdHelper
StoreGateSvc* detStore;
sc = service("DetectorStore", detStore);
if ( sc.isSuccess() ) {
*m_log << MSG::DEBUG << "Retrieved DetectorStore" << endreq;
}else{
*m_log << MSG::ERROR << "Failed to retrieve DetectorStore" << endreq;
return sc;
}
// retrieve the mdt id helper
sc = detStore->retrieve(m_mdtIdHelper, "MDTIDHELPER" );
if (!sc.isSuccess()) {
*m_log << MSG::ERROR << "Can't retrieve MdtIdHelper" << endreq;
return sc;
}
m_chrono1 = "newcab";
m_chrono2 = "oldcab";
m_chrono3 = "OfflineToOnline";
return StatusCode::SUCCESS;
}
StatusCode MdtTestCabling::execute()
{
/** call the function to run a timing test of the test map
(test map must have been initialized) */
// testMapTiming();
bool tested = testMap();
if (!tested) {
}
return StatusCode::SUCCESS;
}
StatusCode MdtTestCabling::finalize()
{
return StatusCode::SUCCESS;
}
/** test the map content */
bool MdtTestCabling::testMap()
{
// print the list of ROBids
std::vector<uint32_t> robVector = m_cablingSvc->getAllROBId();
std::cout << "============================= List of ROBids:" << std::endl;
for (unsigned int i=0 ; i<robVector.size() ; ++i) {
std::cout << std::hex << robVector[i] << std::dec << std::endl;
}
std::cout << "=============================================" << std::endl;
// loop on the hardware objects to get online identifiers
// if (m_debug) {
*m_log << MSG::DEBUG << "in testMap()" << endreq;
//}
DataHandle<MuonMDT_CablingMap> cablingMap = m_cablingSvc->getCablingMap();
//if (m_debug) {
*m_log << MSG::DEBUG << "retrieved the map from the service" << endreq;
//}
std::map<uint8_t, MdtSubdetectorMap*, std::less<uint8_t> >* listOfSubdet;
std::map<uint8_t, MdtSubdetectorMap*, std::less<uint8_t> >::const_iterator it_sub;
std::map<uint8_t, MdtRODMap*, std::less<uint8_t> >* listOfROD;
std::map<uint8_t, MdtRODMap*, std::less<uint8_t> >::const_iterator it_rod;
std::map<uint8_t, MdtCsmMap*, std::less<uint8_t> >* listOfCsm;
std::map<uint8_t, MdtCsmMap*, std::less<uint8_t> >::const_iterator it_csm;
std::map<uint8_t, MdtAmtMap*, std::less<uint8_t> >* listOfAmt;
std::map<uint8_t, MdtAmtMap*, std::less<uint8_t> >::const_iterator it_amt;
listOfSubdet = cablingMap->getListOfElements();
// if (m_debug) {
*m_log << MSG::DEBUG << "Got the list of subdetectors" << endreq;
*m_log << MSG::DEBUG << "Number of subdetectors: " << listOfSubdet->size() << endreq;
//}
int ntotal = 0;
// loop on the subdetectors
for (it_sub=listOfSubdet->begin() ; it_sub !=listOfSubdet->end() ; ++it_sub) {
int subdetectorId = ((*it_sub).second)->moduleId();
*m_log << MSG::DEBUG << "Now in subdetector: 0x" << MSG::hex
<< (int) subdetectorId << MSG::dec << endreq;
// loop on the RODs of this subdetector
listOfROD = ((*it_sub).second)->getListOfElements();
for (it_rod=listOfROD->begin() ; it_rod !=listOfROD->end() ; ++it_rod) {
int rodId = ((*it_rod).second)->moduleId();
*m_log << MSG::DEBUG << "Now in ROD: 0x" << MSG::hex
<< (int) rodId << MSG::dec << endreq;
// loop on the CSMs of this ROD
listOfCsm = ((*it_rod).second)->getListOfElements();
for (it_csm=listOfCsm->begin() ; it_csm !=listOfCsm->end() ; ++it_csm) {
int csmId = ((*it_csm).second)->moduleId();
*m_log << MSG::DEBUG << "Now in csm: 0x" << MSG::hex
<< (int) csmId << MSG::dec << endreq;
bool csmTested = false;
listOfAmt = ((*it_csm).second)->getListOfElements();
for (it_amt=listOfAmt->begin() ; it_amt !=listOfAmt->end() ; ++it_amt) {
int amtId = ((*it_amt).second)->moduleId();
*m_log << MSG::DEBUG << "Now in amt: 0x" << MSG::hex
<< (int) amtId << MSG::dec << endreq;
for (int chanId = 0 ; chanId<24 ; ++chanId) {
// convert the channel
int station=0;
int eta=0;
int phi=0;
int multi=0;
int layer=0;
int tube=0;
m_chronoSvc->chronoStart(m_chrono1);
bool cabling = m_cablingSvc->getOfflineId(subdetectorId,rodId,csmId,
amtId,chanId,
station,eta,phi,multi,
layer,tube);
m_chronoSvc->chronoStop(m_chrono1);
if (!cabling) {
//*m_log << MSG::ERROR << "channel not found !" << endreq;
}
else {
*m_log << MSG::DEBUG << "Channel converted to: station: " << station
<< " eta: " << eta << " phi: "<< phi << " multi: " << multi
<< " layer: " << layer << " tube: " << tube << endreq;
uint8_t newSubdet = 0;
uint8_t newRod = 0;
uint8_t newCsm = 0;
uint8_t newAmt = 0;
uint8_t newChan = 0;
// test the back-conversion to online indeces
m_chronoSvc->chronoStart(m_chrono3);
cabling = m_cablingSvc->getOnlineId(station,eta,phi,multi,layer,tube,
newSubdet,newRod,newCsm,newAmt,newChan);
m_chronoSvc->chronoStop(m_chrono3);
if (!cabling) {
// *m_log << MSG::WARNING << "Could not convert back offline->online" << endreq;
}
else {
if (newSubdet!=subdetectorId || newRod!=rodId || newCsm!=csmId ||
newAmt!=amtId || newChan!=chanId) {
*m_log << MSG::ERROR << "=================================" << endreq;
*m_log << MSG::ERROR << "Back conversion gives a different result !"
<< endreq;
*m_log << MSG::ERROR << "Original online: subdet 0x" << MSG::hex
<< subdetectorId << MSG::dec
<< " rodId 0x" << MSG::hex << rodId << MSG::dec
<< " csmId 0x" << MSG::hex << csmId << MSG::dec
<< " amtId 0x" << MSG::hex << amtId << MSG::dec
<< " chanId 0x" << MSG::hex << chanId << MSG:: dec << endreq;
*m_log << MSG::ERROR << "converted to station: " << station
<< " name: " << m_mdtIdHelper->stationNameString(station)
<< " eta: " << eta << " phi: " << phi << " multi: " << multi
<< " layer: " << layer << " tube: " << tube << endreq;
*m_log << MSG::ERROR << "New online: subdet 0x" << MSG::hex
<< (int) newSubdet << MSG::dec
<< " rodId 0x" << MSG::hex << (int) newRod << MSG::dec
<< " csmId 0x" << MSG::hex << (int) newCsm << MSG::dec
<< " amtId 0x" << MSG::hex << (int) newAmt << MSG::dec
<< " chanId 0x" << MSG::hex << (int) newChan << MSG:: dec << endreq;
*m_log << MSG::ERROR << "=================================" << endreq;
}
}
int stationOld=0;
int etaOld=0;
int phiOld=0;
int multiOld=0;
int layerOld=0;
int tubeOld=0;
// convert using the old cabling service
m_chronoSvc->chronoStart(m_chrono2);
bool old_cabling = m_oldCablingSvc->getOfflineIDfromOnlineID(subdetectorId,rodId,
csmId,amtId,chanId,
stationOld,etaOld,
phiOld,multiOld,
layerOld,tubeOld );
m_chronoSvc->chronoStop(m_chrono2);
if (!old_cabling) {
*m_log << MSG::ERROR << "*******************************************" << endreq;
*m_log << MSG::ERROR << "channel not found in the old cabling service!" << endreq;
ntotal++;
*m_log << MSG::ERROR << "subdet: 0x" << MSG::hex << (int) subdetectorId
<< MSG::dec << " rod: 0x" << MSG::hex << (int) rodId << MSG::dec
<< " csm: 0x" << MSG::hex << (int) csmId << MSG::dec
<< " amt: 0x" << MSG::hex << (int) amtId << MSG::dec
<< " chan: 0x" << MSG::hex << (int) chanId << MSG::dec << endreq;
*m_log << MSG::ERROR << "station: " << station << " name: "
<< m_mdtIdHelper->stationNameString(station) << " eta: " << eta
<< " phi: " << phi << " multilayer: " << multi
<< " layer: " << layer << " tube: " << tube << endreq;
*m_log << MSG::ERROR << "*******************************************" << endreq;
}
else {
if ( (station != stationOld || eta != etaOld || phi != phiOld || multi != multiOld
|| layer != layerOld || tube != tubeOld) && !csmTested) {
*m_log << MSG::ERROR << "Maps differ for: subdet 0x"
<< MSG::hex << (int) subdetectorId << MSG::dec
<< " rodId: 0x" << MSG::hex << (int) rodId << MSG::dec
<< " csmId: 0x" << MSG::hex << (int) csmId << MSG::dec
<< " amtId: 0x" << MSG::hex << (int) amtId << MSG::dec
<< " chanId: 0x" << MSG::hex << (int) chanId << MSG::dec << endreq;
*m_log << MSG::ERROR << "New cabling says: " << m_mdtIdHelper->stationNameString(station)
<< " " << eta << " " << phi << " " << multi << " " << layer << " " << tube
<< endreq;
*m_log << MSG::ERROR << "Difference (new-old): "
<< station-stationOld << " " << eta-etaOld << " "
<< phi-phiOld << " " << multi-multiOld << " " << layer-layerOld
<< " " << tube-tubeOld << endreq;
// if it's just a csm id difference then print it just once
// if (tube==tubeOld) csmTested=true;
}
}
}
} // loop on the channels
}
}
}
}
return true;
}
/** Run a timing test of the MDT map */
bool MdtTestCabling::testMapTiming()
{
int stationName=0;
int stationEta=0;
int stationPhi=0;
int multiLayer=0;
int layer=0;
int tube=0;
bool found;
//
m_chronoSvc->chronoStart(m_chrono1);
for (int i = 0 ; i<1000 ; i++) {
found = m_cablingSvc->getOfflineId(1,1,1,1,1,
stationName,stationEta,stationPhi,
multiLayer,layer,tube);
if (!found) {
*m_log<< MSG::FATAL << " coul dnot find the test channel" << endreq;
return found;
}
//found = m_cablingSvc->getOfflineId(1,1,1,1,1,
// stationName,stationEta,stationPhi,
// multiLayer,layer,tube);
found = m_cablingSvc->getOfflineId(1,1,1,1,3,
stationName,stationEta,stationPhi,
multiLayer,layer,tube);
if (!found) {
*m_log<< MSG::FATAL << " coul dnot find the test channel" << endreq;
return StatusCode::FAILURE;
}
}
m_chronoSvc->chronoStop(m_chrono1);
return true;
}
/** Initialize the test map */
bool MdtTestCabling::initTestMap()
{
// fill the map with dummy numbers
// for (int subdet = 0 ; subdet < 4 ; subdet++) {
// MdtSubdetectorMap* subdetectorMap = new MdtSubdetectorMap(subdet);
// for (int rod=0 ; rod <50 ; rod++) {
// MdtRODMap* rodMap = new MdtRODMap(rod);
// for (int csm=0 ; csm<6 ; csm++) {
// MdtCsmMap* csmMap = new MdtCsmMap(csm);
// for (int tdc=0 ; tdc<18 ; tdc++) {
// MdtAmtMap* amtMap = new MdtAmtMap(tdc);
// for (int channel=0 ; channel<24 ; channel++) {
// amtMap->setChannel(channel,3,3);
// }
// csmMap->setAmtMap(tdc,amtMap);
// }
//
// rodMap->setCsmMap(csm,csmMap);
// }
// subdetectorMap->setRODMap(rod,rodMap);
// }
// m_cablingSvc->getCablingMap()->setSubdetectorMap(subdet,subdetectorMap);
// }
return true;
}
/*
Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
*/
#include "MuonMDT_Cabling/MuonMDT_CablingSvc.h"
// include the old cabling service for backwards-compatibility when reading old data
#include "MDTcabling/IMDTcablingSvc.h"
#include "GaudiKernel/ServiceHandle.h"
#include "GaudiKernel/IIncidentSvc.h"
#include "StoreGate/StoreGateSvc.h"
#include "MuonCablingData/MuonMDT_CablingMap.h"
#include "MuonCablingData/MdtMezzanineType.h"
#include "MuonCondInterface/IMDTCablingDbTool.h"
#include "AthenaPoolUtilities/CondAttrListCollection.h"
#include "EventInfo/TagInfo.h"
#include "EventInfoMgt/ITagInfoMgr.h"
MuonMDT_CablingSvc::MuonMDT_CablingSvc(const std::string& svcName,ISvcLocator* sl) :
AthService(svcName,sl),
m_cablingMap(0),
m_useOldCabling(false),
m_dbTool("MDTCablingDbTool/MDTCablingDbTool"),
m_firstAccess(true),
m_oldCablingSvc("MDTcablingSvc", svcName),
m_tagInfoMgr("TagInfoMgr", svcName),
m_detStore(0),
m_forceUse(false)
{
declareProperty("UseOldCabling", m_useOldCabling);
declareProperty("DBTool", m_dbTool);
declareProperty("OldCablingSvc", m_oldCablingSvc);
declareProperty("TagInfoManager", m_tagInfoMgr);
declareProperty("ForcedUse", m_forceUse);
}
MuonMDT_CablingSvc::~MuonMDT_CablingSvc()
{ }
/** Initialization method */
StatusCode MuonMDT_CablingSvc::initialize()
{
StatusCode sc = StatusCode::SUCCESS;
msg(MSG::INFO) << "in initialize() with Configuration: "<<(m_useOldCabling ? "'Old MDT Cabling'" : "'New MDT Cabling'") <<", callback "<< (m_forceUse?"Disabled":"Enabled")<< endreq;
sc = serviceLocator()->service("DetectorStore", m_detStore);
if ( sc.isFailure()) {
msg(MSG::WARNING)<< "Could not find det store. Exiting."
<< endreq;
return StatusCode::FAILURE;
}
msg(MSG::DEBUG)<<"Trying to locate the DB Tool"<<endreq;
if (!m_useOldCabling){
if ( m_dbTool.retrieve().isFailure()) {
msg(MSG::WARNING)<< "Could not find tool " << m_dbTool << ". Exiting."
<< endreq;
return StatusCode::FAILURE;
} else {
msg(MSG::DEBUG)<< "Database tool \"" << m_dbTool << "\" retrieved."
<< endreq;
}
} else {
// for old cabling, don't do this.
m_firstAccess=false;
}
if(m_forceUse) {
// Selected cabling is used without comparison
m_tagsCompared = true;
msg(MSG::DEBUG)<< "'ForcedUse' property is set to 'True', so disabling the callback. Configuration fixed to: "<<(m_useOldCabling ? "'Old MDT Cabling'" : "'New MDT Cabling'") << endreq;
} else {
// The cabling to be used and the cabling in tag info will be compared by compareTags method
const DataHandle<TagInfo> tagInfoH;
std::string tagInfoKey = "";
// get the key
if(m_tagInfoMgr.retrieve().isFailure() || m_tagInfoMgr==0) {
msg(MSG::WARNING) << " Unable to locate TagInfoMgr service" << endreq;
} else {
tagInfoKey = m_tagInfoMgr->tagInfoKey();
}
if(m_detStore->regFcn(&MuonMDT_CablingSvc::compareTags,
this,
tagInfoH,
tagInfoKey)
!= StatusCode::SUCCESS) {
msg(MSG::WARNING)<< "Cannot register compareTags function for key " << tagInfoKey << endreq;
} else {
msg(MSG::DEBUG)<< "Registered compareTags callback for key: " << tagInfoKey << endreq;
}
}
/** Get a pointer to the old cabling if needed */
if (m_useOldCabling || (!m_forceUse)) {
if (m_useOldCabling) msg(MSG::DEBUG) << "===> The old cabling service is being used within the new one" << endreq;
if (m_oldCablingSvc.retrieve().isFailure()) {
msg(MSG::ERROR) << "Could not get a pointer to the MDTcablingSvc" << endreq;
return StatusCode::FAILURE;
}
}
if ( !m_useOldCabling )
{
// register the init mapping model for callback against the
// cabling folders --- only if not using the old cabling
msg(MSG::INFO) << "Registering for callback the initMappingModel function"
<< endreq;
std::string mapFolderName = m_dbTool->mapFolderName();
msg(MSG::INFO) << "Map folder name: " << m_dbTool->mapFolderName() << endreq;
const DataHandle<CondAttrListCollection> MapData;
sc = m_detStore->regFcn(&MuonMDT_CablingSvc::initMappingModel,
this,
MapData, mapFolderName);
if (sc.isFailure()) {
msg(MSG::ERROR)
<< "Could not register initMapping function for callback against: " << mapFolderName
<< endreq;
return sc;
}
// register the mezzanine folder for callback
std::string mezzanineFolderName = m_dbTool->mezzanineFolderName();
msg(MSG::INFO) << "Mezzanine folder name: "
<< mezzanineFolderName << endreq;
const DataHandle<CondAttrListCollection> MapData_mez;
sc = m_detStore->regFcn(&MuonMDT_CablingSvc::initMappingModel,
this,MapData_mez, mezzanineFolderName);
if (sc.isFailure()) {
msg(MSG::ERROR)
<< "Could not register initMapping function for callback against: " << mezzanineFolderName
<< endreq;
return sc;
}
}// new model in use => register for call back the initMappingModel method
return sc;
}
/** Finalization method */
StatusCode MuonMDT_CablingSvc::finalize()
{
return StatusCode::SUCCESS;
}
// queryInterface
StatusCode MuonMDT_CablingSvc::queryInterface(const InterfaceID& riid, void** ppvIF)
{
if(IID_IMuonMDT_CablingSvc.versionMatch(riid) )
{
*ppvIF = (MuonMDT_CablingSvc*)this;
} else {
return AthService::queryInterface(riid, ppvIF);
}
return StatusCode::SUCCESS;
}
StatusCode
MuonMDT_CablingSvc::compareTags(IOVSVC_CALLBACK_ARGS)
{
StatusCode sc;
msg(MSG::DEBUG) << "compareTags() callback triggered. Current configuration is: "<<(m_useOldCabling ? "OldMDT_Cabling" : "NewMDT_Cabling") << endreq;
if (m_forceUse) {
// shouldn't ever be called, as callback shouldn't have been registered.
m_tagsCompared=true;
msg(MSG::INFO) <<"Aborting compareTags call back because ForcedUse property is true. Will use current configuration: "<<(m_useOldCabling ? "OldMDT_Cabling" : "NewMDT_Cabling")<<endreq;
return StatusCode::SUCCESS;
}
// Get TagInfo and retrieve tags
const TagInfo* tagInfo = 0;
StoreGateSvc* detStore=0;
sc = serviceLocator()->service("DetectorStore", detStore);
sc= detStore->retrieve(tagInfo);
std::string cablingType;
if (sc.isFailure() || tagInfo==0) {
msg(MSG::WARNING)<< "No TagInfo in DetectorStore while attempting to compare tags. Will use current configuration: "<<(m_useOldCabling ? "OldMDT_Cabling" : "NewMDT_Cabling") << endreq;
return StatusCode::RECOVERABLE;
} else {
tagInfo->findInputTag("MDT_CablingType", cablingType);
msg(MSG::DEBUG)<< "MDT_CablingType from TagInfo: " << cablingType << endreq;
// either have empty cabling tag and set to old cabling, or new and don't use old cabling
bool tagMatch = (cablingType=="" && m_useOldCabling) || (cablingType == "NewMDT_Cabling"&& !m_useOldCabling);
if (!tagMatch) {
// Trying to use wrong cabling map! Flip configuration
if (m_useOldCabling) {
m_useOldCabling = false;
m_firstAccess=true;
//retrieve tool now to avoid unpleasent surprises later!
if ( m_dbTool.retrieve().isFailure()) {
msg(MSG::WARNING)<< "Could not find tool " << m_dbTool << ". Exiting."<< endreq;
return StatusCode::FAILURE;
}
} else {
m_useOldCabling = true;
m_firstAccess=false;
}
msg(MSG::INFO)<< "MDT_CablingType : " << cablingType << " is mismatched "
<< "with configuration of this service ."
<< "m_useOldCabling flag is flipped to " << (m_useOldCabling ? "true" : "false") << " ."
<< endreq;
}
}
msg(MSG::INFO)<< "compareTags() callback determined that the taginfo for MDT cabling is: "<< cablingType << " (blank = old). Current configuration is: "
<<(m_useOldCabling ? "OldMDT_Cabling" : "NewMDT_Cabling") << endreq;
m_tagsCompared=true;
return StatusCode::SUCCESS;
}
//// to be fixed: get the cabling map directly from the tool
DataHandle<MuonMDT_CablingMap> MuonMDT_CablingSvc::getCablingMap()
{
return m_cablingMap;
}
uint32_t MuonMDT_CablingSvc::getROBId(int stationName, int stationEta, int stationPhi)
{
int rodId = m_cablingMap->getROBId(stationName,stationEta,stationPhi);
return rodId;
}
uint32_t MuonMDT_CablingSvc::getROBId(const IdentifierHash mdtIdHash)
{
int rodId = m_cablingMap->getROBId(mdtIdHash);
return rodId;
}
std::vector<uint32_t> MuonMDT_CablingSvc::getROBId(const std::vector<IdentifierHash>& mdtHashVector)
{
std::vector<uint32_t> robVector;
for ( unsigned int i = 0 ; i<mdtHashVector.size() ; ++i ) {
int robId = this->getROBId(mdtHashVector[i]);
if (robId==0) {
msg(MSG::ERROR) << "ROB id not found for Hash Id: " << mdtHashVector[i] << endreq;
} else {
ATH_MSG_DEBUG("Found ROB id 0x" << MSG::hex << robId << MSG::dec << " for hashId " << mdtHashVector[i]);
}
robVector.push_back(robId);
}
ATH_MSG_DEBUG("Size of ROB vector is: " << robVector.size());
return robVector;
}
//
const std::vector<IdentifierHash> MuonMDT_CablingSvc::getChamberHashVec(const std::vector< uint32_t> &ROBId_list)
{
return m_cablingMap->getChamberHashVec(ROBId_list);
}
const std::vector<IdentifierHash>& MuonMDT_CablingSvc::getChamberHashVec(const uint32_t ROBId)
{
return m_cablingMap->getChamberHashVec(ROBId);
}
/** This function returns the full list of ROBids */
std::vector<uint32_t> MuonMDT_CablingSvc::getAllROBId()
{
std::vector<uint32_t> allROBId;
if (m_useOldCabling) {
std::set< uint32_t > setOfRobIds = m_oldCablingSvc->getROBid(0.,2.*3.141592,-3.,3.);
std::vector< uint32_t > robIds(setOfRobIds.size());
std::copy(setOfRobIds.begin(), setOfRobIds.end(), robIds.begin());
return robIds;
}
allROBId = m_cablingMap->getAllROBId();
return allROBId;
}
/** convert an online id to an offline one */
bool MuonMDT_CablingSvc::getOfflineId(uint8_t subdetectorId,
uint8_t rodId,
uint8_t csmId,
uint8_t tdcId,
uint8_t channelId,
int& stationName, int& stationEta, int& stationPhi,
int& multiLayer, int& layer, int& tube)
{
if (m_useOldCabling) {
bool found_old = m_oldCablingSvc->getOfflineIDfromOnlineID(subdetectorId,
rodId,
csmId,
tdcId,
channelId,
stationName, stationEta, stationPhi,
multiLayer, layer, tube);
if (!found_old) {
msg(MSG::ERROR) << "Can't find subdetector: 0x" << MSG::hex << (int) subdetectorId
<< MSG::dec << " rod: 0x" << MSG::hex << (int) rodId
<< MSG::dec << " rod: 0x" << MSG::hex << (int) csmId
<< MSG::dec << " rod: 0x" << MSG::hex << (int) tdcId
<< MSG::dec << " rod: 0x" << MSG::hex << (int) channelId;
}
return found_old;
}
bool found = m_cablingMap->getOfflineId(subdetectorId,rodId,csmId,
tdcId,channelId,
stationName,stationEta,stationPhi,
multiLayer,layer,tube);
return found;
}
/* get the online Id given the offline id */
bool MuonMDT_CablingSvc::getOnlineId(int stationName, int stationEta, int stationPhi,
int multiLayer, int layer, int tube,
uint8_t& subdetectorId, uint8_t& rodId,
uint8_t& csmId,
uint8_t& tdcId, uint8_t& channelId)
{
if (m_useOldCabling) {
short unsigned int subdet=0;
short unsigned int rod=0;
short unsigned int csm=0;
short unsigned int tdc=0;
short unsigned int channel=0;
bool found_old = m_oldCablingSvc->getOnlineIDfromOfflineID(stationName, stationEta, stationPhi,
multiLayer,layer,tube,
subdet,rod,csm,tdc,channel);
if (!found_old) {
msg(MSG::ERROR)<< "Can't find station: " << stationName
<< " eta: " << stationEta
<< " phi: " << stationPhi
<< " multilayer: " << multiLayer
<< " layer: " << layer
<< " tube: " << tube << endreq;
}
else {
subdetectorId = (uint8_t) subdet;
rodId = (uint8_t) rod;
csmId = (uint8_t) csm;
tdcId = (uint8_t) tdc;
channelId = (uint8_t) channel;
}
return found_old;
}
bool found = m_cablingMap->getOnlineId(stationName, stationEta, stationPhi,
multiLayer, layer, tube,
subdetectorId, rodId,
csmId, tdcId, channelId);
return found;
}
/** callback registered function to initialize the map object */
StatusCode MuonMDT_CablingSvc::initMappingModel(IOVSVC_CALLBACK_ARGS_P(I,keys))
{
msg(MSG::INFO) << "initMappingModel has been called" << endreq;
msg(MSG::INFO) << "ToolHandle in initMappingModel - <" << m_dbTool << ">" << endreq;
if(!m_useOldCabling) {
StatusCode sc = m_dbTool->loadParameters(I, keys);
if (sc.isFailure()) {
msg(MSG::ERROR)<<"Reading Cabling maps from COOL failed; try to read from file"<<endreq;
return StatusCode::FAILURE;
}
// retrieve the map from the detector store
sc = m_detStore->retrieve(m_cablingMap);
if (sc!=StatusCode::SUCCESS) {
msg(MSG::ERROR) << "Can't retrieve the cabling map from the detector store" << endreq;
return false;
}
else {
msg(MSG::DEBUG) << "Retrieved map from the detector store" << endreq;
}
}
else {
msg(MSG::INFO) << "Using the old cabling, no callback" << endreq;
}
return StatusCode::SUCCESS;
}
#include "GaudiKernel/DeclareFactoryEntries.h"
#include "MuonMDT_Cabling/MuonMDT_CablingSvc.h"
#include "MuonMDT_Cabling/MdtTestCabling.h"
DECLARE_SERVICE_FACTORY(MuonMDT_CablingSvc)
DECLARE_ALGORITHM_FACTORY(MdtTestCabling)
DECLARE_FACTORY_ENTRIES(MuonMDT_Cabling) {
DECLARE_SERVICE(MuonMDT_CablingSvc)
DECLARE_ALGORITHM(MdtTestCabling)
}
#include "GaudiKernel/LoadFactoryEntries.h"
LOAD_FACTORY_ENTRIES(MuonMDT_Cabling)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment