Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:16:20

0001 #include "SingleStreamingInputv2.h"
0002 
0003 #include <frog/FROG.h>
0004 
0005 #include <phool/phool.h>
0006 
0007 #include <Event/Eventiterator.h>
0008 #include <Event/fileEventiterator.h>
0009 
0010 #include <cstdint>   // for uint64_t
0011 #include <iostream>  // for operator<<, basic_ostream, endl
0012 #include <set>
0013 #include <utility>  // for pair
0014 
0015 SingleStreamingInputv2::SingleStreamingInputv2(const std::string &name)
0016   : Fun4AllBase(name)
0017 {
0018 }
0019 
0020 SingleStreamingInputv2::~SingleStreamingInputv2()
0021 {
0022   delete m_EventIterator;
0023 }
0024 
0025 int SingleStreamingInputv2::fileopen(const std::string &filenam)
0026 {
0027   std::cout << PHWHERE << "trying to open " << filenam << std::endl;
0028   if (IsOpen())
0029   {
0030     std::cout << "Closing currently open file "
0031               << FileName()
0032               << " and opening " << filenam << std::endl;
0033     fileclose();
0034   }
0035   FileName(filenam);
0036   FROG frog;
0037   std::string fname = frog.location(FileName());
0038   if (Verbosity() > 0)
0039   {
0040     std::cout << Name() << ": opening file " << FileName() << std::endl;
0041   }
0042   int status = 0;
0043   m_EventIterator = new fileEventiterator(fname.c_str(), status);
0044   m_EventsThisFile = 0;
0045   if (status)
0046   {
0047     delete m_EventIterator;
0048     m_EventIterator = nullptr;
0049     std::cout << PHWHERE << Name() << ": could not open file " << fname << std::endl;
0050     return -1;
0051   }
0052   IsOpen(1);
0053   AddToFileOpened(fname);  // add file to the list of files which were opened
0054   return 0;
0055 }
0056 
0057 int SingleStreamingInputv2::fileclose()
0058 {
0059   if (!IsOpen())
0060   {
0061     std::cout << Name() << ": fileclose: No Input file open" << std::endl;
0062     return -1;
0063   }
0064   delete m_EventIterator;
0065   m_EventIterator = nullptr;
0066   IsOpen(0);
0067   // if we have a file list, move next entry to top of the list
0068   // or repeat the same entry again
0069   UpdateFileList();
0070   return 0;
0071 }
0072 
0073 void SingleStreamingInputv2::Print(const std::string &what) const
0074 {
0075   if (what == "ALL" || what == "FEE")
0076   {
0077     for (const auto &bcliter : m_BeamClockFEE)
0078     {
0079       std::cout << "Beam clock 0x" << std::hex << bcliter.first << std::dec << std::endl;
0080       for (auto feeiter : bcliter.second)
0081       {
0082         std::cout << "FEM: " << feeiter << std::endl;
0083       }
0084     }
0085   }
0086   if (what == "ALL" || what == "FEEBCLK")
0087   {
0088     for (auto bcliter : m_FEEBclkMap)
0089     {
0090       std::cout << "FEE" << bcliter.first << " bclk: 0x"
0091                 << std::hex << bcliter.second << std::dec << std::endl;
0092     }
0093   }
0094   if (what == "ALL" || what == "STACK")
0095   {
0096     for (auto iter : m_BclkStack)
0097     {
0098       std::cout << "stacked bclk: 0x" << std::hex << iter << std::dec << std::endl;
0099     }
0100   }
0101 }
0102 
0103 bool SingleStreamingInputv2::CheckPoolDepth(const uint64_t bclk)
0104 {
0105   // if (m_FEEBclkMap.size() < 10)
0106   // {
0107   //   std::cout << "not all FEEs in map: " << m_FEEBclkMap.size() << std::endl;
0108   //   return true;
0109   // }
0110   for (auto iter : m_FEEBclkMap)
0111   {
0112     if (Verbosity() > 2)
0113     {
0114       std::cout << "my bclk 0x" << std::hex << iter.second
0115                 << " req: 0x" << bclk << std::dec << std::endl;
0116     }
0117     if (iter.second < bclk)
0118     {
0119       if (Verbosity() > 1)
0120       {
0121         std::cout << "FEE " << iter.first << " beamclock 0x" << std::hex << iter.second
0122                   << " smaller than req bclk: 0x" << bclk << std::dec << std::endl;
0123       }
0124       return true;
0125     }
0126   }
0127   return false;
0128 }
0129 
0130 void SingleStreamingInputv2::ClearCurrentEvent()
0131 {
0132   // called interactively, to get rid of the current event
0133   uint64_t currentbclk = *m_BclkStack.begin();
0134   std::cout << "clearing bclk 0x" << std::hex << currentbclk << std::dec << std::endl;
0135   CleanupUsedPackets(currentbclk);
0136   m_BclkStack.erase(currentbclk);
0137   m_BeamClockFEE.erase(currentbclk);
0138   return;
0139 }