File indexing completed on 2023-05-17 02:07:44
0001 #include "L1Trigger/TrackerTFP/interface/DistServer.h"
0002 #include "L1Trigger/TrackerTFP/interface/DataFormats.h"
0003
0004 #include <algorithm>
0005 #include <iostream>
0006
0007 using namespace std;
0008 using namespace trackerTFP;
0009
0010 DistServer::DistServer(unsigned int nInputs, unsigned int nOutputs, unsigned int nInterleaving)
0011 : nInputs_(nInputs), nOutputs_(nOutputs), nInterleaving_(nInterleaving), inputs_(nInputs_) {
0012 for (unsigned int iInput = 0; iInput < this->nInputs(); ++iInput) {
0013 addr_.emplace_back(this->nInterleaving(), 0);
0014 for (unsigned int iInterleave = 0; iInterleave < this->nInterleaving(); ++iInterleave) {
0015 addr_[iInput][iInterleave] = iInterleave;
0016 }
0017 }
0018 }
0019
0020 TrackKFOutSAPtrCollection DistServer::clock(TrackKFOutSAPtrCollection& data) {
0021 for (unsigned int iInput = 0; iInput < nInputs(); ++iInput) {
0022 if (data[iInput]->dataValid()) {
0023 inputs()[iInput].push_back(data[iInput]);
0024 }
0025 }
0026
0027 vector<vector<bool> > lMap(nInputs(), vector<bool>(nOutputs()));
0028
0029 TrackKFOutSAPtrCollection lInputs(nInputs(), std::make_shared<TrackKFOut>());
0030
0031 std::vector<std::vector<unsigned int> >& addr = this->addr();
0032
0033 for (unsigned int iInput = 0; iInput < nInputs(); ++iInput) {
0034 unsigned int lAddr = addr[iInput][0];
0035 if (lAddr < inputs()[iInput].size()) {
0036 lInputs[iInput] = inputs()[iInput][lAddr];
0037 lMap[iInput][lInputs[iInput]->sortKey()] = true;
0038 }
0039 }
0040
0041 for (unsigned int iInput = 0; iInput < nInputs(); ++iInput) {
0042 vector<unsigned int>& toRotate = addr[iInput];
0043 rotate(toRotate.begin(), toRotate.begin() + 1, toRotate.end());
0044 }
0045
0046 TrackKFOutSAPtrCollection lOutputs(nOutputs(), std::make_shared<TrackKFOut>());
0047
0048 for (unsigned int iOutput = 0; iOutput < lOutputs.size(); ++iOutput) {
0049 for (unsigned int iInput = 0; iInput < nInputs(); ++iInput) {
0050 if (lMap[iInput][iOutput]) {
0051 lOutputs[iOutput] = lInputs[iInput];
0052 addr[iInput].back() += this->nInterleaving();
0053 break;
0054 }
0055 }
0056 }
0057
0058 return lOutputs;
0059 }