00001 #ifndef artdaq_ArtModules_InputUtilities_hh
00002 #define artdaq_ArtModules_InputUtilities_hh
00003
00004 #include "art/Framework/Core/FileBlock.h"
00005 #include "art/Framework/Core/InputSourceMacros.h"
00006 #include "art/Framework/Core/ProductRegistryHelper.h"
00007 #include "art/Framework/IO/Sources/Source.h"
00008 #include "art/Framework/IO/Sources/SourceHelper.h"
00009 #include "art/Framework/IO/Sources/SourceTraits.h"
00010 #include "art/Framework/Services/Registry/ServiceHandle.h"
00011 #if ART_HEX_VERSION < 0x20703
00012 #include "art/Persistency/Provenance/BranchIDListHelper.h"
00013 #endif
00014 #if ART_HEX_VERSION < 0x20900
00015 #include "art/Persistency/Provenance/BranchIDListRegistry.h"
00016 #include "canvas/Persistency/Provenance/BranchIDList.h"
00017 #endif
00018 #include "art/Persistency/Provenance/MasterProductRegistry.h"
00019 #include "art/Persistency/Provenance/ProcessHistoryRegistry.h"
00020 #include "art/Persistency/Provenance/ProductMetaData.h"
00021
00022 #include "canvas/Persistency/Common/EDProduct.h"
00023 #include "canvas/Persistency/Common/Wrapper.h"
00024 #include "canvas/Persistency/Provenance/BranchDescription.h"
00025 #include "canvas/Persistency/Provenance/BranchKey.h"
00026 #include "canvas/Persistency/Provenance/History.h"
00027 #include "canvas/Persistency/Provenance/ParentageRegistry.h"
00028 #include "canvas/Persistency/Provenance/ProcessConfiguration.h"
00029 #include "canvas/Persistency/Provenance/ProcessHistory.h"
00030 #include "canvas/Persistency/Provenance/ProcessHistoryID.h"
00031 #include "canvas/Persistency/Provenance/ProductList.h"
00032 #include "canvas/Persistency/Provenance/ProductProvenance.h"
00033 #include "canvas/Utilities/DebugMacros.h"
00034
00035 #include <TBufferFile.h>
00036
00037
00038 #define TRACE_NAME "InputUtilities"
00039 #define TLVL_READOBJANY 32
00040 #define TLVL_PROCESSHISTORYID 33
00041 #define TLVL_PROCESSMAP 34
00042
00043 #include "tracemf.h"
00044 #include <memory>
00045 #include <string>
00046 #include <iostream>
00047
00048
00049
00050 namespace art
00051 {
00060 template <typename T>
00061 T* ReadObjectAny(const std::unique_ptr<TBufferFile>& infile, const std::string& className, const std::string& callerName)
00062 {
00063 static TClass* tclassPtr = TClass::GetClass(className.c_str());
00064
00065 if (tclassPtr == nullptr)
00066 {
00067 throw art::Exception(art::errors::DictionaryNotFound) <<
00068 callerName << " call to ReadObjectAny: "
00069 "Could not get TClass for " << className << "!";
00070 }
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 T* ptr = reinterpret_cast<T*>(infile->ReadObjectAny(tclassPtr));
00082 TLOG(TLVL_READOBJANY) << "ReadObjectAny: Got object of class " << className <<
00083 ", located at " << static_cast<void*>(ptr) << " caller:" << callerName << TLOG_ENDL;
00084
00085 return ptr;
00086 }
00087
00094 template <typename T>
00095 void printProcessHistoryID(const std::string& label, const T& object)
00096 {
00097
00098 if (object->processHistoryID().isValid())
00099 {
00100
00101
00102 TLOG(TLVL_PROCESSHISTORYID) << label << ": " << "ProcessHistoryID: " << object->processHistoryID() << TLOG_ENDL;
00103 }
00104 else
00105 {
00106 TLOG(TLVL_PROCESSHISTORYID) << label << ": " << "ProcessHistoryID: 'INVALID'";
00107 }
00108 }
00109
00116 template <typename T>
00117 void printProcessMap(const T& mappable, const std::string description)
00118 {
00119 TLOG(TLVL_PROCESSMAP) << "Got " << description;
00120
00121 TLOG(TLVL_PROCESSMAP) << "Dumping " << description << "...";
00122 TLOG(TLVL_PROCESSMAP) << "Size: " << (unsigned long)mappable.size();
00123 for (auto I = mappable.begin(), E = mappable.end(); I != E; ++I)
00124 {
00125 std::ostringstream OS;
00126 I->first.print(OS);
00127 TLOG(TLVL_PROCESSMAP) << description << ": id: '" << OS.str() << "'";
00128 OS.str("");
00129 TLOG(TLVL_PROCESSMAP) << description << ": data.size(): " << I->second.data().size();
00130 I->second.data().back().id().print(OS);
00131
00132 TLOG(TLVL_PROCESSMAP) << description << ": data.back().id(): '" << OS.str() << "'";
00133 }
00134 }
00135 }
00136
00137
00138 #endif