diff --git a/DQMServices/FwkIO/plugins/DQMRootOutputModule.cc b/DQMServices/FwkIO/plugins/DQMRootOutputModule.cc index 826250964acf1..ef7149dd9185e 100644 --- a/DQMServices/FwkIO/plugins/DQMRootOutputModule.cc +++ b/DQMServices/FwkIO/plugins/DQMRootOutputModule.cc @@ -38,6 +38,7 @@ #include "FWCore/Framework/interface/MakerMacros.h" #include "FWCore/MessageLogger/interface/JobReport.h" #include "FWCore/Utilities/interface/Digest.h" +#include "FWCore/Utilities/interface/GlobalIdentifier.h" #include "DataFormats/Provenance/interface/ProcessHistory.h" #include "DataFormats/Provenance/interface/ProcessHistoryID.h" @@ -334,8 +335,10 @@ void DQMRootOutputModule::openFile(edm::FileBlock const&) { edm::Service jr; cms::Digest branchHash; - std::string guid{m_file->GetUUID().AsString()}; + std::string guid{edm::createGlobalIdentifier()}; std::transform(guid.begin(), guid.end(), guid.begin(), (int (*)(int))std::toupper); + + m_file->WriteObject(&guid, kCmsGuid); m_jrToken = jr->outputFileOpened(m_fileName, m_logicalFileName, std::string(), diff --git a/DQMServices/FwkIO/plugins/DQMRootSource.cc b/DQMServices/FwkIO/plugins/DQMRootSource.cc index bb3b7710f510a..b3fd902676fe5 100644 --- a/DQMServices/FwkIO/plugins/DQMRootSource.cc +++ b/DQMServices/FwkIO/plugins/DQMRootSource.cc @@ -369,8 +369,23 @@ class DQMRootSource : public edm::PuttableSourceBase, DQMTTreeIO { // Index of currenlty processed row in m_fileMetadatas unsigned int m_currentIndex; + // All open DQMIO files - std::vector m_openFiles; + struct OpenFileInfo { + OpenFileInfo(TFile* file, edm::JobReport::Token jrToken) : m_file(file), m_jrToken(jrToken) {} + ~OpenFileInfo() { + edm::Service jr; + jr->inputFileClosed(edm::InputType::Primary, m_jrToken); + } + + OpenFileInfo(OpenFileInfo&&) = default; + OpenFileInfo& operator=(OpenFileInfo&&) = default; + + std::unique_ptr m_file; + edm::JobReport::Token m_jrToken; + }; + std::vector m_openFiles; + // An item here is a row read from DQMIO indices (metadata) table std::vector m_fileMetadatas; }; @@ -422,7 +437,7 @@ DQMRootSource::DQMRootSource(edm::ParameterSet const& iPSet, const edm::InputSou m_nextItemType(edm::InputSource::IsFile), m_treeReaders(kNIndicies, std::shared_ptr()), m_currentIndex(0), - m_openFiles(std::vector()), + m_openFiles(std::vector()), m_fileMetadatas(std::vector()) { edm::sortAndRemoveOverlaps(m_lumisToProcess); @@ -450,8 +465,7 @@ DQMRootSource::DQMRootSource(edm::ParameterSet const& iPSet, const edm::InputSou DQMRootSource::~DQMRootSource() { for (auto& file : m_openFiles) { - if (file != nullptr && file->IsOpen()) { - file->Close(); + if (file.m_file && file.m_file->IsOpen()) { logFileAction("Closed file", ""); } } @@ -470,6 +484,8 @@ std::shared_ptr DQMRootSource::readFile_() { for (auto& fileitem : m_catalog.fileCatalogItems()) { TFile* file; + std::string pfn; + std::string lfn; std::list exInfo; //loop over names of a file, each of them corresponds to a data catalog bool isGoodFile(true); @@ -493,7 +509,7 @@ std::shared_ptr DQMRootSource::readFile_() { if (!m_skipBadFiles) { edm::Exception ex(edm::errors::FileOpenError, "", e); ex.addContext("Opening DQM Root file"); - ex << "\nInput file " << it->c_str() << " was not found, could not be opened, or is corrupted.\n"; + ex << "\nInput file " << *it << " was not found, could not be opened, or is corrupted.\n"; //report previous exceptions when use other names to open file for (auto const& s : exInfo) ex.addAdditionalInfo(s); @@ -509,12 +525,14 @@ std::shared_ptr DQMRootSource::readFile_() { // Check if a file is usable if (file && !file->IsZombie()) { logFileAction("Successfully opened file ", it->c_str()); + pfn = *it; + lfn = fileitem.logicalFileName(); break; } else { if (std::next(it) == fNames.end()) { if (!m_skipBadFiles) { edm::Exception ex(edm::errors::FileOpenError); - ex << "Input file " << it->c_str() << " could not be opened.\n"; + ex << "Input file " << *it << " could not be opened.\n"; ex.addContext("Opening DQM Root file"); //report previous exceptions when use other names to open file for (auto const& s : exInfo) @@ -533,12 +551,21 @@ std::shared_ptr DQMRootSource::readFile_() { if (!isGoodFile && m_skipBadFiles) continue; - m_openFiles.insert(m_openFiles.begin(), file); + std::unique_ptr guid{file->Get(kCmsGuid)}; + if (not guid) { + guid = std::make_unique(file->GetUUID().AsString()); + std::transform(guid->begin(), guid->end(), guid->begin(), (int (*)(int))std::toupper); + } + + edm::Service jr; + auto jrToken = jr->inputFileOpened( + pfn, lfn, std::string(), std::string(), "DQMRootSource", "source", *guid, std::vector()); + m_openFiles.emplace_back(file, jrToken); // Check file format version, which is encoded in the Title of the TFile if (strcmp(file->GetTitle(), "1") != 0) { edm::Exception ex(edm::errors::FileReadError); - ex << "Input file " << fNames[0].c_str() << " does not appear to be a DQM Root file.\n"; + ex << "Input file " << fNames[0] << " does not appear to be a DQM Root file.\n"; } // Read metadata from the file diff --git a/DQMServices/FwkIO/plugins/format.h b/DQMServices/FwkIO/plugins/format.h index cf8a1cf8eeae4..197dd185c9d59 100644 --- a/DQMServices/FwkIO/plugins/format.h +++ b/DQMServices/FwkIO/plugins/format.h @@ -65,6 +65,9 @@ static const char* const kTypeBranch = "Type"; static const char* const kFirstIndex = "FirstIndex"; static const char* const kLastIndex = "LastIndex"; +//File GUID +static const char* const kCmsGuid = "cms::edm::GUID"; + //Meta data info static const char* const kMetaDataDirectoryAbsolute = "/MetaData"; static const char* const kMetaDataDirectory = kMetaDataDirectoryAbsolute + 1; diff --git a/DQMServices/FwkIO/test/check_guid_file1.py b/DQMServices/FwkIO/test/check_guid_file1.py index cd54d4c5475a9..e43080c870eca 100644 --- a/DQMServices/FwkIO/test/check_guid_file1.py +++ b/DQMServices/FwkIO/test/check_guid_file1.py @@ -6,8 +6,10 @@ fname_root = "dqm_file1.root" fname_report = "dqm_file1_jobreport.xml" +kCmsGuid = "cms::edm::GUID" + f = ROOT.TFile.Open(fname_root) -guid_file = f.GetUUID().AsString().upper() +guid_file = getattr(f, kCmsGuid) f.Close() guid_report = None