CMS 3D CMS Logo

TotemVFATRawToDigi.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of TOTEM offline software.
4 * Authors:
5 * Jan Kašpar (jan.kaspar@gmail.com)
6 * Nicola Minafra
7 * Laurent Forthomme
8 *
9 ****************************************************************************/
10 
18 
22 
26 
30 
34 
37 
40 
41 #include <string>
42 
44 public:
45  explicit TotemVFATRawToDigi(const edm::ParameterSet &);
46  ~TotemVFATRawToDigi() override;
47 
48  void produce(edm::Event &, const edm::EventSetup &) override;
49  void endStream() override;
51 
52 private:
54 
56 
57  std::vector<unsigned int> fedIds;
58 
62 
65 
66  template <typename DigiType>
67  void run(edm::Event &, const edm::EventSetup &);
68 };
69 
70 using namespace edm;
71 using namespace std;
72 
74  : subSystemName(conf.getParameter<string>("subSystem")),
75  subSystem(ssUndefined),
76  fedIds(conf.getParameter<vector<unsigned int>>("fedIds")),
77  rawDataUnpacker(conf.getParameterSet("RawUnpacking")),
78  rawToDigiConverter(conf.getParameterSet("RawToDigi")) {
79  fedDataToken = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("rawDataTag"));
80 
81  // validate chosen subSystem
82  if (subSystemName == "TrackingStrip")
84  else if (subSystemName == "TimingDiamond")
86  else if (subSystemName == "TotemTiming")
88  else if (subSystemName == "TotemT2")
90 
91  if (subSystem == ssUndefined)
92  throw cms::Exception("TotemVFATRawToDigi::TotemVFATRawToDigi")
93  << "Unknown sub-system string " << subSystemName << "." << endl;
94 
95  // FED (OptoRx) headers and footers
96  produces<vector<TotemFEDInfo>>(subSystemName);
97 
98  // declare products
100  produces<DetSetVector<TotemRPDigi>>(subSystemName);
101 
102  else if (subSystem == ssTimingDiamond)
103  produces<DetSetVector<CTPPSDiamondDigi>>(subSystemName);
104 
105  else if (subSystem == ssTotemTiming)
106  produces<DetSetVector<TotemTimingDigi>>(subSystemName);
107 
108  else if (subSystem == ssTotemT2)
109  produces<edmNew::DetSetVector<TotemT2Digi>>(subSystemName);
110 
111  // set default IDs
112  if (fedIds.empty()) {
113  if (subSystem == ssTrackingStrip) {
115  fedIds.push_back(id);
116 
118  fedIds.push_back(id);
119  }
120 
121  else if (subSystem == ssTimingDiamond) {
123  fedIds.push_back(id);
124  }
125 
126  else if (subSystem == ssTotemTiming) {
128  ++id)
129  fedIds.push_back(id);
130  }
131 
132  else if (subSystem == ssTotemT2) {
134  fedIds.push_back(id);
135  }
136  }
137  LogDebug("TotemVFATRawToDigi").log([this](auto &log) {
138  log << "List of FEDs handled by this instance: ";
139  string sep;
140  for (const auto &fedId : fedIds)
141  log << sep << fedId, sep = ", ";
142  });
143 
144  // conversion status
145  produces<DetSetVector<TotemVFATStatus>>(subSystemName);
146 
147  totemMappingToken = esConsumes<TotemDAQMapping, TotemReadoutRcd>(ESInputTag("", subSystemName));
148  analysisMaskToken = esConsumes<TotemAnalysisMask, TotemReadoutRcd>(ESInputTag("", subSystemName));
149 }
150 
152 
154  if (subSystem == ssTrackingStrip)
155  run<DetSetVector<TotemRPDigi>>(event, es);
156 
157  else if (subSystem == ssTimingDiamond)
158  run<DetSetVector<CTPPSDiamondDigi>>(event, es);
159 
160  else if (subSystem == ssTotemTiming)
161  run<DetSetVector<TotemTimingDigi>>(event, es);
162 
163  else if (subSystem == ssTotemT2)
164  run<edmNew::DetSetVector<TotemT2Digi>>(event, es);
165 }
166 
167 template <typename DigiType>
169  // get DAQ mapping
171 
172  // get analysis mask to mask channels
174 
175  // raw data handle
177  event.getByToken(fedDataToken, rawData);
178 
179  // book output products
180  vector<TotemFEDInfo> fedInfo;
181  DigiType digi;
182  DetSetVector<TotemVFATStatus> conversionStatus;
183 
184  // raw-data unpacking
185  SimpleVFATFrameCollection vfatCollection;
186  for (const auto &fedId : fedIds) {
187  const FEDRawData &data = rawData->FEDData(fedId);
188  if (data.size() > 0)
189  rawDataUnpacker.run(fedId, data, fedInfo, vfatCollection);
190  }
191 
192  // raw-to-digi conversion
193  rawToDigiConverter.run(vfatCollection, *mapping, *analysisMask, digi, conversionStatus);
194 
195  // commit products to event
196  event.put(make_unique<vector<TotemFEDInfo>>(fedInfo), subSystemName);
197  event.put(make_unique<DigiType>(digi), subSystemName);
198  event.put(make_unique<DetSetVector<TotemVFATStatus>>(conversionStatus), subSystemName);
199 }
200 
202 
204  // totemVFATRawToDigi
206  desc.add<edm::InputTag>("rawDataTag", edm::InputTag(""));
207  desc.add<std::string>("subSystem", "")->setComment("options: RP");
208  desc.add<std::vector<unsigned int>>("fedIds", {})
209  ->setComment(
210  "IMPORTANT: leave empty to load the default configuration from "
211  "DataFormats/FEDRawData/interface/FEDNumbering.h");
212  {
214  psd0.addUntracked<unsigned int>("verbosity", 0);
215  desc.add<edm::ParameterSetDescription>("RawUnpacking", psd0);
216  }
217  {
219  psd0.addUntracked<unsigned int>("verbosity", 0)
220  ->setComment(
221  "0-3: 1=one line/event with some corrupted VFAT frame, 2=list all corrupt VFAT frames/event, 3=all "
222  "problems with every corrupt frame");
223  psd0.add<unsigned int>("testFootprint", 2)->setComment("0=no test, 1=warn only, 2=warn and skip");
224  psd0.add<unsigned int>("testCRC", 2);
225  psd0.add<unsigned int>("testID", 2)->setComment("compare the ID from data and mapping");
226  psd0.add<unsigned int>("testECMostFrequent", 2)
227  ->setComment("compare frame EC with the most frequent value in the event");
228  psd0.add<unsigned int>("testBCMostFrequent", 2);
229  psd0.addUntracked<unsigned int>("EC_min", 10)
230  ->setComment("minimal number of frames to search for the most frequent counter value");
231  psd0.addUntracked<unsigned int>("BC_min", 10);
232  psd0.addUntracked<double>("EC_fraction", 0.6)
233  ->setComment(
234  "the most frequent counter value is accepted provided its relative occupancy is higher than this fraction");
235  psd0.addUntracked<double>("BC_fraction", 0.6);
236  psd0.add<bool>("useOlderT2TestFile", false)
237  ->setComment("treat hwID field as two separate 8-bit fields instead of one 16-bit");
238  psd0.addUntracked<bool>("printErrorSummary", false)->setComment("per-VFAT error summary at the end of the job");
239  psd0.addUntracked<bool>("printUnknownFrameSummary", false)
240  ->setComment("summary of frames found in data, but not in the mapping");
241  desc.add<edm::ParameterSetDescription>("RawToDigi", psd0);
242  }
243  descriptions.add("totemVFATRawToDigi", desc);
244  // or use the following to generate the label from the module's C++ type
245  //descriptions.addWithDefaultLabel(desc);
246 }
247 
void setComment(std::string const &value)
enum TotemVFATRawToDigi::@510 subSystem
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
edm::ESGetToken< TotemAnalysisMask, TotemReadoutRcd > analysisMaskToken
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
pps::RawDataUnpacker rawDataUnpacker
edm::ESGetToken< TotemDAQMapping, TotemReadoutRcd > totemMappingToken
void run(edm::Event &, const edm::EventSetup &)
std::vector< unsigned int > fedIds
TotemVFATRawToDigi(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ParameterDescriptionBase * add(U const &iLabel, T const &value)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
int run(int fedId, const FEDRawData &data, std::vector< TotemFEDInfo > &fedInfoColl, SimpleVFATFrameCollection &coll) const
Unpack data from FED with fedId into ‘coll’ collection.
Collection of code to convert TOTEM raw data into digi.
edm::EDGetTokenT< FEDRawDataCollection > fedDataToken
void add(std::string const &label, ParameterSetDescription const &psetDescription)
Collection of code for unpacking of TOTEM raw-data.
ParameterSet const & getParameterSet(ParameterSetID const &id)
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
void printSummaries() const
Print error summaries.
RawToDigiConverter rawToDigiConverter
static void fillDescriptions(edm::ConfigurationDescriptions &)
void produce(edm::Event &, const edm::EventSetup &) override
void run(const VFATFrameCollection &coll, const TotemDAQMapping &mapping, const TotemAnalysisMask &mask, edm::DetSetVector< TotemRPDigi > &digi, edm::DetSetVector< TotemVFATStatus > &status)
Creates RP digi.
Definition: event.py:1
void endStream() override
#define LogDebug(id)