ATLAS Offline Software
Namespaces | Classes | Enumerations | Functions
RCU Namespace Reference

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

Namespaces

 Check
 
 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 More...
 
void disable_root_version_check ()
 effects: disable the root version check guarantee: no-fail More...
 
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 More...
 
std::string locate (const std::string &locations)
 effects: find the file with the given name from a list of locations separated by "::". More...
 
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. More...
 
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() More...
 
bool match_expr (const boost::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 More...
 
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 More...
 

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  };

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 56 of file StringUtil.cxx.

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

◆ 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  }

◆ 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 = 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);
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  }

◆ match_expr()

bool RCU::match_expr ( const boost::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 40 of file StringUtil.cxx.

41  {
42  boost::match_results<std::string::const_iterator> what;
43  std::size_t count = boost::regex_match (str, what, expr);
44 
45  for (std::size_t iter = 0; iter != count; ++ iter)
46  {
47  if (what[iter].matched && what[iter].first == str.begin() &&
48  what[iter].second == str.end())
49  return true;
50  }
51  return false;
52  }

◆ 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  {
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  }

◆ 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  {
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  }

◆ 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  }

◆ 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  }

◆ 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  }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
mergePhysValFiles.pattern
pattern
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:26
checkFileSG.line
line
Definition: checkFileSG.py:75
get_generator_info.result
result
Definition: get_generator_info.py:21
FullCPAlgorithmsTest_eljob.flush
flush
Definition: FullCPAlgorithmsTest_eljob.py:186
RCU::MESSAGE_ERROR
@ MESSAGE_ERROR
description: print an error
Definition: MessageType.h:32
plotmaker.hist
hist
Definition: plotmaker.py:148
RCU_REQUIRE
#define RCU_REQUIRE(x)
Definition: Assert.h:208
tree
TChain * tree
Definition: tile_monitor.h:30
RCU::MESSAGE_UNSPECIFIED
@ MESSAGE_UNSPECIFIED
description: unspecified message type
Definition: MessageType.h:41
sg-dump.input_files
list input_files
Definition: sg-dump.py:124
ReweightUtils.message
message
Definition: ReweightUtils.py:15
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
efficiency
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="")
Definition: dependence.cxx:128
DeMoScan.directory
string directory
Definition: DeMoScan.py:80
LArG4FSStartPointFilter.exec
exec
Definition: LArG4FSStartPointFilter.py:103
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
generateReferenceFile.files
files
Definition: generateReferenceFile.py:12
file
TFile * file
Definition: tile_monitor.h:29
RCU::MESSAGE_EXCEPTION
@ MESSAGE_EXCEPTION
description: send out an exception
Definition: MessageType.h:35
mergePhysValFiles.output_file
output_file
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:27
python.ExitCodes.what
def what(code)
Definition: ExitCodes.py:73
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
RCU::send_message_abort
void send_message_abort(const char *package, const char *file, unsigned line, MessageType type, const TString &msg)
Definition: PrintMsg.cxx:81
RCU_PRINT_MSG
#define RCU_PRINT_MSG(message)
Definition: PrintMsg.h:49
python.ElectronD3PDObject.matched
matched
Definition: ElectronD3PDObject.py:138
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:536
RCU::MESSAGE_ABORT
@ MESSAGE_ABORT
description: print and abort
Definition: MessageType.h:38
pickleTool.object
object
Definition: pickleTool.py:30
RCU_ASSERT0
#define RCU_ASSERT0(y)
Definition: Assert.h:226
str
Definition: BTagTrackIpAccessor.cxx:11
merge.status
status
Definition: merge.py:17
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
IOVDbNamespace::quote
std::string quote(const std::string &sentence)
Enclose a string in ".
Definition: IOVDbStringFunctions.cxx:85
RCU_ASSERT
#define RCU_ASSERT(x)
Definition: Assert.h:222
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
Trk::split
@ split
Definition: LayerMaterialProperties.h:38
run.Message
Message
Definition: run.py:57
RCU::MESSAGE_WARNING
@ MESSAGE_WARNING
description: print a warning
Definition: MessageType.h:29
RCU::MESSAGE_REGULAR
@ MESSAGE_REGULAR
description: print a regular message
Definition: MessageType.h:26
RCU::send_message
void send_message(const char *package, const char *file, unsigned line, MessageType type, const TString &msg)
Definition: PrintMsg.cxx:49