diff --git a/Database/AthenaPOOL/AthenaPoolUtilities/AthenaPoolUtilities/CondAttrListCollection.h b/Database/AthenaPOOL/AthenaPoolUtilities/AthenaPoolUtilities/CondAttrListCollection.h index aee61872909d128686ece41b642695d85229971b..7c31a9aa3473b50c7155ec39063592cfdbf6bb62 100644 --- a/Database/AthenaPOOL/AthenaPoolUtilities/AthenaPoolUtilities/CondAttrListCollection.h +++ b/Database/AthenaPOOL/AthenaPoolUtilities/AthenaPoolUtilities/CondAttrListCollection.h @@ -114,6 +114,8 @@ public: /// channel number for index: (index = 0 to size-1) ChanNum chanNum(unsigned int index) const; + + bool fixChanNum(ChanNum oldChan, ChanNum newChan); /// attribute list for a given channel number const AttributeList& attributeList(ChanNum chanNum) const; @@ -674,6 +676,26 @@ CondAttrListCollection::isSameButMinRange ( const CondAttrListCollection& rhs, } +inline bool + CondAttrListCollection::fixChanNum(const ChanNum oldChan, + const ChanNum newChan) { + auto attrRet = m_attrMap.emplace(newChan, m_attrMap[oldChan]); + // if a new element was inserted, erase the old one + if (attrRet.second) m_attrMap.erase(oldChan); + + auto iovRet = m_iovMap.emplace(newChan, m_iovMap[oldChan]); + // if a new element was inserted, erase the old one + if (iovRet.second) m_iovMap.erase(oldChan); + + auto nameRet = m_nameMap.emplace(newChan, m_nameMap[oldChan]); + // if a new element was inserted, erase the old one + if (nameRet.second) m_nameMap.erase(oldChan); + + return attrRet.first->first == newChan + && iovRet.first->first == newChan + && nameRet.first->first == newChan; + } + #endif // DBDATAOBJECTS_CONDATTRLISTCOLLECTION_H diff --git a/Generators/EvgenProdTools/CMakeLists.txt b/Generators/EvgenProdTools/CMakeLists.txt index a15920cd613ca9791369f4c68a76fc5824308252..6ff81b8bc62bed06cae425a81159bbf49bce08ea 100644 --- a/Generators/EvgenProdTools/CMakeLists.txt +++ b/Generators/EvgenProdTools/CMakeLists.txt @@ -12,11 +12,11 @@ atlas_add_library( EvgenProdToolsLib PUBLIC_HEADERS EvgenProdTools INCLUDE_DIRS ${ROOT_INCLUDE_DIRS} LINK_LIBRARIES ${ROOT_LIBRARIES} AtlasHepMCLib AtlasHepMCsearchLib AthenaBaseComps TruthHelper GeneratorModulesLib GenInterfacesLib - PRIVATE_LINK_LIBRARIES AthenaKernel EventInfo GaudiKernel TruthUtils ) + PRIVATE_LINK_LIBRARIES AthenaKernel EventInfo GaudiKernel TruthUtils IOVDbDataModel AthenaPoolUtilities ) atlas_add_component( EvgenProdTools src/components/*.cxx - LINK_LIBRARIES EvgenProdToolsLib ) + LINK_LIBRARIES EvgenProdToolsLib IOVDbDataModel AthenaPoolUtilities ) # Install files from the package: atlas_install_python_modules( python/*.py POST_BUILD_CMD ${ATLAS_FLAKE8} ) diff --git a/Generators/EvgenProdTools/EvgenProdTools/CountHepMC.h b/Generators/EvgenProdTools/EvgenProdTools/CountHepMC.h index 1e4e196cfd59c7be53ca76aec3a8569e89880c0a..16bab10dfbdca75ddbd609a723d00c2963ba20d9 100644 --- a/Generators/EvgenProdTools/EvgenProdTools/CountHepMC.h +++ b/Generators/EvgenProdTools/EvgenProdTools/CountHepMC.h @@ -28,6 +28,8 @@ public: private: + ServiceHandle< StoreGateSvc > m_metaDataStore{ + "StoreGateSvc/MetaDataStore", name()}; int m_nPass; int m_nCount; diff --git a/Generators/EvgenProdTools/src/CountHepMC.cxx b/Generators/EvgenProdTools/src/CountHepMC.cxx index 4f9d5a38afba435e9b9ff3281ead41293aee38b4..c0f8d0ff26603017009e432d4395f9d3fdf05c0f 100644 --- a/Generators/EvgenProdTools/src/CountHepMC.cxx +++ b/Generators/EvgenProdTools/src/CountHepMC.cxx @@ -15,6 +15,9 @@ #include "EventInfo/EventInfo.h" #include "EventInfo/EventID.h" #include "EventInfo/EventType.h" +#include "IOVDbDataModel/IOVMetaDataContainer.h" +#include "IOVDbDataModel/IOVPayloadContainer.h" +#include "AthenaPoolUtilities/CondAttrListCollection.h" #include <cmath> #include <cassert> @@ -100,10 +103,12 @@ else{ // Change the EventID in the eventinfo header const EventInfo* pInputEvt(0); ATH_MSG_INFO("Set new run number called !!" << m_newRunNumber); + unsigned int oldRunNumber = 0; if (evtStore()->retrieve(pInputEvt).isSuccess()) { assert(pInputEvt); EventID* eventID = const_cast<EventID*>(pInputEvt->event_ID()); ATH_MSG_INFO("git eventid !! " ); + oldRunNumber = eventID->run_number(); eventID->set_run_number(m_newRunNumber); ATH_MSG_INFO("Set new run number" << m_newRunNumber); ATH_MSG_DEBUG("Set new run number in event_ID"); @@ -118,6 +123,65 @@ else{ ATH_MSG_ERROR("No EventInfo object found"); return StatusCode::SUCCESS; } + + { + // change the channel number where /Generation/Parameters are found + auto newChannelNumber = + static_cast< const CondAttrListCollection::ChanNum >(m_newRunNumber); + auto oldChannelNumber = + static_cast< const CondAttrListCollection::ChanNum >(oldRunNumber); + + const char* key = "/Generation/Parameters"; + const IOVMetaDataContainer * iovContainer = nullptr; + if (m_metaDataStore->retrieve(iovContainer, key).isSuccess() + && iovContainer) { + // get a hold of the payload + const IOVPayloadContainer * payloadContainer = + iovContainer->payloadContainer(); + + // Grab the attribute list + for (CondAttrListCollection* collection : *payloadContainer) { + for(unsigned int index = 0; index < collection->size(); ++index) { + if (collection->chanNum(index) != oldChannelNumber) { + ATH_MSG_INFO("Not updating \"" << key << "\" on channel number " + << collection->chanNum(index)); + continue; + } + + if (collection->fixChanNum(oldChannelNumber, newChannelNumber)) + ATH_MSG_INFO("Updated \"" << key << "\" channel number from " + << oldChannelNumber << " to " << newChannelNumber); + else + ATH_MSG_ERROR("Channel number update from " << oldChannelNumber + << " to " << newChannelNumber << " on \"" << key + << "\" FAILED"); + } + } + + { + // Update the MC channel number in the "/TagInfo" + const char* key = "/TagInfo"; + const IOVMetaDataContainer * iovContainer = nullptr; + if (m_metaDataStore->retrieve(iovContainer, key).isSuccess() + && iovContainer) { + // get a hold of the payload + const IOVPayloadContainer * payloadContainer = + iovContainer->payloadContainer(); + + // Grab the attribute list + for (CondAttrListCollection* collection : *payloadContainer) { + for (auto pair : *collection) { + // pair is a pair of Channel number and AttributeList + if (pair.second.exists("mc_channel_number")) + pair.second["mc_channel_number"].setValue(m_newRunNumber); + } + } + } + } + } else { + ATH_MSG_INFO("Could not retrieve \"" << key << "\" from MetaDataStore"); + } + } }