diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/Assert.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/Assert.cxx new file mode 100644 index 0000000000000000000000000000000000000000..5e4f62c0ec1b344a41a61061cc5349d8440a2cc6 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/Assert.cxx @@ -0,0 +1,123 @@ +// Copyright Nils Krumnack 2010 - 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/Assert.h> + +#include <cstdlib> +#include <string> +#include <RootCoreUtils/Message.h> +#include <RootCoreUtils/PrintMsg.h> + +// +// method implementations +// + +namespace RCU +{ + namespace Check + { + const char *typeLiteral [typeNum] = + { + "assertion failed", + "assertion failed", + "assertion failed", + + "requirement failed", + "requirement failed", + "requirement failed", + + "postcondition violated", + "postcondition violated", + "postcondition violated", + + "invariant violated" + }; + + + + bool typeAbort [typeNum] = + { + false, + true, + true, + + false, + true, + true, + + false, + true, + true, + + true, + }; + + + + void fail (const char *package, const char *file, unsigned line, + Type type, const char *error) + { + RCU_REQUIRE (file != 0); + RCU_REQUIRE (line != 0); + RCU_REQUIRE (type < typeNum); + RCU_REQUIRE (error != 0); + + Message msg; + msg.package = package; + msg.file = file; + msg.line = line; + msg.type = typeAbort[type] ? MESSAGE_ABORT : MESSAGE_EXCEPTION; + + std::string mymessage = typeLiteral[type]; + mymessage += ": "; + mymessage += error; + msg.message = mymessage.c_str(); + + msg.send(); + } + + + + TestInvariant :: + TestInvariant (TestInvariantFunction function, + const void *object) + : m_function (function), m_object (object) + { + (*m_function) (m_object); + } + + + + TestInvariant :: + ~TestInvariant () + { + (*m_function) (m_object); + } + + + + bool testInvariantPrint (TestInvariantFunction function, + const void *object) + { + try + { + (*function) (object); + return false; + } catch (std::exception& e) + { + RCU_ERROR_MSG (e.what()); + return true; + }; + } + } +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/CheckRootVersion.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/CheckRootVersion.cxx new file mode 100644 index 0000000000000000000000000000000000000000..4355327b4094b8581d0ce3639491c30b5c067547 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/CheckRootVersion.cxx @@ -0,0 +1,58 @@ +// Copyright Iowa State University 2013. +// Author: Nils Krumnack +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (nils.erik.krumnack@cern.ch) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/CheckRootVersion.h> + +#include <cstdlib> +#include <iostream> +#include <TROOT.h> +#include <RootCoreUtils/Assert.h> + +// +// method implementations +// + +namespace RCU +{ + namespace + { + bool checked = false; + } + + void check_root_version () + { + if (checked) + return; + if (gROOT->GetVersionCode() != Int_t(ROOT_VERSION_CODE)) + { + std::cout + << "root version used is not compatible with the one used for\n" + << "compilation. please load either the correct root version, or\n" + << "recompile with the new version\n\n" + << "alternatively deactivate this check using:\n" + << "#include <RootCoreUtils/CheckRootVersion.hh>\n" + << " RCU::disable_root_version_check()\n" + << std::flush; + std::abort (); + } + checked = true; + } + + + + void disable_root_version_check () + { + checked = true; + } +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/ExceptionMsg.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/ExceptionMsg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e732bce708abb162ea9c046c0fa508aa006942d2 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/ExceptionMsg.cxx @@ -0,0 +1,65 @@ +// Copyright Nils Krumnack 2008 - 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +//protect +#include <RootCoreUtils/ExceptionMsg.h> + +#include <memory> +#include <RootCoreUtils/Assert.h> + +// +// method implementations +// + +namespace RCU +{ + void ExceptionMsg :: + testInvariant () const + { + RCU_INVARIANT (this != 0); + RCU_INVARIANT (m_file != 0); + RCU_INVARIANT (m_line != 0); + RCU_INVARIANT (!m_message.empty()); + } + + + + ExceptionMsg :: + ExceptionMsg (const char *const val_file, const unsigned val_line, + const std::string& val_message) + : m_file ((RCU_REQUIRE (val_file != 0), + RCU_REQUIRE (val_line != 0), + RCU_REQUIRE (!val_message.empty()), + val_file)), + m_line (val_line), m_message (val_message) + { + RCU_NEW_INVARIANT (this); + } + + + + ExceptionMsg :: + ~ExceptionMsg () throw () + { + RCU_DESTROY_INVARIANT (this); + } + + + + const char *ExceptionMsg :: + what () const throw () + { + RCU_READ_INVARIANT (this); + return m_message.c_str(); + } +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/LinkDef.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/LinkDef.h new file mode 100644 index 0000000000000000000000000000000000000000..a0972c5a9ff59443b386336859d240c6d4d22cd7 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/LinkDef.h @@ -0,0 +1,14 @@ +#include <RootCoreUtils/hadd.h> + +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; +#pragma link C++ nestedclass; + +#pragma link C++ namespace RCU; + +#pragma link C++ function RCU::hadd_core (std::string, std::vector<std::string>, unsigned); + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/Locate.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/Locate.cxx new file mode 100644 index 0000000000000000000000000000000000000000..8e02e0f4d8a81632d048f3d4ff6dcf1cb127afbc --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/Locate.cxx @@ -0,0 +1,93 @@ +// Copyright Nils Krumnack 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/Locate.h> + +#include <deque> +#include <TSystem.h> +#include <RootCoreUtils/Assert.h> +#include <RootCoreUtils/ShellExec.h> +#include <RootCoreUtils/ThrowMsg.h> + +// +// method implementations +// + +namespace RCU +{ + std::string locate (const std::string& locations) + { + std::deque<std::string> files; + { + std::string::size_type pos = 0, pos2 = 0; + while ((pos2 = locations.find ("::", pos)) != std::string::npos) + { + files.push_back (locations.substr (pos, pos2 - pos)); + pos = pos2 + 2; + } + files.push_back (locations.substr (pos)); + } + std::string name; + { + for (std::deque<std::string>::const_iterator file = files.begin(), + end = files.end(); file != end; ++ file) + { + std::string::size_type split = file->rfind ('/'); + if (split == std::string::npos) + RCU_THROW_MSG ("file name " + *file + " does not contain a \"/\""); + std::string myname = file->substr (split + 1); + if (myname.empty()) + RCU_THROW_MSG ("file name " + *file + " should not end with a \"/\""); + if (name.empty()) + name = myname; + else if (name != myname) + RCU_THROW_MSG ("inconsistent file names " + name + " and " + myname); + } + } + RCU_ASSERT (!name.empty()); + + files.push_front ("$ROOTCOREBIN/data/RootCoreUtils/download/" + name); + for (std::deque<std::string>::iterator file = files.begin(), + end = files.end(); file != end; ++ file) + { + TString myfile = *file; + gSystem->ExpandPathName (myfile); + *file = myfile.Data(); + } + + for (std::deque<std::string>::const_iterator file = files.begin(), + end = files.end(); file != end; ++ file) + { + if (file->find ("http://") == 0) + { + try + { + Shell::exec ("$ROOTCOREDIR/scripts/download.sh " + Shell::quote (*file) + " " + Shell::quote (files[0])); + return files[0]; + } catch (...) + { + // rationale: ignoring all exceptions, since we might have + // more locations to try + } + } else + { + if (gSystem->AccessPathName (file->c_str()) == 0) + { + return *file; + } + } + } + RCU_THROW_MSG ("failed to find file at " + locations); + return ""; // compiler dummy + } +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/Message.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/Message.cxx new file mode 100644 index 0000000000000000000000000000000000000000..6b84627837249d0a7d24424eb578a61004aa9f20 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/Message.cxx @@ -0,0 +1,109 @@ +// Copyright Nils Krumnack 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/Message.h> + +#include <cstdlib> +#include <cstring> +#include <iostream> +#include <sstream> +#include <RootCoreUtils/Assert.h> +#include <RootCoreUtils/ExceptionMsg.h> +#include <RootCoreUtils/PrintMsg.h> + +// +// method implementations +// + +namespace RCU +{ + Message :: + Message () + : package (0), file (0), line (0), type (MESSAGE_UNSPECIFIED), + message (0) + { + } + + + + void Message :: + send () const + { + MessageType mytype = type; + if (mytype < 0 || mytype > MESSAGE_UNSPECIFIED) + mytype = MESSAGE_UNSPECIFIED; + + std::ostringstream str; + + if (package != 0) + { + str << package << ":"; + } + if (file != 0) + { + if (strncmp (file, "../", 3) == 0) + str << (file+3) << ":"; + else + str << file << ":"; + } + if (line != 0) + str << line << ":"; + + if (mytype != MESSAGE_UNSPECIFIED) + { + static const char *type_names[MESSAGE_UNSPECIFIED] = + {"message", "warning", "error", "exception", "abort"}; + str << type_names[mytype] << ":"; + } + + if (!str.str().empty()) + str << " "; + if (message != 0) + str << message; + else + str << "(null)"; + + const char *envname = 0; + if (mytype == MESSAGE_ABORT) + envname = "ROOTCOREUTILS_ABORT"; + else if (mytype == MESSAGE_EXCEPTION) + envname = "ROOTCOREUTILS_EXCEPTION"; + if (envname) + { + const char *abort_type = getenv (envname); + const MessageType def_type = MESSAGE_EXCEPTION; + + if (abort_type == 0) + { + mytype = def_type; + } else if (strcmp (abort_type, "abort") == 0) + { + mytype = MESSAGE_ABORT; + } else if (strcmp (abort_type, "exception") == 0) + { + mytype = MESSAGE_EXCEPTION; + } else + { + mytype = def_type; + + RCU_WARN_MSG (std::string ("unknown value for ROOTCOREUTILS_ABORT ") + abort_type); + } + } + + std::cout << str.str() << std::endl; + if (mytype == MESSAGE_EXCEPTION) + throw ExceptionMsg (file, line, str.str()); + if (mytype == MESSAGE_ABORT) + std::abort (); + } +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/PrintMsg.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/PrintMsg.cxx new file mode 100644 index 0000000000000000000000000000000000000000..2085e6a92a2111c591db8a85ccb4170bcca0edfc --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/PrintMsg.cxx @@ -0,0 +1,52 @@ +// Copyright Nils Krumnack 2011. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/PrintMsg.h> + +#include <TString.h> +#include <RootCoreUtils/Message.h> + +// +// method implementations +// + +namespace RCU +{ + void send_message (const char *package, const char *file, unsigned line, + MessageType type, const char *msg) + { + Message message; + message.package = package; + message.file = file; + message.line = line; + message.type = type; + message.message = msg; + message.send (); + } + + + + void send_message (const char *package, const char *file, unsigned line, + MessageType type, const std::string& msg) + { + send_message (package, file, line, type, msg.c_str()); + } + + + + void send_message (const char *package, const char *file, unsigned line, + MessageType type, const TString& msg) + { + send_message (package, file, line, type, msg.Data()); + } +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/RootUtils.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/RootUtils.cxx new file mode 100644 index 0000000000000000000000000000000000000000..cd0dd2472ad464ba1a1e1e5bf054f972fa19b5b2 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/RootUtils.cxx @@ -0,0 +1,47 @@ +// Copyright Nils Krumnack 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/RootUtils.h> + +#include <TDirectory.h> +#include <TH1.h> +#include <TTree.h> +#include <RootCoreUtils/Assert.h> + +// +// method implementations +// + +namespace RCU +{ + bool SetDirectory (TObject *object, TDirectory *directory) + { + RCU_ASSERT (object != 0); + + TH1 *const hist = dynamic_cast<TH1*>(object); + if (hist) + { + hist->SetDirectory (directory); + return true; + } + + TTree *const tree = dynamic_cast<TTree*>(object); + if (tree) + { + tree->SetDirectory (directory); + return true; + } + + return false; + } +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/ShellExec.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/ShellExec.cxx new file mode 100644 index 0000000000000000000000000000000000000000..3e3eec5a65f17529af9fe3a33746601e8bd0cade --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/ShellExec.cxx @@ -0,0 +1,80 @@ +// Copyright Nils Krumnack 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/ShellExec.h> + +#include <cstdio> +#include <vector> +#include <TSystem.h> +#include <RootCoreUtils/ThrowMsg.h> + +// +// method implementations +// + +namespace RCU +{ + namespace Shell + { + void exec (const std::string& cmd) + { + if (gSystem->Exec (cmd.c_str()) != 0) + RCU_THROW_MSG ("command failed: " + cmd); + } + + + + std::string exec_read (const std::string& cmd) + { + std::string result; + FILE *pipe = 0; + try + { + std::vector<char> buffer (1024); + size_t read; + + pipe = popen (cmd.c_str(), "r"); + while ((read = fread (&buffer[0], 1, buffer.size(), pipe)) > 0) + { + result.append (&buffer[0], read); + } + } catch (...) + { + if (pipe) + pclose (pipe); + throw; + } + if (pclose (pipe) != 0) + RCU_THROW_MSG ("command failed: " + cmd + "\nwith output:\n" + result); + return result; + } + + + + std::string quote (const std::string& name) + { + std::string result; + for (std::string::const_iterator iter = name.begin(), + end = name.end(); iter != end; ++ iter) + { + if (!isalnum (*iter) && *iter != '/' && *iter != '.' && + *iter != '-') + result += '\\'; + result += *iter; + }; + if (result.empty()) + result = "\"\""; + return result; + } + } +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/StringUtil.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/StringUtil.cxx new file mode 100644 index 0000000000000000000000000000000000000000..392cc28f9a7342c8a75f4a47f0d6f61ef1820393 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/StringUtil.cxx @@ -0,0 +1,73 @@ +// Copyright Nils Krumnack 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/StringUtil.h> + +#include <TRegexp.h> +#include <TString.h> +#include <RootCoreUtils/Assert.h> + +// +// method implementations +// + +namespace RCU +{ + std::string substitute (const std::string& str, const std::string& pattern, + const std::string& with) + { + RCU_REQUIRE (!pattern.empty()); + + std::string result = str; + std::string::size_type pos; + while ((pos = result.find (pattern)) != std::string::npos) + result = result.substr (0, pos) + with + result.substr (pos + pattern.size()); + return result; + } + + + + bool match_expr (const TRegexp& expr, const std::string& str) + { + Ssiz_t len = 0; + TString mystr (str); + return expr.Index (mystr, &len) == 0 && len == mystr.Length(); + } + + + + TString glob_to_regexp (const std::string& glob) + { + TString result; + + for (std::string::const_iterator iter = glob.begin(), + end = glob.end(); iter != end; ++ iter) + { + if (*iter == '*') + { + result += ".*"; + } else if (*iter == '?') + { + result += "."; + } else if (*iter == '^' || *iter == '$' || *iter == '+' || *iter == '.') + { + result += '\\'; + result += *iter; + } else + { + result += *iter; + } + } + return result; + } +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/UnitTestDir.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/UnitTestDir.cxx new file mode 100644 index 0000000000000000000000000000000000000000..f23da16d9a8d2acc855f5064a88c277748caaefd --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/UnitTestDir.cxx @@ -0,0 +1,93 @@ +// Copyright Nils Krumnack 2011 - 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/UnitTestDir.h> + +#include <cstdlib> +#include <TSystem.h> +#include <TString.h> +#include <RootCoreUtils/Assert.h> +#include <RootCoreUtils/ThrowMsg.h> + +// +// method implementations +// + +namespace RCU +{ + void UnitTestDir :: + testInvariant () const + { + RCU_INVARIANT (this != 0); + } + + + + UnitTestDir :: + UnitTestDir (const std::string& package, const std::string& name) + : m_cleanup (getenv ("ROOTCORE_AUTO_UT") != 0) + { + TString output = "/tmp"; + { + const char *tmpdir = getenv ("TMPDIR"); + if (tmpdir) + output = tmpdir; + }; + output += ("/ut-" + package + "-" + name + ".$$").c_str(); + gSystem->ExpandPathName (output); + m_path = output.Data (); + + if (gSystem->MakeDirectory (output.Data()) != 0) + RCU_THROW_MSG (("could not create output directory " + output).Data()); + } + + + + UnitTestDir :: + ~UnitTestDir () + { + RCU_DESTROY_INVARIANT (this); + + if (m_cleanup) + gSystem->Exec (("rm -rf " + m_path).c_str()); + else + RCU_PRINT_MSG ("unit test data located at " + m_path); + } + + + + const std::string& UnitTestDir :: + path () const + { + RCU_READ_INVARIANT (this); + return m_path; + } + + + + bool UnitTestDir :: + cleanup () const + { + RCU_READ_INVARIANT (this); + return m_cleanup; + } + + + + void UnitTestDir :: + cleanup (bool val_cleanup) + { + RCU_CHANGE_INVARIANT (this); + m_cleanup = val_cleanup; + } +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/hadd.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/hadd.cxx new file mode 100644 index 0000000000000000000000000000000000000000..c5febb6ee047cc93b60c48940d7ffc4aa0ac0964 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/Root/hadd.cxx @@ -0,0 +1,90 @@ +// Copyright Nils Krumnack 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/hadd.h> + +#include <sstream> +#include <TFileMerger.h> +#include <TList.h> +#include <TSystem.h> +#include <RootCoreUtils/Assert.h> +#include <RootCoreUtils/PrintMsg.h> + +// +// method implementations +// + +namespace RCU +{ + void hadd (std::string output_file, + std::vector<std::string> input_files, + unsigned max_files) + { + std::ostringstream cmd; + cmd << "$ROOTCOREBIN/user_scripts/RootCoreUtils/rcu_hadd " << max_files + << " " << output_file; + for (std::vector<std::string>::const_iterator input = input_files.begin(), + end = input_files.end(); input != end; ++ input) + { + cmd << " " << *input; + } + int result = gSystem->Exec (cmd.str().c_str()); + if (result != 0) + RCU_THROW_MSG ("failed to make merged file: " + output_file); + } + + + + void hadd_core (std::string output_file, + std::vector<std::string> input_files, + unsigned max_files) + { + TFileMerger merger (false, false); + + merger.SetMsgPrefix ("rcu_hadd"); + merger.SetPrintLevel (98); + + if (max_files > 0) + { + merger.SetMaxOpenedFiles (max_files); + } + + if (!merger.OutputFile (output_file.c_str(), false, 1) ) + { + RCU_THROW_MSG ("error opening target file: " + output_file); + } + + for (std::vector<std::string>::const_iterator input = input_files.begin(), + end = input_files.end(); input != end; ++ input) + { + if (!merger.AddFile (input->c_str())) + { + RCU_THROW_MSG ("error adding input file: " + *input); + } + } + merger.SetNotrees (false); + + bool status = merger.Merge(); + + if (status) + { + std::ostringstream msg; + msg << "merged " << merger.GetMergeList()->GetEntries() + << " input files into " << output_file; + RCU_PRINT_MSG (msg.str()); + } else + { + RCU_THROW_MSG ("hadd failure during the merge"); + } + } +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Assert.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Assert.h new file mode 100644 index 0000000000000000000000000000000000000000..39595ec546dedeac41ab96bcc3b0c0ca4cf14f98 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Assert.h @@ -0,0 +1,330 @@ +#ifndef ROOT_CORE_UTILS__ASSERT_H +#define ROOT_CORE_UTILS__ASSERT_H + +// Copyright Nils Krumnack 2010 - 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +/// This module defines a variety of assert style macros. 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 + + + + + +//protect +#include <RootCoreUtils/Global.h> + +namespace RCU +{ + namespace Check + { + enum Type + { + /// regular old style assertion + assert_soft, + assert_hard, + assert_noimp, + + /// function parameter requirement + require_soft, + require_hard, + require_noimp, + + /// function postcondition + provide_soft, + provide_hard, + provide_noimp, + + /// invariant violation + invariant + }; + const int typeNum = invariant + 1; + extern const char *typeLiteral [typeNum]; + extern bool typeAbort [typeNum]; + + + /// effects: report the error and abort either by exception or + /// assert like + /// guarantee: all-fail + /// failures: as requested + /// requires: file != 0 + /// requires: line != 0 + /// requires: type < typeNum + /// requires: error != 0 + /// availability: experts only + void fail (const char *package, const char *file, unsigned line, + Type type, const char *error); + + + /// effects: apply the test invariant method on an object + /// guarantee: no-fail + /// availability: experts only + /// rationale: this is a templated wrapper for the class specific + /// invariant testers + typedef void (*TestInvariantFunction) (const void *object); + template<class T> void + testInvariantVoid (const void *object) + { + static_cast<const T *>(object)->testInvariant (); + } + + + + struct TestInvariant + { + /// availability: experts only + /// description: this class will perform an invariant test as + /// the object goes in and out of scope. + + TestInvariant (TestInvariantFunction function, + const void *object); + ~TestInvariant (); + + private: + TestInvariantFunction m_function; + const void *m_object; + }; + + + + /// effects: create the right invariant testing object + /// returns: the tester + template<class T> inline TestInvariant invariant_tester (T *object) + { + return TestInvariant (testInvariantVoid<T>, object); + } + } +} + + + + + +#ifndef ROOTCORE_PACKAGE +#define ROOTCORE_PACKAGE 0 +#endif + +/// effects: perform a check +/// guarantee: strong +/// failures: !condition +#define RCU_CHECK(type,condition,message) \ + (condition) ? (void) 0 : ::RCU::Check::fail (ROOTCORE_PACKAGE, __FILE__, __LINE__, ::RCU::Check::type, message) + +/// effects: join together two tokens +#define RCU_CHECK_JOIN2(a,b) RCU_CHECK_JOIN2_HIDDEN(a,b) +#define RCU_CHECK_JOIN2_HIDDEN(a,b) a ## b + + + +#define RCU_REQUIRE_SOFT(x) \ + RCU_CHECK (require_soft, x, #x) +#define RCU_REQUIRE2_SOFT(x,y) \ + RCU_CHECK (require_soft, x, y) +#define RCU_REQUIRE0_SOFT(y) \ + RCU_CHECK (require_soft, 0, y) + +#define RCU_PROVIDE_SOFT(x) \ + RCU_CHECK (provide_soft, x, #x) +#define RCU_PROVIDE2_SOFT(x,y) \ + RCU_CHECK (provide_soft, x, y) +#define RCU_PROVIDE0_SOFT(y) \ + RCU_CHECK (provide_soft, 0, y) + +#define RCU_ASSERT_SOFT(x) \ + RCU_CHECK (assert_soft, x, #x) +#define RCU_ASSERT2_SOFT(x,y) \ + RCU_CHECK (assert_soft, x, y) +#define RCU_ASSERT0_SOFT(y) \ + RCU_CHECK (assert_soft, 0, y) + + + +#define RCU_REQUIRE_NOIMP(x) \ + RCU_CHECK (require_noimp, x, #x) +#define RCU_REQUIRE2_NOIMP(x,y) \ + RCU_CHECK (require_noimp, x, y) +#define RCU_REQUIRE0_NOIMP(y) \ + RCU_CHECK (require_noimp, 0, y) + +#define RCU_PROVIDE_NOIMP(x) \ + RCU_CHECK (provide_noimp, x, #x) +#define RCU_PROVIDE2_NOIMP(x,y) \ + RCU_CHECK (provide_noimp, x, y) +#define RCU_PROVIDE0_NOIMP(y) \ + RCU_CHECK (provide_noimp, 0, y) + +#define RCU_ASSERT_NOIMP(x) \ + RCU_CHECK (assert_noimp, x, #x) +#define RCU_ASSERT2_NOIMP(x,y) \ + RCU_CHECK (assert_noimp, x, y) +#define RCU_ASSERT0_NOIMP(y) \ + RCU_CHECK (assert_noimp, 0, y) + + + +#ifndef NDEBUG + +#define RCU_INVARIANT(x) \ + RCU_CHECK (invariant, x, #x) +#define RCU_INVARIANT2(x,y) \ + RCU_CHECK (invariant, x, y) +#define RCU_INVARIANT0(y) \ + RCU_CHECK (invariant, 0, y) + +#define RCU_REQUIRE(x) \ + RCU_CHECK (require_hard, x, #x) +#define RCU_REQUIRE2(x,y) \ + RCU_CHECK (require_hard, x, y) +#define RCU_REQUIRE0(y) \ + RCU_CHECK (require_hard, 0, y) + +#define RCU_PROVIDE(x) \ + RCU_CHECK (provide_hard, x, #x) +#define RCU_PROVIDE2(x,y) \ + RCU_CHECK (provide_hard, x, y) +#define RCU_PROVIDE0(y) \ + RCU_CHECK (provide_hard, 0, y) + +#define RCU_ASSERT(x) \ + RCU_CHECK (assert_hard, x, #x) +#define RCU_ASSERT2(x,y) \ + RCU_CHECK (assert_hard, x, y) +#define RCU_ASSERT0(y) \ + RCU_CHECK (assert_hard, 0, y) + +#define RCU_READ_INVARIANT(x) \ + (x)->testInvariant () +#define RCU_CHANGE_INVARIANT(x) \ + ::RCU::Check::TestInvariant RCU_CHECK_JOIN2 (invariant, __LINE__) = ::RCU::Check::invariant_tester (x); +#define RCU_NEW_INVARIANT(x) \ + (x)->testInvariant () +#define RCU_DESTROY_INVARIANT(x) \ + (x)->testInvariant () + + + +#else + +#define RCU_INVARIANT(x) \ + (void) 0 +#define RCU_INVARIANT2(x,y) \ + (void) 0 +#define RCU_INVARIANT0(y) \ + (void) 0 +#define RCU_REQUIRE(x) \ + (void) 0 +#define RCU_REQUIRE2(x,y) \ + (void) 0 +#define RCU_REQUIRE0(y) \ + (void) 0 +#define RCU_PROVIDE(x) \ + (void) 0 +#define RCU_PROVIDE2(x,y) \ + (void) 0 +#define RCU_PROVIDE0(y) \ + (void) 0 +#define RCU_ASSERT(x) \ + (void) 0 +#define RCU_ASSERT2(x,y) \ + (void) 0 +#define RCU_ASSERT0(y) \ + (void) 0 +#define RCU_READ_INVARIANT(x) \ + (void) 0 +#define RCU_CHANGE_INVARIANT(x) \ + (void) 0 +#define RCU_NEW_INVARIANT(x) \ + (void) 0 +#define RCU_DESTROY_INVARIANT(x) \ + (void) 0 + +#endif + + + + + +#ifdef RCU_DEBUG_SLOW + +#define RCU_REQUIRE_SLOW(x) \ + RCU_REQUIRE(x) +#define RCU_REQUIRE2_SLOW(x,y) \ + RCU_REQUIRE2(x,y) +#define RCU_PROVIDE_SLOW(x) \ + RCU_PROVIDE(x) +#define RCU_PROVIDE2_SLOW(x,y) \ + RCU_PROVIDE2(x,y) +#define RCU_ASSERT_SLOW(x) \ + RCU_ASSERT(x) +#define RCU_ASSERT2_SLOW(x,y) \ + RCU_ASSERT2(x,y) +#define RCU_READ_INVARIANT_SLOW(x) \ + RCU_READ_INVARIANT (x) +#define RCU_CHANGE_INVARIANT_SLOW(x) \ + RCU_CHANGE_INVARIANT (x) +#define RCU_NEW_INVARIANT_SLOW(x) \ + RCU_NEW_INVARIANT (x) +#define RCU_DESTROY_INVARIANT_SLOW(x) \ + RCU_DESTROY_INVARIANT (x) + +#else + +#define RCU_REQUIRE_SLOW(x) \ + (void) 0 +#define RCU_REQUIRE2_SLOW(x,y) \ + (void) 0 +#define RCU_PROVIDE_SLOW(x) \ + (void) 0 +#define RCU_PROVIDE2_SLOW(x,y) \ + (void) 0 +#define RCU_ASSERT_SLOW(x) \ + (void) 0 +#define RCU_ASSERT2_SLOW(x,y) \ + (void) 0 +#define RCU_READ_INVARIANT_SLOW(x) \ + (void) 0 +#define RCU_CHANGE_INVARIANT_SLOW(x) \ + (void) 0 +#define RCU_NEW_INVARIANT_SLOW(x) \ + (void) 0 +#define RCU_DESTROY_INVARIANT_SLOW(x) \ + (void) 0 + +#endif + + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/CheckRootVersion.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/CheckRootVersion.h new file mode 100644 index 0000000000000000000000000000000000000000..30523d4e0703212bb5f2af3f725bbd7664f8c20b --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/CheckRootVersion.h @@ -0,0 +1,34 @@ +#ifndef ROOT_CORE_UTILS__CHECK_ROOT_VERSION_H +#define ROOT_CORE_UTILS__CHECK_ROOT_VERSION_H + +// Copyright Iowa State University 2013. +// Author: Nils Krumnack +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (nils.erik.krumnack@cern.ch) for bug +// reports, feature suggestions, praise and complaints. + + +// This module still needs to be documented. The interface provided +// in this module is intended for experts only. The module is +// considered to be in the pre-alpha stage. + + + +#include <RootCoreUtils/Global.h> + +namespace RCU +{ + /// effects: check whether we are using a consistent root version + /// guarantee: strong + /// failures: version missmatch + void check_root_version (); + + /// effects: disable the root version check + /// guarantee: no-fail + void disable_root_version_check (); +} + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ExceptionMsg.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ExceptionMsg.h new file mode 100644 index 0000000000000000000000000000000000000000..a0c7276cf5abf1e23f72b774c4989ede3e446ef5 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ExceptionMsg.h @@ -0,0 +1,85 @@ +#ifndef ROOT_CORE_UTILS__EXCEPTION_MSG_H +#define ROOT_CORE_UTILS__EXCEPTION_MSG_H + +// Copyright Nils Krumnack 2008 - 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// This module defines an exception that contains nothing more than an +// error message. The interface provided in this module is intended +// for the general user. The module is considered to be in the +// pre-alpha stage. + + + +//protect +#include <RootCoreUtils/Global.h> + +#include <exception> +#include <string> + +namespace RCU +{ + class ExceptionMsg : public std::exception + { + // + // public interface + // + + // effects: test the invariant of this object + // guarantee: no-fail + public: + void testInvariant () const; + + + // effects: create an exception with the given message + // guarantee: strong + // failures: out of memory II + // requires: val_file != 0 + // requires: val_line != 0 + // requires: !val_message.empty() + public: + ExceptionMsg (const char *const val_file, const unsigned val_line, + const std::string& val_message); + + + // effects: destroy this object + // guarantee: no-fail + public: + virtual ~ExceptionMsg () throw (); + + + + // + // interface inherited from std::exception + // + + // returns: the message associated with this exception + // guarantee: no-fail + public: + virtual const char *what () const throw (); + + + + // + // private interface + // + + /// description: the location where the message occured + private: + const char *m_file; + private: + unsigned m_line; + + /// description: the actual message + private: + std::string m_message; + }; +} + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Global.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Global.h new file mode 100644 index 0000000000000000000000000000000000000000..1136d3471f01b07dea21d6e9750956009a06eef7 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Global.h @@ -0,0 +1,26 @@ +#ifndef ROOT_CORE_UTILS__GLOBAL_H +#define ROOT_CORE_UTILS__GLOBAL_H + +// Copyright Nils Krumnack 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +/// This module provides a lot of global definitions, forward +/// declarations and includes that are used by all modules. As such it +/// doesn't fall into the user vs. expert classification. + +namespace RCU +{ + class ExceptionMsg; + struct Message; + class UnitTestDir; + + namespace Shell {} +} + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Locate.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Locate.h new file mode 100644 index 0000000000000000000000000000000000000000..1519453f319e0b3d776d02cbf71b272806c6af77 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Locate.h @@ -0,0 +1,42 @@ +#ifndef ROOT_CORE_UTILS__LOCATE_H +#define ROOT_CORE_UTILS__LOCATE_H + +// Copyright Nils Krumnack 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// This module still needs to be documented. The interface provided +// in this module is intended for experts only. The module is +// considered to be in the pre-alpha stage. + + + +#include <RootCoreUtils/Global.h> + +#include <string> + +namespace RCU +{ + /// 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. + std::string locate (const std::string& locations); +} + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Message.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Message.h new file mode 100644 index 0000000000000000000000000000000000000000..a3a1b643853706c3181b1f4a879a3442839d7e2f --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/Message.h @@ -0,0 +1,63 @@ +#ifndef ROOT_CORE_UTILS__MESSAGE_H +#define ROOT_CORE_UTILS__MESSAGE_H + +// Copyright Nils Krumnack 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// This module still needs to be documented. The interface provided +// in this module is intended for experts only. The module is +// considered to be in the pre-alpha stage. + + + +#include <RootCoreUtils/Global.h> + +#include <RootCoreUtils/MessageType.h> + +namespace RCU +{ + struct Message + { + // + // public interface + // + + /// description: the location where the message was send + public: + const char *package; + public: + const char *file; + public: + unsigned line; + + /// description: the type of this message + public: + MessageType type; + + /// description: the actual message we are sending or 0 if there + /// isn't one + public: + const char *message; + + + /// effects: standard constructor + /// guarantee: no-fail + public: + Message (); + + + /// effects: print the given message + /// guarantee: basic + /// failures: i/o errors + public: + void send () const; + }; +} + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/MessageType.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/MessageType.h new file mode 100644 index 0000000000000000000000000000000000000000..f528cbe64682d13716fc8a61f116c725106b60b9 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/MessageType.h @@ -0,0 +1,45 @@ +#ifndef ROOT_CORE_UTILS__MESSAGE_TYPE_H +#define ROOT_CORE_UTILS__MESSAGE_TYPE_H + +// Copyright Nils Krumnack 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +/// This module defines macros for reporting errors. The interface in +/// this module is indended for experts only. This module is +/// considered to be in the pre-alpha stage. + + + +#include <RootCoreUtils/Global.h> + +namespace RCU +{ + enum MessageType + { + /// description: print a regular message + MESSAGE_REGULAR, + + /// description: print a warning + MESSAGE_WARNING, + + /// description: print an error + MESSAGE_ERROR, + + /// description: send out an exception + MESSAGE_EXCEPTION, + + /// description: print and abort + MESSAGE_ABORT, + + /// description: unspecified message type + MESSAGE_UNSPECIFIED + }; +} + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/PrintMsg.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/PrintMsg.h new file mode 100644 index 0000000000000000000000000000000000000000..d2ef773550b6aae35764bd63dd92790146bd3a74 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/PrintMsg.h @@ -0,0 +1,52 @@ +#ifndef ROOT_CORE_UTILS__PRINT_MSG_H +#define ROOT_CORE_UTILS__PRINT_MSG_H + +// Copyright Nils Krumnack 2011 - 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +/// This module defines macros for reporting errors. The interface in +/// this module is indended for experts only. This module is +/// considered to be in the pre-alpha stage. + + + +#include <RootCoreUtils/Global.h> + +#include <string> +#include <RootCoreUtils/MessageType.h> + +class TString; + +namespace RCU +{ + 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); +} + +#ifndef ROOTCORE_PACKAGE +#define ROOTCORE_PACKAGE 0 +#endif + +#define RCU_PRINT_MSG(message) \ + ::RCU::send_message (ROOTCORE_PACKAGE, __FILE__, __LINE__, ::RCU::MESSAGE_REGULAR, (message)); + +#define RCU_WARN_MSG(message) \ + ::RCU::send_message (ROOTCORE_PACKAGE, __FILE__, __LINE__, ::RCU::MESSAGE_WARNING, (message)); + +#define RCU_ERROR_MSG(message) \ + ::RCU::send_message (ROOTCORE_PACKAGE, __FILE__, __LINE__, ::RCU::MESSAGE_ERROR, (message)); + +#define RCU_THROW_MSG(message) \ + ::RCU::send_message (ROOTCORE_PACKAGE, __FILE__, __LINE__, ::RCU::MESSAGE_EXCEPTION, (message)); + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/RootUtils.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/RootUtils.h new file mode 100644 index 0000000000000000000000000000000000000000..5db132608aeefcc5104743cfd00fcaeebd0e5f79 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/RootUtils.h @@ -0,0 +1,40 @@ +#ifndef ROOT_CORE_UTILS__ROOT_UTILS_H +#define ROOT_CORE_UTILS__ROOT_UTILS_H + +// Copyright Nils Krumnack 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +/// This module defines simple utility functions for root. The +/// interface in this module is indended for experts only. This +/// module is considered to be in the pre-alpha stage. + + + +#include <RootCoreUtils/Global.h> + +class TDirectory; +class TObject; + +namespace RCU +{ + /// 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. + bool SetDirectory (TObject *object, TDirectory *directory); +} + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ShellExec.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ShellExec.h new file mode 100644 index 0000000000000000000000000000000000000000..b977dec847ebb4acdc19ec3b9f307a4ae3ba30bb --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ShellExec.h @@ -0,0 +1,52 @@ +#ifndef ROOT_CORE_UTILS__SHELL_EXEC_H +#define ROOT_CORE_UTILS__SHELL_EXEC_H + +// Copyright Nils Krumnack 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// This module still needs to be documented. The interface provided +// in this module is intended for experts only. The module is +// considered to be in the pre-alpha stage. + + + +#include <RootCoreUtils/Global.h> + +#include <string> + +namespace RCU +{ + namespace Shell + { + /// effects: execute the given command + /// guarantee: strong + /// failures: out of memory II + /// failures: system failure + /// failures: command failure + void exec (const std::string& cmd); + + + /// effects: execute the given command and return the output + /// returns: the output of the command + /// guarantee: strong + /// failures: out of memory III + /// failures: system failure + /// failures: command failure + std::string exec_read (const std::string& cmd); + + + /// effects: quote the given name to protect it from the shell + /// returns: the quoted name + /// guarantee: strong + /// failures: out of memory II + std::string quote (const std::string& name); + } +} + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/StringUtil.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/StringUtil.h new file mode 100644 index 0000000000000000000000000000000000000000..5888ec74afdac05ba353e4f34f168ec00da678c7 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/StringUtil.h @@ -0,0 +1,53 @@ +#ifndef ROOT_CORE_UTILS__STRING_UTIL_H +#define ROOT_CORE_UTILS__STRING_UTIL_H + +// Copyright Nils Krumnack 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// This module still needs to be documented. The interface provided +// in this module is intended for experts only. The module is +// considered to be in the pre-alpha stage. + + + +#include <RootCoreUtils/Global.h> + +#include <string> + +class TRegexp; +class TString; + +namespace RCU +{ + /// effects: substitute all occurences of "pattern" with "with" in + /// the string "str" + /// returns: the substituted string + /// guarantee: out of memory II + /// requires: !pattern.empty() + std::string substitute (const std::string& str, const std::string& pattern, + const std::string& with); + + + /// returns: whether we can match the entire string with the regular + /// expression + /// guarantee: strong + /// failures: out of memory II + bool match_expr (const TRegexp& expr, const std::string& str); + + + /// 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 + TString glob_to_regexp (const std::string& glob); +} + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ThrowMsg.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ThrowMsg.h new file mode 100644 index 0000000000000000000000000000000000000000..bb28d74723af353b2f178ed933ede53fbd0810be --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/ThrowMsg.h @@ -0,0 +1,23 @@ +#ifndef ROOT_CORE_UTILS__THROW_MSG_H +#define ROOT_CORE_UTILS__THROW_MSG_H + +// Copyright Nils Krumnack 2011 - 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +/// This module defines macros for reporting errors. The interface in +/// this module is indended for experts only. This module is +/// considered to be in the pre-alpha stage. + + + +#include <RootCoreUtils/Global.h> + +#include <RootCoreUtils/PrintMsg.h> + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/UnitTestDir.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/UnitTestDir.h new file mode 100644 index 0000000000000000000000000000000000000000..d1aaf20045406e7b22fc4535fef3b4ef9070475c --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/UnitTestDir.h @@ -0,0 +1,84 @@ +#ifndef ROOT_CORE_UTILS_UNIT_TEST_DIR_HH +#define ROOT_CORE_UTILS_UNIT_TEST_DIR_HH + +// Copyright Nils Krumnack 2011 - 2012. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +/// This module defines a class that manages a temporary directory for +/// unit tests. The interface provided in this module is intended for +/// experts only. The module is considered to be in the pre-alpha +/// stage. + + + +#include <RootCoreUtils/Global.h> + +#include <string> + +namespace RCU +{ + class UnitTestDir + { + // + // public interface + // + + /// effects: test the invariant of this object + /// guarantee: no-fail + public: + void testInvariant () const; + + + /// effects: standard constructor + /// guarantee: strong + /// failures: out of memory + /// failures: directory creation errors + public: + UnitTestDir (const std::string& package, const std::string& name); + + + /// rationale: I'm making these private to avoid copying + private: + UnitTestDir (const UnitTestDir&); + UnitTestDir& operator = (const UnitTestDir&); + + + /// effects: standard destructor + /// guarantee: no-fail + public: + ~UnitTestDir (); + + + /// description: the path to the directory + /// guarantee: no-fail + public: + const std::string& path () const; + + + /// description: whether we clean up on completion + /// guarantee: no-fail + public: + bool cleanup () const; + void cleanup (bool val_cleanup); + + + + // + // private interface + // + + /// description: members directly corresponding to accessors + private: + std::string m_path; + private: + bool m_cleanup; + }; +} + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/hadd.h b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/hadd.h new file mode 100644 index 0000000000000000000000000000000000000000..6c5b3d752fbcebeb2c632edba779fb961338e1f7 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/RootCoreUtils/hadd.h @@ -0,0 +1,38 @@ +#ifndef ROOT_CORE_UTILS__HADD_H +#define ROOT_CORE_UTILS__HADD_H + +// Copyright Nils Krumnack 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +#include <RootCoreUtils/Global.h> + +#include <string> +#include <vector> + +namespace RCU +{ + /// effects: perform the hadd functionality + /// guarantee: basic + /// failures: out of memory III + /// failures: i/o errors + void hadd (std::string output_file, + std::vector<std::string> input_files, + unsigned max_files = 0); + + + /// effects: perform the core hadd functionality + /// guarantee: basic + /// failures: out of memory III + /// failures: i/o errors + void hadd_core (std::string output_file, + std::vector<std::string> input_files, + unsigned max_files); +} + +#endif diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/cmt/Makefile.RootCore b/PhysicsAnalysis/D3PDTools/RootCoreUtils/cmt/Makefile.RootCore new file mode 100644 index 0000000000000000000000000000000000000000..23eab9580ad26adf6017c3f14f5b891e06d87b1d --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/cmt/Makefile.RootCore @@ -0,0 +1,19 @@ +# this makefile also gets parsed by shell scripts +# therefore it does not support full make syntax and features +# edit with care + +PACKAGE = RootCoreUtils +PACKAGE_PRELOAD = Hist Tree +PACKAGE_CXXFLAGS = +PACKAGE_OBJFLAGS = +PACKAGE_LDFLAGS = +PACKAGE_BINFLAGS = +PACKAGE_DEP = +PACKAGE_TRYDEP = +PACKAGE_CLEAN = +PACKAGE_NOGRID = data/download +PACKAGE_PEDANTIC = 1 +PACKAGE_NOOPT = 0 +PACKAGE_NOCC = 0 + +include $(ROOTCOREDIR)/Makefile-common diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/cmt/requirements b/PhysicsAnalysis/D3PDTools/RootCoreUtils/cmt/requirements new file mode 100644 index 0000000000000000000000000000000000000000..7e8a99f2083cd508660ae95b946c6ca0a14a5137 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/cmt/requirements @@ -0,0 +1,23 @@ +## automatically generated CMT requirements file +package RootCoreUtils +author cburgard + +## for athena policies: this has to be the first use statement +use AtlasPolicy AtlasPolicy-* +use AtlasROOT AtlasROOT-* External + +## for gaudi tools, services and objects + +## put here your package dependencies... + +## + +branches Root + +# create an installed library, i.e., one where others can inherit from +library RootCoreUtils ../Root/*.cxx +apply_pattern installed_library + +private +use AtlasROOT AtlasROOT-* External +end_private diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/scripts/rcu_hadd b/PhysicsAnalysis/D3PDTools/RootCoreUtils/scripts/rcu_hadd new file mode 100755 index 0000000000000000000000000000000000000000..06caf30d792a3bf3c4d0a217f2c63e56239061aa --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/scripts/rcu_hadd @@ -0,0 +1,16 @@ +#!/bin/bash + +set -e +set -u + +max_files=$1 +shift +output_file=$1 +shift + +for file in "$@" +do + echo $file +done | root -l -b -q "$ROOTCOREBIN/user_scripts/RootCoreUtils/rcu_hadd.C ($max_files, "\""$output_file"\"")" + +test -f "$output_file" diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/scripts/rcu_hadd.C b/PhysicsAnalysis/D3PDTools/RootCoreUtils/scripts/rcu_hadd.C new file mode 100644 index 0000000000000000000000000000000000000000..a740e2fc1cb5dc7e1eeb17ffb036d593eb0dcd7f --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/scripts/rcu_hadd.C @@ -0,0 +1,13 @@ +void rcu_hadd (unsigned max_files, std::string output_file) +{ + // load the libraries for all packages + gROOT->ProcessLine(".x $ROOTCOREDIR/scripts/load_packages.C"); + + // read the input files from standard input + std::vector<std::string> input_files; + std::string line; + while (std::getline (std::cin, line)) + input_files.push_back (line); + + RCU::hadd_core (output_file, input_files, max_files); +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/test/test_message_svc.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/test/test_message_svc.cxx new file mode 100644 index 0000000000000000000000000000000000000000..a454388fb035c961535a2dc09afd96d60f3d45e0 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/test/test_message_svc.cxx @@ -0,0 +1,37 @@ +// Copyright Nils Krumnack 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/Global.h> + +#include <iostream> +#include <RootCoreUtils/Assert.h> +#include <RootCoreUtils/PrintMsg.h> + +// +// method implementations +// + +int main () +{ + RCU_PRINT_MSG ("print message"); + RCU_WARN_MSG ("warn message"); + RCU_ERROR_MSG ("error message"); + try + { + RCU_THROW_MSG ("throw message"); + } catch (std::exception& e) + { + std::cout << "caught: " << e.what() << std::endl; + } + RCU_ASSERT (false); +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/test/ut_expression.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/test/ut_expression.cxx new file mode 100644 index 0000000000000000000000000000000000000000..e90999b0f434093069ebe079d9c833205f72a178 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/test/ut_expression.cxx @@ -0,0 +1,34 @@ +// Copyright Nils Krumnack 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/Global.h> + +#include <TRegexp.h> +#include <TString.h> +#include <RootCoreUtils/Assert.h> +#include <RootCoreUtils/StringUtil.h> + +// +// main program +// + +using namespace RCU; + +int main () +{ + RCU_ASSERT_SOFT (match_expr (TRegexp (".*\\.root.*"), "test.root_4")); + RCU_ASSERT_SOFT (!match_expr (TRegexp (".*\\.root.*"), "test.asdroot_4")); + RCU_ASSERT_SOFT (!match_expr (TRegexp (".*\\.root"), "test.root_4")); + RCU_ASSERT_SOFT (match_expr (TRegexp (glob_to_regexp ("*.root*")), "test.root_4")); + RCU_ASSERT_SOFT (!match_expr (TRegexp (glob_to_regexp ("*.root*")), "test.asdroot_4")); +} diff --git a/PhysicsAnalysis/D3PDTools/RootCoreUtils/util/rcu_locate.cxx b/PhysicsAnalysis/D3PDTools/RootCoreUtils/util/rcu_locate.cxx new file mode 100644 index 0000000000000000000000000000000000000000..d42ca90cc5c20385cbd1eb23cbfb08ca953ef481 --- /dev/null +++ b/PhysicsAnalysis/D3PDTools/RootCoreUtils/util/rcu_locate.cxx @@ -0,0 +1,33 @@ +// Copyright Nils Krumnack 2013. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +// Please feel free to contact me (krumnack@iastate.edu) for bug +// reports, feature suggestions, praise and complaints. + + +// +// includes +// + +#include <RootCoreUtils/Global.h> + +#include <iostream> +#include <RootCoreUtils/Locate.h> + +// +// method implementations +// + +int main (int argc, char **argv) +{ + if (argc != 2) + { + std::cerr << "usage: " << argv[0] << " locations" << std::endl; + return 1; + } + + std::cout << RCU::locate (argv[1]) << std::endl; + return 0; +}