Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:12:21

0001 #include "GenericUnpackPRDF.h"
0002 
0003 #include "PROTOTYPE4_FEM.h"
0004 #include "RawTower_Prototype4.h"
0005 
0006 #include <calobase/RawTower.h>  // for RawTower
0007 #include <calobase/RawTowerContainer.h>
0008 #include <calobase/RawTowerDefs.h>  // for NONE
0009 
0010 #include <fun4all/Fun4AllBase.h>  // for Fun4AllBase::VERBOSITY_SOME
0011 #include <fun4all/Fun4AllReturnCodes.h>
0012 #include <fun4all/SubsysReco.h>  // for SubsysReco
0013 
0014 #include <phool/PHCompositeNode.h>
0015 #include <phool/PHIODataNode.h>    // for PHIODataNode
0016 #include <phool/PHNodeIterator.h>  // for PHNodeIterator
0017 #include <phool/PHObject.h>        // for PHObject
0018 #include <phool/getClass.h>
0019 
0020 #include <Event/Event.h>
0021 #include <Event/EventTypes.h>
0022 #include <Event/packet.h>
0023 
0024 #include <cassert>
0025 #include <cmath>    // for NAN
0026 #include <cstdlib>  // for exit
0027 #include <iostream>
0028 #include <string>
0029 
0030 using namespace std;
0031 
0032 //____________________________________
0033 GenericUnpackPRDF::GenericUnpackPRDF(const string &detector)
0034   : SubsysReco("GenericUnpackPRDF_" + detector)
0035   ,  //
0036   _detector(detector)
0037   , _towers(nullptr)
0038 {
0039 }
0040 
0041 //_____________________________________
0042 int GenericUnpackPRDF::InitRun(PHCompositeNode *topNode)
0043 {
0044   CreateNodeTree(topNode);
0045   return Fun4AllReturnCodes::EVENT_OK;
0046 }
0047 
0048 //____________________________________
0049 int GenericUnpackPRDF::process_event(PHCompositeNode *topNode)
0050 {
0051   Event *_event = findNode::getClass<Event>(topNode, "PRDF");
0052   if (!_event)
0053   {
0054     if (Verbosity() >= VERBOSITY_SOME)
0055       cout << "GenericUnpackPRDF::Process_Event - Event not found" << endl;
0056     return Fun4AllReturnCodes::DISCARDEVENT;
0057   }
0058 
0059   if (Verbosity() >= VERBOSITY_SOME)
0060     _event->identify();
0061 
0062   // search for data event
0063   if (_event->getEvtType() != DATAEVENT)
0064     return Fun4AllReturnCodes::EVENT_OK;
0065 
0066   map<int, Packet *> packet_list;
0067 
0068   for (channel_map::const_iterator it = _channel_map.begin();
0069        it != _channel_map.end(); ++it)
0070   {
0071     const int packet_id = it->first.first;
0072     const int channel = it->first.second;
0073     const int tower_id = it->second;
0074 
0075     if (packet_list.find(packet_id) == packet_list.end())
0076     {
0077       packet_list[packet_id] = _event->getPacket(packet_id);
0078 
0079       if (packet_list[packet_id] and Verbosity() >= VERBOSITY_MORE)
0080       {
0081         cout << "GenericUnpackPRDF::process_event - open packet " << packet_id
0082              << ":" << endl;
0083         //        packet_list[packet_id]->identify(cout);
0084         packet_list[packet_id]->dump(cout);
0085       }
0086     }
0087 
0088     Packet *packet = packet_list[packet_id];
0089 
0090     if (!packet)
0091     {
0092       //          if (Verbosity() >= VERBOSITY_SOME)
0093       cout << "GenericUnpackPRDF::process_event - failed to locate packet "
0094            << packet_id << endl;
0095       continue;
0096     }
0097     assert(packet);
0098 
0099     //    packet->setNumSamples(PROTOTYPE4_FEM::NSAMPLES);
0100 
0101     RawTower_Prototype4 *tower =
0102         dynamic_cast<RawTower_Prototype4 *>(_towers->getTower(tower_id));
0103     if (!tower)
0104     {
0105       tower = new RawTower_Prototype4();
0106       tower->set_energy(NAN);
0107       _towers->AddTower(tower_id, tower);
0108     }
0109     tower->set_HBD_channel_number(channel);
0110     for (int isamp = 0; isamp < PROTOTYPE4_FEM::NSAMPLES; isamp++)
0111     {
0112       tower->set_signal_samples(isamp, (packet->iValue(isamp, channel)) &
0113                                            PROTOTYPE4_FEM::ADC_DATA_MASK);
0114     }
0115   }
0116 
0117   for (map<int, Packet *>::iterator it = packet_list.begin();
0118        it != packet_list.end(); ++it)
0119   {
0120     if (it->second)
0121       delete it->second;
0122   }
0123 
0124   return Fun4AllReturnCodes::EVENT_OK;
0125 }
0126 
0127 //_______________________________________
0128 void GenericUnpackPRDF::CreateNodeTree(PHCompositeNode *topNode)
0129 {
0130   PHNodeIterator nodeItr(topNode);
0131   // DST node
0132   PHCompositeNode *dst_node = static_cast<PHCompositeNode *>(
0133       nodeItr.findFirst("PHCompositeNode", "DST"));
0134   if (!dst_node)
0135   {
0136     cout << "PHComposite node created: DST" << endl;
0137     dst_node = new PHCompositeNode("DST");
0138     topNode->addNode(dst_node);
0139   }
0140 
0141   // DATA nodes
0142   PHCompositeNode *data_node = static_cast<PHCompositeNode *>(
0143       nodeItr.findFirst("PHCompositeNode", "RAW_DATA"));
0144   if (!data_node)
0145   {
0146     if (Verbosity())
0147       cout << "PHComposite node created: RAW_DATA" << endl;
0148     data_node = new PHCompositeNode("RAW_DATA");
0149     dst_node->addNode(data_node);
0150   }
0151 
0152   // output as towers
0153   _towers = new RawTowerContainer(RawTowerDefs::NONE);
0154   PHIODataNode<PHObject> *towerNode =
0155       new PHIODataNode<PHObject>(_towers, "TOWER_RAW_" + _detector, "PHObject");
0156   data_node->addNode(towerNode);
0157 }
0158 
0159 void GenericUnpackPRDF::add_channel(const int packet_id,  //! packet id
0160                                     const int channel,    //! channel in packet
0161                                     const int tower_id    //! output tower id
0162 )
0163 {
0164   channel_typ hbd_channel(packet_id, channel);
0165 
0166   if (_channel_map.find(hbd_channel) != _channel_map.end())
0167   {
0168     cout << "GenericUnpackPRDF::add_channel - packet " << packet_id
0169          << ", channel " << channel << " is already registered as tower "
0170          << _channel_map.find(hbd_channel)->second << endl;
0171     exit(12);
0172   }
0173   _channel_map[hbd_channel] = tower_id;
0174 }