artdaq  v2_03_00
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
InputUtilities.hh
1 #ifndef artdaq_ArtModules_InputUtilities_hh
2 #define artdaq_ArtModules_InputUtilities_hh
3 
4 #include "art/Framework/Core/FileBlock.h"
5 #include "art/Framework/Core/InputSourceMacros.h"
6 #include "art/Framework/Core/ProductRegistryHelper.h"
7 #include "art/Framework/IO/Sources/Source.h"
8 #include "art/Framework/IO/Sources/SourceHelper.h"
9 #include "art/Framework/IO/Sources/SourceTraits.h"
10 #include "art/Framework/Services/Registry/ServiceHandle.h"
11 #include "art/Persistency/Provenance/BranchIDListHelper.h"
12 #include "art/Persistency/Provenance/BranchIDListRegistry.h"
13 #include "art/Persistency/Provenance/MasterProductRegistry.h"
14 #include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
15 #include "art/Persistency/Provenance/ProductMetaData.h"
16 
17 #include "canvas/Persistency/Common/EDProduct.h"
18 #include "canvas/Persistency/Common/Wrapper.h"
19 #include "canvas/Persistency/Provenance/BranchDescription.h"
20 #include "canvas/Persistency/Provenance/BranchIDList.h"
21 #include "canvas/Persistency/Provenance/BranchKey.h"
22 #include "canvas/Persistency/Provenance/History.h"
23 #include "canvas/Persistency/Provenance/ParentageRegistry.h"
24 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
25 #include "canvas/Persistency/Provenance/ProcessHistory.h"
26 #include "canvas/Persistency/Provenance/ProcessHistoryID.h"
27 #include "canvas/Persistency/Provenance/ProductList.h"
28 #include "canvas/Persistency/Provenance/ProductProvenance.h"
29 #include "canvas/Utilities/DebugMacros.h"
30 
31 #include "TBufferFile.h"
32 
33 #include <memory>
34 #include <string>
35 #include <iostream>
36 
37 // JCF, Jul-18-2016
38 
39 // If LOGDEBUG is defined, the TLOG_DEBUG calls will print into the
40 // aggregator logfiles using artdaq v1_13_00; this creates HUGE files
41 // and slows things down considerably, so only define this if you're
42 // troubleshooting
43 //#define LOGDEBUG
44 
45 namespace art
46 {
55  template <typename T>
56  T* ReadObjectAny(const std::unique_ptr<TBufferFile>& infile, const std::string& className, const std::string& callerName)
57  {
58  static TClass* tclassPtr = TClass::GetClass(className.c_str());
59 
60  if (tclassPtr == nullptr)
61  {
62  throw art::Exception(art::errors::DictionaryNotFound) <<
63  callerName << " call to ReadObjectAny: "
64  "Could not get TClass for " << className << "!";
65  }
66 
67  // JCF, May-24-2016
68 
69  // Be aware of the following from the TBufferFile documentation,
70  // concerning TBufferFile::ReadObjectAny:
71 
72  // " In case of multiple inheritance, the return value might not be
73  // the real beginning of the object in memory. You will need to use
74  // a dynamic_cast later if you need to retrieve it."
75 
76  T* ptr = reinterpret_cast<T*>(infile->ReadObjectAny(tclassPtr));
77 #ifdef LOGDEBUG
78  TLOG_DEBUG(callerName) << "ReadObjectAny: Got object of class " << className <<
79  ", located at " << static_cast<void*>(ptr);
80 #endif
81 
82  return ptr;
83  }
84 
91  template <typename T>
92  void printProcessHistoryID(const std::string& label, const T& object)
93  {
94  (void)label; // Otherwise we get an error if LOGDEBUG isn't defined, since description won't be used
95 
96  if (art::debugit() >= 1)
97  {
98  if (object->processHistoryID().isValid())
99  {
100  std::ostringstream OS;
101  object->processHistoryID().print(OS);
102 #ifdef LOGDEBUG
103  TLOG_DEBUG("printProcessHistoryID") << label << ": "
104  << "ProcessHistoryID: '"
105  << OS.str() << "'\n";
106 #endif
107  }
108  else
109  {
110 #ifdef LOGDEBUG
111  TLOG_DEBUG("printProcessHistoryID") << label << ": "
112  << "ProcessHistoryID: 'INVALID'\n";
113 #endif
114  }
115  }
116  }
117 
124  template <typename T>
125  void printProcessMap(const T& mappable, const std::string description)
126  {
127  (void) description; // Otherwise we get an error if LOGDEBUG isn't defined, since description won't be used
128 
129 #ifdef LOGDEBUG
130  TLOG_DEBUG("printProcessMap") << "Got " << description << "\n";
131 #endif
132 
133  if (art::debugit() >= 1)
134  {
135 #ifdef LOGDEBUG
136  TLOG_DEBUG("printProcessMap") << "Dumping " << description << "...\n";
137  TLOG_DEBUG("printProcessMap") << "Size: "
138  << (unsigned long) mappable.size() << '\n';
139 #endif
140  for (auto I = mappable.begin(), E = mappable.end(); I != E; ++I)
141  {
142  std::ostringstream OS;
143  I->first.print(OS);
144 #ifdef LOGDEBUG
145  TLOG_DEBUG("printProcessMap") << description << ": id: '" << OS.str() << "'\n";
146 #endif
147  OS.str("");
148 #ifdef LOGDEBUG
149  TLOG_DEBUG("printProcessMap") << description << ": data.size(): "
150  << I->second.data().size() << '\n';
151 #endif
152  I->second.data().back().id().print(OS);
153 
154 #ifdef LOGDEBUG
155  TLOG_DEBUG("printProcessMap") << description << ": data.back().id(): '"
156  << OS.str() << "'\n";
157 #endif
158  }
159  }
160  }
161 }
162 
163 
164 #endif
void printProcessHistoryID(const std::string &label, const T &object)
Print the processHistoryID from the object.
void printProcessMap(const T &mappable, const std::string description)
Print data from a map-like class.
T * ReadObjectAny(const std::unique_ptr< TBufferFile > &infile, const std::string &className, const std::string &callerName)
ReadObjectAny reads data from a TBufferFile and casts it to the given type.