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

class  ExceptionMsg
struct  Message
class  UnitTestDir

Enumerations

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

Functions

void check_root_version ()
 effects: check whether we are using a consistent root version guarantee: strong failures: version missmatch
void disable_root_version_check ()
 effects: disable the root version check guarantee: no-fail
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
std::string locate (const std::string &locations)
 effects: find the file with the given name from a list of locations separated by "::".
void send_message (const char *package, const char *file, unsigned line, MessageType type, const char *msg)
void send_message (const char *package, const char *file, unsigned line, MessageType type, const std::string &msg)
void send_message (const char *package, const char *file, unsigned line, MessageType type, const TString &msg)
void send_message_abort (const char *package, const char *file, unsigned line, MessageType type, const char *msg)
void send_message_abort (const char *package, const char *file, unsigned line, MessageType type, const std::string &msg)
void send_message_abort (const char *package, const char *file, unsigned line, MessageType type, const TString &msg)
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 (const std::string &str, const std::string &pattern, const std::string &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, const std::string &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 (const std::string &glob)
 returns: a string that is the regular expression equivalent of the given glob expression guarantee: strong failures: out of memory II rationale: I am returning a TString instead of an std::string, so that this can be passed directly into regexp

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.

This module provides a lot of global definitions, forward declarations and includes that are used by all modules.

Author
Nils Krumnack

The interface in this module is indended for experts only. This module is considered to be in the pre-alpha stage. 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

As such it doesn't fall into the user vs. expert classification.

The interface in this module is indended for experts only. This module is considered to be in the pre-alpha stage.

The interface provided in this module is intended for experts only. The module is considered to be in the pre-alpha stage.

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 23 of file MessageType.h.

24 {
27
30
33
36
39
42 };
@ MESSAGE_ABORT
description: print and abort
Definition MessageType.h:38
@ MESSAGE_UNSPECIFIED
description: unspecified message type
Definition MessageType.h:41
@ MESSAGE_WARNING
description: print a warning
Definition MessageType.h:29
@ MESSAGE_EXCEPTION
description: send out an exception
Definition MessageType.h:35
@ MESSAGE_REGULAR
description: print a regular message
Definition MessageType.h:26
@ MESSAGE_ERROR
description: print an error
Definition MessageType.h:32

Function Documentation

◆ check_root_version()

void RCU::check_root_version ( )

effects: check whether we are using a consistent root version guarantee: strong failures: version missmatch

Definition at line 31 of file CheckRootVersion.cxx.

32 {
33 if (checked)
34 return;
35 if (gROOT->GetVersionCode() != Int_t(ROOT_VERSION_CODE))
36 {
37 std::cout
38 << "root version used is not compatible with the one used for\n"
39 << "compilation. please load either the correct root version, or\n"
40 << "recompile with the new version\n\n"
41 << "alternatively deactivate this check using:\n"
42 << "#include <RootCoreUtils/CheckRootVersion.hh>\n"
43 << " RCU::disable_root_version_check()\n"
44 << std::flush;
45 std::abort ();
46 }
47 checked = true;
48 }

◆ disable_root_version_check()

void RCU::disable_root_version_check ( )

effects: disable the root version check guarantee: no-fail

Definition at line 52 of file CheckRootVersion.cxx.

53 {
54 checked = true;
55 }

◆ glob_to_regexp()

std::string RCU::glob_to_regexp ( const std::string & glob)

returns: a string that is the regular expression equivalent of the given glob expression guarantee: strong failures: out of memory II rationale: I am returning a TString instead of an std::string, so that this can be passed directly into regexp

Definition at line 52 of file StringUtil.cxx.

53 {
54 std::string result;
55
56 for (std::string::const_iterator iter = glob.begin(),
57 end = glob.end(); iter != end; ++ iter)
58 {
59 if (*iter == '*')
60 {
61 result += ".*";
62 } else if (*iter == '?')
63 {
64 result += ".";
65 } else if (*iter == '^' || *iter == '$' || *iter == '+' || *iter == '.')
66 {
67 result += '\\';
68 result += *iter;
69 } else
70 {
71 result += *iter;
72 }
73 }
74 return result;
75 }

◆ 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 28 of file hadd.cxx.

31 {
32 if (input_files.size() == 1)
33 {
34 // if there is only one input file, create a symlink instead of merging
35 std::filesystem::create_symlink (input_files.front(), output_file);
36 return;
37 }
38
39 TFileMerger merger (false, false);
40
41 merger.SetMsgPrefix ("rcu_hadd");
42 merger.SetPrintLevel (98);
43
44 if (max_files > 0)
45 {
46 merger.SetMaxOpenedFiles (max_files);
47 }
48
49 if (!merger.OutputFile (output_file.c_str(), false, 1) )
50 {
51 RCU_THROW_MSG ("error opening target file: " + output_file);
52 }
53
54 for (std::vector<std::string>::const_iterator input = input_files.begin(),
55 end = input_files.end(); input != end; ++ input)
56 {
57 if (!merger.AddFile (input->c_str()))
58 {
59 RCU_THROW_MSG ("error adding input file: " + *input);
60 }
61 }
62 merger.SetNotrees (false);
63
64 bool status = merger.Merge();
65
66 if (status)
67 {
68 std::ostringstream msg;
69 msg << "merged " << merger.GetMergeList()->GetEntries()
70 << " input files into " << output_file;
71 RCU_PRINT_MSG (msg.str());
72 } else
73 {
74 RCU_THROW_MSG ("hadd failure during the merge");
75 }
76 }
#define RCU_THROW_MSG(message)
Definition PrintMsg.h:58
#define RCU_PRINT_MSG(message)
Definition PrintMsg.h:49
status
Definition merge.py:16
list input_files
Definition sg-dump.py:123
MsgStream & msg
Definition testRead.cxx:32

◆ locate()

std::string RCU::locate ( const std::string & locations)

effects: find the file with the given name from a list of locations separated by "::".

the list may contain either files or URLs starting with "http://". URLs will be downloaded into the data/ directory, where they will stay permanently. returns: the path in the local filesystem guarantee: strong failures: out of memory III failures: inconsistent file names failures: download errors rationale: depending on where you are executing your code, you may or may not have access to /cvmfs where important data files are kept. this mechanism allows to pick it up from various alternate places.

Definition at line 28 of file Locate.cxx.

29 {
30 std::deque<std::string> files;
31 {
32 std::string::size_type pos = 0, pos2 = 0;
33 while ((pos2 = locations.find ("::", pos)) != std::string::npos)
34 {
35 files.push_back (locations.substr (pos, pos2 - pos));
36 pos = pos2 + 2;
37 }
38 files.push_back (locations.substr (pos));
39 }
40 std::string name;
41 {
42 for (std::deque<std::string>::const_iterator file = files.begin(),
43 end = files.end(); file != end; ++ file)
44 {
45 std::string::size_type split = file->rfind ('/');
46 if (split == std::string::npos)
47 RCU_THROW_MSG ("file name " + *file + " does not contain a \"/\"");
48 std::string myname = file->substr (split + 1);
49 if (myname.empty())
50 RCU_THROW_MSG ("file name " + *file + " should not end with a \"/\"");
51 if (name.empty())
52 name = std::move(myname);
53 else if (name != myname)
54 RCU_THROW_MSG ("inconsistent file names " + name + " and " + myname);
55 }
56 }
57 RCU_ASSERT (!name.empty());
58
59 files.push_front ("$ROOTCOREBIN/data/RootCoreUtils/download/" + name);
60 for (std::deque<std::string>::iterator file = files.begin(),
61 end = files.end(); file != end; ++ file)
62 {
63 TString myfile = *file;
64 gSystem->ExpandPathName (myfile);
65 *file = myfile.Data();
66 }
67
68 for (std::deque<std::string>::const_iterator file = files.begin(),
69 end = files.end(); file != end; ++ file)
70 {
71 if (file->find ("http://") == 0)
72 {
73 try
74 {
75 Shell::exec ("$ROOTCOREDIR/scripts/download.sh " + Shell::quote (*file) + " " + Shell::quote (files[0]));
76 return files[0];
77 } catch (...)
78 {
79 // rationale: ignoring all exceptions, since we might have
80 // more locations to try
81 }
82 } else
83 {
84 if (gSystem->AccessPathName (file->c_str()) == 0)
85 {
86 return *file;
87 }
88 }
89 }
90 RCU_THROW_MSG ("failed to find file at " + locations);
91 return ""; // compiler dummy
92 }
#define RCU_ASSERT(x)
Definition Assert.h:222
std::vector< std::string > files
file names and file pointers
Definition hcg.cxx:50
std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition hcg.cxx:177
void exec(const std::string &cmd)
effects: execute the given command guarantee: strong failures: out of memory II failures: system fail...
Definition ShellExec.cxx:29
std::string quote(const std::string &name)
effects: quote the given name to protect it from the shell returns: the quoted name guarantee: strong...
Definition ShellExec.cxx:75
TFile * file

◆ match_expr()

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

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

Definition at line 39 of file StringUtil.cxx.

40 {
41 std::match_results<std::string::const_iterator> what;
42 std::size_t count = std::regex_match(str.begin(), str.end(), what, expr);
43 for (std::size_t iter = 0; iter != count; ++iter)
44 {
45 if (what[iter].matched && what[iter].first == str.begin() &&
46 what[iter].second == str.end())
47 return true;
48 }
49 return false;
50 }
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146

◆ send_message() [1/3]

void RCU::send_message ( const char * package,
const char * file,
unsigned line,
MessageType type,
const char * msg )

Definition at line 27 of file PrintMsg.cxx.

29 {
30 Message message;
31 message.package = package;
32 message.file = file;
33 message.line = line;
34 message.type = type;
35 message.message = msg;
36 message.send ();
37 }

◆ send_message() [2/3]

void RCU::send_message ( const char * package,
const char * file,
unsigned line,
MessageType type,
const std::string & msg )

Definition at line 41 of file PrintMsg.cxx.

43 {
44 send_message (package, file, line, type, msg.c_str());
45 }
void send_message(const char *package, const char *file, unsigned line, MessageType type, const char *msg)
Definition PrintMsg.cxx:27

◆ send_message() [3/3]

void RCU::send_message ( const char * package,
const char * file,
unsigned line,
MessageType type,
const TString & msg )

Definition at line 49 of file PrintMsg.cxx.

51 {
52 send_message (package, file, line, type, msg.Data());
53 }

◆ send_message_abort() [1/3]

void RCU::send_message_abort ( const char * package,
const char * file,
unsigned line,
MessageType type,
const char * msg )

Definition at line 57 of file PrintMsg.cxx.

59 {
60 Message message;
61 message.package = package;
62 message.file = file;
63 message.line = line;
64 message.type = type;
65 message.message = msg;
66 message.send ();
67 RCU_ASSERT0 ("shouldn't get here");
68 std::abort ();
69 }
#define RCU_ASSERT0(y)
Definition Assert.h:226

◆ send_message_abort() [2/3]

void RCU::send_message_abort ( const char * package,
const char * file,
unsigned line,
MessageType type,
const std::string & msg )

Definition at line 73 of file PrintMsg.cxx.

75 {
76 send_message_abort (package, file, line, type, msg.c_str());
77 }
void send_message_abort(const char *package, const char *file, unsigned line, MessageType type, const char *msg)
Definition PrintMsg.cxx:57

◆ send_message_abort() [3/3]

void RCU::send_message_abort ( const char * package,
const char * file,
unsigned line,
MessageType type,
const TString & msg )

Definition at line 81 of file PrintMsg.cxx.

83 {
84 send_message_abort (package, file, line, type, msg.Data());
85 }

◆ 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 28 of file RootUtils.cxx.

29 {
30 RCU_ASSERT (object != 0);
31
32 TH1 *const hist = dynamic_cast<TH1*>(object);
33 if (hist)
34 {
35 hist->SetDirectory (directory);
36 return true;
37 }
38
39 TEfficiency *const efficiency = dynamic_cast<TEfficiency*>(object);
40 if (efficiency)
41 {
42 efficiency->SetDirectory (directory);
43 return true;
44 }
45
46 TTree *const tree = dynamic_cast<TTree*>(object);
47 if (tree)
48 {
49 tree->SetDirectory (directory);
50 return true;
51 }
52
53 return false;
54 }
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 ( const std::string & str,
const std::string & pattern,
const std::string & 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 24 of file StringUtil.cxx.

26 {
27 RCU_REQUIRE (!pattern.empty());
28
29 std::string result = str;
30 std::string::size_type pos;
31 while ((pos = result.find (pattern)) != std::string::npos) {
32 // cppcheck-suppress uselessCallsSubstr
33 result = result.substr (0, pos) + with + result.substr (pos + pattern.size());
34 }
35 return result;
36 }
#define RCU_REQUIRE(x)
Definition Assert.h:208