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 
31 
36 
39 
42 
43 #include <string>
44 
46 public:
47  explicit TotemVFATRawToDigi(const edm::ParameterSet &);
48  ~TotemVFATRawToDigi() override;
49 
50  void produce(edm::Event &, const edm::EventSetup &) override;
51  void endStream() override;
53 
54 private:
56 
58 
59  std::vector<unsigned int> fedIds;
60 
64 
68 
69  template <typename DigiType>
70  void run(edm::Event &, const edm::EventSetup &);
71 };
72 
73 using namespace edm;
74 using namespace std;
75 
77  : subSystemName(conf.getParameter<string>("subSystem")),
78  subSystem(ssUndefined),
79  fedIds(conf.getParameter<vector<unsigned int>>("fedIds")),
80  rawDataUnpacker(conf.getParameterSet("RawUnpacking")),
81  rawToDigiConverter(conf.getParameterSet("RawToDigi")),
82  errSummary("TotemVFATRawToDigi", "[TotemVFATRawToDigi]", false) {
83  fedDataToken = consumes<FEDRawDataCollection>(conf.getParameter<edm::InputTag>("rawDataTag"));
84 
85  // validate chosen subSystem
86  if (subSystemName == "TrackingStrip")
88  else if (subSystemName == "TimingDiamond")
90  else if (subSystemName == "TotemTiming")
92  else if (subSystemName == "TotemT2")
94 
95  if (subSystem == ssUndefined)
96  throw cms::Exception("TotemVFATRawToDigi::TotemVFATRawToDigi")
97  << "Unknown sub-system string " << subSystemName << "." << endl;
98 
99  // FED (OptoRx) headers and footers
100  produces<vector<TotemFEDInfo>>(subSystemName);
101 
102  // declare products
103  if (subSystem == ssTrackingStrip)
104  produces<DetSetVector<TotemRPDigi>>(subSystemName);
105 
106  else if (subSystem == ssTimingDiamond)
107  produces<DetSetVector<CTPPSDiamondDigi>>(subSystemName);
108 
109  else if (subSystem == ssTotemTiming)
110  produces<DetSetVector<TotemTimingDigi>>(subSystemName);
111 
112  else if (subSystem == ssTotemT2)
113  produces<edmNew::DetSetVector<TotemT2Digi>>(subSystemName);
114 
115  // set default IDs
116  if (fedIds.empty()) {
117  if (subSystem == ssTrackingStrip) {
119  fedIds.push_back(id);
120 
122  fedIds.push_back(id);
123  }
124 
125  else if (subSystem == ssTimingDiamond) {
127  fedIds.push_back(id);
128  }
129 
130  else if (subSystem == ssTotemTiming) {
132  ++id)
133  fedIds.push_back(id);
134  }
135 
136  else if (subSystem == ssTotemT2) {
138  fedIds.push_back(id);
139  }
140  }
141  LogDebug("TotemVFATRawToDigi").log([this](auto &log) {
142  log << "List of FEDs handled by this instance: ";
143  string sep;
144  for (const auto &fedId : fedIds)
145  log << sep << fedId, sep = ", ";
146  });
147 
148  // conversion status
149  produces<DetSetVector<TotemVFATStatus>>(subSystemName);
150 
151  totemMappingToken = esConsumes<TotemDAQMapping, TotemReadoutRcd>(ESInputTag("", subSystemName));
152  analysisMaskToken = esConsumes<TotemAnalysisMask, TotemAnalysisMaskRcd>(ESInputTag("", subSystemName));
153 }
154 
156 
158  if (subSystem == ssTrackingStrip)
159  run<DetSetVector<TotemRPDigi>>(event, es);
160 
161  else if (subSystem == ssTimingDiamond)
162  run<DetSetVector<CTPPSDiamondDigi>>(event, es);
163 
164  else if (subSystem == ssTotemTiming)
165  run<DetSetVector<TotemTimingDigi>>(event, es);
166 
167  else if (subSystem == ssTotemT2)
168  run<edmNew::DetSetVector<TotemT2Digi>>(event, es);
169 }
170 
171 template <typename DigiType>
173  // mapping and analysis mask
175  ESHandle<TotemAnalysisMask> analysisMaskHandle;
177 
178  // raw data handle
180  event.getByToken(fedDataToken, rawData);
181 
182  // book output products
183  vector<TotemFEDInfo> fedInfo;
184  DigiType digi;
185  DetSetVector<TotemVFATStatus> conversionStatus;
186 
187  // raw-data unpacking
188  bool data_exist = false;
189  SimpleVFATFrameCollection vfatCollection;
190  for (const auto &fedId : fedIds) {
191  const FEDRawData &data = rawData->FEDData(fedId);
192  if (data.size() > 0) {
193  rawDataUnpacker.run(fedId, data, fedInfo, vfatCollection);
194  data_exist = true;
195  }
196  }
197 
198  // get mapping records and do raw-to-digi conversion only if some data exists
199  if (data_exist) {
200  // get DAQ mapping
202  if (!mapping.isValid() || mapping.failedToGet()) {
203  throw cms::Exception("TotemVFATRawToDigi::TotemVFATRawToDigi")
204  << "No DAQMapping found for " << subSystemName << "." << endl;
205  }
206 
207  // get analysis mask to mask channels
208  analysisMaskHandle = es.getHandle(analysisMaskToken);
209  if (analysisMaskHandle.isValid() && !analysisMaskHandle.failedToGet()) {
210  analysisMask = *analysisMaskHandle;
211  } else {
212  errSummary.add(fmt::format("No AnalysisMask found for {0}", subSystemName), "");
214  }
215 
216  // raw-to-digi conversion
217  rawToDigiConverter.run(vfatCollection, *mapping, analysisMask, digi, conversionStatus);
218  }
219 
220  // commit products to event
221  event.put(make_unique<vector<TotemFEDInfo>>(fedInfo), subSystemName);
222  event.put(make_unique<DigiType>(digi), subSystemName);
223  event.put(make_unique<DetSetVector<TotemVFATStatus>>(conversionStatus), subSystemName);
224 }
225 
229 }
230 
232  // totemVFATRawToDigi
234  desc.add<edm::InputTag>("rawDataTag", edm::InputTag(""));
235  desc.add<std::string>("subSystem", "")->setComment("options: RP");
236  desc.add<std::vector<unsigned int>>("fedIds", {})
237  ->setComment(
238  "IMPORTANT: leave empty to load the default configuration from "
239  "DataFormats/FEDRawData/interface/FEDNumbering.h");
240  {
242  psd0.addUntracked<unsigned int>("verbosity", 0);
243  desc.add<edm::ParameterSetDescription>("RawUnpacking", psd0);
244  }
245  {
247  psd0.addUntracked<unsigned int>("verbosity", 0)
248  ->setComment(
249  "0-3: 1=one line/event with some corrupted VFAT frame, 2=list all corrupt VFAT frames/event, 3=all "
250  "problems with every corrupt frame");
251  psd0.add<unsigned int>("testFootprint", 2)->setComment("0=no test, 1=warn only, 2=warn and skip");
252  psd0.add<unsigned int>("testCRC", 2);
253  psd0.add<unsigned int>("testID", 2)->setComment("compare the ID from data and mapping");
254  psd0.add<unsigned int>("testECMostFrequent", 2)
255  ->setComment("compare frame EC with the most frequent value in the event");
256  psd0.add<unsigned int>("testBCMostFrequent", 2);
257  psd0.addUntracked<unsigned int>("EC_min", 10)
258  ->setComment("minimal number of frames to search for the most frequent counter value");
259  psd0.addUntracked<unsigned int>("BC_min", 10);
260  psd0.addUntracked<double>("EC_fraction", 0.6)
261  ->setComment(
262  "the most frequent counter value is accepted provided its relative occupancy is higher than this fraction");
263  psd0.addUntracked<double>("BC_fraction", 0.6);
264  psd0.add<bool>("useOlderT2TestFile", false)
265  ->setComment("treat hwID field as two separate 8-bit fields instead of one 16-bit");
266  psd0.addUntracked<bool>("printErrorSummary", false)->setComment("per-VFAT error summary at the end of the job");
267  psd0.addUntracked<bool>("printUnknownFrameSummary", false)
268  ->setComment("summary of frames found in data, but not in the mapping");
269  desc.add<edm::ParameterSetDescription>("RawToDigi", psd0);
270  }
271  descriptions.add("totemVFATRawToDigi", desc);
272  // or use the following to generate the label from the module's C++ type
273  //descriptions.addWithDefaultLabel(desc);
274 }
275 
void setComment(std::string const &value)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
Channel-mask mapping.
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
pps::RawDataUnpacker rawDataUnpacker
edm::ESGetToken< TotemDAQMapping, TotemReadoutRcd > totemMappingToken
edm::ESGetToken< TotemAnalysisMask, TotemAnalysisMaskRcd > analysisMaskToken
void run(edm::Event &, const edm::EventSetup &)
std::vector< unsigned int > fedIds
CTPPSRawToDigiErrorSummary errSummary
TotemVFATRawToDigi(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void add(const std::string &message, const std::string &details="")
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.
bool isValid() const
Definition: ESHandle.h:44
bool failedToGet() const
Definition: ESHandle.h:46
Collection of code to convert TOTEM raw data into digi.
enum TotemVFATRawToDigi::@481 subSystem
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)