artdaq  v3_06_00
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 < 0x30000
12 #include "art/Persistency/Provenance/MasterProductRegistry.h"
13 #include "art/Persistency/Provenance/ProductMetaData.h"
14 #endif
15 #include "art/Persistency/Provenance/ProcessHistoryRegistry.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/BranchKey.h"
21 #include "canvas/Persistency/Provenance/History.h"
22 #include "canvas/Persistency/Provenance/ParentageRegistry.h"
23 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
24 #include "canvas/Persistency/Provenance/ProcessHistory.h"
25 #include "canvas/Persistency/Provenance/ProcessHistoryID.h"
26 #include "canvas/Persistency/Provenance/ProductList.h"
27 #include "canvas/Persistency/Provenance/ProductProvenance.h"
28 #include "canvas/Utilities/DebugMacros.h"
29 
30 #include <TBufferFile.h>
31 
32 
33 #define TLVL_READOBJANY 32
34 #define TLVL_PROCESSHISTORYID 33
35 #define TLVL_PROCESSMAP 34
36 
37 #include "tracemf.h" // TLOG - note: no #define TRACE_NAME in .hh files -
38 // could conflict with TRACE_NAME in .cc files.
39 #include <memory>
40 #include <string>
41 #include <iostream>
42 
43 
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  TLOG(TLVL_READOBJANY, "InputUtilities") << "ReadObjectAny: Got object of class " << className <<
78  ", located at " << static_cast<void*>(ptr) << " caller:" << callerName;
79 
80  return ptr;
81  }
82 
89  template <typename T>
90  void printProcessHistoryID(const std::string& label, const T& object)
91  {
92 
93  if (object->processHistoryID().isValid())
94  {
95  //std::ostringstream OS;
96  //object->processHistoryID().print(OS);
97  TLOG(TLVL_PROCESSHISTORYID, "InputUtilities") << label << ": " << "ProcessHistoryID: " << object->processHistoryID();
98  }
99  else
100  {
101  TLOG(TLVL_PROCESSHISTORYID, "InputUtilities") << label << ": " << "ProcessHistoryID: 'INVALID'";
102  }
103  }
104 
111  template <typename T>
112  void printProcessMap(const T& mappable, const std::string description)
113  {
114  TLOG(TLVL_PROCESSMAP, "InputUtilities") << "Got " << description;
115 
116  TLOG(TLVL_PROCESSMAP, "InputUtilities") << "Dumping " << description << "...";
117  TLOG(TLVL_PROCESSMAP, "InputUtilities") << "Size: " << (unsigned long)mappable.size();
118  for (auto I = mappable.begin(), E = mappable.end(); I != E; ++I)
119  {
120  std::ostringstream OS;
121  I->first.print(OS);
122  TLOG(TLVL_PROCESSMAP, "InputUtilities") << description << ": id: '" << OS.str() << "'";
123  OS.str("");
124  TLOG(TLVL_PROCESSMAP, "InputUtilities") << description << ": data.size(): " << I->second.data().size();
125  I->second.data().back().id().print(OS);
126 
127  TLOG(TLVL_PROCESSMAP, "InputUtilities") << description << ": data.back().id(): '" << OS.str() << "'";
128  }
129  }
130 }
131 
132 
133 #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.