diff --git a/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisAlgorithm.h b/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisAlgorithm.h index b338a9231f7250f0c84a5581fda61cbe3e760860..a96d7cd6d865d4773cbcd817b373b440c2f7f444 100644 --- a/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisAlgorithm.h +++ b/Control/AthAnalysisBaseComps/AthAnalysisBaseComps/AthAnalysisAlgorithm.h @@ -1,7 +1,7 @@ ///////////////////////// -*- C++ -*- ///////////////////////////// /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // AthAnalysisAlgorithm.h @@ -15,7 +15,6 @@ /** @class AthAnalysisAlgorithm AthAnalysisAlgorithm.h AthAnalysisBaseComps/AthAnalysisAlgorithm.h * - * Same as AthAlgorithm but adds a handle method for incident listening * Update Feb 2016: Made inherit from AthHistogramAlgorithm, since that has nice histogram booking features * @author Will Buttinger @@ -24,14 +23,12 @@ #include "AthenaBaseComps/AthHistogramAlgorithm.h" #include "GaudiKernel/ToolHandle.h" //included under assumption you'll want to use some tools! -#include "GaudiKernel/IIncidentSvc.h" #include "AthAnalysisBaseComps/AthAnalysisHelper.h" #include "TFile.h" class AthAnalysisAlgorithm : public ::AthHistogramAlgorithm - , virtual public IIncidentListener { public: @@ -63,28 +60,16 @@ public: protected: void updateEvtStore(Property& prop); - /// Function receiving incidents from IncidentSvc/TEvent - /// Experts can override but they should ensure they add - /// AthAnalysisAlgorithm::handle(); - /// to the end of their own implementation - virtual void handle( const Incident& inc ) override; - /// Function called when first execute is encountered /// user can read event information with evtStore() virtual StatusCode firstExecute(); - /// Function returning the TFile pointer of the currently open file of the - /// given EventSelector (in athena jobs this defaults to "EventSelector") - virtual TFile* currentFile(const char* evtSelName="EventSelector") final; - private: /// Object accessing the input metadata store mutable ServiceHandle< StoreGateSvc > m_inputMetaStore; /// Object accessing the output metadata store mutable ServiceHandle< StoreGateSvc > m_outputMetaStore; - TFile* m_currentFile{nullptr}; //used to cache the current file - bool m_doneFirstEvent{false}; }; diff --git a/Control/AthAnalysisBaseComps/src/AthAnalysisAlgorithm.cxx b/Control/AthAnalysisBaseComps/src/AthAnalysisAlgorithm.cxx index f711c6b5db1f757957b00aacb133e2a7f5e05eea..5a3a154d2b7fdb034cb0e0758c7b68277d73187f 100644 --- a/Control/AthAnalysisBaseComps/src/AthAnalysisAlgorithm.cxx +++ b/Control/AthAnalysisBaseComps/src/AthAnalysisAlgorithm.cxx @@ -1,7 +1,7 @@ ///////////////////////// -*- C++ -*- ///////////////////////////// /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // AthAnalysisAlgorithm.cxx @@ -59,19 +59,6 @@ ServiceHandle<StoreGateSvc>& AthAnalysisAlgorithm::outputMetaStore() const { StatusCode AthAnalysisAlgorithm::sysInitialize() { - // Connect to the IncidentSvc: - ServiceHandle< IIncidentSvc > incSvc( "IncidentSvc", name() ); - ATH_CHECK( incSvc.retrieve() ); - - // Set up the right callbacks: //but ensure we don't double-register if sysInitialize called twice (appears to be the case) - incSvc->removeListener( this, IncidentType::BeginInputFile ); - incSvc->addListener( this, IncidentType::BeginInputFile, 0, true ); - incSvc->removeListener( this, IncidentType::EndInputFile ); - incSvc->addListener( this, IncidentType::EndInputFile, 0, true ); - incSvc->removeListener( this, "MetaDataStop" ); - incSvc->addListener( this, "MetaDataStop", 0, true ); - - // Let the base class do its thing: ATH_CHECK( AthHistogramAlgorithm::sysInitialize() ); @@ -90,22 +77,6 @@ StatusCode AthAnalysisAlgorithm::sysExecute(const EventContext& ctx) { return AthHistogramAlgorithm::sysExecute(ctx); } -void AthAnalysisAlgorithm::handle( const Incident& inc ) { - - // Tell the user what's happening: - ATH_MSG_VERBOSE( "Callback received with incident: " << inc.type() ); - - // Call the appropriate member function: - if( inc.type() == IncidentType::BeginInputFile ) { - m_currentFile=0; - } - else { - ATH_MSG_WARNING( "Unknown incident type received: " << inc.type() ); - } - - return; -} - /// Dummy implementation that can be overridden by the derived tool. /// StatusCode AthAnalysisAlgorithm::firstExecute() { @@ -113,100 +84,3 @@ StatusCode AthAnalysisAlgorithm::firstExecute() { // Return gracefully: return StatusCode::SUCCESS; } - - -TFile* AthAnalysisAlgorithm::currentFile(const char* evtSelName) { - if(m_currentFile) return m_currentFile; - - //get the EventSelector so we can get it's list of input files - //dont get it with a ServiceHandle, because that invokes initialize, can get into init loop - - IProperty* evtSelector = 0; - if(service(evtSelName,evtSelector,false).isFailure()) { - ATH_MSG_ERROR("currentFile(): Couldn't find the service: " << evtSelName);return 0; - } - //SmartIF<IProperty> evtSelector(mysel); - /* - ServiceHandle<IProperty> evtSelector(evtSelName,name()); - - if(evtSelector.retrieve().isFailure()) { - ATH_MSG_ERROR("currentFile(): Couldn't find the service: " << evtSelName);return 0; - }*/ - - StringArrayProperty inputCollectionsName; - try { - //get the list of input files - use this to determine which open file is the current input file - inputCollectionsName = dynamic_cast<const StringArrayProperty&>(evtSelector->getProperty("InputCollections")); - } catch(...) { - ATH_MSG_ERROR("currentFile(): Couldn't load InputCollections property of " << evtSelName); return 0; - } - ATH_MSG_VERBOSE("nOpenFile=" << gROOT->GetListOfFiles()->GetSize() << ". nFilesInInputCollection=" << inputCollectionsName.value().size()); - if(msgLvl(MSG::VERBOSE)) { - for(int i=0;i<gROOT->GetListOfFiles()->GetSize();i++) { - ATH_MSG_VERBOSE("Open file: " << gROOT->GetListOfFiles()->At(i)->GetName()); - } - } - - //look through list of files and find the one from the input collection that is currently open - - for(int i=0;i<gROOT->GetListOfFiles()->GetSize();i++) { - TFile *g = (TFile*)gROOT->GetListOfFiles()->At(i); - //see if this file is in the input file list - //strip everything except stuff either side of last / - TString s(g->GetName()); - TObjArray* tokens = s.Tokenize("/"); - TObjString* lastToken = dynamic_cast<TObjString*>(tokens->Last()); - TString sToCompare(""); - bool shortComparison(false); - if(tokens->GetEntries()>1) { - TString beforeSlash((dynamic_cast<TObjString*>(tokens->At(tokens->GetEntries()-2)))->GetString()); - if(beforeSlash.Length()>0) sToCompare += beforeSlash; - sToCompare += "/"; - } else { - shortComparison=true; - } - sToCompare += lastToken->GetString(); - TString sToCompare_short(lastToken->GetString()); //short versions search - delete tokens; -// ATH_MSG_VERBOSE("Look at " << sToCompare); - for(unsigned int j=0;j<inputCollectionsName.value().size();j++) { - TString t(inputCollectionsName.value()[j].c_str()); - //try perfect match first - if(s.EqualTo(t)) { - ATH_MSG_VERBOSE("Current File is: " << inputCollectionsName.value()[j]); - m_currentFile = g; - return g; - } - TObjArray* tokens = t.Tokenize("/"); - TObjString* lastToken = dynamic_cast<TObjString*>(tokens->Last()); - TString tToCompare = ""; - bool shortComparison2(false); - if(tokens->GetEntries()>1) { - TString beforeSlash((dynamic_cast<TObjString*>(tokens->At(tokens->GetEntries()-2)))->GetString()); - if(beforeSlash.Length()>0) tToCompare += beforeSlash; - tToCompare += "/"; - } else { - shortComparison2=true; - } - tToCompare += lastToken->GetString(); - TString tToCompare_short(lastToken->GetString()); - delete tokens; - //ATH_MSG_VERBOSE("cf with : " << inputCollectionsName.value()[j]); - if(shortComparison || shortComparison2) { //doing short version search, no directories to distinguish files! - if(sToCompare_short.EqualTo(tToCompare_short)) { - ATH_MSG_VERBOSE("Current File is: " << inputCollectionsName.value()[j]); - m_currentFile = g; - return g; - } - } else - if(sToCompare.EqualTo(tToCompare)) { - ATH_MSG_VERBOSE("Current File is: " << inputCollectionsName.value()[j]); - m_currentFile=g; - return g; - } - } - } - ATH_MSG_ERROR("currentFile(): Could not find the current file!"); - return 0; //something went wrong :-( - -}