CMS 3D CMS Logo

PixelSLinkDataInputSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelInputSources
4 // Class: PixelSLinkDataInputSource
5 //
14 //
15 // Original Author: Freya Blekman
16 // Created: Fri Sep 7 15:46:34 CEST 2007
17 //
18 //
19 
28 #include <iostream>
29 #include <memory>
30 
31 using namespace edm;
32 
33 // function to get the trigger number from fill words
34 int PixelSLinkDataInputSource::getEventNumberFromFillWords(const std::vector<uint64_t> &buffer, uint32_t &totword) {
35  // buffer validity, should already be pretty clean as this is exactly what
36  // goes into the FEDRawDataobject.
37 
38  // code copied directly from A. Ryd's fill word checker in
39  // PixelFEDInterface::PwordSlink64
40 
41  int fif2cnt = 0;
42  int dumcnt = 0;
43  int gapcnt = 0;
44  uint32_t gap[9];
45  uint32_t dum[9];
46  uint32_t word[2] = {0, 0};
47  uint32_t chan = 0;
48  uint32_t roc = 0;
49 
50  const uint32_t rocmsk = 0x3e00000;
51  const uint32_t chnlmsk = 0xfc000000;
52 
53  for (int jk = 1; jk < 9; jk++)
54  gap[jk] = 0;
55  for (int jk = 1; jk < 9; jk++)
56  dum[jk] = 0;
57 
58  int fifcnt = 1;
59  for (size_t kk = 0; kk < buffer.size(); ++kk) {
60  word[0] = (uint32_t)buffer[kk];
61  word[1] = (uint32_t)(buffer[kk] >> 32);
62 
63  for (size_t iw = 0; iw < 2; iw++) {
64  chan = ((word[iw] & chnlmsk) >> 26);
65  roc = ((word[iw] & rocmsk) >> 21);
66 
67  // count non-error words
68  if (roc < 25) {
69  if ((chan > 4) && (chan < 10) && (fifcnt != 2)) {
70  fif2cnt = 0;
71  fifcnt = 2;
72  }
73  if ((chan > 9) && (chan < 14) && (fifcnt != 3)) {
74  fif2cnt = 0;
75  fifcnt = 3;
76  }
77  if ((chan > 13) && (chan < 19) && (fifcnt != 4)) {
78  fif2cnt = 0;
79  fifcnt = 4;
80  }
81  if ((chan > 18) && (chan < 23) && (fifcnt != 5)) {
82  fif2cnt = 0;
83  fifcnt = 5;
84  }
85  if ((chan > 22) && (chan < 28) && (fifcnt != 6)) {
86  fif2cnt = 0;
87  fifcnt = 6;
88  }
89  if ((chan > 27) && (chan < 32) && (fifcnt != 7)) {
90  fif2cnt = 0;
91  fifcnt = 7;
92  }
93  if ((chan > 31) && (fifcnt != 8)) {
94  fif2cnt = 0;
95  fifcnt = 8;
96  }
97  fif2cnt++;
98  }
99  if (roc == 26) {
100  gap[fifcnt] = (0x1000 + (word[iw] & 0xff));
101  gapcnt++;
102  }
103 
104  if ((roc == 27) && ((fif2cnt + dumcnt) < 6)) {
105  dumcnt++;
106  dum[fifcnt] = (0x1000 + (word[iw] & 0xff));
107  } else if ((roc == 27) && ((fif2cnt + dumcnt) > 6)) {
108  dumcnt = 1;
109  fif2cnt = 0;
110  fifcnt++;
111  }
112  }
113 
114  // word check complete
115  if (((fif2cnt + dumcnt) == 6) && (dumcnt > 0)) // done with this fifo
116  {
117  dumcnt = 0;
118  fif2cnt = 0;
119  fifcnt++;
120  }
121  if ((gapcnt > 0) && ((dumcnt + fif2cnt) > 5)) // done with this fifo
122  {
123  gapcnt = 0;
124  fifcnt++;
125  fif2cnt = 0;
126  dumcnt = 0;
127  } else if ((gapcnt > 0) && ((dumcnt + fif2cnt) < 6))
128  gapcnt = 0;
129 
130  } // end of fifo-3 word loop-see what we got!
131 
132  int status = 0;
133 
134  if (gap[1] > 0) {
135  totword = (gap[1] & 0xff);
136  status = 1;
137  } else if (gap[2] > 0) {
138  totword = (gap[2] & 0xff);
139  status = 1;
140  } else if (dum[1] > 0) {
141  totword = (dum[1] & 0xff);
142  status = 1;
143  } else if (dum[2] > 0) {
144  totword = (dum[2] & 0xff);
145  status = 1;
146  }
147 
148  if (gap[3] > 0) {
149  totword = totword | ((gap[3] & 0xff) << 8);
150  status = status | 0x2;
151  } else if (gap[4] > 0) {
152  totword = totword | ((gap[4] & 0xff) << 8);
153  status = status | 0x2;
154  } else if (dum[3] > 0) {
155  totword = totword | ((dum[3] & 0xff) << 8);
156  status = status | 0x2;
157  } else if (dum[4] > 0) {
158  totword = totword | ((dum[4] & 0xff) << 8);
159  status = status | 0x2;
160  }
161 
162  if (gap[5] > 0) {
163  totword = totword | ((gap[5] & 0xff) << 16);
164  status = status | 0x4;
165  } else if (gap[6] > 0) {
166  totword = totword | ((gap[6] & 0xff) << 16);
167  status = status | 0x4;
168  } else if (dum[5] > 0) {
169  totword = totword | ((dum[5] & 0xff) << 16);
170  status = status | 0x4;
171  } else if (dum[6] > 0) {
172  totword = totword | ((dum[6] & 0xff) << 16);
173  status = status | 0x4;
174  }
175 
176  if (gap[7] > 0) {
177  totword = totword | ((gap[7] & 0xff) << 24);
178  status = status | 0x8;
179  } else if (gap[8] > 0) {
180  totword = totword | ((gap[8] & 0xff) << 24);
181  status = status | 0x8;
182  } else if (dum[7] > 0) {
183  totword = totword | ((dum[7] & 0xff) << 24);
184  status = status | 0x8;
185  } else if (dum[8] > 0) {
186  totword = totword | ((dum[8] & 0xff) << 24);
187  status = status | 0x8;
188  }
189  return (status);
190 }
191 
192 // constructor
196  m_fedid(pset.getUntrackedParameter<int>("fedid")),
197  m_fileindex(0),
198  m_runnumber(pset.getUntrackedParameter<int>("runNumber", -1)),
199  m_currenteventnumber(0),
200  m_currenttriggernumber(0),
201  m_eventnumber_shift(0) {
202  produces<FEDRawDataCollection>();
203 
204  if (m_fileindex >= fileNames(0).size()) {
205  edm::LogInfo("") << "no more file to read " << std::endl;
206  return; // ???
207  }
208  std::string currentfilename = fileNames(0)[m_fileindex];
209  edm::LogInfo("") << "now examining file " << currentfilename;
210  m_fileindex++;
211  // reading both castor and other ('normal'/dcap) files.
212  IOOffset size = -1;
214 
215  edm::LogInfo("PixelSLinkDataInputSource")
216  << " unsigned long int size = " << sizeof(unsigned long int)
217  << "\n unsigned long size = " << sizeof(unsigned long)
218  << "\n unsigned long long size = " << sizeof(unsigned long long) << "\n uint32_t size = " << sizeof(uint32_t)
219  << "\n uint64_t size = " << sizeof(uint64_t) << std::endl;
220 
221  bool exists = StorageFactory::get()->check(currentfilename, &size);
222 
223  edm::LogInfo("PixelSLinkDataInputSource") << "file size " << size << std::endl;
224 
225  if (!exists) {
226  edm::LogInfo("") << "file " << currentfilename << " cannot be found.";
227  return;
228  }
229  // now open the file stream:
230  storage = StorageFactory::get()->open(currentfilename);
231  // (throw if storage is 0)
232 
233  // check run number by opening up data file...
234 
235  Storage &temp_file = *storage;
236  // IOSize n =
237  temp_file.read((char *)&m_data, 8);
238  if ((m_data >> 60) != 0x5) {
239  uint32_t runnum = m_data;
240  if (m_runnumber != -1)
241  edm::LogInfo("") << "WARNING: observed run number encoded in S-Link dump. Overwriting "
242  "run number as defined in .cfg file!!! Run number now set to "
243  << runnum << " (was " << m_runnumber << ")";
244  m_runnumber = runnum;
245  }
246  temp_file.read((char *)&m_data, 8);
247  m_currenteventnumber = (m_data >> 32) & 0x00ffffff;
248 }
249 
250 // destructor
252 
256  Storage &m_file = *storage;
257 
258  // create product (raw data)
259  buffers = std::make_unique<FEDRawDataCollection>();
260 
261  // uint32_t currenteventnumber = (m_data >> 32)&0x00ffffff;
262  uint32_t eventnumber = (m_data >> 32) & 0x00ffffff;
263 
264  do {
265  std::vector<uint64_t> buffer;
266 
267  uint16_t count = 0;
268  eventnumber = (m_data >> 32) & 0x00ffffff;
269  if (m_currenteventnumber == 0)
270  m_currenteventnumber = eventnumber;
271  edm::LogInfo("PixelSLinkDataInputSource::produce()")
272  << "**** event number = " << eventnumber << " global event number " << m_currenteventnumber << " data "
273  << std::hex << m_data << std::dec << std::endl;
274  while ((m_data >> 60) != 0x5) {
275  // std::cout << std::hex << m_data << std::dec << std::endl;
276  if (count == 0) {
277  edm::LogWarning("") << "DATA CORRUPTION!";
278  edm::LogWarning("") << "Expected to find header, but read: 0x" << std::hex << m_data << std::dec;
279  }
280 
281  count++;
282  int n = m_file.read((char *)&m_data, 8);
283  edm::LogWarning("") << "next data " << std::hex << m_data << std::dec << std::endl;
284 
285  if (n != 8) {
286  edm::LogInfo("") << "End of input file";
287  return false;
288  }
289  }
290 
291  if (count > 0) {
292  edm::LogWarning("") << "Had to read " << count << " words before finding header!" << std::endl;
293  }
294 
295  if (m_fedid > -1) {
296  m_data = (m_data & 0xfffffffffff000ffLL) | ((m_fedid & 0xfff) << 8);
297  }
298 
299  uint16_t fed_id = (m_data >> 8) & 0xfff;
300  // std::cout << "fed id = " << fed_id << std::endl;
301  buffer.push_back(m_data);
302 
303  do {
304  m_file.read((char *)&m_data, 8);
305  buffer.push_back(m_data);
306  } while ((m_data >> 60) != 0xa);
307  // std::cout << "read " << buffer.size() << " long words" << std::endl;
308 
309  auto rawData = std::make_unique<FEDRawData>(8 * buffer.size());
310  // FEDRawData * rawData = new FEDRawData(8*buffer.size());
311  unsigned char *dataptr = rawData->data();
312 
313  for (uint16_t i = 0; i < buffer.size(); i++) {
314  ((uint64_t *)dataptr)[i] = buffer[i];
315  }
316  uint32_t thetriggernumber = 0;
317  int nfillwords = 0; // getEventNumberFromFillWords(buffer,thetriggernumber);
318 
319  if (nfillwords > 0) {
320  LogInfo("") << "n fill words = " << nfillwords << ", trigger numbers: " << thetriggernumber << ","
321  << m_currenttriggernumber << std::endl;
322  m_eventnumber_shift = thetriggernumber - m_currenttriggernumber;
323  }
324  m_currenttriggernumber = thetriggernumber;
325  FEDRawData &fedRawData = buffers->FEDData(fed_id);
326  fedRawData = *rawData;
327 
328  // read the first data member of the next blob to check on event number
329  int n = m_file.read((char *)&m_data, 8);
330  if (n == 0) {
331  edm::LogInfo("") << "End of input file";
332  }
333  m_currenteventnumber = (m_data >> 32) & 0x00ffffff;
334  if (m_currenteventnumber < eventnumber)
335  LogError("PixelSLinkDataInputSource")
336  << " error, the previous event number (" << eventnumber << ") is LARGER than the next event number ("
337  << m_currenteventnumber << ")" << std::endl;
338 
339  } while (eventnumber == m_currenteventnumber);
340 
341  uint32_t realeventno = synchronizeEvents();
342  if (m_runnumber != 0)
343  id = edm::EventID(m_runnumber, id.luminosityBlock(), realeventno);
344  else
345  id = edm::EventID(id.run(), id.luminosityBlock(), realeventno);
346  return true;
347 }
348 
349 // produce() method. This is the worker method that is called every event.
351  event.put(std::move(buffers));
352  buffers.reset();
353 }
354 
355 // this function sets the m_globaleventnumber quantity. It uses the
356 // m_currenteventnumber and m_currenttriggernumber values as input
358  int32_t result = m_currenteventnumber - 1;
359 
360  return (uint32_t)result;
361 }
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
mps_update.status
status
Definition: mps_update.py:68
edm::IDGeneratorSourceBase< PuttableSourceBase >::run
RunNumber_t run() const
Definition: IDGeneratorSourceBase.h:37
edm
HLT enums.
Definition: AlignableModifier.h:19
StorageFactory::open
std::unique_ptr< Storage > open(const std::string &url, int mode=IOFlags::OpenRead) const
Definition: StorageFactory.cc:124
l1tstage2_dqm_sourceclient-live_cfg.rawData
rawData
Definition: l1tstage2_dqm_sourceclient-live_cfg.py:163
edm::InputSourceDescription
Definition: InputSourceDescription.h:21
protons_cff.time
time
Definition: protons_cff.py:35
edm::IDGeneratorSourceBase< PuttableSourceBase >::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: IDGeneratorSourceBase.h:39
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
FEDRawData.h
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
PixelSLinkDataInputSource::m_fedid
int m_fedid
Definition: PixelSLinkDataInputSource.h:50
FEDRawData
Definition: FEDRawData.h:19
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
StorageFactory::getToModify
static StorageFactory * getToModify(void)
Definition: StorageFactory.cc:30
PixelSLinkDataInputSource::m_eventnumber_shift
int32_t m_eventnumber_shift
Definition: PixelSLinkDataInputSource.h:58
word
uint64_t word
Definition: CTPPSTotemDataFormatter.cc:29
l1t_dqm_sourceclient-live_cfg.fedRawData
fedRawData
Definition: l1t_dqm_sourceclient-live_cfg.py:188
PixelSLinkDataInputSource::m_currenttriggernumber
uint32_t m_currenttriggernumber
Definition: PixelSLinkDataInputSource.h:56
PixelSLinkDataInputSource::~PixelSLinkDataInputSource
~PixelSLinkDataInputSource() override
Definition: PixelSLinkDataInputSource.cc:251
StorageFactory::get
static const StorageFactory * get(void)
Definition: StorageFactory.cc:28
StorageAccount.h
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
GetRecoTauVFromDQM_MC_cff.kk
kk
Definition: GetRecoTauVFromDQM_MC_cff.py:84
HLT_FULL_cff.gap
gap
Definition: HLT_FULL_cff.py:8513
PixelSLinkDataInputSource::synchronizeEvents
uint32_t synchronizeEvents()
Definition: PixelSLinkDataInputSource.cc:357
funct::true
true
Definition: Factorize.h:173
PixelSLinkDataInputSource::produce
void produce(edm::Event &event) override
Definition: PixelSLinkDataInputSource.cc:350
edm::ParameterSet
Definition: ParameterSet.h:47
PixelSLinkDataInputSource::storage
std::unique_ptr< Storage > storage
Definition: PixelSLinkDataInputSource.h:52
Storage::read
virtual IOSize read(void *into, IOSize n, IOOffset pos)
Definition: Storage.cc:12
StorageFactory::check
bool check(const std::string &url, IOOffset *size=nullptr) const
Definition: StorageFactory.cc:181
IOOffset
int64_t IOOffset
Definition: IOTypes.h:19
StorageFactory.h
createfilelist.int
int
Definition: createfilelist.py:10
PixelSLinkDataInputSource::buffers
std::unique_ptr< FEDRawDataCollection > buffers
Definition: PixelSLinkDataInputSource.h:60
FEDRawDataCollection.h
PixelSLinkDataInputSource::PixelSLinkDataInputSource
PixelSLinkDataInputSource(const edm::ParameterSet &pset, const edm::InputSourceDescription &desc)
Definition: PixelSLinkDataInputSource.cc:193
IOTypes.h
edm::FromFiles::fileNames
std::vector< std::string > fileNames(unsigned iCatalog) const
Definition: FromFiles.h:22
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
PixelSLinkDataInputSource.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
L1DTConfigBti_cff.LL
LL
Definition: L1DTConfigBti_cff.py:25
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
eostools.move
def move(src, dest)
Definition: eostools.py:511
Frameworkfwd.h
edm::ProducerSourceFromFiles
Definition: ProducerSourceFromFiles.h:17
PixelSLinkDataInputSource::m_fileindex
uint32_t m_fileindex
Definition: PixelSLinkDataInputSource.h:51
officialStyle.chan
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi....
Definition: officialStyle.py:106
edm::EventAuxiliary::ExperimentType
ExperimentType
Definition: EventAuxiliary.h:18
PixelMapPlotter.roc
roc
Definition: PixelMapPlotter.py:498
StorageFactory::enableAccounting
bool enableAccounting(bool enabled)
Definition: StorageFactory.cc:32
PixelSLinkDataInputSource::m_data
uint64_t m_data
Definition: PixelSLinkDataInputSource.h:54
PixelSLinkDataInputSource::m_runnumber
int m_runnumber
Definition: PixelSLinkDataInputSource.h:53
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
PixelSLinkDataInputSource::setRunAndEventInfo
bool setRunAndEventInfo(edm::EventID &id, edm::TimeValue_t &time, edm::EventAuxiliary::ExperimentType &) override
Definition: PixelSLinkDataInputSource.cc:253
mps_fire.result
result
Definition: mps_fire.py:311
PixelSLinkDataInputSource::m_currenteventnumber
uint32_t m_currenteventnumber
Definition: PixelSLinkDataInputSource.h:55
event
Definition: event.py:1
edm::EventID
Definition: EventID.h:31
edm::Event
Definition: Event.h:73
Storage
Definition: Storage.h:20
TauDecayModes.dec
dec
Definition: TauDecayModes.py:142
PixelSLinkDataInputSource::getEventNumberFromFillWords
int getEventNumberFromFillWords(const std::vector< uint64_t > &data, uint32_t &totword)
Definition: PixelSLinkDataInputSource.cc:34
edm::TimeValue_t
unsigned long long TimeValue_t
Definition: Timestamp.h:28
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443