LCOV - code coverage report
Current view: top level - artdaq/ArtModules - InputUtilities.hh (source / functions) Coverage Total Hit
Test: artdaq.info.cleaned Lines: 0.0 % 28 0
Test Date: 2025-09-04 00:45:34 Functions: 0.0 % 36 0

            Line data    Source code
       1              : #ifndef artdaq_ArtModules_InputUtilities_hh
       2              : #define artdaq_ArtModules_InputUtilities_hh
       3              : 
       4              : #include "TRACE/tracemf.h"  // TLOG - note: no #define TRACE_NAME in .hh files -
       5              : //  could conflict with TRACE_NAME in .cc files.
       6              : 
       7              : #include "canvas/Utilities/Exception.h"
       8              : 
       9              : #include <TBufferFile.h>
      10              : #include <TClass.h>
      11              : 
      12              : #include <iostream>
      13              : #include <memory>
      14              : #include <sstream>
      15              : #include <string>
      16              : 
      17              : #define TLVL_READOBJANY 32
      18              : #define TLVL_PROCESSHISTORYID 33
      19              : #define TLVL_PROCESSMAP 34
      20              : 
      21              : namespace art {
      22              : /**
      23              :  * \brief ReadObjectAny reads data from a TBufferFile and casts it to the given type
      24              :  * \tparam T The type of the data being read
      25              :  * \param infile A pointer to the TBufferFile being read
      26              :  * \param className Name of the class to retrieve (must be in ROOT dictionary)
      27              :  * \param callerName Name of the calling class, for logging purposes
      28              :  * \return Pointer to object of type T
      29              :  */
      30              : template<typename T>
      31            0 : T* ReadObjectAny(const std::unique_ptr<TBufferFile>& infile, const std::string& className, const std::string& callerName)
      32              : {
      33            0 :         static TClass* tclassPtr = TClass::GetClass(className.c_str());
      34              : 
      35            0 :         if (tclassPtr == nullptr)
      36              :         {
      37            0 :                 throw art::Exception(art::errors::DictionaryNotFound) << callerName << " call to ReadObjectAny: "  // NOLINT(cert-err60-cpp)
      38              :                                                                                        "Could not get TClass for "
      39            0 :                                                                       << className << "!";
      40              :         }
      41              : 
      42              :         // JCF, May-24-2016
      43              : 
      44              :         // Be aware of the following from the TBufferFile documentation,
      45              :         // concerning TBufferFile::ReadObjectAny:
      46              : 
      47              :         // " In case of multiple inheritance, the return value might not be
      48              :         // the real beginning of the object in memory. You will need to use
      49              :         // a dynamic_cast later if you need to retrieve it."
      50              : 
      51            0 :         T* ptr = reinterpret_cast<T*>(infile->ReadObjectAny(tclassPtr));  // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
      52            0 :         TLOG(TLVL_READOBJANY, "InputUtilities") << "ReadObjectAny: Got object of class " << className << ", located at " << static_cast<void*>(ptr) << " caller:" << callerName;
      53              : 
      54            0 :         return ptr;
      55              : }
      56              : 
      57              : /**
      58              :  * \brief Print the processHistoryID from the object
      59              :  * \tparam T Type of the object
      60              :  * \param label Label for the object
      61              :  * \param object Object to print processHistoryID from
      62              :  */
      63              : template<typename T>
      64            0 : void printProcessHistoryID(const std::string& label, const T& object)
      65              : {
      66            0 :         if (object->processHistoryID().isValid())
      67              :         {
      68              :                 // std::ostringstream OS;
      69              :                 // object->processHistoryID().print(OS);
      70            0 :                 TLOG(TLVL_PROCESSHISTORYID, "InputUtilities") << label << ": "
      71            0 :                                                               << "ProcessHistoryID: " << object->processHistoryID();
      72              :         }
      73              :         else
      74              :         {
      75            0 :                 TLOG(TLVL_PROCESSHISTORYID, "InputUtilities") << label << ": "
      76            0 :                                                               << "ProcessHistoryID: 'INVALID'";
      77              :         }
      78            0 : }
      79              : 
      80              : /**
      81              :  * \brief Print data from a map-like class
      82              :  * \tparam T Type of the class
      83              :  * \param mappable Map-like class to print
      84              :  * \param description Description of the map-like class
      85              :  */
      86              : template<typename T>
      87            0 : void printProcessMap(const T& mappable, const std::string& description)
      88              : {
      89            0 :         TLOG(TLVL_PROCESSMAP, "InputUtilities") << "Got " << description;
      90              : 
      91            0 :         TLOG(TLVL_PROCESSMAP, "InputUtilities") << "Dumping " << description << "...";
      92            0 :         TLOG(TLVL_PROCESSMAP, "InputUtilities") << "Size: " << mappable.size();
      93            0 :         for (auto I = mappable.begin(), E = mappable.end(); I != E; ++I)
      94              :         {
      95            0 :                 std::ostringstream OS;
      96            0 :                 I->first.print(OS);
      97            0 :                 TLOG(TLVL_PROCESSMAP, "InputUtilities") << description << ": id: '" << OS.str() << "'";
      98            0 :                 OS.str("");
      99            0 :                 TLOG(TLVL_PROCESSMAP, "InputUtilities") << description << ": data.size(): " << I->second.data().size();
     100            0 :                 I->second.data().back().id().print(OS);
     101              : 
     102            0 :                 TLOG(TLVL_PROCESSMAP, "InputUtilities") << description << ": data.back().id(): '" << OS.str() << "'";
     103              :         }
     104            0 : }
     105              : }  // namespace art
     106              : 
     107              : #endif
        

Generated by: LCOV version 2.0-1