Skip to content
Snippets Groups Projects
Commit 02d029cb authored by Will Buttinger's avatar Will Buttinger Committed by Graeme Stewart
Browse files

'fix ref counting and add firstEvent method to AthAnalysisAlgorithm'...

'fix ref counting and add firstEvent method to AthAnalysisAlgorithm' (AthAnalysisBaseComps-00-00-20)

        * AthAnalysisHelper: addRef to created algorithms and tools, so that gaudi garbage collection
              wont delete it (saw this problem when had a private toolhandle in an alg)
        * AthAnalysisAlgorithm: firstEvent method to fire before the first execute is fired (useful alternative to initialize method)
        * Tagging AthAnalysisBaseComps-00-00-20

2016-06-08  scott snyder  <snyder@bnl.gov>

	* Tagging AthAnalysisBaseComps-00-00-19.
	* Comply with ATLAS naming conventions.  Fix gcc6 indentation
	warnings.
parent bee29670
No related merge requests found
......@@ -55,6 +55,8 @@ class AthAnalysisAlgorithm : public ::AthHistogramAlgorithm, virtual public IInc
/// Function initialising the tool in the correct way in Athena
virtual StatusCode sysInitialize();
/// override to do firstEvent method
virtual StatusCode sysExecute() override;
/// Helper function to access IOVMetaDataContainer information helped in the MetaDataStore
template<typename T> StatusCode retrieveMetadata(const std::string& folder, const std::string& key, T& out) {
......@@ -86,6 +88,9 @@ class AthAnalysisAlgorithm : public ::AthHistogramAlgorithm, virtual public IInc
/// Function called when a new input file is opened
virtual StatusCode beginInputFile();
/// Function called when first event is encountered
virtual StatusCode firstEvent();
virtual TFile* currentFile(const char* evtSelName="EventSelector") final;
......@@ -96,7 +101,11 @@ class AthAnalysisAlgorithm : public ::AthHistogramAlgorithm, virtual public IInc
mutable ServiceHandle< StoreGateSvc > m_outputMetaStore;
TFile* m_currentFile = 0; //used to cache the current file
bool m_doneFirstEvent=false;
};
......
......@@ -167,11 +167,12 @@ public:
//use ToolSvc as parent
parent = Gaudi::svcLocator()->service( "ToolSvc" );
}
IAlgTool* m_algtool = AlgTool::Factory::create(type,type,name,parent);
W* out = dynamic_cast<W*>(m_algtool);
if(!out && m_algtool) {
IAlgTool* algtool = AlgTool::Factory::create(type,type,name,parent);
algtool->addRef(); //important to increment the reference count so that Gaudi Garbage collection wont delete alg ahead of time
W* out = dynamic_cast<W*>(algtool);
if(!out && algtool) {
std::cout << "ERROR: Tool of type " << type << " does not implement the interface " << System::typeinfoName(typeid(W)) << std::endl;
delete m_algtool;
delete algtool;
return 0;
}
return out;
......@@ -185,7 +186,9 @@ public:
static IAlgorithm* createAlgorithm(const std::string& typeAndName) {
std::string type = typeAndName; std::string name = typeAndName;
if(type.find("/")!=std::string::npos) { type = type.substr(0,type.find("/")); name = name.substr(name.find("/")+1,name.length()); }
return Algorithm::Factory::create(type,name,Gaudi::svcLocator());
IAlgorithm* out = Algorithm::Factory::create(type,name,Gaudi::svcLocator());
out->addRef(); //important to increment the reference count so that Gaudi Garbage collection wont delete alg ahead of time
return out;
}
......
......@@ -54,6 +54,17 @@ StatusCode AthAnalysisAlgorithm::sysInitialize() {
return StatusCode::SUCCESS;
}
StatusCode AthAnalysisAlgorithm::sysExecute() {
if(!m_doneFirstEvent) {
m_doneFirstEvent=true;
if( firstEvent().isFailure() ) {
ATH_MSG_FATAL("Failure in firstEvent method");
return StatusCode::FAILURE;
}
}
return AthHistogramAlgorithm::sysExecute();
}
void AthAnalysisAlgorithm::handle( const Incident& inc ) {
// Tell the user what's happening:
......@@ -82,6 +93,16 @@ StatusCode AthAnalysisAlgorithm::beginInputFile() {
}
/// Dummy implementation that can be overridden by the derived tool.
///
StatusCode AthAnalysisAlgorithm::firstEvent() {
// Return gracefully:
return StatusCode::SUCCESS;
}
TFile* AthAnalysisAlgorithm::currentFile(const char* evtSelName) {
if(m_currentFile) return m_currentFile;
......@@ -93,8 +114,8 @@ TFile* AthAnalysisAlgorithm::currentFile(const char* evtSelName) {
}
//get the list of input files - use this to determine which open file is the current input file
const StringArrayProperty& m_inputCollectionsName = dynamic_cast<const StringArrayProperty&>(evtSelector->getProperty("InputCollections"));
ATH_MSG_VERBOSE("nOpenFile=" << gROOT->GetListOfFiles()->GetSize() << ". nFilesInInputCollection=" << m_inputCollectionsName.value().size());
const StringArrayProperty& inputCollectionsName = dynamic_cast<const StringArrayProperty&>(evtSelector->getProperty("InputCollections"));
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());
......@@ -114,7 +135,8 @@ TFile* AthAnalysisAlgorithm::currentFile(const char* evtSelName) {
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 += "/";
if(beforeSlash.Length()>0) sToCompare += beforeSlash;
sToCompare += "/";
} else {
shortComparison=true;
}
......@@ -122,11 +144,11 @@ TFile* AthAnalysisAlgorithm::currentFile(const char* evtSelName) {
TString sToCompare_short(lastToken->GetString()); //short versions search
delete tokens;
// ATH_MSG_VERBOSE("Look at " << sToCompare);
for(unsigned int j=0;j<m_inputCollectionsName.value().size();j++) {
TString t(m_inputCollectionsName.value()[j].c_str());
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: " << m_inputCollectionsName.value()[j]);
ATH_MSG_VERBOSE("Current File is: " << inputCollectionsName.value()[j]);
m_currentFile = g;
return g;
}
......@@ -136,23 +158,24 @@ TFile* AthAnalysisAlgorithm::currentFile(const char* evtSelName) {
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 += "/";
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 : " << m_inputCollectionsName.value()[j]);
//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: " << m_inputCollectionsName.value()[j]);
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: " << m_inputCollectionsName.value()[j]);
ATH_MSG_VERBOSE("Current File is: " << inputCollectionsName.value()[j]);
m_currentFile=g;
return g;
}
......
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