artdaq  v3_02_01
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 < 0x20900
12 #include "art/Persistency/Provenance/BranchIDListRegistry.h"
13 #include "canvas/Persistency/Provenance/BranchIDList.h"
14 #endif
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/BranchKey.h"
23 #include "canvas/Persistency/Provenance/History.h"
24 #include "canvas/Persistency/Provenance/ParentageRegistry.h"
25 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
26 #include "canvas/Persistency/Provenance/ProcessHistory.h"
27 #include "canvas/Persistency/Provenance/ProcessHistoryID.h"
28 #include "canvas/Persistency/Provenance/ProductList.h"
29 #include "canvas/Persistency/Provenance/ProductProvenance.h"
30 #include "canvas/Utilities/DebugMacros.h"
31 
32 #include <TBufferFile.h>
33 
34 
35 #define TLVL_READOBJANY 32
36 #define TLVL_PROCESSHISTORYID 33
37 #define TLVL_PROCESSMAP 34
38 
39 #include "tracemf.h" // TLOG - note: no #define TRACE_NAME in .hh files -
40 // could conflict with TRACE_NAME in .cc files.
41 #include <memory>
42 #include <string>
43 #include <iostream>
44 
45 
46 
47 namespace art
48 {
57  template <typename T>
58  T* ReadObjectAny(const std::unique_ptr<TBufferFile>& infile, const std::string& className, const std::string& callerName)
59  {
60  static TClass* tclassPtr = TClass::GetClass(className.c_str());
61 
62  if (tclassPtr == nullptr)
63  {
64  throw art::Exception(art::errors::DictionaryNotFound) <<
65  callerName << " call to ReadObjectAny: "
66  "Could not get TClass for " << className << "!";
67  }
68 
69  // JCF, May-24-2016
70 
71  // Be aware of the following from the TBufferFile documentation,
72  // concerning TBufferFile::ReadObjectAny:
73 
74  // " In case of multiple inheritance, the return value might not be
75  // the real beginning of the object in memory. You will need to use
76  // a dynamic_cast later if you need to retrieve it."
77 
78  T* ptr = reinterpret_cast<T*>(infile->ReadObjectAny(tclassPtr));
79  TLOG(TLVL_READOBJANY, "InputUtilities") << "ReadObjectAny: Got object of class " << className <<
80  ", located at " << static_cast<void*>(ptr) << " caller:" << callerName;
81 
82  return ptr;
83  }
84 
91  template <typename T>
92  void printProcessHistoryID(const std::string& label, const T& object)
93  {
94 
95  if (object->processHistoryID().isValid())
96  {
97  //std::ostringstream OS;
98  //object->processHistoryID().print(OS);
99  TLOG(TLVL_PROCESSHISTORYID, "InputUtilities") << label << ": " << "ProcessHistoryID: " << object->processHistoryID();
100  }
101  else
102  {
103  TLOG(TLVL_PROCESSHISTORYID, "InputUtilities") << label << ": " << "ProcessHistoryID: 'INVALID'";
104  }
105  }
106 
113  template <typename T>
114  void printProcessMap(const T& mappable, const std::string description)
115  {
116  TLOG(TLVL_PROCESSMAP, "InputUtilities") << "Got " << description;
117 
118  TLOG(TLVL_PROCESSMAP, "InputUtilities") << "Dumping " << description << "...";
119  TLOG(TLVL_PROCESSMAP, "InputUtilities") << "Size: " << (unsigned long)mappable.size();
120  for (auto I = mappable.begin(), E = mappable.end(); I != E; ++I)
121  {
122  std::ostringstream OS;
123  I->first.print(OS);
124  TLOG(TLVL_PROCESSMAP, "InputUtilities") << description << ": id: '" << OS.str() << "'";
125  OS.str("");
126  TLOG(TLVL_PROCESSMAP, "InputUtilities") << description << ": data.size(): " << I->second.data().size();
127  I->second.data().back().id().print(OS);
128 
129  TLOG(TLVL_PROCESSMAP, "InputUtilities") << description << ": data.back().id(): '" << OS.str() << "'";
130  }
131  }
132 }
133 
134 
135 #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.