ATLAS Offline Software
Loading...
Searching...
No Matches
RCU Namespace Reference

This module defines a variety of assert style macros. More...

Namespaces

namespace  Check
namespace  Shell

Classes

struct  Message
class  UnitTestDir

Enumerations

enum  MessageType {
  MESSAGE_REGULAR , MESSAGE_WARNING , MESSAGE_ERROR , MESSAGE_EXCEPTION ,
  MESSAGE_ABORT , MESSAGE_UNSPECIFIED
}

Functions

void hadd (const std::string &output_file, const std::vector< std::string > &input_files, unsigned max_files=0)
 effects: perform the hadd functionality guarantee: basic failures: out of memory III failures: i/o errors
bool SetDirectory (TObject *object, TDirectory *directory)
 effects: set the directory this object is associated with returns: whether the object type actively knows its directory, otherwise this is a no-op guarantee: strong failures: directory add errors requires: object != 0 rationale: this is mainly meant to allow calling SetDirectory(0) on arbitrary objects, but it also tries to do the right thing when adding objects to a directory.
std::string substitute (std::string_view str, std::string_view pattern, std::string_view with)
 effects: substitute all occurences of "pattern" with "with" in the string "str" returns: the substituted string guarantee: out of memory II requires: !pattern.empty()
bool match_expr (const std::regex &expr, std::string_view str)
 returns: whether we can match the entire string with the regular expression guarantee: strong failures: out of memory II
std::string glob_to_regexp (std::string_view glob)
 returns: a string that is the regular expression equivalent of the given glob expression guarantee: strong failures: out of memory II

Detailed Description

This module defines a variety of assert style macros.

This module defines a class that manages a temporary directory for unit tests.

This module defines macros for reporting errors.

Author
Nils Krumnack
Nils Krumnack This module defines a variety of assert style macros for different situations, i.e. macros that test whether a particular condition has been met and that trigger an error if the condition is not met. The exact error behavior depends on the configuration options as well as the macro called. The main distinction is the purpose of the test: RCU_REQUIRE: checks on the arguments to a function RCU_PROVIDE: checks on the results of a function RCU_ASSERT: checks that happen in the middle of a function RCU_INVARIANT: checks that happen in the invariant test These can be further modified using postfixes: _SLOW: tests that are in the critical path of a program _SOFT: tests that are expected to fail in correctly implemented programs, i.e. should trigger an exception 2: tests that have a textual description of the condition 0: tests that always fail Furthermore there are also invariant tests in here (calling MyClass::testInvariant()): RCU_READ_INVARIANT: an invariant is read, but not modified RCU_CHANGE_INVARIANT: an invariant is read and modified RCU_NEW_INVARIANT: an invariant has been newly established RCU_DESTROY_INVARIANT: an invariant is about to be decomissioned

Enumeration Type Documentation

◆ MessageType

Enumerator
MESSAGE_REGULAR 

description: print a regular message

MESSAGE_WARNING 

description: print a warning

MESSAGE_ERROR 

description: print an error

MESSAGE_EXCEPTION 

description: send out an exception

MESSAGE_ABORT 

description: print and abort

MESSAGE_UNSPECIFIED 

description: unspecified message type

Definition at line 16 of file MessageType.h.

17 {
20
23
26
29
32
35 };
@ MESSAGE_ABORT
description: print and abort
Definition MessageType.h:31
@ MESSAGE_UNSPECIFIED
description: unspecified message type
Definition MessageType.h:34
@ MESSAGE_WARNING
description: print a warning
Definition MessageType.h:22
@ MESSAGE_EXCEPTION
description: send out an exception
Definition MessageType.h:28
@ MESSAGE_REGULAR
description: print a regular message
Definition MessageType.h:19
@ MESSAGE_ERROR
description: print an error
Definition MessageType.h:25

Function Documentation

◆ glob_to_regexp()

std::string RCU::glob_to_regexp ( std::string_view glob)

returns: a string that is the regular expression equivalent of the given glob expression guarantee: strong failures: out of memory II

Definition at line 35 of file StringUtil.cxx.

