<commit_before># -*- coding: utf-8 -*-

"""
CMS-related job helpers.
"""


__all__ = ["CMSJobDashboard"]


import time
import socket

import six

from law.job.base import BaseJobManager, BaseJobDashboard


class CMSJobDashboard(BaseJobDashboard):
    """
    This CMS job dashboard interface requires ``apmon`` to be installed on your system.
    See http://monalisa.caltech.edu/monalisa__Documentation__ApMon_User_Guide__apmon_ug_py.html and
    https://twiki.cern.ch/twiki/bin/view/ArdaGrid/CMSJobMonitoringCollector.
    """

    PENDING = "pending"
    RUNNING = "running"
    CANCELLED = "cancelled"
    POSTPROC = "postproc"
    SUCCESS = "success"
    FAILED = "failed"

    default_apmon_config = {
        "cms-jobmon.cern.ch:8884": {
            "sys_monitoring": 0,
            "general_info": 0,
            "job_monitoring": 0,
        },
    }

    tracking_url = "http://dashb-cms-job.cern.ch/dashboard/templates/task-analysis/#" + \
        "table=Jobs&p=1&activemenu=2&tid={dashboard_task_id}"

    persistent_attributes = ["task_id", "cms_user", "voms_user", "init_timestamp"]

    def __init__(self, task, cms_user, voms_user, apmon_config=None, log_level="INFO", max_rate=20,
            task_type="analysis", site=None, executable="law", application=None,
            application_version=None, submission_tool="law", submission_type="direct",
            submission_ui=None):
        super(CMSJobDashboard, self).__init__(max_rate=max_rate)

        # setup the apmon interface
        import apmon
        apmon_config = apmon_config or self.default_apmon_config
        log_level = getattr(apmon.Logger, log_level.upper())
        self.apmon = apmon.ApMon(apmon_config, log_level)

        # hotfix of a bug occurring in apmon for too large pids
        for key, value in self.apmon.senderRef.items():
            value["INSTANCE_ID"] = value["INSTANCE_ID"] & 0x7fffffff

        # mandatory (persistent) attributes
        self.task_id = task
        self.cms_user = cms_user
        self.voms_user = voms_user
        self.init_timestamp = self.create_timestamp()

        # optional attributes
        self.task_type = task_type
        self.site = site
        self.executable = executable
        self.application = application or task.task_family
        self.application_version = application_version or self.task_id.rsplit("_", 1)[1]<commit_msg>Fix CMS job dashboard init.<commit_after># -*- coding: utf-8 -*-

"""
CMS-related job helpers.
"""


__all__ = ["CMSJobDashboard"]


import time
import socket

import six

from law.job.base import BaseJobManager, BaseJobDashboard


class CMSJobDashboard(BaseJobDashboard):
    """
    This CMS job dashboard interface requires ``apmon`` to be installed on your system.
    See http://monalisa.caltech.edu/monalisa__Documentation__ApMon_User_Guide__apmon_ug_py.html and
    https://twiki.cern.ch/twiki/bin/view/ArdaGrid/CMSJobMonitoringCollector.
    """

    PENDING = "pending"
    RUNNING = "running"
    CANCELLED = "cancelled"
    POSTPROC = "postproc"
    SUCCESS = "success"
    FAILED = "failed"

    default_apmon_config = {
        "cms-jobmon.cern.ch:8884": {
            "sys_monitoring": 0,
            "general_info": 0,
            "job_monitoring": 0,
        },
    }

    tracking_url = "http://dashb-cms-job.cern.ch/dashboard/templates/task-analysis/#" + \
        "table=Jobs&p=1&activemenu=2&tid={dashboard_task_id}"

    persistent_attributes = ["task_id", "cms_user", "voms_user", "init_timestamp"]

    def __init__(self, task, cms_user, voms_user, apmon_config=None, log_level="INFO", max_rate=20,
            task_type="analysis", site=None, executable="law", application=None,
            application_version=None, submission_tool="law", submission_type="direct",
            submission_ui=None):
        # setup the apmon interface
        import apmon
        apmon_config = apmon_config or self.default_apmon_config
        log_level = getattr(apmon.Logger, log_level.upper())
        self.apmon = apmon.ApMon(apmon_config, log_level)

        # hotfix of a bug occurring in apmon for too large pids
        for key, value in self.apmon.senderRef.items():
            value["INSTANCE_ID"] = value["INSTANCE_ID"] & 0x7fffffff

        super(CMSJobDashboard, self).__init__(max_rate=max_rate)

        # mandatory (persistent) attributes
        self.task_id = task
        self.cms_user = cms_user
        self.voms_user = voms_user
        self.init_timestamp = self.create_timestamp()

        # optional attributes
        self.task_type = task_type
        self.site = site
        self.executable = executable
        self.application = application or task.task_family
        self.application_version = application_version or self.task_id.rsplit("_", 1)[1]
{'fraction_non_alphanumeric': 0.10973562736046999, 'fraction_numerical': 0.006714225765841376, 'mean_word_length': 3.0126262626262625, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1320800', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1501, 'n_words': 297}