diff --git a/CAFxAODUtils/Root/TQxAODskimmingAlgorithm.cxx b/CAFxAODUtils/Root/TQxAODskimmingAlgorithm.cxx index 76752ccd4cfe5c5492f113fd25336b9544041404..2c9cf724dde94d927c410fed990a7400d4323e6a 100644 --- a/CAFxAODUtils/Root/TQxAODskimmingAlgorithm.cxx +++ b/CAFxAODUtils/Root/TQxAODskimmingAlgorithm.cxx @@ -288,50 +288,44 @@ bool TQxAODskimmingAlgorithm::initializeSingleton(const std::vector<TQSample*>& } //Take care of TruthMetaData: - const xAOD::EventInfo* eventInfo = nullptr; - if( !this->fEvent->retrieve(eventInfo, "EventInfo").isSuccess() ) { - throw std::runtime_error("Failed to retrieve EventInfo!"); - return false; - } - if( eventInfo->eventType(xAOD::EventInfo::EventType::IS_SIMULATION) ) { // Only needed for simulation - std::string tmdName = "TruthMetaData"; // Should be fixed - xAOD::TruthMetaDataContainer* outTmd = nullptr; - const xAOD::TruthMetaDataContainer* inTmd = nullptr; - if ( fEvent->retrieveMetaInput(inTmd,tmdName).isSuccess() ) { - int oldErrorIgnoreLevel = gErrorIgnoreLevel; - gErrorIgnoreLevel = 2000; //silence errors (we sort of expect them) - if (inTmd->size() == 0) { - throw std::runtime_error(TString::Format("No elements found in TruthMetaDataContainer named '%s'",tmdName.c_str()).Data()); + std::string tmdName = "TruthMetaData"; // Should be fixed + xAOD::TruthMetaDataContainer* outTmd = nullptr; + const xAOD::TruthMetaDataContainer* inTmd = nullptr; + if( fEvent->retrieveMetaInput(inTmd,tmdName).isSuccess() ) { + int oldErrorIgnoreLevel = gErrorIgnoreLevel; + gErrorIgnoreLevel = 2000; //silence errors (we sort of expect them) + if (inTmd->size() == 0) { + throw std::runtime_error(TString::Format("No elements found in TruthMetaDataContainer named '%s'",tmdName.c_str()).Data()); + return false; + } + else if (inTmd->size() > 1) { + WARNclass("%d elements found in TruthMetaDataContainer named '%s' while only 1 was expected", inTmd->size(), tmdName); + } + if ( fEvent->retrieveMetaOutput<xAOD::TruthMetaDataContainer>(outTmd,tmdName).isSuccess() ) { //we got a matching TruthMetaDataContainer in the output file, let's merge with the new one. + if (!truthMetaDataEqual(inTmd, outTmd)) { + throw std::runtime_error(TString::Format("Input/output TruthMetaDataContainers named '%s' are not equal - are they different DSIDs?", tmdName.c_str()).Data()); return false; } - else if (inTmd->size() > 1) { - WARNclass("%d elements found in TruthMetaDataContainer named '%s' while only 1 was expected", inTmd->size(), tmdName); + } else { + xAOD::TruthMetaDataContainer* inCopy = new xAOD::TruthMetaDataContainer(); + xAOD::TruthMetaDataAuxContainer* inCopyAux = new xAOD::TruthMetaDataAuxContainer(); + inCopy->setStore(inCopyAux); + xAOD::TruthMetaData* ele = new xAOD::TruthMetaData(); + inCopy->push_back(ele); + *ele = *(inTmd->at(0)); + if (!fEvent->recordMeta<xAOD::TruthMetaDataContainer>(inCopy,tmdName).isSuccess()) { + throw std::runtime_error(TString::Format("Failed to record TruthMetaDataContainer '%s'",tmdName.c_str()).Data()); + return false; } - if ( fEvent->retrieveMetaOutput<xAOD::TruthMetaDataContainer>(outTmd,tmdName).isSuccess() ) { //we got a matching TruthMetaDataContainer in the output file, let's merge with the new one. - if (!truthMetaDataEqual(inTmd, outTmd)) { - throw std::runtime_error(TString::Format("Input/output TruthMetaDataContainers named '%s' are not equal - are they different DSIDs?", tmdName.c_str()).Data()); - return false; - } - } else { - xAOD::TruthMetaDataContainer* inCopy = new xAOD::TruthMetaDataContainer(); - xAOD::TruthMetaDataAuxContainer* inCopyAux = new xAOD::TruthMetaDataAuxContainer(); - inCopy->setStore(inCopyAux); - xAOD::TruthMetaData* ele = new xAOD::TruthMetaData(); - inCopy->push_back(ele); - *ele = *(inTmd->at(0)); - if (!fEvent->recordMeta<xAOD::TruthMetaDataContainer>(inCopy,tmdName).isSuccess()) { - throw std::runtime_error(TString::Format("Failed to record TruthMetaDataContainer '%s'",tmdName.c_str()).Data()); - return false; - } - if (!fEvent->recordMeta<xAOD::TruthMetaDataAuxContainer>(inCopyAux,tmdName+"Aux.").isSuccess()) { - throw std::runtime_error(TString::Format("Failed to record TruthMetaDataAuxContainer '%sAux.'",tmdName.c_str()).Data()); - return false; - } + if (!fEvent->recordMeta<xAOD::TruthMetaDataAuxContainer>(inCopyAux,tmdName+"Aux.").isSuccess()) { + throw std::runtime_error(TString::Format("Failed to record TruthMetaDataAuxContainer '%sAux.'",tmdName.c_str()).Data()); + return false; } - gErrorIgnoreLevel = oldErrorIgnoreLevel; - } else { - WARNclass("Failed to obtain TruthMetaDataContainer named '%s' from input file",tmdName.c_str()); } + gErrorIgnoreLevel = oldErrorIgnoreLevel; + } + else { + WARNclass("Failed to obtain TruthMetaDataContainer named '%s' from input file - perhaps you are processing data?",tmdName.c_str()); } return true; diff --git a/QFramework/Root/TQSampleInitializerBase.cxx b/QFramework/Root/TQSampleInitializerBase.cxx index e854c579a116052f41dc53978f5c14db4844e7f3..bebab219974ce02a36a2887c4b36a2542bd39a9e 100644 --- a/QFramework/Root/TQSampleInitializerBase.cxx +++ b/QFramework/Root/TQSampleInitializerBase.cxx @@ -257,8 +257,8 @@ bool TQSampleInitializerBase::getTreeInformation(TQSample* sample, const TString } else { treeName = "CollectionTree"; - TTree* tree =(TTree*)f->Get(treeName.Data()); - nEntries =tree->GetEntries(); + TTree* tree = (TTree*)f->Get(treeName.Data()); + nEntries = (tree) ? tree->GetEntries() : 0; nEvents = 0; }