Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F8723390
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Subscribers
None
View Options
diff --git a/Utilities/DebugItem.cc b/Utilities/DebugItem.cc
new file mode 100644
--- /dev/null
+++ b/Utilities/DebugItem.cc
@@ -0,0 +1,71 @@
+// -*- C++ -*-
+//
+// This is the implementation of the non-inlined, non-templated member
+// functions of the DebugItem class.
+//
+
+#include "DebugItem.h"
+#include "ThePEG/Utilities/Debug.h"
+
+using namespace ThePEG;
+
+DebugItem::DebugItem(string itemname): debug(false) {
+ items()[itemname] = this;
+ map<string,long>::iterator it = nametics().find(itemname);
+ if ( it != nametics().end() ) {
+ if ( ticker() >= it->second ) debug = true;
+ else itemtics().insert(make_pair(it->second, this));
+ } else {
+ itemname = itemname.substr(0, itemname.rfind("::")) + "::all";
+ it = nametics().find(itemname);
+ if ( it != nametics().end() ) {
+ if ( ticker() >= it->second ) debug = true;
+ else itemtics().insert(make_pair(it->second, this));
+ }
+ }
+}
+
+void DebugItem::tic() {
+ ticker()++;
+ multimap<long,DebugItem*>::iterator it = itemtics().begin();
+ while ( it != itemtics().end() &&
+ ticker() >= it->first ) (it++)->second->debug = true;
+ itemtics().erase(itemtics().begin(), it);
+}
+
+void DebugItem::setDebugItem(string itemname, long after) {
+ nametics()[itemname] = after;
+ map<string,DebugItem*>::iterator it = items().find(itemname);
+ if ( it != items().end() ) {
+ if ( ticker() >= after ) it->second->debug = true;
+ else itemtics().insert(make_pair(after, it->second));
+ } else if ( itemname.substr(itemname.length() - 5) == "::all" ) {
+ itemname = itemname.substr(itemname.length() - 3);
+ for ( map<string,DebugItem*>::iterator it = items().begin();
+ it != items().end(); ++it )
+ if ( it->first.substr(0, itemname.length()) == itemname ) {
+ if ( ticker() >= after ) it->second->debug = true;
+ else itemtics().insert(make_pair(after, it->second));
+ }
+ }
+}
+
+long & DebugItem::ticker() {
+ static long tics = 0;
+ return tics;
+}
+
+map<string,DebugItem*> & DebugItem::items() {
+ static map<string,DebugItem*> itemmap;
+ return itemmap;
+}
+
+multimap<long,DebugItem*> & DebugItem::itemtics() {
+ static multimap<long,DebugItem*> itemmap;
+ return itemmap;
+}
+
+map<string,long> & DebugItem::nametics() {
+ static map<string,long> namemap;
+ return namemap;
+}
diff --git a/Utilities/DebugItem.h b/Utilities/DebugItem.h
new file mode 100644
--- /dev/null
+++ b/Utilities/DebugItem.h
@@ -0,0 +1,100 @@
+// -*- C++ -*-
+#ifndef ThePEG_DebugItem_H
+#define ThePEG_DebugItem_H
+//
+// This is the declaration of the DebugItem class.
+//
+
+#include "ThePEG/Config/ThePEG.h"
+
+namespace ThePEG {
+
+/**
+ * The DebugItem class can be used to efficiently handle detailed
+ * debug options. The actual objects are used anywhere in a function
+ * where optional debugging should be done. At that point a static
+ * object of DebugItem should be constructed giving a name to be used
+ * (it should be static to ensure that the initialization is only done
+ * once). After that the object is automatically cast to a bool
+ * indicating whether or not debugging has been requested for this
+ * item.
+ */
+class DebugItem {
+
+public:
+
+ /** @name Standard constructors and destructors. */
+ //@{
+ /**
+ * The only relevant constructor. The string should typically be on
+ * the form "namspace::class::function".
+ */
+ DebugItem(string itemname);
+ //@}
+
+public:
+
+ /**
+ * Switch on all DebugItem objects matching the given string. If \a
+ * after is positive delay the DebugItem until that number of tics.
+ */
+ static void setDebugItem(string itemname, long after = 0);
+
+ /**
+ * Advance one tic, opssibly switching on more debug items.
+ */
+ static void tic();
+
+ /**
+ * Cheap way of testing if debugging should be done.
+ */
+ operator bool () const {
+#ifndef ThePEG_NO_DEBUG
+ return debug;
+#else
+ return false;
+#endif
+ }
+
+private:
+
+ /**
+ * Set to true if debugging requested.
+ */
+ bool debug;
+
+ /**
+ * Counter for number of tics.
+ */
+ static long & ticker();
+
+ /**
+ * The DebugItem objects registered, indexed by their name.
+ */
+ static map<string,DebugItem*> & items();
+
+ /**
+ * The DebugItem objects registered, indexed by the tic at which
+ * they should be turned on..
+ */
+ static multimap<long,DebugItem*> & itemtics();
+
+ /**
+ * The DebugItem names registered together with the tic at which it
+ * should be turned on.
+ */
+ static map<string,long> & nametics();
+
+private:
+
+ /**
+ * The assignment operator is private and must never be called.
+ * In fact, it should not even be implemented.
+ */
+ DebugItem & operator=(const DebugItem &);
+
+};
+
+}
+
+#endif /* ThePEG_DebugItem_H */
diff --git a/Utilities/Makefile.am b/Utilities/Makefile.am
--- a/Utilities/Makefile.am
+++ b/Utilities/Makefile.am
@@ -1,30 +1,30 @@
mySOURCES = SimplePhaseSpace.cc Debug.cc DescriptionList.cc Maths.cc \
Direction.cc DynamicLoader.cc StringUtils.cc \
Exception.cc ClassDescription.cc CFileLineReader.cc \
- XSecStat.cc CFile.cc
+ XSecStat.cc CFile.cc DebugItem.cc
DOCFILES = ClassDescription.h ClassTraits.h Debug.h DescriptionList.h \
HoldFlag.h Interval.h Maths.h Rebinder.h Selector.h \
SimplePhaseSpace.h Triplet.h Direction.h UtilityBase.h \
TypeInfo.h DynamicLoader.h UnitIO.h EnumIO.h \
DIterator.h StringUtils.h Exception.h Named.h \
VSelector.h LoopGuard.h ObjectIndexer.h \
CFileLineReader.h CompSelector.h XSecStat.h Throw.h MaxCmp.h \
- Level.h Current.h CFile.h DescribeClass.h
+ Level.h Current.h CFile.h DescribeClass.h DebugItem.h
INCLUDEFILES = $(DOCFILES) ClassDescription.fh \
Interval.fh Interval.tcc Rebinder.fh \
Selector.tcc SimplePhaseSpace.tcc SimplePhaseSpace.xh \
Direction.xh UtilityBase.tcc \
Exception.fh VSelector.tcc CFileLineReader.fh
noinst_LTLIBRARIES = libThePEGUtilities.la
libThePEGUtilities_la_SOURCES = $(mySOURCES) $(INCLUDEFILES)
libThePEGUtilities_la_CPPFLAGS = $(AM_CPPFLAGS) \
-DTHEPEG_PKGLIBDIR="\"$(pkglibdir)\""
include $(top_srcdir)/Config/Makefile.aminclude
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Jan 20, 8:25 PM (9 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4242221
Default Alt Text
(6 KB)
Attached To
rTHEPEGHG thepeghg
Event Timeline
Log In to Comment