36 {
37 std::string result;
38 result.reserve(glob.size() * 2);
39
40 for (char c : glob)
41 {
42 switch (c)
43 {
44 case '*':
45 result += ".*";
46 break;
47 case '?':
48 result += '.';
49 break;
50 case '^': case '$': case '+': case '.': case '\\':
51 case '(': case ')': case '[': case ']': case '{': case '}': case '|':
52 result += '\\';
53 result += c;
54 break;
55 default:
56 result += c;
57 break;
58 }
59 }
60 return result;
61 }

◆ hadd()

void RCU::hadd ( const std::string & output_file,
const std::vector< std::string > & input_files,
unsigned max_files )

effects: perform the hadd functionality guarantee: basic failures: out of memory III failures: i/o errors

Definition at line 29 of file hadd.cxx.

32 {
33 using namespace msgRootCoreUtils;
34
35 if (input_files.size() == 1)
36 {
37 // if there is only one input file, create a symlink instead of merging
38 std::filesystem::create_symlink (input_files.front(), output_file);
39 return;
40 }
41
42 TFileMerger merger (false, false);
43
44 merger.SetMsgPrefix ("rcu_hadd");
45 merger.SetPrintLevel (98);
46
47 if (max_files > 0)
48 {
49 merger.SetMaxOpenedFiles (max_files);
50 }
51
52 if (!merger.OutputFile (output_file.c_str(), false, 1) )
53 {
54 throw std::runtime_error ("error opening target file: " + output_file);
55 }
56
57 for (const std::string& input : input_files)
58 {
59 if (!merger.AddFile (input.c_str()))
60 {
61 throw std::runtime_error ("error adding input file: " + input);
62 }
63 }
64 merger.SetNotrees (false);
65
66 bool status = merger.Merge();
67
68 if (status)
69 {
70 ANA_MSG_INFO ("merged " << merger.GetMergeList()->GetEntries() << " input files into " << output_file);
71 } else
72 {
73 throw std::runtime_error ("hadd failure during the merge");
74 }
75 }
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
status
Definition merge.py:16

◆ match_expr()

bool RCU::match_expr ( const std::regex & expr,
std::string_view str )

returns: whether we can match the entire string with the regular expression guarantee: strong failures: out of memory II

Definition at line 30 of file StringUtil.cxx.

31 {
32 return std::regex_match(str.begin(), str.end(), expr);
33 }

◆ SetDirectory()

bool RCU::SetDirectory ( TObject * object,
TDirectory * directory )

effects: set the directory this object is associated with returns: whether the object type actively knows its directory, otherwise this is a no-op guarantee: strong failures: directory add errors requires: object != 0 rationale: this is mainly meant to allow calling SetDirectory(0) on arbitrary objects, but it also tries to do the right thing when adding objects to a directory.

For the most part it is a workaround for TH1 objects keeping track of which directory they belong to.

Definition at line 25 of file RootUtils.cxx.

26 {
27 RCU_ASSERT (object != nullptr);
28
29 TH1 *const hist = dynamic_cast<TH1*>(object);
30 if (hist)
31 {
32 hist->SetDirectory (directory);
33 return true;
34 }
35
36 TEfficiency *const efficiency = dynamic_cast<TEfficiency*>(object);
37 if (efficiency)
38 {
39 efficiency->SetDirectory (directory);
40 return true;
41 }
42
43 TTree *const tree = dynamic_cast<TTree*>(object);
44 if (tree)
45 {
46 tree->SetDirectory (directory);
47 return true;
48 }
49
50 return false;
51 }
#define RCU_ASSERT(x)
Definition Assert.h:210
void efficiency(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")
TChain * tree

◆ substitute()

std::string RCU::substitute ( std::string_view str,
std::string_view pattern,
std::string_view with )

effects: substitute all occurences of "pattern" with "with" in the string "str" returns: the substituted string guarantee: out of memory II requires: !pattern.empty()

Definition at line 14 of file StringUtil.cxx.

16 {
17 if (pattern.empty())
18 throw std::runtime_error ("substitute: pattern must not be empty");
19
20 std::string result(str);
21 std::string::size_type pos = 0;
22
23 while ((pos = result.find(pattern, pos)) != std::string::npos) {
24 result.replace(pos, pattern.size(), with);
25 pos += with.size();
26 }
27 return result;
28 }