artdaq  v2_03_02
 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 #if ART_HEX_VERSION < 0x20703
12 #include "art/Persistency/Provenance/BranchIDListHelper.h"
13 #endif
14 #include "art/Persistency/Provenance/BranchIDListRegistry.h"
15 #include "art/Persistency/Provenance/MasterProductRegistry.h"
16 #include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
17 #include "art/Persistency/Provenance/ProductMetaData.h"
18 
19 #include "canvas/Persistency/Common/EDProduct.h"
20 #include "canvas/Persistency/Common/Wrapper.h"
21 #include "canvas/Persistency/Provenance/BranchDescription.h"
22 #include "canvas/Persistency/Provenance/BranchIDList.h"
23 #include "canvas/Persistency/Provenance/BranchKey.h"
24 #include "canvas/Persistency/Provenance/History.h"
25 #include "canvas/Persistency/Provenance/ParentageRegistry.h"
26 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
27 #include "canvas/Persistency/Provenance/ProcessHistory.h"
28 #include "canvas/Persistency/Provenance/ProcessHistoryID.h"
29 #include "canvas/Persistency/Provenance/ProductList.h"
30 #include "canvas/Persistency/Provenance/ProductProvenance.h"
31 #include "canvas/Utilities/DebugMacros.h"
32 
33 #include <TBufferFile.h>
34 
35 #include "tracemf.h" // TLOG_ARB
36 #include <memory>
37 #include <string>
38 #include <iostream>
39 
40 
41 namespace art
42 {
51  template <typename T>
52  T* ReadObjectAny(const std::unique_ptr<TBufferFile>& infile, const std::string& className, const std::string& callerName)
53  {
54  static TClass* tclassPtr = TClass::GetClass(className.c_str());
55 
56  if (tclassPtr == nullptr)
57  {
58  throw art::Exception(art::errors::DictionaryNotFound) <<
59  callerName << " call to ReadObjectAny: "
60  "Could not get TClass for " << className << "!";
61  }
62 
63  // JCF, May-24-2016
64 
65  // Be aware of the following from the TBufferFile documentation,
66  // concerning TBufferFile::ReadObjectAny:
67 
68  // " In case of multiple inheritance, the return value might not be
69  // the real beginning of the object in memory. You will need to use
70  // a dynamic_cast later if you need to retrieve it."
71 
72  T* ptr = reinterpret_cast<T*>(infile->ReadObjectAny(tclassPtr));
73  TLOG_ARB(5,"InputUtilities") << "ReadObjectAny: Got object of class " << className <<
74  ", located at " << static_cast<void*>(ptr) << " caller:" << callerName << TLOG_ENDL;
75 
76  return ptr;
77  }
78 
85  template <typename T>
86  void printProcessHistoryID(const std::string& label, const T& object)
87  {
88  (void)label; // Otherwise we get an error if LOGDEBUG isn't defined, since description won't be used
89 
90  if (art::debugit() >= 1)
91  {
92  if (object->processHistoryID().isValid())
93  {
94  //std::ostringstream OS;
95  //object->processHistoryID().print(OS);
96  TLOG_ARB(5,"InputUtilities") << label << ": "
97  << "ProcessHistoryID: "
98  << object->processHistoryID() << TLOG_ENDL;
99  }
100  else
101  {
102 #ifdef LOGDEBUG
103  TLOG_DEBUG("printProcessHistoryID") << label << ": "
104  << "ProcessHistoryID: 'INVALID'\n";
105 #endif
106  }
107  }
108  }
109 
116  template <typename T>
117  void printProcessMap(const T& mappable, const std::string description)
118  {
119  (void) description; // Otherwise we get an error if LOGDEBUG isn't defined, since description won't be used
120 
121 #ifdef LOGDEBUG
122  TLOG_DEBUG("printProcessMap") << "Got " << description << "\n";
123 #endif
124 
125  if (art::debugit() >= 1)
126  {
127 #ifdef LOGDEBUG
128  TLOG_DEBUG("printProcessMap") << "Dumping " << description << "...\n";
129  TLOG_DEBUG("printProcessMap") << "Size: "
130  << (unsigned long) mappable.size() << '\n';
131 #endif
132  for (auto I = mappable.begin(), E = mappable.end(); I != E; ++I)
133  {
134  std::ostringstream OS;
135  I->first.print(OS);
136 #ifdef LOGDEBUG
137  TLOG_DEBUG("printProcessMap") << description << ": id: '" << OS.str() << "'\n";
138 #endif
139  OS.str("");
140 #ifdef LOGDEBUG
141  TLOG_DEBUG("printProcessMap") << description << ": data.size(): "
142  << I->second.data().size() << '\n';
143 #endif
144  I->second.data().back().id().print(OS);
145 
146 #ifdef LOGDEBUG
147  TLOG_DEBUG("printProcessMap") << description << ": data.back().id(): '"
148  << OS.str() << "'\n";
149 #endif
150  }
151  }
152  }
153 }
154 
155 
156 #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.