diff --git a/Event/EventBookkeeperTools/src/CutFlowSvc.cxx b/Event/EventBookkeeperTools/src/CutFlowSvc.cxx index 88cd945ebdb1032aa00657e63f36a212544ec752..74b9467cee4eaedc1840b269ff8459dc5f7c420c 100644 --- a/Event/EventBookkeeperTools/src/CutFlowSvc.cxx +++ b/Event/EventBookkeeperTools/src/CutFlowSvc.cxx @@ -83,13 +83,9 @@ CutFlowSvc::initialize() incSvc->addListener(this, IncidentType::EndInputFile, 50); // pri has to be > 10 to be before MetaDataSvc. incSvc->addListener(this, "MetaDataStop", 50); - xAOD::CutBookkeeperContainer* fileBook(NULL); - fileBook = new xAOD::CutBookkeeperContainer(); + // Create bookkeeper container for bookkeepers in _this_ processing + auto fileBook = new xAOD::CutBookkeeperContainer(); ATH_CHECK( recordCollection( fileBook, m_fileCollName) ); - if (m_outMetaDataStore->retrieve(m_completeBook,m_fileCollName).isFailure()) { - ATH_MSG_ERROR("Could not retrieve handle to cutflowsvc bookkeeper"); - //return StatusCode::RECOVERABLE; - } // Determine the skimming cycle number that we should use now from the input file ATH_MSG_VERBOSE("Have currently the cycle number = " << m_skimmingCycle ); @@ -137,6 +133,7 @@ CutIdentifier CutFlowSvc::registerFilter( const std::string& name, { ATH_MSG_DEBUG("calling registerFilter(" << name << ", " << description << ")" ); + // *FIXME* This should probably be a unique_ptr, but requires changes in xAODCutFlow as well xAOD::CutBookkeeper* tmpEBK = new xAOD::CutBookkeeper(); tmpEBK->setName(name); tmpEBK->setDescription(description); @@ -144,12 +141,18 @@ CutIdentifier CutFlowSvc::registerFilter( const std::string& name, tmpEBK->setCycle(m_skimmingCycle); CutIdentifier cutID = tmpEBK->uniqueIdentifier(); + DataHandle<xAOD::CutBookkeeperContainer> fileBook; + if (m_outMetaDataStore->retrieve(fileBook,m_fileCollName).isFailure()) { + ATH_MSG_ERROR("Could not retrieve handle to cutflowsvc bookkeeper"); + return 0; + } + // Let's see if an CutBookkeeper of this name already exists ATH_MSG_VERBOSE("in registerFilter(" << name << ", " << description << "): " << "Going to search if this CutBookkeeper already exists" ); bool existsAlready=false; - for ( std::size_t i=0; i<m_completeBook->size(); ++i ) { - xAOD::CutBookkeeper* ebk = m_completeBook->at(i); + for ( std::size_t i=0; i<fileBook->size(); ++i ) { + xAOD::CutBookkeeper* ebk = fileBook->at(i); if( tmpEBK->isEqualTo( ebk) ) { ATH_MSG_DEBUG("The CutBookkeeper with name " << name << " and cutID " << cutID << " already exists... not adding!" ); @@ -172,7 +175,7 @@ CutIdentifier CutFlowSvc::registerFilter( const std::string& name, // If it is a new CutBookkeeper, add it to the container ATH_MSG_DEBUG( "You are DECLARING a new filter of name " << name << " and cutID " << cutID ); - m_completeBook->push_back(tmpEBK); + fileBook->push_back(tmpEBK); ATH_MSG_VERBOSE("done calling registerFilter(" << name << ", " << description << ")" ); return cutID; @@ -256,17 +259,23 @@ CutIdentifier CutFlowSvc::declareUsedOtherFilter( const std::string& name, } // Create a temporary CutBookkeeper object + // *FIXME* This should probably be a unique_ptr, but requires changes in xAODCutFlow as well xAOD::CutBookkeeper* tmpEBK = new xAOD::CutBookkeeper(); - // tmpEBK->makePrivateStore(); tmpEBK->setName(name); tmpEBK->setInputStream(m_inputStream); tmpEBK->setCycle(m_skimmingCycle); CutIdentifier cutID = tmpEBK->uniqueIdentifier(); + DataHandle<xAOD::CutBookkeeperContainer> fileBook; + if (m_outMetaDataStore->retrieve(fileBook,m_fileCollName).isFailure()) { + ATH_MSG_ERROR("Could not retrieve handle to cutflowsvc bookkeeper"); + return 0; + } + // See if the CutBookkeeper already exists or not bool existsAlready = false; - for ( std::size_t i=0; i<m_completeBook->size(); ++i ) { - xAOD::CutBookkeeper* ebk = m_completeBook->at(i); + for ( std::size_t i=0; i<fileBook->size(); ++i ) { + xAOD::CutBookkeeper* ebk = fileBook->at(i); if( tmpEBK->isEqualTo( ebk ) ) { originEBK->addUsedOther( ebk ); cutID = ebk->uniqueIdentifier(); @@ -284,7 +293,7 @@ CutIdentifier CutFlowSvc::declareUsedOtherFilter( const std::string& name, // Otherwise, add the new one to the collection tmpEBK->setDescription( "Registered by origin filter" ); originEBK->addUsedOther( tmpEBK ); - m_completeBook->push_back( tmpEBK ); + fileBook->push_back( tmpEBK ); return cutID; } @@ -312,9 +321,9 @@ CutFlowSvc::addEvent( CutIdentifier cutID ) double evtWeight=1.0; - const xAOD::EventInfo* evtInfo = 0; + const xAOD::EventInfo* evtInfo = nullptr; StatusCode sc = m_eventStore->retrieve(evtInfo); - if ( sc.isFailure() || NULL == evtInfo ) { + if ( sc.isFailure() || nullptr == evtInfo ) { ATH_MSG_WARNING("Could not retrieve EventInfo from StoreGate "); evtWeight=-1000.; } else { @@ -336,17 +345,27 @@ CutFlowSvc::addEvent( CutIdentifier cutID, double weight) { ATH_MSG_INFO("calling addEvent(" << cutID << ", " << weight << ")" ); + // Create bookkeeper container for bookkeepers in _this_ processing + DataHandle<xAOD::CutBookkeeperContainer> fileBook; + if (m_outMetaDataStore->retrieve(fileBook,m_fileCollName).isFailure()) { + ATH_MSG_WARNING("Could not retrieve handle to cutflowsvc bookkeeper " << m_fileCollName << " creating new one"); + auto fileBook = new xAOD::CutBookkeeperContainer(); + if( recordCollection( fileBook, m_fileCollName).isFailure() ) { + ATH_MSG_ERROR("Could not create empty " << m_fileCollName << " CutBookkeeperContainer"); + } + } + xAOD::CutBookkeeper* eb = this->getCutBookkeeper(cutID); if ( !eb ) { ATH_MSG_INFO("Could not find eb"); // Iterate over the complete bookkeepers and update the cutID-to-bookkeeper map ATH_MSG_DEBUG( "addEvent: Going to re-populate the map. Have " - << m_completeBook->size() << " CutBookkeepers" + << fileBook->size() << " CutBookkeepers" << " and skimming cycle " << m_skimmingCycle << " and input Stream name " << m_inputStream ); - xAOD::CutBookkeeperContainer::iterator iter = m_completeBook->begin(); - xAOD::CutBookkeeperContainer::iterator iterEnd = m_completeBook->end(); + xAOD::CutBookkeeperContainer::iterator iter = fileBook->begin(); + xAOD::CutBookkeeperContainer::iterator iterEnd = fileBook->end(); for ( ; iter != iterEnd; ++iter ) { xAOD::CutBookkeeper* ebk = *iter; CutIdentifier cutID2 = ebk->uniqueIdentifier(); @@ -419,11 +438,16 @@ void CutFlowSvc::handle( const Incident& inc ) } } + DataHandle<xAOD::CutBookkeeperContainer> fileBook; + if( !(m_outMetaDataStore->retrieve(fileBook, m_fileCollName) ).isSuccess() ) { + ATH_MSG_WARNING( "Could not get " << m_fileCollName + << " CutBookkeepers from output MetaDataStore" ); + } // Clear the file bookkeeper - if (m_completeBook.isValid()) { + if (fileBook.isValid()) { // Reset existing container - for (xAOD::CutBookkeeperContainer::iterator it = m_completeBook->begin(); - it != m_completeBook->end(); ++it) { + for (xAOD::CutBookkeeperContainer::iterator it = fileBook->begin(); + it != fileBook->end(); ++it) { (*it)->setNAcceptedEvents(0); (*it)->setSumOfEventWeights(0); (*it)->setSumOfEventWeightsSquared(0); @@ -432,27 +456,18 @@ void CutFlowSvc::handle( const Incident& inc ) } // Clean up the bookkeeper before output - //if ( inc.type() == "MetaDataStop" || inc.type() == "EndInputFile") { if ( inc.type() == "MetaDataStop" ) { - if (m_completeBook.isValid()) { - // Reset existing container - for (xAOD::CutBookkeeperContainer::iterator it = m_completeBook->begin(); - it != m_completeBook->end(); ++it) { - } - } - const xAOD::CutBookkeeperContainer* fileBook(NULL); + DataHandle<xAOD::CutBookkeeperContainer> fileBook; if( !(m_outMetaDataStore->retrieve(fileBook, m_fileCollName) ).isSuccess() ) { ATH_MSG_WARNING( "Could not get " << m_fileCollName << " CutBookkeepers from output MetaDataStore" ); } - else { - const SG::IConstAuxStore* fileBookAux = fileBook->getConstStore(); - if (m_outMetaDataStore->removeDataAndProxy(fileBook).isFailure()) { - ATH_MSG_ERROR("Unable to remove " << m_fileCollName); - } - if (m_outMetaDataStore->removeDataAndProxy(fileBookAux).isFailure()) { - ATH_MSG_ERROR("Unable to remove " << m_fileCollName); - } + // reset counters + for (xAOD::CutBookkeeperContainer::iterator it = fileBook->begin(); + it != fileBook->end(); ++it) { + (*it)->setNAcceptedEvents(0); + (*it)->setSumOfEventWeights(0); + (*it)->setSumOfEventWeightsSquared(0); } } @@ -518,7 +533,7 @@ CutFlowSvc::recordCollection( xAOD::CutBookkeeperContainer * coll, // Take care of the peculiarities of the new xAOD EDM, i.e., create the needed AuxStore - xAOD::CutBookkeeperAuxContainer* auxCont = new xAOD::CutBookkeeperAuxContainer; + auto auxCont = new xAOD::CutBookkeeperAuxContainer; coll->setStore( auxCont ); //gives it a new associated aux container // Record the aux container @@ -531,13 +546,18 @@ CutFlowSvc::recordCollection( xAOD::CutBookkeeperContainer * coll, xAOD::CutBookkeeper* CutFlowSvc::getCutBookkeeper( const CutIdentifier cutID ) { - xAOD::CutBookkeeperContainer::iterator it = m_completeBook->begin(); - xAOD::CutBookkeeperContainer::iterator ite = m_completeBook->end(); + DataHandle<xAOD::CutBookkeeperContainer> fileBook; + if (m_outMetaDataStore->retrieve(fileBook,m_fileCollName).isFailure()) { + ATH_MSG_ERROR("Could not retrieve handle to cutflowsvc bookkeeper"); + return nullptr; + } + xAOD::CutBookkeeperContainer::iterator it = fileBook->begin(); + xAOD::CutBookkeeperContainer::iterator ite = fileBook->end(); while (it != ite) { if ((*it)->uniqueIdentifier()==cutID) return (*it); ++it; } - return 0; + return nullptr; } diff --git a/Event/EventBookkeeperTools/src/CutFlowSvc.h b/Event/EventBookkeeperTools/src/CutFlowSvc.h index 062f3ec3ebbab2a96dd80c78498830f7c2f8d139..0f96f2f46671ff382ae9916e98a9a71fe4088526 100644 --- a/Event/EventBookkeeperTools/src/CutFlowSvc.h +++ b/Event/EventBookkeeperTools/src/CutFlowSvc.h @@ -154,8 +154,6 @@ private: /// The event store StoreGateSvc_t m_eventStore; - DataHandle<xAOD::CutBookkeeperContainer> m_completeBook; - /// The name of the completed, i.e., fully processed, CutBookkeeperContainer std::string m_completeCollName; @@ -171,9 +169,6 @@ private: /// The name of the currently used input file stream std::string m_inputStream; - /// A flag to say if the input file is currently open or not - //bool m_fileCurrentlyOpened; - /// Declare a simple typedef for the internal map typedef MAP_NS::unordered_map<CutIdentifier, xAOD::CutBookkeeper*> CutIDMap_t; diff --git a/Reconstruction/RecExample/RecExPers/share/RecoOutputMetadataList_jobOptions.py b/Reconstruction/RecExample/RecExPers/share/RecoOutputMetadataList_jobOptions.py index a0d5b3a9b47bc3d90781c4206a8a87e163aba353..1ed14f7c9317b8abc89674487298e0cd3c8212ec 100644 --- a/Reconstruction/RecExample/RecExPers/share/RecoOutputMetadataList_jobOptions.py +++ b/Reconstruction/RecExample/RecExPers/share/RecoOutputMetadataList_jobOptions.py @@ -14,6 +14,10 @@ recoMetadataItemList = CfgItemList("RecoMetadata", items = ["IOVMetaDataContainer#*", "xAOD::LumiBlockRangeContainer#*", "xAOD::LumiBlockRangeAuxContainer#*", +# "xAOD::CutBookkeeperContainer#IncompleteCutBookkeepers", +# "xAOD::CutBookkeeperAuxContainer#IncompleteCutBookkeepersAux.", +# "xAOD::CutBookkeeperContainer#CutBookkeepers", +# "xAOD::CutBookkeeperAuxContainer#CutBookkeepersAux.", "xAOD::CutBookkeeperContainer#*", "xAOD::CutBookkeeperAuxContainer#*", "ByteStreamMetadataContainer#*",