1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
// -*- C++ -*-
//
// Package: temp/CTPPSTotemDigiToRaw
// Class: CTPPSTotemDigiToRaw
//
/**\class CTPPSTotemDigiToRaw CTPPSTotemDigiToRaw.cc temp/CTPPSTotemDigiToRaw/plugins/CTPPSTotemDigiToRaw.cc
Description: [one line class summary]
Implementation:
[Notes on implementation]
*/
//
// Original Author: Dilson De Jesus Damiao
// Maria Elena Pol
// Created: Tue, 11 Sep 2018 17:12:12 GMT
//
//
// system include files
#include <memory>
// user include files
#include "FWCore/Framework/interface/ESHandle.h"
#include "FWCore/Framework/interface/ESWatcher.h"
#include "FWCore/Framework/interface/Event.h"
#include "FWCore/Framework/interface/EventSetup.h"
#include "FWCore/Framework/interface/Frameworkfwd.h"
#include "FWCore/Framework/interface/MakerMacros.h"
#include "FWCore/Framework/interface/stream/EDProducer.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/PluginManager/interface/ModuleDef.h"
#include "FWCore/Utilities/interface/InputTag.h"
#include "FWCore/Utilities/interface/StreamID.h"
#include "FWCore/Utilities/interface/ESGetToken.h"
#include "CondFormats/PPSObjects/interface/TotemDAQMapping.h"
#include "CondFormats/PPSObjects/interface/TotemFramePosition.h"
#include "CondFormats/DataRecord/interface/TotemReadoutRcd.h"
#include "DataFormats/CTPPSDetId/interface/TotemRPDetId.h"
#include "DataFormats/CTPPSDigi/interface/TotemRPDigi.h"
#include "DataFormats/CTPPSDigi/interface/TotemVFATStatus.h"
#include "DataFormats/Common/interface/DetSetVector.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/DetId/interface/DetIdCollection.h"
#include "DataFormats/FEDRawData/interface/FEDNumbering.h"
#include "DataFormats/FEDRawData/interface/FEDRawData.h"
#include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
#include "EventFilter/CTPPSRawToDigi/interface/CTPPSTotemDataFormatter.h"
#include "EventFilter/CTPPSRawToDigi/interface/VFATFrameCollection.h"
//
// class declaration
//
class CTPPSTotemDigiToRaw : public edm::stream::EDProducer<> {
public:
explicit CTPPSTotemDigiToRaw(const edm::ParameterSet&);
~CTPPSTotemDigiToRaw() override;
static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
private:
void beginStream(edm::StreamID) override;
void produce(edm::Event&, const edm::EventSetup&) override;
unsigned long eventCounter_;
std::set<unsigned int> fedIds_;
int allDigiCounter_;
int allWordCounter_;
bool debug_;
edm::ESWatcher<TotemReadoutRcd> recordWatcher_;
edm::EDGetTokenT<edm::DetSetVector<TotemRPDigi>> tTotemRPDigi_;
edm::ESGetToken<TotemDAQMapping, TotemReadoutRcd> tTotemDAQMapping_;
std::vector<CTPPSTotemDataFormatter::PPSStripIndex> v_iDdet2fed_;
TotemFramePosition fPos_;
// ----------member data ---------------------------
};
//
// constants, enums and typedefs
//
//
// static data member definitions
//
//
// constructors and destructor
//
CTPPSTotemDigiToRaw::CTPPSTotemDigiToRaw(const edm::ParameterSet& iConfig)
: eventCounter_(0), allDigiCounter_(0), allWordCounter_(0) {
//register your products
tTotemRPDigi_ = consumes<edm::DetSetVector<TotemRPDigi>>(iConfig.getParameter<edm::InputTag>("InputLabel"));
tTotemDAQMapping_ = esConsumes<TotemDAQMapping, TotemReadoutRcd>();
produces<FEDRawDataCollection>();
}
CTPPSTotemDigiToRaw::~CTPPSTotemDigiToRaw() {
edm::LogInfo("CTPPSTotemDigiToRaw") << " CTPPSTotemDigiToRaw destructor!";
}
//
// member functions
//
// ------------ method called to produce the data ------------
void CTPPSTotemDigiToRaw::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) {
using namespace edm;
using namespace std;
eventCounter_++;
edm::Handle<edm::DetSetVector<TotemRPDigi>> digiCollection;
iEvent.getByToken(tTotemRPDigi_, digiCollection);
CTPPSTotemDataFormatter::RawData rawdata;
CTPPSTotemDataFormatter::Digis digis;
int digiCounter = 0;
for (auto const& di : *digiCollection) {
digiCounter += (di.data).size();
digis[di.detId()] = di.data;
}
allDigiCounter_ += digiCounter;
edm::ESHandle<TotemDAQMapping> mapping;
// label of the CTPPS sub-system
if (recordWatcher_.check(iSetup)) {
mapping = iSetup.getHandle(tTotemDAQMapping_);
for (const auto& p : mapping->VFATMapping) {
//get TotemVFATInfo information
fedIds_.emplace(p.first.getFEDId());
CTPPSTotemDataFormatter::PPSStripIndex iDdet2fed = {(p.second.symbolicID).symbolicID,
p.second.hwID,
p.first.getFEDId(),
p.first.getIdxInFiber(),
p.first.getGOHId()};
v_iDdet2fed_.emplace_back(iDdet2fed);
}
}
CTPPSTotemDataFormatter formatter(mapping->VFATMapping);
// create product (raw data)
auto buffers = std::make_unique<FEDRawDataCollection>();
std::sort(v_iDdet2fed_.begin(), v_iDdet2fed_.end(), CTPPSTotemDataFormatter::compare);
// convert data to raw
formatter.formatRawData(iEvent.id().event(), rawdata, digis, v_iDdet2fed_);
// pack raw data into collection
for (auto it : fedIds_) {
FEDRawData& fedRawData = buffers->FEDData(it);
CTPPSTotemDataFormatter::RawData::iterator fedbuffer = rawdata.find(it);
if (fedbuffer != rawdata.end())
fedRawData = fedbuffer->second;
}
allWordCounter_ += formatter.nWords();
if (debug_)
LogDebug("CTPPSTotemDigiToRaw") << "Words/Digis this iEvent: " << digiCounter << "(fm:" << formatter.nDigis()
<< ")/" << formatter.nWords() << " all: " << allDigiCounter_ << "/"
<< allWordCounter_;
iEvent.put(std::move(buffers));
}
// ------------ method called once each stream before processing any runs, lumis or events ------------
void CTPPSTotemDigiToRaw::beginStream(edm::StreamID) {}
// ------------ method fills 'descriptions' with the allowed parameters for the module ------------
void CTPPSTotemDigiToRaw::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
edm::ParameterSetDescription desc;
desc.add<edm::InputTag>("InputLabel", edm::InputTag("RPSiDetDigitizer"));
descriptions.add("ctppsTotemRawData", desc);
}
//define this as a plug-in
DEFINE_FWK_MODULE(CTPPSTotemDigiToRaw);
|