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