CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RawToDigiConverter.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 *
7 ****************************************************************************/
8 
10 
12 
14 
16 
17 //----------------------------------------------------------------------------------------------------
18 
19 using namespace std;
20 using namespace edm;
21 
22 //----------------------------------------------------------------------------------------------------
23 
25  verbosity(conf.getUntrackedParameter<unsigned int>("verbosity", 0)),
26  printErrorSummary(conf.getUntrackedParameter<unsigned int>("printErrorSummary", 1)),
27  printUnknownFrameSummary(conf.getUntrackedParameter<unsigned int>("printUnknownFrameSummary", 1)),
28 
29  testFootprint(conf.getParameter<unsigned int>("testFootprint")),
30  testCRC(conf.getParameter<unsigned int>("testCRC")),
31  testID(conf.getParameter<unsigned int>("testID")),
32  testECMostFrequent(conf.getParameter<unsigned int>("testECMostFrequent")),
33  testBCMostFrequent(conf.getParameter<unsigned int>("testBCMostFrequent")),
34 
35  EC_min(conf.getUntrackedParameter<unsigned int>("EC_min", 10)),
36  BC_min(conf.getUntrackedParameter<unsigned int>("BC_min", 10)),
37 
38  EC_fraction(conf.getUntrackedParameter<double>("EC_fraction", 0.6)),
39  BC_fraction(conf.getUntrackedParameter<double>("BC_fraction", 0.6))
40 {
41 }
42 
43 //----------------------------------------------------------------------------------------------------
44 
46  map<TotemFramePosition, RawToDigiConverter::Record> &records)
47 {
48  // EC and BC checks (wrt. the most frequent value), BC checks per subsystem
51 
52  // initialise structure merging vfat frame data with the mapping
53  for (auto &p : mapping.VFATMapping)
54  {
55  TotemVFATStatus st;
56  st.setMissing(true);
57  records[p.first] = { &p.second, NULL, st };
58  }
59 
60  // event error message buffer
61  stringstream ees;
62 
63  // associate data frames with records
64  for (VFATFrameCollection::Iterator fr(&input); !fr.IsEnd(); fr.Next())
65  {
66  // frame error message buffer
67  stringstream fes;
68 
69  bool problemsPresent = false;
70  bool stopProcessing = false;
71 
72  // skip data frames not listed in the DAQ mapping
73  auto records_it = records.find(fr.Position());
74  if (records_it == records.end())
75  {
76  unknownSummary[fr.Position()]++;
77  continue;
78  }
79 
80  // update record
81  Record &record = records_it->second;
82  record.frame = fr.Data();
83  record.status.setMissing(false);
84 
85  // check footprint
86  if (testFootprint != tfNoTest && !record.frame->checkFootprint())
87  {
88  problemsPresent = true;
89 
90  if (verbosity > 0)
91  fes << " invalid footprint\n";
92 
93  if ((testFootprint == tfErr))
94  {
95  record.status.setFootprintError();
96  stopProcessing = true;
97  }
98  }
99 
100  // check CRC
101  if (testCRC != tfNoTest && !record.frame->checkCRC())
102  {
103  problemsPresent = true;
104 
105  if (verbosity > 0)
106  fes << " CRC failure\n";
107 
108  if (testCRC == tfErr)
109  {
110  record.status.setCRCError();
111  stopProcessing = true;
112  }
113  }
114 
115  // check the id mismatch
116  if (testID != tfNoTest && record.frame->isIDPresent() && (record.frame->getChipID() & 0xFFF) != (record.info->hwID & 0xFFF))
117  {
118  problemsPresent = true;
119 
120  if (verbosity > 0)
121  fes << " ID mismatch (data: 0x" << hex << record.frame->getChipID()
122  << ", mapping: 0x" << record.info->hwID << dec << ", symbId: " << record.info->symbolicID.symbolicID << ")\n";
123 
124  if (testID == tfErr)
125  {
126  record.status.setIDMismatch();
127  stopProcessing = true;
128  }
129  }
130 
131  // if there were errors, put the information to ees buffer
132  if (verbosity > 0 && problemsPresent)
133  {
134  string message = (stopProcessing) ? "(and will be dropped)" : "(but will be used though)";
135  if (verbosity > 2)
136  {
137  ees << " Frame at " << fr.Position() << " seems corrupted " << message << ":\n";
138  ees << fes.rdbuf();
139  } else
140  ees << " Frame at " << fr.Position() << " seems corrupted " << message << ".\n";
141  }
142 
143  // if there were serious errors, do not process this frame
144  if (stopProcessing)
145  continue;
146 
147  // fill EC and BC values to the statistics
148  if (fr.Data()->isECPresent())
149  ECChecker.Fill(fr.Data()->getEC(), fr.Position());
150 
151  if (fr.Data()->isBCPresent())
152  BCChecker.Fill(fr.Data()->getBC(), fr.Position());
153  }
154 
155  // analyze EC and BC statistics
157  ECChecker.Analyze(records, (testECMostFrequent == tfErr), ees);
158 
160  BCChecker.Analyze(records, (testBCMostFrequent == tfErr), ees);
161 
162  // add error message for missing frames
163  if (verbosity > 1)
164  {
165  for (const auto &p : records)
166  {
167  if (p.second.status.isMissing())
168  ees << "Frame for VFAT " << p.first << " is not present in the data.\n";
169  }
170  }
171 
172  // print error message
173  if (verbosity > 0 && !ees.rdbuf()->str().empty())
174  {
175  if (verbosity > 1)
176  LogProblem("Totem") << "Error in RawToDigiConverter::RunCommon > " << "event contains the following problems:\n" << ees.rdbuf() << endl;
177  else
178  LogProblem("Totem") << "Error in RawToDigiConverter::RunCommon > " << "event contains problems." << endl;
179  }
180 
181  // increase error counters
182  if (printErrorSummary)
183  {
184  for (const auto &it : records)
185  {
186  if (!it.second.status.isOK())
187  {
188  auto &m = errorSummary[it.first];
189  m[it.second.status]++;
190  }
191  }
192  }
193 }
194 
195 //----------------------------------------------------------------------------------------------------
196 
198  const TotemDAQMapping &mapping, const TotemAnalysisMask &analysisMask,
200 {
201  // structure merging vfat frame data with the mapping
202  map<TotemFramePosition, Record> records;
203 
204  // common processing - frame validation
205  RunCommon(input, mapping, records);
206 
207  // second loop over data
208  for (auto &p : records)
209  {
210  Record &record = p.second;
211 
212  // check whether the data come from RP VFATs
213  if (record.info->symbolicID.subSystem != TotemSymbID::RP)
214  {
215  LogProblem("Totem") << "Error in RawToDigiConverter::Run > "
216  << "VFAT is not from RP. subSystem = " << record.info->symbolicID.subSystem;
217  continue;
218  }
219 
220  // silently ignore RP CC VFATs
221  if (record.info->type != TotemVFATInfo::data)
222  continue;
223 
224  // calculate ids
225  unsigned short chipId = record.info->symbolicID.symbolicID;
226  det_id_type detId = TotemRPDetId::decToRawId(chipId / 10);
227  uint8_t chipPosition = chipId % 10;
228 
229  // update chipPosition in status
230  record.status.setChipPosition(chipPosition);
231 
232  // produce digi only for good frames
233  if (record.status.isOK())
234  {
235  // find analysis mask (needs a default=no mask, if not in present the mapping)
237  anMa.fullMask = false;
238 
239  auto analysisIter = analysisMask.analysisMask.find(record.info->symbolicID);
240  if (analysisIter != analysisMask.analysisMask.end())
241  {
242  // if there is some information about masked channels - save it into conversionStatus
243  anMa = analysisIter->second;
244  if (anMa.fullMask)
245  record.status.setFullyMaskedOut();
246  else
247  record.status.setPartiallyMaskedOut();
248  }
249 
250  // create the digi
251  unsigned short offset = chipPosition * 128;
252  const vector<unsigned char> &activeChannels = record.frame->getActiveChannels();
253 
254  for (auto ch : activeChannels)
255  {
256  // skip masked channels
257  if (!anMa.fullMask && anMa.maskedChannels.find(ch) == anMa.maskedChannels.end())
258  {
259  DetSet<TotemRPDigi> &digiDetSet = rpData.find_or_insert(detId);
260  digiDetSet.push_back(TotemRPDigi(offset + ch));
261  }
262  }
263  }
264 
265  // save status
266  DetSet<TotemVFATStatus> &statusDetSet = finalStatus.find_or_insert(detId);
267  statusDetSet.push_back(record.status);
268  }
269 }
270 
271 //----------------------------------------------------------------------------------------------------
272 
274 {
275  if (printErrorSummary)
276  {
277  LogVerbatim("Totem") << "* Error summary (error signature : number of such events)" << endl;
278  for (const auto &vit : errorSummary)
279  {
280  LogVerbatim("Totem") << vit.first << endl;
281 
282  for (const auto &it : vit.second)
283  LogVerbatim("Totem") << " " << it.first << " : " << it.second << endl;
284  }
285  }
286 
288  {
289  LogVerbatim("Totem") << "* Frames found in data, but not in the mapping (frame position : number of events)" << endl;
290  for (const auto &it : unknownSummary)
291  LogVerbatim("Totem") << " " << it.first << " : " << it.second << endl;
292  }
293 }
void Run(const VFATFrameCollection &coll, const TotemDAQMapping &mapping, const TotemAnalysisMask &mask, edm::DetSetVector< TotemRPDigi > &digi, edm::DetSetVector< TotemVFATStatus > &status)
Creates RP digi.
bool isOK() const
Contains data on masked channels of a VFAT.
void push_back(const T &t)
Definition: DetSet.h:68
unsigned int testECMostFrequent
Channel-mask mapping.
unsigned int printErrorSummary
void setCRCError(bool val=true)
Class for finding the most popular both EC and BC counter, and filling the conversion status &#39;wrong E...
JetCorrectorParameters::Record record
Definition: classes.h:7
void Analyze(T &status, bool error, std::ostream &es)
summarizes and fill the status (wrong EC and BC progress error for some frames)
enum TotemSymbID::@179 subSystem
identifies the TOTEM subsystem
TotemSymbID symbolicID
the symbolic id
#define NULL
Definition: scimark2.h:8
bool checkFootprint() const
Definition: VFATFrame.cc:62
RawToDigiConverter(const edm::ParameterSet &conf)
virtual bool checkCRC() const
Definition: VFATFrame.cc:78
unsigned int testFootprint
flags for which tests to run
std::map< TotemSymbID, TotemVFATAnalysisMask > analysisMask
void setFullyMaskedOut()
static std::string const input
Definition: EdmProvDump.cc:44
reference find_or_insert(det_id_type id)
Definition: DetSetVector.h:254
the VFATFrameCollection interator
unsigned int printUnknownFrameSummary
The mapping between FramePosition and VFATInfo.
enum TotemVFATInfo::@178 type
is data of coincidence-chip VFAT
const TotemVFATInfo * info
bool fullMask
whether all channels of the VFAT shall be masked
void PrintSummaries()
Print error summaries.
void setMissing(bool val=true)
unsigned int symbolicID
integer-encoded symbolic ID
Definition: TotemSymbId.h:24
void setFootprintError(bool val=true)
uint32_t det_id_type
Definition: DetSet.h:21
unsigned char verbosity
std::map< TotemFramePosition, unsigned int > unknownSummary
unsigned int hwID
the hardware ID (16 bit)
unsigned int testBCMostFrequent
std::map< TotemFramePosition, TotemVFATInfo > VFATMapping
void Fill(word counter, TotemFramePosition fr)
add new value to map, counter takes value of EC or BC number
void setPartiallyMaskedOut()
std::set< unsigned char > maskedChannels
list of channels to be masked
std::map< TotemFramePosition, std::map< TotemVFATStatus, unsigned int > > errorSummary
error summaries
bool IsEnd()
returns whether the iterator points over the end of the collection
void setIDMismatch(bool val=true)
bool isIDPresent() const
Returns true if the ID word is present in the frame.
Definition: VFATFrame.h:87
double EC_fraction
the minimal required (relative) occupancy of the most frequent counter value to be accepted ...
VFATFrame::word getChipID() const
Returns ChipID (ChipID&lt;11:0&gt;).
Definition: VFATFrame.h:63
void setChipPosition(uint8_t _cp)
virtual std::vector< unsigned char > getActiveChannels() const
Definition: VFATFrame.cc:37
static unsigned int decToRawId(unsigned int dec)
fast conversion Decimal to Raw ID
Definition: TotemRPDetId.h:129
void RunCommon(const VFATFrameCollection &input, const TotemDAQMapping &mapping, std::map< TotemFramePosition, Record > &records)
Common processing for all VFAT based sub-systems.
unsigned int EC_min
the minimal required number of frames to determine the most frequent counter value ...