Skip to content
  • Below code also can't properly set up different compression level or algorithm

    #include "MyCompressionAlg/MyCompressionAlg.h"
    #include "xAODParticleEvent/ParticleContainer.h"
    #include "xAODParticleEvent/ParticleAuxContainer.h"
    #include "GaudiKernel/EventContext.h"
    #include "TFile.h"
    
    DECLARE_COMPONENT(MyCompressionAlg)
    
    MyCompressionAlg::MyCompressionAlg(const std::string& name, ISvcLocator* svcLoc)
        : AthReentrantAlgorithm(name, svcLoc) {}
    
    StatusCode MyCompressionAlg::initialize() {
        ATH_CHECK(m_inputKey.initialize());
        ATH_CHECK(m_outputKey.initialize());
    
        // Retrieve compression settings from job options (if provided)
        if (!m_compressionAlgorithm.value().empty()) {
            ATH_MSG_INFO("Using compression algorithm: " << m_compressionAlgorithm.value());
        }
        if (m_compressionLevel > 0) {
            ATH_MSG_INFO("Using compression level: " << m_compressionLevel);
        }
    
        return StatusCode::SUCCESS;
    }
    
    StatusCode MyCompressionAlg::execute(const EventContext& ctx) const {
        SG::ReadHandle<xAOD::ParticleContainer> inputParticles(m_inputKey, ctx);
        if (!inputParticles.isValid()) {
            ATH_MSG_ERROR("Failed to retrieve " << m_inputKey.key());
            return StatusCode::FAILURE;
        }
    
        SG::WriteHandle<xAOD::ParticleContainer> outputParticles(m_outputKey, ctx);
        auto outputContainer = std::make_unique<xAOD::ParticleContainer>();
        auto outputAuxContainer = std::make_unique<xAOD::ParticleAuxContainer>();
        outputContainer->setStore(outputAuxContainer.get());
    
        for (const xAOD::Particle* particle : *inputParticles) {
            xAOD::Particle* newParticle = new xAOD::Particle();
            outputContainer->push_back(newParticle);
    
            *newParticle = *particle;
        }
    
        // Set compression settings on the auxiliary store
        TFile* file = dynamic_cast<TFile*>(outputAuxContainer->getOutputFile());
        if (file) {
            int rootCompressionAlgorithm = 0; // Default ROOT algorithm (ZLIB)
            if (m_compressionAlgorithm.value() == "LZMA") {
                rootCompressionAlgorithm = 2; // LZMA
            } else if (m_compressionAlgorithm.value() == "LZ4") {
                rootCompressionAlgorithm = 4; // LZ4
            }
    
            file->SetCompressionAlgorithm(rootCompressionAlgorithm);
            file->SetCompressionLevel(m_compressionLevel);
    
            ATH_MSG_INFO("Applied compression settings: Algorithm = " << rootCompressionAlgorithm
                          << ", Level = " << m_compressionLevel);
        } else {
            ATH_MSG_WARNING("Output TFile not available for setting compression.");
        }
    
        ATH_CHECK(outputParticles.record(std::move(outputContainer), std::move(outputAuxContainer)));
    
        return StatusCode::SUCCESS;
    }
    
    StatusCode MyCompressionAlg::finalize() {
        return StatusCode::SUCCESS;
    }
    
    Edited by Yuriy Volkotrub
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