diff --git a/InnerDetector/InDetConditions/SCT_ConditionsData/SCT_ConditionsData/SCT_TdaqEnabledCondData.h b/InnerDetector/InDetConditions/SCT_ConditionsData/SCT_ConditionsData/SCT_TdaqEnabledCondData.h new file mode 100644 index 0000000000000000000000000000000000000000..8b780f1704002d966a828f6fe7b00f57b4903dae --- /dev/null +++ b/InnerDetector/InDetConditions/SCT_ConditionsData/SCT_ConditionsData/SCT_TdaqEnabledCondData.h @@ -0,0 +1,74 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +/** + * @file SCT_TdaqEnabledCondData.h + * header file for data object + * @author Susumu Oda - 2017-05-15 + **/ + +#ifndef SCT_TDAQENABLEDCONDDATA_H +#define SCT_TDAQENABLEDCONDDATA_H + +#include <set> +#include <vector> + +// Include Athena stuff +#include "CLIDSvc/CLASS_DEF.h" +#include "Identifier/IdentifierHash.h" + +class SCT_TdaqEnabledCondData { +public: + + // Constructor + SCT_TdaqEnabledCondData(); + + // Destructor + virtual ~SCT_TdaqEnabledCondData(); + + // Set a good ROD + bool setGoodRod(const unsigned int rodNumber); + + // Get good RODs + const std::set<unsigned int>& getGoodRods() const; + + // Set a list of good modules + void setGoodModules(const std::vector<IdentifierHash>& idVec); + + // Set filled variable + void setFilled(const bool filled); + + // Get filled variable + bool isFilled() const; + + // Set noneBad value + void setNoneBad(const bool noneBad); + + // Get noneBad value + bool isNoneBad() const; + + // Check if a module is good + bool isGood(const IdentifierHash& hashId) const; + + // Clear m_goodRods, m_goodIds, m_noneBad, m_filled + void clear(); + +private: + + std::set<unsigned int> m_goodRods; + std::set<IdentifierHash> m_goodIds; + bool m_noneBad; + bool m_filled; + +}; + +CLASS_DEF( SCT_TdaqEnabledCondData , 137549585 , 1 ) + +#include "AthenaKernel/CondCont.h" +CLASS_DEF( CondCont<SCT_TdaqEnabledCondData> , 31730865 , 1 ) + +#include "SGTools/BaseInfo.h" +SG_BASE( CondCont<SCT_TdaqEnabledCondData>, CondContBase ); + +#endif // SCT_TDAQENABLEDDATA_H diff --git a/InnerDetector/InDetConditions/SCT_ConditionsData/src/SCT_TdaqEnabledCondData.cxx b/InnerDetector/InDetConditions/SCT_ConditionsData/src/SCT_TdaqEnabledCondData.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2ea407dc026700ab10ed2ab0a3bce36b6e117ac6 --- /dev/null +++ b/InnerDetector/InDetConditions/SCT_ConditionsData/src/SCT_TdaqEnabledCondData.cxx @@ -0,0 +1,93 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +//---------------------------------------------------------------------- +// Implementation file for the data object class for SCT_TdaqEnabledSvc +//---------------------------------------------------------------------- + +#include "SCT_ConditionsData/SCT_TdaqEnabledCondData.h" + +#include <algorithm> +#include <iterator> + +//---------------------------------------------------------------------- +// Constructor +SCT_TdaqEnabledCondData::SCT_TdaqEnabledCondData(): + m_goodRods(), + m_goodIds(), + m_noneBad(false), + m_filled(false) +{} + +//---------------------------------------------------------------------- +// Destructor +SCT_TdaqEnabledCondData::~SCT_TdaqEnabledCondData() +{} + +//---------------------------------------------------------------------- +// Set a good ROD number +bool SCT_TdaqEnabledCondData::setGoodRod(const unsigned int rodNumber) +{ + return m_goodRods.insert(rodNumber).second; +} + +//---------------------------------------------------------------------- +// Get good ROD numbers +const std::set<unsigned int>& SCT_TdaqEnabledCondData::getGoodRods() const +{ + return m_goodRods; +} + +//---------------------------------------------------------------------- +// Set a list of good modules +void SCT_TdaqEnabledCondData::setGoodModules(const std::vector<IdentifierHash>& idVec) +{ + std::copy(idVec.begin(), idVec.end(), std::inserter(m_goodIds, m_goodIds.end())); +} + +//---------------------------------------------------------------------- +// Set filled variable +void SCT_TdaqEnabledCondData::setFilled(const bool filled) +{ + m_filled = filled; +} + +//---------------------------------------------------------------------- +// Get filled variable +bool SCT_TdaqEnabledCondData::isFilled() const +{ + return m_filled; +} + +//---------------------------------------------------------------------- +// Set noneBad variable +void SCT_TdaqEnabledCondData::setNoneBad(const bool noneBad) +{ + m_noneBad = noneBad; +} + +//---------------------------------------------------------------------- +// Get noneBad variable +bool SCT_TdaqEnabledCondData::isNoneBad() const +{ + return m_noneBad; +} + +//---------------------------------------------------------------------- +// Check if a module is good +bool SCT_TdaqEnabledCondData::isGood(const IdentifierHash& hashId) const +{ + if(m_noneBad) return true; + return (m_goodIds.find(hashId)!=m_goodIds.end()); +} + +//---------------------------------------------------------------------- +// Clear +void SCT_TdaqEnabledCondData::clear() { + m_goodRods.clear(); + m_goodIds.clear(); + m_noneBad = false; + m_filled = false; +} + diff --git a/InnerDetector/InDetConditions/SCT_ConditionsServices/share/testTdaqEnabled.py b/InnerDetector/InDetConditions/SCT_ConditionsServices/share/testTdaqEnabled.py index 6f5843c817ceb57280a516f0aa3b879dcceb3d24..5234a5808826fe7d4311b490b215edff9377c0a4 100644 --- a/InnerDetector/InDetConditions/SCT_ConditionsServices/share/testTdaqEnabled.py +++ b/InnerDetector/InDetConditions/SCT_ConditionsServices/share/testTdaqEnabled.py @@ -29,10 +29,10 @@ theApp.AuditAlgorithms=False # Load Geometry #-------------------------------------------------------------- from AthenaCommon.GlobalFlags import globalflags -globalflags.DetDescrVersion="ATLAS-GEO-16-00-00" +globalflags.DetDescrVersion="ATLAS-R2-2016-01-00-01" globalflags.DetGeo="atlas" globalflags.InputFormat="pool" -globalflags.DataSource="geant4" +globalflags.DataSource="data" print 'globalTags.DatabaseInstance', globalflags.DatabaseInstance @@ -65,6 +65,11 @@ DetFlags.writeRIOPool.all_setOff() import AtlasGeoModel.SetGeometryVersion import AtlasGeoModel.GeoModelInit +# Disable SiLorentzAngleSvc to remove +# ERROR ServiceLocatorHelper::createService: wrong interface id IID_665279653 for service +ServiceMgr.GeoModelSvc.DetectorTools['PixelDetectorTool'].LorentzAngleSvc="" +ServiceMgr.GeoModelSvc.DetectorTools['SCT_DetectorTool'].LorentzAngleSvc="" + #-------------------------------------------------------------- # Load DCSConditions Alg and Service #-------------------------------------------------------------- @@ -77,24 +82,18 @@ topSequence+= SCT_TdaqEnabledTestAlg() from SCT_ConditionsServices.SCT_ConditionsServicesConf import SCT_TdaqEnabledSvc ServiceMgr += SCT_TdaqEnabledSvc() -SCT_TdaqEnabledSvc.AttrListCollFolders=["/TDAQ/EnabledResources/ATLAS/SCT/Robins"] +SCT_TdaqEnabledSvc.AttrListCollFolders=["/TDAQ/Resources/ATLAS/SCT/Robins"] #-------------------------------------------------------------- # Event selector settings. Use McEventSelector #-------------------------------------------------------------- import AthenaCommon.AtlasUnixGeneratorJob -#ServiceMgr+= EventSelector() -#ServiceMgr.EventSelector.FirstEvent = 1 -#ServiceMgr.EventSelector.EventsPerRun = 5 -#ServiceMgr.EventSelector.RunNumber = 140975 -ServiceMgr.EventSelector.RunNumber = 90975 +ServiceMgr.EventSelector.RunNumber = 310809 # initial time stamp - this is number of seconds since 1st Jan 1970 GMT -# the value given here corresponds to 10-09-2009 17:01 geneva local time -#ServiceMgr.EventSelector.InitialTimeStamp = 1252594860 -#run 140975 started on 2009-Nov-27 03:16:37 CET and lasted 4:32:40: -ServiceMgr.EventSelector.InitialTimeStamp = 1259289060 +# run 310809 Recording start/end 2016-Oct-17 21:39:18 / 2016-Oct-18 16:45:23 UTC +ServiceMgr.EventSelector.InitialTimeStamp = 1476741326 # LB 18 of run 310809, 10/17/2016 @ 9:55pm (UTC) # increment of 3 minutes ServiceMgr.EventSelector.TimeStampInterval = 180 @@ -111,12 +110,10 @@ ServiceMgr.MessageSvc.OutputLevel = 3 IOVDbSvc = Service("IOVDbSvc") from IOVDbSvc.CondDB import conddb #IOVDbSvc.GlobalTag="HEAD" -IOVDbSvc.GlobalTag="OFLCOND-FDR-01-02-00" +IOVDbSvc.GlobalTag="CONDBR2-BLKPA-2017-06" IOVDbSvc.OutputLevel = 3 -conddb.addFolder('',"<db>COOLONL_TDAQ/COMP200</db> /TDAQ/EnabledResources/ATLAS/SCT/Robins") -conddb.addFolder("","<db>COOLONL_SCT/COMP200</db> /SCT/DAQ/Configuration/ROD") -conddb.addFolder("","<db>COOLONL_SCT/COMP200</db> /SCT/DAQ/Configuration/Geog") -conddb.addFolder("","<db>COOLONL_SCT/COMP200</db> /SCT/DAQ/Configuration/RODMUR") -conddb.addFolder("","<db>COOLONL_SCT/COMP200</db> /SCT/DAQ/Configuration/MUR") - - +conddb.addFolder("TDAQ", "/TDAQ/Resources/ATLAS/SCT/Robins") +conddb.addFolderSplitMC("SCT", "/SCT/DAQ/Config/ROD", "/SCT/DAQ/Config/ROD") +conddb.addFolderSplitMC("SCT", "/SCT/DAQ/Config/Geog", "/SCT/DAQ/Config/Geog") +conddb.addFolderSplitMC("SCT", "/SCT/DAQ/Config/RODMUR", "/SCT/DAQ/Config/RODMUR") +conddb.addFolderSplitMC("SCT", "/SCT/DAQ/Config/MUR", "/SCT/DAQ/Config/MUR") diff --git a/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledCondAlg.cxx b/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledCondAlg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..dff3acf750e129be43020cd17b1b8d169519c4f3 --- /dev/null +++ b/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledCondAlg.cxx @@ -0,0 +1,218 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#include "SCT_TdaqEnabledCondAlg.h" + +#include "Identifier/IdentifierHash.h" +#include "SCT_Cabling/SCT_OnlineId.h" +#include "EventInfo/EventID.h" + +#include "GaudiKernel/EventIDRange.h" + +SCT_TdaqEnabledCondAlg::SCT_TdaqEnabledCondAlg(const std::string& name, ISvcLocator* pSvcLocator) + : ::AthAlgorithm(name, pSvcLocator) + , m_readKey("/TDAQ/Resources/ATLAS/SCT/Robins") + , m_writeKey("SCT_TdaqEnabledCondData", "SCT_TdaqEnabledCondData") + , m_condSvc("CondSvc", name) + , m_cablingSvc("SCT_CablingSvc", name) +{ + declareProperty("ReadKey", m_readKey); + declareProperty("WriteKey", m_writeKey); + declareProperty("EventInfoKey", m_eventInfoKey=std::string("ByteStreamEventInfo")); +} + +SCT_TdaqEnabledCondAlg::~SCT_TdaqEnabledCondAlg() +{ +} + +StatusCode SCT_TdaqEnabledCondAlg::initialize() +{ + ATH_MSG_DEBUG("initialize " << name()); + + // CondSvc + ATH_CHECK( m_condSvc.retrieve() ); + // SCT cabling service + ATH_CHECK( m_cablingSvc.retrieve() ); + + // Read Cond Handle + ATH_CHECK( m_readKey.initialize() ); + + // Write Cond Handle + ATH_CHECK( m_writeKey.initialize() ); + // Register write handle + if(m_condSvc->regHandle(this, m_writeKey, m_writeKey.dbKey()).isFailure()) { + ATH_MSG_ERROR("unable to register WriteCondHandle " << m_writeKey.fullKey() << " with CondSvc"); + return StatusCode::FAILURE; + } + + // Read Handle + ATH_CHECK( m_eventInfoKey.initialize() ); + + return StatusCode::SUCCESS; +} + +StatusCode SCT_TdaqEnabledCondAlg::execute() +{ + ATH_MSG_DEBUG("execute " << name()); + + // Write Cond Handle + SG::WriteCondHandle<SCT_TdaqEnabledCondData> writeHandle{m_writeKey}; + + // Do we have a valid Write Cond Handle for current time? + if(writeHandle.isValid()) { + // in theory this should never be called in MT + writeHandle.updateStore(); + ATH_MSG_DEBUG("CondHandle " << writeHandle.fullKey() << " is already valid." + << ". In theory this should not be called, but may happen" + << " if multiple concurrent events are being processed out of order." + << " Forcing update of Store contents"); + return StatusCode::SUCCESS; + } + + // Construct the output Cond Object and fill it in + SCT_TdaqEnabledCondData* writeCdo = new SCT_TdaqEnabledCondData(); + // clear structures before filling + writeCdo->clear(); + + // Define validity of the output cond obbject and record it + EventIDRange rangeW; + + // check whether we expect valid data at this time + if(unfilledRun()) { + EventIDBase unfilledStart(0, 0, 0, 0); // run 0, event 0, timestamp 0, timestamp_ns 0 + EventIDBase unfilledStop(s_earliestRunForFolder, 0, s_earliestTimeStampForFolder, 0); // run 119253, event 0, timestamp 1245064619, timestamp_ns 0 + EventIDRange unfilledRange(unfilledStart, unfilledStop); + rangeW = unfilledRange; + writeCdo->setNoneBad(true); + writeCdo->setFilled(true); + } else { + // Read Cond Handle + SG::ReadCondHandle<CondAttrListCollection> readHandle{m_readKey}; + const CondAttrListCollection* readCdo{*readHandle}; + if(readCdo==nullptr) { + ATH_MSG_ERROR("Null pointer to the read conditions object"); + return StatusCode::FAILURE; + } + + ATH_MSG_INFO("Size of CondAttrListCollection readCdo->size()= " << readCdo->size()); + + CondAttrListCollection::const_iterator attrList(readCdo->begin()); + CondAttrListCollection::const_iterator end(readCdo->end()); + // CondAttrListCollection doesnt support C++11 type loops, no generic 'begin' + for(; attrList!=end; ++attrList) { + // A CondAttrListCollection is a map of ChanNum and AttributeList + CondAttrListCollection::ChanNum channelNumber = attrList->first; + CondAttrListCollection::AttributeList payload = attrList->second; + std::string enabled = payload["class"].data<std::string>(); + std::string chanName = readCdo->chanName(channelNumber); + unsigned int rodNumber = parseChannelName(chanName); + // range check on the rod channel number has been removed, since it refers both to existing channel names + // which can be rods in slots 1-128 but also historical names which have since been removed + if(SCT_OnlineId::rodIdInRange(rodNumber)) { + if((not enabled.empty()) and (not writeCdo->setGoodRod(rodNumber))) { + ATH_MSG_WARNING("Set insertion failed for rod "<<rodNumber); + } + } else { + ATH_MSG_WARNING("Names in "<<m_readKey.key()<<" should be of the form ROL-SCT-BA-00-210000 this channel, number "<<channelNumber<<", is: "<<chanName); + } + } + + if(writeCdo->getGoodRods().size()>s_NRODS) { + ATH_MSG_ERROR("The number of rods declared as good appears to be greater than the permissible number of rods ("<<s_NRODS<<")"); + writeCdo->setFilled(false); + return StatusCode::FAILURE; + } + + unsigned int nBad = s_NRODS-writeCdo->getGoodRods().size(); + std::string howMany = inWords(nBad); + ATH_MSG_DEBUG(howMany << " declared bad in the database."); + + // provide short-cut for no rods bad (hopefully the most common case) + writeCdo->setNoneBad(nBad==0); + if(writeCdo->isNoneBad()) { + writeCdo->setFilled(true); + } else { + // now find the modules which belong to those rods... + // const int modulesPerRod(48); + std::vector<IdentifierHash> tmpIdVec(0); + tmpIdVec.reserve(s_modulesPerRod); + for(const auto & thisRod : writeCdo->getGoodRods()) { + tmpIdVec.clear(); + m_cablingSvc->getHashesForRod(tmpIdVec, thisRod); + writeCdo->setGoodModules(tmpIdVec); + } + writeCdo->setFilled(true); + } + + if(!readHandle.range(rangeW)) { + ATH_MSG_ERROR("Failed to retrieve validity range for " << readHandle.key()); + return StatusCode::FAILURE; + } + } + + if(writeHandle.record(rangeW, writeCdo).isFailure()) { + ATH_MSG_ERROR("Could not record SCT_TdaqEnabledCondData " << writeHandle.key() + << " with EventRange " << rangeW + << " into Conditions Store"); + return StatusCode::FAILURE; + } + ATH_MSG_INFO("recorded new CDO " << writeHandle.key() << " with range " << rangeW << " into Conditions Store"); + + return StatusCode::SUCCESS; +} + +StatusCode SCT_TdaqEnabledCondAlg::finalize() +{ + ATH_MSG_DEBUG("finalize " << name()); + return StatusCode::SUCCESS; +} + +bool SCT_TdaqEnabledCondAlg::unfilledRun() const { + SG::ReadHandle<EventInfo> event(m_eventInfoKey); + if (event.isValid()) { + const unsigned int runNumber=event->event_ID()->run_number(); + const bool noDataExpected=(runNumber < s_earliestRunForFolder); + if (noDataExpected) ATH_MSG_INFO("This run occurred before the /TDAQ/EnabledResources/ATLAS/SCT/Robins folder was filled in COOL; assuming the SCT is all ok."); + return noDataExpected; + } + ATH_MSG_ERROR("The event information could not be retrieved in this service"); + return false; //this means the service will attempt to access the folder and fill it, even though the run number is unknown +} + +//parse a rod channel name to a rod number, names are of the format 'ROL-SCT-BA-00-210000' +//October 2014: names can now also be of format 'ROL-SCT-B-00-210100' +unsigned int SCT_TdaqEnabledCondAlg::parseChannelName(const std::string &chanNameString) const { + unsigned int result(0); + const unsigned int length=chanNameString.size(); + if (length < 19) return result; //very rough check on sanity of string, should use regex + //get the last six numbers, these are in hex + std::istringstream iss(chanNameString.substr(length-6, 6)); + iss.exceptions(std::ios_base::badbit|std::ios_base::failbit); + try{ + iss>>std::hex>>result; + } catch (std::ios_base::failure){ //bad conversion to int + std::cerr<<"Bad conversion of last 6 digits of "<<chanNameString<<" to a hex number"<<std::endl; + throw(std::ios_base::failure("stringToInt failure in SCT_TdaqEnabledSvc")); + } + return result; +} + +std::string SCT_TdaqEnabledCondAlg::inWords(const unsigned int aNumber) const { + switch (aNumber){ + case 0: + return std::string("No SCT rods were"); + break; + case 1: + return std::string("One SCT rod was"); + break; + default: + return std::to_string(aNumber) + " SCT rods were"; //C++11 + break; + } +} + +const unsigned int SCT_TdaqEnabledCondAlg::s_NRODS(128); +const unsigned int SCT_TdaqEnabledCondAlg::s_modulesPerRod(48); +const unsigned int SCT_TdaqEnabledCondAlg::s_earliestRunForFolder(119253); +const unsigned int SCT_TdaqEnabledCondAlg::s_earliestTimeStampForFolder(1245064619); // 20090615T111659 UTC for run 119253 diff --git a/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledCondAlg.h b/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledCondAlg.h new file mode 100644 index 0000000000000000000000000000000000000000..87c66209ed69003af01b99f99becee3f55cbff09 --- /dev/null +++ b/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledCondAlg.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration +*/ + +#ifndef SCT_TDAQENABLEDCONDALG +#define SCT_TDAQENABLEDCONDALG + +#include "AthenaBaseComps/AthAlgorithm.h" +#include "StoreGate/ReadCondHandleKey.h" +#include "AthenaPoolUtilities/CondAttrListCollection.h" +#include "StoreGate/WriteCondHandleKey.h" +#include "SCT_ConditionsData/SCT_TdaqEnabledCondData.h" +#include "StoreGate/ReadHandleKey.h" +#include "EventInfo/EventInfo.h" +#include "GaudiKernel/ICondSvc.h" +#include "SCT_Cabling/ISCT_CablingSvc.h" + +class SCT_TdaqEnabledCondAlg : public AthAlgorithm +{ + public: + SCT_TdaqEnabledCondAlg(const std::string& name, ISvcLocator* pSvcLocator); + ~SCT_TdaqEnabledCondAlg(); + StatusCode initialize(); + StatusCode execute(); + StatusCode finalize(); + + private: + bool unfilledRun() const; + + SG::ReadCondHandleKey<CondAttrListCollection> m_readKey; + SG::WriteCondHandleKey<SCT_TdaqEnabledCondData> m_writeKey; + SG::ReadHandleKey<EventInfo> m_eventInfoKey; + ServiceHandle<ICondSvc> m_condSvc; + ServiceHandle<ISCT_CablingSvc> m_cablingSvc; //!< Handle on SCT cabling service + + unsigned int parseChannelName(const std::string &chanNameString) const; + std::string inWords(const unsigned int aNumber) const; + + static const unsigned int s_NRODS; + static const unsigned int s_modulesPerRod; + static const unsigned int s_earliestRunForFolder; + static const unsigned int s_earliestTimeStampForFolder; +}; + +#endif // SCT_TDAQENABLEDCONDALG diff --git a/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledSvc.cxx b/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledSvc.cxx index f6a96ec41291029d6a48d1e3eabded08b3718ab0..2043ec435b781fa14079a740dc94a92503bf292b 100644 --- a/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledSvc.cxx +++ b/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledSvc.cxx @@ -9,6 +9,7 @@ **/ #include "SCT_TdaqEnabledSvc.h" + //STL includes #include <vector> #include <list> @@ -18,15 +19,14 @@ #include "boost/array.hpp" #include <iostream> //Use Event info to determine whether folder is expetd to have valid data -#include "EventInfo/EventInfo.h" #include "EventInfo/EventID.h" +#include "EventInfo/EventInfo.h" + #include "SCT_Cabling/SCT_OnlineId.h" -// Read Handle +// Read (Cond) Handle #include "StoreGate/ReadHandle.h" - -// Event Info -#include "EventInfo/EventID.h" +#include "StoreGate/ReadCondHandle.h" //Gaudi includes #include "GaudiKernel/StatusCode.h" @@ -35,63 +35,13 @@ #include "InDetIdentifier/SCT_ID.h" -//static const member initializer -const unsigned int SCT_TdaqEnabledSvc::NRODS=128; - -static const std::string databaseSignature("database"); -//The folder name changed between run 1 and run 2 -static const std::string run1FolderName("/TDAQ/EnabledResources/ATLAS/SCT/Robins"); //a multi-channel, single version folder in the DB -static const std::string run2FolderName("/TDAQ/Resources/ATLAS/SCT/Robins"); -static const unsigned int earliestRunForFolder(119253); -namespace{ //anonymous namespace to introduce file scope -/** - //utility; is integer in given range - bool - inRange(const int var, const int lo, const int hi){ - return ((var>=lo) and (var<=hi)); - } - **/ - //parse a rod channel name to a rod number, names are of the format 'ROL-SCT-BA-00-210000' - //October 2014: names can now also be of format 'ROL-SCT-B-00-210100' - unsigned int - parseChannelName(const std::string & chanNameString){ - unsigned int result(0); - const unsigned int length=chanNameString.size(); - if (length < 19) return result; //very rough check on sanity of string, should use regex - //get the last six numbers, these are in hex - std::istringstream iss(chanNameString.substr(length-6, 6)); - iss.exceptions(std::ios_base::badbit|std::ios_base::failbit); - try{ - iss>>std::hex>>result; - } catch (std::ios_base::failure){ //bad conversion to int - std::cerr<<"Bad conversion of last 6 digits of "<<chanNameString<<" to a hex number"<<std::endl; - throw(std::ios_base::failure("stringToInt failure in SCT_TdaqEnabledSvc")); - } - return result; - } - - //express a number of rods in words - std::string - inWords(const unsigned int aNumber){ - switch (aNumber){ - case 0: - return std::string("No SCT rods were"); - break; - case 1: - return std::string("One SCT rod was"); - break; - default: - return std::to_string(aNumber) + " SCT rods were"; //C++11 - break; - } - } -} // Constructor SCT_TdaqEnabledSvc::SCT_TdaqEnabledSvc( const std::string& name, ISvcLocator* pSvcLocator ) : AthService(name, pSvcLocator), -m_filled(false), m_coolFolderName(""),m_pHelper{nullptr}, +m_data{nullptr}, +m_pHelper{nullptr}, m_useDatabase(true), m_detStore("DetectorStore",name), -m_storeGateSvc("StoreGateSvc",name),m_cablingSvc("SCT_CablingSvc", name), -m_noneBad(true) { +m_condKey(std::string("SCT_TdaqEnabledCondData")) +{ //declareProperty("BadRodIdentifiers",m_badElements); declareProperty("EventInfoKey", m_eventInfoKey=std::string("ByteStreamEventInfo")); } @@ -99,28 +49,22 @@ m_noneBad(true) { //Initialize StatusCode SCT_TdaqEnabledSvc::initialize(){ - // const std::string databaseUseString(m_useDatabase?"":"not "); ATH_MSG_INFO(" Database will "<<databaseUseString<<"be used."); - // - if (m_useDatabase) { - m_coolFolderName=determineFolder(run1FolderName,run2FolderName); - ATH_CHECK(m_detStore->regFcn(&SCT_TdaqEnabledSvc::fillData,this,m_dbList,m_coolFolderName)); - } + ATH_CHECK(m_detStore->retrieve(m_pHelper,"SCT_ID")); - // Retrieve cabling service - ATH_CHECK(m_cablingSvc.retrieve()); - // Read Handle Key + // Read (Cond) Handle Key ATH_CHECK(m_eventInfoKey.initialize()); + if(m_useDatabase) { + ATH_CHECK(m_condKey.initialize()); + } return StatusCode::SUCCESS; } //Finalize StatusCode SCT_TdaqEnabledSvc::finalize(){ - ATH_MSG_INFO(inWords(m_goodRods.size())<<" enabled in this run."); StatusCode sc(StatusCode::SUCCESS); - //Code return sc; } @@ -158,112 +102,30 @@ SCT_TdaqEnabledSvc::isGood(const Identifier & elementId, InDetConditions::Hierar bool SCT_TdaqEnabledSvc::isGood(const IdentifierHash & hashId){ - if (m_noneBad) return true; - bool result = (m_goodIds.find(hashId) != m_goodIds.end()); - return result; -} - -StatusCode -SCT_TdaqEnabledSvc::fillData(){ - StatusCode sc(StatusCode::FAILURE); - return sc; - //remove possibility to fill from job options -} - -StatusCode -SCT_TdaqEnabledSvc::fillData(int& /*i*/ , std::list<std::string>& /*folderList*/){ - //check whether we expect valid data at this time - if (unfilledRun()){ - m_noneBad=true; - m_filled=true; - return StatusCode::SUCCESS; - } - //clear structures before filling - m_goodRods.clear(); - m_goodIds.clear(); - const int modulesPerRod(48); - if (m_detStore->retrieve(m_dbList,m_coolFolderName).isFailure()) return StatusCode::FAILURE; - CondAttrListCollection::const_iterator attrList( m_dbList->begin()); - CondAttrListCollection::const_iterator end( m_dbList->end()); - //CondAttrListCollection doesnt support C++11 type loops, no generic 'begin' - for (;attrList!=end;++attrList) { - //A CondAttrListCollection is a map of ChanNum and AttributeList - CondAttrListCollection::ChanNum channelNumber=attrList->first; - CondAttrListCollection::AttributeList payload=attrList->second; - std::string enabled=payload["class"].data<std::string>(); - std::string chanName=m_dbList->chanName(channelNumber); - unsigned int rodNumber=parseChannelName(chanName); - //range check on the rod channel number has been removed, since it refers both to existing channel names - //which can be rods in slots 1-128 but also historical names which have since been removed - if (SCT_OnlineId::rodIdInRange(rodNumber)){ - if (!enabled.empty() and !m_goodRods.insert(rodNumber).second) msg(MSG::WARNING)<<"Set insertion failed for rod "<<rodNumber<<endmsg; - } else { - msg(MSG::WARNING)<<"Names in "<<m_coolFolderName<<" should be of the form ROL-SCT-BA-00-210000 this channel, number "<<channelNumber<<", is: "<<chanName<<endmsg; - } - } - if (m_goodRods.size()>NRODS){ - msg(MSG::ERROR)<<"The number of rods declared as good appears to be greater than the permissible number of rods ("<<NRODS<<")"<<endmsg; - m_filled=false; - return StatusCode::FAILURE; - } - unsigned int nBad = NRODS-m_goodRods.size(); - std::string howMany=inWords(nBad); - ATH_MSG_DEBUG(howMany << " declared bad in the database."); - //provide short-cut for no rods bad (hopefully the most common case) - m_noneBad=(nBad==0); - if (m_noneBad){ - m_filled=true; - return StatusCode::SUCCESS; - } - //now find the modules which belong to those rods... - std::vector<IdentifierHash> tmpIdVec(0); - tmpIdVec.reserve(modulesPerRod); - for (const auto & thisRod : m_goodRods){ - tmpIdVec.clear(); - m_cablingSvc->getHashesForRod(tmpIdVec, thisRod); - copy(tmpIdVec.begin(), tmpIdVec.end(), inserter(m_goodIds, m_goodIds.end())); - } - m_filled=true; - return StatusCode::SUCCESS; + if(not getCondData()) return false; + return m_data->isGood(hashId); } bool SCT_TdaqEnabledSvc::canFillDuringInitialize(){ return (not m_useDatabase);// can only fill during intialize if we don't use the database } + bool SCT_TdaqEnabledSvc::filled() const{ - //code - return m_filled; + if(not getCondData()) return false; + return m_data->isFilled(); } bool -SCT_TdaqEnabledSvc::unfilledRun() const{ - SG::ReadHandle<EventInfo> event(m_eventInfoKey); - if (event.isValid()) { - const unsigned int runNumber=event->event_ID()->run_number(); - const bool noDataExpected=(runNumber < earliestRunForFolder); - if (noDataExpected) ATH_MSG_INFO("This run occurred before the /TDAQ/EnabledResources/ATLAS/SCT/Robins folder was filled in COOL; assuming the SCT is all ok."); - return noDataExpected; +SCT_TdaqEnabledSvc::getCondData() const { + if(!m_data) { + SG::ReadCondHandle<SCT_TdaqEnabledCondData> data(m_condKey); + if((not data.isValid()) or !(*data)) { + ATH_MSG_ERROR("Failed to get " << m_condKey.key()); + return false; + } + m_data = *data; } - ATH_MSG_ERROR("The event information could not be retrieved in this service"); - return false; //this means the service will attempt to access the folder and fill it, even though the run number is unknown -} - -std::string -SCT_TdaqEnabledSvc::determineFolder(const std::string& option1, const std::string& option2) const{ -std::string result(""); - const bool option1Exists = m_detStore->contains<CondAttrListCollection>(option1); - const bool option2Exists = m_detStore->contains<CondAttrListCollection>(option2); - //its only sensible if either of these exists (but not both) - const bool nonsense = (option1Exists == option2Exists); - if (nonsense) { - ATH_MSG_ERROR("The folder names "<<option1<<" or "<<option2<<" could not be found"); - } else { - result = option1Exists ? option1 : option2; - ATH_MSG_INFO("Sct_TdaqEnabledSvc will use the folder "<<result); - } - - return result; + return true; } - diff --git a/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledSvc.h b/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledSvc.h index 7071556c098447a476d092404e27c2411c39cec8..ac6caded4bbfc7bff9ac198179fbe42909a1bb33 100644 --- a/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledSvc.h +++ b/InnerDetector/InDetConditions/SCT_ConditionsServices/src/SCT_TdaqEnabledSvc.h @@ -17,16 +17,16 @@ #include "AthenaBaseComps/AthService.h" #include "GaudiKernel/ServiceHandle.h" -#include "StoreGate/DataHandle.h" #include "StoreGate/StoreGateSvc.h" -#include "AthenaPoolUtilities/CondAttrListCollection.h" #include "InDetConditionsSummaryService/InDetHierarchy.h" #include "SCT_ConditionsServices/ISCT_ConditionsSvc.h" -#include "SCT_Cabling/ISCT_CablingSvc.h" + +#include "SCT_ConditionsData/SCT_TdaqEnabledCondData.h" // Read Handle Key #include "StoreGate/ReadHandleKey.h" +#include "StoreGate/ReadCondHandleKey.h" // Event Info #include "EventInfo/EventInfo.h" @@ -65,10 +65,10 @@ public: virtual bool isGood(const IdentifierHash & hashId); ///Manually get the data in the structure before proceeding - virtual StatusCode fillData(); - + virtual StatusCode fillData() { return StatusCode::FAILURE; }; + ///Overload 'fillData' to provide callback to data folder - virtual StatusCode fillData(int& /*i*/ , std::list<std::string>& /*l*/); + virtual StatusCode fillData(int& /*i*/ , std::list<std::string>& /*l*/) { return StatusCode::FAILURE; }; ///Are the data available? virtual bool filled() const; @@ -77,27 +77,17 @@ public: virtual bool canFillDuringInitialize(); private: - static const unsigned int NRODS; //!< This was 90 in run 1; changed to 128 on Oct 22, 2014 - //StringArrayProperty m_badElements; //list of bad (unconfigured) robs - std::set<unsigned int> m_goodRods; - std::set<IdentifierHash> m_goodIds; - bool m_filled; - std::string m_coolFolderName; - // + // static const unsigned int NRODS; //!< This was 90 in run 1; changed to 128 on Oct 22, 2014 + const mutable SCT_TdaqEnabledCondData *m_data; const SCT_ID * m_pHelper; bool m_useDatabase; ServiceHandle<StoreGateSvc> m_detStore; //!< Handle on the detector store - ServiceHandle<StoreGateSvc> m_storeGateSvc; //!< Handle on storegate - ServiceHandle<ISCT_CablingSvc> m_cablingSvc; //!< Handle on SCT cabling service - const DataHandle<CondAttrListCollection> m_dbList; //!< implies multi channel folder used - bool m_noneBad; SG::ReadHandleKey<EventInfo> m_eventInfoKey; + SG::ReadCondHandleKey<SCT_TdaqEnabledCondData> m_condKey; - bool unfilledRun() const; //!<Before run 119253, the folder was never filled so it looks like a disabled detector: this is to flag that condition - ///The folder name changed from run 1 to run 2; this function looks to see which folder has been pre-loaded - std::string determineFolder(const std::string& option1, const std::string& option2) const; + bool getCondData() const; }; inline const InterfaceID & SCT_TdaqEnabledSvc::interfaceID(){ @@ -105,4 +95,4 @@ inline const InterfaceID & SCT_TdaqEnabledSvc::interfaceID(){ return IID_SCT_TdaqEnabledSvc; } -#endif \ No newline at end of file +#endif diff --git a/InnerDetector/InDetConditions/SCT_ConditionsServices/src/components/SCT_ConditionsServices_entries.cxx b/InnerDetector/InDetConditions/SCT_ConditionsServices/src/components/SCT_ConditionsServices_entries.cxx index 5f0cb7c51d6a47f7f494a862a66cfc5697d2c11e..785c332e9a73f160154789b55eca892e870b7efe 100644 --- a/InnerDetector/InDetConditions/SCT_ConditionsServices/src/components/SCT_ConditionsServices_entries.cxx +++ b/InnerDetector/InDetConditions/SCT_ConditionsServices/src/components/SCT_ConditionsServices_entries.cxx @@ -31,6 +31,7 @@ #include "../SCT_LinkMaskingTestAlg.h" #include "../SCT_TdaqEnabledSvc.h" +#include "../SCT_TdaqEnabledCondAlg.h" #include "../SCT_TdaqEnabledTestAlg.h" #include "../SCT_ConditionsParameterSvc.h" @@ -72,6 +73,7 @@ DECLARE_ALGORITHM_FACTORY(SCT_ConfigurationConditionsTestAlg) DECLARE_ALGORITHM_FACTORY(SCT_MajorityConditionsTestAlg) DECLARE_ALGORITHM_FACTORY(SCT_ConditionsParameterTestAlg) DECLARE_ALGORITHM_FACTORY(SCT_SensorsTestAlg) +DECLARE_ALGORITHM_FACTORY(SCT_TdaqEnabledCondAlg) DECLARE_ALGORITHM_FACTORY(SCT_TdaqEnabledTestAlg) DECLARE_SERVICE_FACTORY(SCT_ConditionsSummarySvc) @@ -137,6 +139,7 @@ DECLARE_ALGORITHM( SCT_RODVetoTestAlg ) DECLARE_ALGORITHM( SCT_MajorityConditionsTestAlg ) DECLARE_ALGORITHM( SCT_ConditionsParameterTestAlg ) DECLARE_ALGORITHM( SCT_SensorsTestAlg ) + DECLARE_ALGORITHM(SCT_TdaqEnabledCondAlg) DECLARE_ALGORITHM(SCT_TdaqEnabledTestAlg) diff --git a/InnerDetector/InDetExample/InDetRecExample/share/InDetRecConditionsAccess.py b/InnerDetector/InDetExample/InDetRecExample/share/InDetRecConditionsAccess.py index 5804bb0ce0630b8d28ec62cb7972a052f1b32cb6..671284509d6be0a130077ed4b4bffff90969e0d4 100644 --- a/InnerDetector/InDetExample/InDetRecExample/share/InDetRecConditionsAccess.py +++ b/InnerDetector/InDetExample/InDetRecExample/share/InDetRecConditionsAccess.py @@ -292,8 +292,12 @@ if DetFlags.haveRIO.SCT_on(): if (globalflags.DataSource() == 'data'): # Load TdaqEnabled service if not conddb.folderRequested(tdaqFolder): - conddb.addFolder("TDAQ",tdaqFolder) - #conddb.addFolder("","<db>COOLONL_TDAQ/COMP200</db> /TDAQ/EnabledResources/ATLAS/SCT/Robins") + conddb.addFolder("TDAQ",tdaqFolder,className="CondAttrListCollection") + from AthenaCommon.AlgSequence import AthSequencer + condSequence = AthSequencer("AthCondSeq") + from SCT_ConditionsServices.SCT_ConditionsServicesConf import SCT_TdaqEnabledCondAlg + condSequence += SCT_TdaqEnabledCondAlg(name = "SCT_TdaqEnabledCondAlg", + ReadKey = tdaqFolder) from SCT_ConditionsServices.SCT_ConditionsServicesConf import SCT_TdaqEnabledSvc InDetSCT_TdaqEnabledSvc = SCT_TdaqEnabledSvc(name = "InDetSCT_TdaqEnabledSvc",