CRAB Logo

CRAB user functions

Complete: 5 Go to SWGuideCrab

CRAB user functions

All the functions listed below are in the CRABClient.UserUtilities module. To use them, the user should import them with, for example, the following syntax:

from CRABClient.UserUtilities import functionName

var = functionName()

The usage examples shown below correspond to either using the functions inside the python CRAB configuration file or in the context of the CRAB client library API.

config

Description: This function has the only purpose of saving the user from typing the definition of the configuration sections in the CRAB configuration file, since these sections are always the same.

Input arguments: None.

Returns:

  • A Configuration object (from WMCore.Configuration) with all sections expected/known by CRAB already defined.

CRAB exceptions raised: None.

Usage example:

from CRABClient.UserUtilities import config

config = config()

config.General.requestName = 'my_crab3_task'
...

which, from the point of view of the Configuration instance, is equivalent to:

from WMCore.Configuration import Configuration

config = Configuration()

config.section_("General")
config.section_("JobType")
config.section_("Data")
config.section_("Site")
config.section_("User")
config.section_("Debug")

config.General.requestName = 'my_crab3_task'
...

getUsernameFromSiteDB

Description: This function retrieves the users' CERN primary account username from SiteDB.

Input arguments: None.

Returns:

  • The username (as a string) if the retrieval of the username from SiteDB was successful; None if SiteDB returned the string 'null'.

CRAB exceptions raised:

  • ProxyException (from CRABClient.ClientExceptions): E.g. if the user doesn't have a valid proxy.
  • UsernameException (from CRABClient.ClientExceptions): E.g. if the certificate registered in SiteDB is not the one used with CRAB.

Usage example: See Retrieving the CERN username in the CRAB configuration file.

note.gif Note: Using the function within CRAB is safe in terms of proxy validity, because the crab submit command checks before loading the configuration file if the user has a valid proxy and creates one if not. Using the function outside CRAB requires the user to have a valid proxy; if not, the function will raise the CRAB client exception ProxyException.

getFileFromURL

Description: Loads a file from a user provided URL and writes it in a local file.

Input arguments:

  • url: The input URL from where to load the file.
  • filename: The name of the local file where the content of the file loaded from the URL should be written.

Returns:

  • The name of the local file (as a string) where the content of the file loaded from the given URL was saved. This is the same as the input argument filename, which defaults None and in which case the basename of the file path in the input URL will be used.

CRAB exceptions raised:

  • ClientException (from CRABClient.ClientExceptions): In case anything goes wrong.

Usage example:

from CRABClient.UserUtilities import config, getFileFromURL

config = config()

config.General.requestName = 'my_crab3_task'
...
config.JobType.psetName = getFileFromURL(url = 'http://blablabla.com/apset.py', filename = 'myCMSSWPSet.py')
...
config.Data.lumiMask = getFileFromURL(url = 'https://blablabla.com/atxtfile.txt', filename = 'myLumiMaskFile.txt')
...

getLumiListInValidFiles

Description: Retrieve the runs and luminosity sections in (the valid files of) a dataset.

Input arguments:

  • dataset: The dataset for which to retrieve the runs and luminosity sections.

  • dbsurl: The DBS Reader URL where dataset is published. The following shortcuts are accepted: 'global', 'phys01', 'phys02' and 'phys03'. Defaults to 'phys03'.

Returns:

  • A LumiList object (from WMCore.DataStructs.LumiList) of runs and lumis.

CRAB exceptions raised:

  • ClientException (from CRABClient.ClientExceptions): In case of error querying the DBS client or dataset not found in DBS.

Usage example: See usage example in Dealing with a growing input dataset and/or lumi-mask.

getLoggers

Description: Retrieve the current CRAB loggers.

Input arguments: None.

Returns:

  • A dictionary with the CRAB loggers. The keys of the dictionary are the names of the loggers and the values are the loggers objects.

CRAB exceptions raised: None.

getConsoleLogLevel

Description: Retrieve the current logging level of the CRAB3.all logger (console) stream-handler.

Input arguments: None.

Returns:

  • The current logging level of the CRAB3.all logger (console) stream-handler. The logging level is an integer.

CRAB exceptions raised: None.

Usage example: See usage example in setConsoleLogLevel.

setConsoleLogLevel

Description: Set/modify the logging level of the CRAB3.all logger (console) stream-handler.

Input arguments:

  • lvl: The new logging level for the stream-handler.

Returns: Nothing.

CRAB exceptions raised: None.

Usage example:

from CRABAPI.RawCommand import crabCommand
from CRABClient.ClientUtilities import LOGLEVEL_MUTE
from CRABClient.UserUtilities import setConsoleLogLevel

# Retrieve the original CRAB console log level.
origConsoleLogLevel = getConsoleLogLevel()

# Turn off the logging of CRAB to the console.
setConsoleLogLevel(LOGLEVEL_MUTE)

# Execute some crab commands.
crabCommand(...)
...
crabCommand(...)
...

# Set back the original CRAB console log level.
setConsoleLogLevel(origConsoleLogLevel)

# Execute some more crab commands.
crabCommand(...)
crabCommand(...)
...

-- AndresTanasijczuk - 2015-01-08

Edit | Attach | Watch | Print version | History: r10 < r9 < r8 < r7 < r6 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r10 - 2015-10-08 - AndresTanasijczuk
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    CMSPublic All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback