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