File indexing completed on 2025-08-06 08:22:01
0001 #include "GenericUnpackPRDF.h"
0002
0003 #include "PROTOTYPE3_FEM.h"
0004 #include "RawTower_Prototype3.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/packet.h> // for Packet
0022
0023 #include <cassert>
0024 #include <cmath> // for NAN
0025 #include <cstdlib> // for exit
0026 #include <iostream>
0027 #include <string>
0028
0029 using namespace std;
0030
0031
0032 GenericUnpackPRDF::GenericUnpackPRDF(const string &detector)
0033 : SubsysReco("GenericUnpackPRDF_" + detector)
0034 ,
0035 _detector(detector)
0036 , _towers(nullptr)
0037 {
0038 }
0039
0040
0041 int GenericUnpackPRDF::InitRun(PHCompositeNode *topNode)
0042 {
0043 CreateNodeTree(topNode);
0044 return Fun4AllReturnCodes::EVENT_OK;
0045 }
0046
0047
0048 int GenericUnpackPRDF::process_event(PHCompositeNode *topNode)
0049 {
0050 Event *_event = findNode::getClass<Event>(topNode, "PRDF");
0051 if (!_event)
0052 {
0053 if (Verbosity() >= VERBOSITY_SOME)
0054 cout << "GenericUnpackPRDF::Process_Event - Event not found" << endl;
0055 return Fun4AllReturnCodes::DISCARDEVENT;
0056 }
0057
0058 if (Verbosity() >= VERBOSITY_SOME)
0059 _event->identify();
0060
0061 map<int, Packet *> packet_list;
0062
0063 for (hbd_channel_map::const_iterator it = _hbd_channel_map.begin();
0064 it != _hbd_channel_map.end(); ++it)
0065 {
0066 const int packet_id = it->first.first;
0067 const int channel = it->first.second;
0068 const int tower_id = it->second;
0069
0070 if (packet_list.find(packet_id) == packet_list.end())
0071 {
0072 packet_list[packet_id] = _event->getPacket(packet_id);
0073 }
0074
0075 Packet *packet = packet_list[packet_id];
0076
0077 if (!packet)
0078 {
0079
0080 cout << "GenericUnpackPRDF::process_event - failed to locate packet "
0081 << packet_id << endl;
0082 continue;
0083 }
0084 assert(packet);
0085
0086
0087 packet->setInternalParameter(PROTOTYPE3_FEM::NSAMPLES);
0088
0089 RawTower_Prototype3 *tower =
0090 dynamic_cast<RawTower_Prototype3 *>(_towers->getTower(tower_id));
0091 if (!tower)
0092 {
0093 tower = new RawTower_Prototype3();
0094 tower->set_energy(NAN);
0095 _towers->AddTower(tower_id, tower);
0096 }
0097 tower->set_HBD_channel_number(channel);
0098 for (int isamp = 0; isamp < PROTOTYPE3_FEM::NSAMPLES; isamp++)
0099 {
0100 tower->set_signal_samples(isamp, packet->iValue(channel, isamp));
0101 }
0102 }
0103
0104 for (map<int, Packet *>::iterator it = packet_list.begin();
0105 it != packet_list.end(); ++it)
0106 {
0107 if (it->second)
0108 delete it->second;
0109 }
0110
0111 return Fun4AllReturnCodes::EVENT_OK;
0112 }
0113
0114
0115 void GenericUnpackPRDF::CreateNodeTree(PHCompositeNode *topNode)
0116 {
0117 PHNodeIterator nodeItr(topNode);
0118
0119 PHCompositeNode *dst_node = static_cast<PHCompositeNode *>(
0120 nodeItr.findFirst("PHCompositeNode", "DST"));
0121 if (!dst_node)
0122 {
0123 cout << "PHComposite node created: DST" << endl;
0124 dst_node = new PHCompositeNode("DST");
0125 topNode->addNode(dst_node);
0126 }
0127
0128
0129 PHCompositeNode *data_node = static_cast<PHCompositeNode *>(
0130 nodeItr.findFirst("PHCompositeNode", "RAW_DATA"));
0131 if (!data_node)
0132 {
0133 if (Verbosity())
0134 cout << "PHComposite node created: RAW_DATA" << endl;
0135 data_node = new PHCompositeNode("RAW_DATA");
0136 dst_node->addNode(data_node);
0137 }
0138
0139
0140 _towers = new RawTowerContainer(RawTowerDefs::NONE);
0141 PHIODataNode<PHObject> *towerNode =
0142 new PHIODataNode<PHObject>(_towers, "TOWER_RAW_" + _detector, "PHObject");
0143 data_node->addNode(towerNode);
0144 }
0145
0146 void GenericUnpackPRDF::add_channel(const int packet_id,
0147 const int channel,
0148 const int tower_id
0149 )
0150 {
0151 hbd_channel_typ hbd_channel(packet_id, channel);
0152
0153 if (_hbd_channel_map.find(hbd_channel) != _hbd_channel_map.end())
0154 {
0155 cout << "GenericUnpackPRDF::add_channel - packet " << packet_id
0156 << ", channel " << channel << " is already registered as tower "
0157 << _hbd_channel_map.find(hbd_channel)->second << endl;
0158 exit(12);
0159 }
0160 _hbd_channel_map[hbd_channel] = tower_id;
0161 }