Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:20

0001 #include "Fun4AllTriggeredInputManager.h"
0002 
0003 #include "SinglePrdfInput.h"
0004 #include "SingleTriggeredInput.h"
0005 
0006 #include <fun4all/Fun4AllInputManager.h>  // for Fun4AllInputManager
0007 #include <fun4all/Fun4AllReturnCodes.h>
0008 #include <fun4all/Fun4AllServer.h>
0009 #include <fun4all/Fun4AllSyncManager.h>
0010 
0011 #include <ffaobjects/SyncObject.h>    // for SyncObject
0012 #include <ffaobjects/SyncObjectv1.h>  // for SyncObject
0013 
0014 #include <ffarawobjects/CaloPacket.h>
0015 #include <ffarawobjects/CaloPacketContainer.h>
0016 #include <ffarawobjects/Gl1Packet.h>
0017 #include <ffarawobjects/LL1Packet.h>
0018 #include <ffarawobjects/LL1PacketContainer.h>
0019 
0020 #include <phool/PHCompositeNode.h>
0021 #include <phool/PHDataNode.h>
0022 #include <phool/PHNode.h>          // for PHNode
0023 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0024 #include <phool/PHObject.h>        // for PHObject
0025 #include <phool/getClass.h>
0026 #include <phool/phool.h>  // for PHWHERE
0027 
0028 #include <TSystem.h>
0029 
0030 #include <algorithm>  // for std::search
0031 #include <cassert>
0032 #include <climits>
0033 #include <cstdlib>
0034 #include <iostream>  // for operator<<, basic_ostream, endl
0035 #include <utility>   // for pair
0036 
0037 Fun4AllTriggeredInputManager::Fun4AllTriggeredInputManager(const std::string &name, const std::string &prdfnodename, const std::string &topnodename)
0038   : Fun4AllInputManager(name, prdfnodename, topnodename)
0039   , m_SyncObject(new SyncObjectv1())
0040 {
0041   Fun4AllServer *se = Fun4AllServer::instance();
0042   m_topNode = se->topNode(TopNodeName());
0043 }
0044 
0045 Fun4AllTriggeredInputManager::~Fun4AllTriggeredInputManager()
0046 {
0047   if (IsOpen())
0048   {
0049     fileclose();
0050   }
0051   delete m_SyncObject;
0052   for (auto *iter : m_TriggeredInputVector)
0053   {
0054     if (Verbosity() > 1)
0055     {
0056       std::cout << PHWHERE << " deleting " << iter->Name() << std::endl;
0057     }
0058     delete iter;
0059   }
0060 }
0061 
0062 int Fun4AllTriggeredInputManager::run(const int /*nevents*/)
0063 {
0064   m_Gl1TriggeredInput->FillPool();
0065   for (auto *iter : m_TriggeredInputVector)
0066   {
0067     //    std::cout << "prdf input: " << iter->Name() << std::endl;
0068     iter->FillPool();
0069     if (iter->AllDone())
0070     {
0071       return -1;
0072     }
0073   }
0074   m_Gl1TriggeredInput->ReadEvent();
0075   for (auto *iter : m_TriggeredInputVector)
0076   {
0077     //    std::cout << "prdf input: " << iter->Name() << std::endl;
0078     iter->ReadEvent();
0079     if (iter->AllDone())
0080     {
0081       return -1;
0082     }
0083   }
0084 
0085   if (m_RunNumber == 0)
0086   {
0087     m_RunNumber = m_Gl1TriggeredInput->RunNumber();
0088     SetRunNumber(m_RunNumber);
0089   }
0090   if (m_Gl1TriggeredInput->AllDone())
0091   {
0092     return -1;
0093   }
0094   EventNumber(m_Gl1TriggeredInput->EventNumber());
0095   MySyncManager()->CurrentEvent(EventNumber());
0096   //    std::cout << "saving event on dst" << std::endl;
0097   return 0;
0098 }
0099 
0100 int Fun4AllTriggeredInputManager::fileclose()
0101 {
0102   // for (auto iter : m_TriggerInputVector)
0103   // {
0104   //   delete iter;
0105   // }
0106   //  m_TriggerInputVector.clear();
0107   return 0;
0108 }
0109 
0110 void Fun4AllTriggeredInputManager::Print(const std::string &what) const
0111 {
0112   std::cout << "Triggered Inputs" << std::endl;
0113   if (what == "ALL" || what == "INPUT")
0114   {
0115     for (auto *iter : m_TriggeredInputVector)
0116     {
0117       std::cout << "prdf input: " << iter->Name() << std::endl;
0118     }
0119   }
0120   return;
0121 }
0122 
0123 int Fun4AllTriggeredInputManager::ResetEvent()
0124 {
0125   return 0;
0126 }
0127 
0128 int Fun4AllTriggeredInputManager::PushBackEvents(const int /*i*/)
0129 {
0130   return 0;
0131 }
0132 
0133 int Fun4AllTriggeredInputManager::GetSyncObject(SyncObject **mastersync)
0134 {
0135   // here we copy the sync object from the current file to the
0136   // location pointed to by mastersync. If mastersync is a 0 pointer
0137   // the syncobject is cloned. If mastersync allready exists the content
0138   // of syncobject is copied
0139   if (!(*mastersync))
0140   {
0141     if (m_SyncObject)
0142     {
0143       *mastersync = dynamic_cast<SyncObject *>(m_SyncObject->CloneMe());
0144       assert(*mastersync);
0145     }
0146   }
0147   else
0148   {
0149     *(*mastersync) = *m_SyncObject;  // copy syncobject content
0150   }
0151   return Fun4AllReturnCodes::SYNC_OK;
0152 }
0153 
0154 int Fun4AllTriggeredInputManager::SyncIt(const SyncObject *mastersync)
0155 {
0156   if (!mastersync)
0157   {
0158     std::cout << PHWHERE << Name() << " No MasterSync object, cannot perform synchronization" << std::endl;
0159     std::cout << "Most likely your first file does not contain a SyncObject and the file" << std::endl;
0160     std::cout << "opened by the Fun4AllDstInputManager with Name " << Name() << " has one" << std::endl;
0161     std::cout << "Change your macro and use the file opened by this input manager as first input" << std::endl;
0162     std::cout << "and you will be okay. Fun4All will not process the current configuration" << std::endl
0163               << std::endl;
0164     return Fun4AllReturnCodes::SYNC_FAIL;
0165   }
0166   int iret = m_SyncObject->Different(mastersync);
0167   if (iret)
0168   {
0169     std::cout << "big problem" << std::endl;
0170     exit(1);
0171   }
0172   return Fun4AllReturnCodes::SYNC_OK;
0173 }
0174 
0175 std::string Fun4AllTriggeredInputManager::GetString(const std::string &what) const
0176 {
0177   std::cout << PHWHERE << " called with " << what << " , returning empty string" << std::endl;
0178   return "";
0179 }
0180 
0181 void Fun4AllTriggeredInputManager::registerGl1TriggeredInput(SingleTriggeredInput *prdfin)
0182 {
0183   m_Gl1TriggeredInput = prdfin;
0184   prdfin->topNode(m_topNode);
0185   std::cout << "registering " << prdfin->Name() << std::endl;
0186 }
0187 
0188 void Fun4AllTriggeredInputManager::registerTriggeredInput(SingleTriggeredInput *prdfin)
0189 {
0190   if (m_Gl1TriggeredInput == nullptr)
0191   {
0192     std::cout << "You need to register the Gl1 input manager first" << std::endl;
0193     gSystem->Exit(1);
0194     exit(1);
0195   }
0196   m_TriggeredInputVector.push_back(prdfin);
0197   prdfin->Gl1Input(m_Gl1TriggeredInput);
0198   prdfin->topNode(m_topNode);
0199   std::cout << "registering " << prdfin->Name() << std::endl;
0200   //  prdfin->CreateDSTNode(m_topNode);
0201   //  prdfin->TriggerInputManager(this);
0202   return;
0203 }