CMS 3D CMS Logo

LaserSorter.cc
Go to the documentation of this file.
1 //emacs settings:-*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 
3 /***************************************************
4  * TODO: check Matacq *
5  * add DTT *
6  * completion of partial output file *
7  ***************************************************/
8 
11 
12 #include <iostream>
13 //#include <fstream>
14 #include <iomanip>
15 //#include <limits>
16 #include <algorithm>
17 #include <sys/stat.h>
18 #include <sys/types.h>
19 #include <unistd.h>
20 #include <cerrno>
21 
34 
35 using namespace std;
36 
37 const int LaserSorter::ecalDccFedIdMin_ = 601;
38 const int LaserSorter::ecalDccFedIdMax_ = 654;
39 
41 
42 static const struct timeval nullTime = {0, 0};
43 
44 static const char* const detailedTrigNames[] = {
45  "Inv0", //000
46  "Inv1", //001
47  "Inv2", //010
48  "Inv3", //011
49  "Las", //100
50  "Led", //101
51  "TP", //110
52  "Ped" //111
53 };
54 
55 static const char* const colorNames[] = {"Blue", "Green", "Red", "IR"};
56 
57 const LaserSorter::stats_t LaserSorter::stats_init = {0, 0, 0, 0, 0};
58 const int LaserSorter::indexOffset32_ = 1;
59 
60 static std::string now() {
61  struct timeval t;
62  gettimeofday(&t, nullptr);
63 
64  char buf[256];
65  strftime(buf, sizeof(buf), "%F %R %S s", localtime(&t.tv_sec));
66  buf[sizeof(buf) - 1] = 0;
67 
68  stringstream buf2;
69  buf2 << buf << " " << ((t.tv_usec + 500) / 1000) << " ms";
70 
71  return buf2.str();
72 }
73 
75  : lumiBlock_(0),
76  lumiBlockPrev_(0),
77  formatVersion_(5),
78  outputDir_(pset.getParameter<std::string>("outputDir")),
79  fedSubDirs_(pset.getParameter<std::vector<std::string> >("fedSubDirs")),
80  timeLogFile_(pset.getUntrackedParameter<std::string>("timeLogFile", "")),
81  disableOutput_(pset.getUntrackedParameter<bool>("disableOutput", false)),
82  runNumber_(0),
83  outputListFile_(pset.getUntrackedParameter<string>("outputListFile", "")),
84  doOutputList_(false),
85  verbosity_(pset.getUntrackedParameter<int>("verbosity", 0)),
86  iNoFullReadoutDccError_(0),
87  maxFullReadoutDccError_(pset.getParameter<int>("maxFullReadoutDccError")),
88  iNoEcalDataMess_(0),
89  maxNoEcalDataMess_(pset.getParameter<int>("maxNoEcalDataMess")),
90  lumiBlockSpan_(pset.getParameter<int>("lumiBlockSpan")),
91  fedRawDataCollectionTag_(pset.getParameter<edm::InputTag>("fedRawDataCollectionTag")),
92  stats_(stats_init),
93  overWriteLumiBlockId_(pset.getParameter<bool>("overWriteLumiBlockId")),
94  orbitCountInALumiBlock_(pset.getParameter<int>("orbitCountInALumiBlock")),
95  orbit_(-1),
96  orbitZeroTime_(nullTime) {
97  gettimeofday(&timer_, nullptr);
98  logFile_.open("eventSelect.log", ios::app | ios::out);
99 
100  const unsigned nEcalFeds = 54;
101  if (fedSubDirs_.size() != nEcalFeds + 1) {
102  throw cms::Exception("LaserSorter") << "Configuration error: "
103  << "fedSubDirs parameter must be a vector "
104  << " of " << nEcalFeds << " strings"
105  << " (subdirectory for unknown triggered FED followed by "
106  "subdirectories for FED ID 601 "
107  "to FED ID 654 in increasing FED ID order)";
108  }
109 
110  fedRawDataCollectionToken_ = consumes<FEDRawDataCollection>(fedRawDataCollectionTag_);
111 
112  if (!outputListFile_.empty()) {
113  outputList_.open(outputListFile_.c_str(), ios::app);
114  if (outputList_.bad()) {
115  throw cms::Exception("FileOpen") << "Failed to open file '" << outputListFile_
116  << "' for logging of output file path list.";
117  }
118  doOutputList_ = true;
119  }
120 
121  if (!timeLogFile_.empty()) {
122  timeLog_.open(timeLogFile_.c_str());
123  if (timeLog_.fail()) {
124  cout << "[LaserSorter " << now() << "] "
125  << "Failed to open file " << timeLogFile_ << " to log timing.\n";
126  timing_ = false;
127  } else {
128  timing_ = true;
129  }
130  }
131 
132  struct stat fileStat;
133  if (0 == stat(outputDir_.c_str(), &fileStat)) {
134  if (!S_ISDIR(fileStat.st_mode)) {
135  throw cms::Exception("[LaserSorter]") << "File " << outputDir_ << " exists but is not a directory "
136  << " as expected.";
137  }
138  } else { //directory does not exists, let's try to create it
139  if (0 != mkdir(outputDir_.c_str(), 0755)) {
140  throw cms::Exception("[LaserSorter]") << "Failed to create directory " << outputDir_ << " for writing data.";
141  }
142  }
143 
144  logFile_ << "# "
145  "run\t"
146  "LB\t"
147  "event\t"
148  "trigType\t"
149  "FED\t"
150  "side\t"
151  "LB out\t"
152  "Written\t"
153  "ECAL data\n";
154 }
155 
157  logFile_ << "Summary. Event count: " << stats_.nRead << " processed, " << stats_.nWritten << " written, "
158  << stats_.nInvalidDccStrict << " with errors in DCC ID values, " << stats_.nInvalidDccWeak
159  << " with unusable DCC ID values, " << stats_.nRestoredDcc << " restored DCC ID based on DCC block size\n";
160 }
161 
162 // ------------ method called to analyze the data ------------
164  if (timing_) {
165  timeval t;
166  gettimeofday(&t, nullptr);
167  timeLog_ << t.tv_sec << "." << setfill('0') << setw(3) << (t.tv_usec + 500) / 1000 << setfill(' ') << "\t"
168  << (t.tv_usec - timer_.tv_usec) * 1. + (t.tv_sec - timer_.tv_sec) * 1.e6 << "\t";
169  timer_ = t;
170  }
171 
172  ++stats_.nRead;
173 
174  if (event.id().run() != runNumber_) { //run changed or first event
175  //for a new run, starts with a new output stream set.
176  closeAllStreams();
177  runNumber_ = event.id().run();
179  iNoEcalDataMess_ = 0;
180  lumiBlockPrev_ = 0;
181  lumiBlock_ = 0;
182  }
183 
185  event.getByToken(fedRawDataCollectionToken_, rawdata);
186 
187  //orbit number
188  //FIXME: orbit from edm Event is currently wrong. Forcing to use of CMS orbit until
189  //it is fixed. See https://hypernews.cern.ch/HyperNews/CMS/get/commissioning/5343/2.html
190 #if 0
191  orbit_ = event.orbitNumber();
192 #else
193  orbit_ = -1;
194 #endif
195 
196  // std::cerr << "Orbit ID CMS, ECAL: " << orbit_ << "\t" << getOrbitFromDcc(rawdata) << "\n";
197 
198  if (orbit_ < 0) { //For local run CMSSW failed to find the orbit number
199  // cout << "Look for orbit from DCC headers....\n";
200  orbit_ = getOrbitFromDcc(rawdata);
201  }
202 
203  //The "detailed trigger type DCC field content:
204  double dttProba = 0;
205  int dtt = getDetailedTriggerType(rawdata, &dttProba);
206 
207  if (overWriteLumiBlockId_) {
210  if (lb != lumiBlock_) {
211  std::cout << "[LaserSorter " << now() << "] Overwrite LB mode. LB number changed from: " << lb << " to "
212  << lumiBlock_ << "\n";
213  }
214  } else {
216  lumiBlock_ = event.luminosityBlock();
217  if (lb != lumiBlock_) {
218  std::cout << "[LaserSorter " << now() << "] Standard LB mode. LB number changed from: " << lb << " to "
219  << lumiBlock_ << "\n";
220  }
221  }
222 
223  detailedTrigType_ = dtt;
224  const int trigType = (detailedTrigType_ >> 8) & 0x7;
225  const int color = (detailedTrigType_ >> 6) & 0x3;
226  const int dccId = (detailedTrigType_ >> 0) & 0x3F;
227  int triggeredFedId = (detailedTrigType_ == -2) ? -1 : (600 + dccId);
228  const int side = (detailedTrigType_ >> 11) & 0x1;
229  //monitoring region extended id:
230  // const int lme = dcc2Lme(dccId, side);
231 
232  if (detailedTrigType_ > -2) {
233  if (dttProba < 1. || triggeredFedId < ecalDccFedIdMin_ || triggeredFedId > ecalDccFedIdMax_) {
235  }
236 
237  if (triggeredFedId < ecalDccFedIdMin_ || triggeredFedId > ecalDccFedIdMax_) {
238  if (verbosity_)
239  cout << "[LaserSorter " << now() << "] "
240  << "DCC ID (" << dccId << ") found in trigger type is out of range.";
242  vector<int> ids = getFullyReadoutDccs(*rawdata);
243  if (ids.empty()) {
245  cout << " No fully read-out DCC found\n";
247  }
248  } else if (ids.size() == 1) {
249  triggeredFedId = ids[0];
250  if (verbosity_)
251  cout << " ID guessed from DCC payloads\n";
253  } else { //ids.size()>1
254  if (verbosity_) {
255  cout << " Several fully read-out Dccs:";
256  for (unsigned i = 0; i < ids.size(); ++i)
257  cout << " " << ids[i];
258  cout << "\n";
259  }
260  }
261  }
262 
263  if (verbosity_ > 1)
264  cout << "\n----------------------------------------------------------------------\n"
265  << "Event id: "
266  << " " << event.id() << "\n"
267  << "Lumin block: " << lumiBlock_ << "\n"
268  << "TrigType: " << detailedTrigNames[trigType & 0x7] << " Color: " << colorNames[color & 0x3]
269  << " FED: " << triggeredFedId << " side:" << side << "\n"
270  << "\n----------------------------------------------------------------------\n";
271 
272  } else { //NO ECAL DATA
273  if (verbosity_ > 1)
274  cout << "\n----------------------------------------------------------------------\n"
275  << "Event id: "
276  << " " << event.id() << "\n"
277  << "Lumin block: " << lumiBlock_ << "\n"
278  << "No ECAL data\n"
279  << "\n----------------------------------------------------------------------\n";
280  }
281 
282  logFile_ << event.id().run() << "\t" << lumiBlock_ << "\t" << event.id().event() << "\t" << trigType << "\t"
283  << triggeredFedId << "\t" << side;
284 
285  bool written = false;
286  int assignedLB = -1;
287 
288  if (lumiBlock_ != lumiBlockPrev_) {
289  //lumi block change => need for stream garbage collection
290  const int lb = lumiBlock_;
291  closeOldStreams(lb);
294  for (int lb1 = minLumi; lb1 <= maxLumi; ++lb1) {
296  }
297  }
298 
299  // if(lumiBlock_ < lumiBlockPrev_){
300  // throw cms::Exception("LaserSorter")
301  // << "Process event has a lumi block (" << lumiBlock_ << ")"
302  // << "older than previous one (" << lumiBlockPrev_ << "). "
303  // << "This can be due by wrong input file ordering or bad luminosity "
304  // << "block indication is the event header. "
305  // << "Event cannot be processed";
306  // }
307 
308  if (disableOutput_) {
309  /* NO OP*/
310  } else {
311  OutStreamRecord* out = getStream(triggeredFedId, lumiBlock_);
312 
313  if (out != nullptr) {
314  assignedLB = out->startingLumiBlock();
315  if (out->excludedOrbit().find(orbit_) == out->excludedOrbit().end()) {
316  if (verbosity_ > 1)
317  cout << "[LaserSorter " << now() << "] "
318  << "Writing out event from FED " << triggeredFedId << " LB " << lumiBlock_ << " orbit " << orbit_
319  << "\n";
320  int dtt = (detailedTrigType_ >= 0) ? detailedTrigType_ : -1; //shall we use -1 or 0 for undefined value?
321  written = written || writeEvent(*out, event, dtt, *rawdata);
322  ++stats_.nWritten;
323  } else {
324  if (verbosity_)
325  cout << "[LaserSorter " << now() << "] "
326  << "File " << out->finalFileName() << " "
327  << "already contains calibration event from FED " << triggeredFedId << ", LB = " << lumiBlock_
328  << " with orbit ID " << orbit_ << ". Event skipped.\n";
329  }
330  }
331  }
333 
334  logFile_ << "\t";
335  if (assignedLB >= 0)
336  logFile_ << assignedLB;
337  else
338  logFile_ << "-";
339  logFile_ << "\t" << (written ? "Y" : "N") << "\n";
340  logFile_ << "\t" << (detailedTrigType_ == -2 ? "N" : "Y") << "\n";
341 
342  if (timing_) {
343  timeval t;
344  gettimeofday(&t, nullptr);
345  timeLog_ << (t.tv_usec - timer_.tv_usec) * 1. + (t.tv_sec - timer_.tv_sec) * 1.e6 << "\n";
346  timer_ = t;
347  }
348 }
349 
350 int LaserSorter::dcc2Lme(int dcc, int side) {
351  int fedid = (dcc % 600) + 600; //to handle both FED and DCC id.
352  vector<int> lmes;
353  // EE -
354  if (fedid <= 609) {
355  if (fedid <= 607) {
356  lmes.push_back(fedid - 601 + 83);
357  } else if (fedid == 608) {
358  lmes.push_back(90);
359  lmes.push_back(91);
360  } else if (fedid == 609) {
361  lmes.push_back(92);
362  }
363  } //EB
364  else if (fedid >= 610 && fedid <= 645) {
365  lmes.push_back(2 * (fedid - 610) + 1);
366  lmes.push_back(lmes[0] + 1);
367  } // EE+
368  else if (fedid >= 646) {
369  if (fedid <= 652) {
370  lmes.push_back(fedid - 646 + 73);
371  } else if (fedid == 653) {
372  lmes.push_back(80);
373  lmes.push_back(81);
374  } else if (fedid == 654) {
375  lmes.push_back(82);
376  }
377  }
378  return lmes.empty() ? -1 : lmes[min(lmes.size(), (size_t)side)];
379 }
380 
382  const int orbit32 = 6;
383  for (int id = ecalDccFedIdMin_; id <= ecalDccFedIdMax_; ++id) {
384  if (!FEDNumbering::inRange(id))
385  continue;
386  const FEDRawData& data = rawdata->FEDData(id);
387  if (data.size() >= 4 * (orbit32 + 1)) {
388  const uint32_t* pData32 = (const uint32_t*)data.data();
389  // cout << "Found a DCC header: "
390  // << pData32[0] << " "
391  // << pData32[1] << " "
392  // << pData32[2] << " "
393  // << pData32[3] << " "
394  // << pData32[4] << " "
395  // << pData32[5] << " "
396  // << pData32[6] << " "
397  // << "\n";
398  return pData32[orbit32];
399  }
400  }
401  return -1;
402 }
403 
406  bool ecalData = false;
407  for (int id = ecalDccFedIdMin_; id <= ecalDccFedIdMax_; ++id) {
408  if (!FEDNumbering::inRange(id))
409  continue;
410  const FEDRawData& data = rawdata->FEDData(id);
411  const int detailedTrigger32 = 5;
412  if (verbosity_ > 3)
413  cout << "[LaserSorter " << now() << "] "
414  << "FED " << id << " data size: " << data.size() << "\n";
415  if (data.size() >= 4 * (detailedTrigger32 + 1)) {
416  ecalData = true;
417  const uint32_t* pData32 = (const uint32_t*)data.data();
418  int tType = pData32[detailedTrigger32] & 0xFFF;
419  if (verbosity_ > 3)
420  cout << "[LaserSorter " << now() << "] "
421  << "Trigger type " << tType << "\n";
422  stat.add(tType);
423  }
424  }
425  if (!ecalData)
426  return -2;
427  double p;
428  int tType = stat.result(&p);
429  if (p < 0) {
430  //throw cms::Exception("NotFound") << "No ECAL DCC data found\n";
432  edm::LogWarning("NotFound") << "No ECAL DCC data found. "
433  "(This warning will be disabled for the current run after "
434  << maxNoEcalDataMess_ << " occurences.)";
436  }
437  tType = -1;
438  } else if (p < .8) {
439  //throw cms::Exception("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
440  edm::LogWarning("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
441  tType = -1;
442  }
443  if (proba)
444  *proba = p;
445  return tType;
446 }
447 
449  for (OutStreamList::iterator it = outStreamList_.begin(); it != outStreamList_.end(); /*NOOP*/) {
450  it = closeOutStream(it);
451  }
452 }
453 
455  const edm::LuminosityBlockNumber_t minLumiBlock = lumiBlock - lumiBlockSpan_;
456  const edm::LuminosityBlockNumber_t maxLumiBlock = lumiBlock + lumiBlockSpan_;
457  //If container type is ever changed, beware that
458  //closeOutStream call in the loop removes it from outStreamList
459  for (boost::ptr_list<OutStreamRecord>::iterator it = outStreamList_.begin(); it != outStreamList_.end();
460  /*NOOP*/) {
461  if (it->startingLumiBlock() < minLumiBlock || it->startingLumiBlock() > maxLumiBlock) {
462  //event older than 2 lumi block => stream can be closed
463  if (verbosity_)
464  cout << "[LaserSorter " << now() << "] "
465  << "Closing file for "
466  << "FED " << it->fedId() << " LB " << it->startingLumiBlock() << "\n";
467  it = closeOutStream(it);
468  } else {
469  ++it;
470  }
471  }
472 }
473 
475  if ((fedId != -1) && (fedId < ecalDccFedIdMin_ || fedId > ecalDccFedIdMax_))
476  fedId = -1;
477 
478  if (verbosity_ > 1)
479  cout << "[LaserSorter " << now() << "] "
480  << "Looking for an opened output file for FED " << fedId << " LB " << lumiBlock << "\n";
481 
482  //first look if stream is already open:
483  for (OutStreamList::iterator it = outStreamList_.begin(); it != outStreamList_.end(); ++it) {
484  if (it->fedId() == fedId && (abs((int)it->startingLumiBlock() - (int)lumiBlock) <= lumiBlockSpan_)) {
485  //stream found!
486  return &(*it);
487  }
488  }
489  //stream was not found. Let's create one
490 
491  if (verbosity_)
492  cout << "[LaserSorter " << now() << "] "
493  << "File not yet opened. Opening it.\n";
494 
495  OutStreamList::iterator streamRecord = createOutStream(fedId, lumiBlock);
496  return streamRecord != outStreamList_.end() ? &(*streamRecord) : nullptr;
497 }
498 
500  const edm::Event& event,
501  int dtt,
502  const FEDRawDataCollection& data) {
503  ofstream& out = *outRcd.out();
504  bool rc = true;
505  vector<unsigned> fedIds;
506  getOutputFedList(event, data, fedIds);
507 
508  out.clear();
509  uint32_t evtStart = out.tellp();
510  if (out.bad())
511  evtStart = 0;
512  rc &= writeEventHeader(out, event, dtt, fedIds.size());
513 
514  if (orbitZeroTime_.tv_sec == 0 && data.FEDData(matacqFedId_).size() != 0) {
515  struct timeval ts = {0, 0};
517  mre.getTimeStamp(ts);
518  uint32_t orb = mre.getOrbitId();
519  if (ts.tv_sec != 0) {
520  div_t dt = div(orb * 89.1, 1000 * 1000); //an orbit lasts 89.1 microseconds
521  orbitZeroTime_.tv_sec = ts.tv_sec - dt.quot;
522  orbitZeroTime_.tv_usec = ts.tv_usec - dt.rem;
523  if (orbitZeroTime_.tv_usec < 0) {
524  orbitZeroTime_.tv_usec += 1000 * 1000;
525  orbitZeroTime_.tv_sec -= 1;
526  }
527  }
528  }
529 
530  for (unsigned iFed = 0; iFed < fedIds.size() && rc; ++iFed) {
531  if (verbosity_ > 3)
532  cout << "[LaserSorter " << now() << "] "
533  << "Writing data block of FED " << fedIds[iFed] << ". Data size: " << data.FEDData(fedIds[iFed]).size()
534  << "\n";
535  rc &= writeFedBlock(out, data.FEDData(fedIds[iFed]));
536  }
537 
538  if (rc) {
539  //update index table for this file:
540  vector<IndexRecord>& indices = *outRcd.indices();
541  if (verbosity_ > 2) {
542  std::cout << "Event "
543  << " written successfully. "
544  << "Orbit: " << orbit_ << "\tFile index: " << evtStart << "\n";
545  }
546  IndexRecord indexRcd = {(uint32_t)orbit_, evtStart};
547  indices.push_back(indexRcd);
548  }
549  return rc;
550 }
551 
552 bool LaserSorter::writeFedBlock(std::ofstream& out, const FEDRawData& data) {
553  bool rc = false;
554  if (data.size() > 4) {
555  const uint32_t* pData = reinterpret_cast<const uint32_t*>(data.data());
556 
557  uint32_t dccLen64 = pData[2] & 0x00FFFFFF; //in 32-byte unit
558 
559  if (data.size() != dccLen64 * sizeof(uint64_t)) {
560  // throw cms::Exception("Bug") << "Bug found in "
561  // << __FILE__ << ":" << __LINE__ << ".";
562  throw cms::Exception("LaserSorter") << "Mismatch between FED fragment size indicated in header "
563  << "(" << dccLen64 << "*8 Byte) "
564  << "and actual size (" << data.size() << " Byte) "
565  << "for FED ID " << ((pData[0] >> 8) & 0xFFF) << "!\n";
566  }
567 
568  if (verbosity_ > 3)
569  cout << "[LaserSorter " << now() << "] "
570  << "Event fragment size: " << data.size() << " Byte"
571  << "\t From Dcc header: " << dccLen64 * 8 << " Byte\n";
572 
573  const size_t nBytes = data.size();
574  // cout << "[LaserSorter " << now() << "] "
575  // << "Writing " << nBytes << " byte from adress "
576  // << (void*) data.data() << " to file.\n";
577  if (out.fail())
578  cout << "[LaserSorter " << now() << "] "
579  << "Problem with stream!\n";
580  out.write((char*)data.data(), nBytes);
581  rc = true;
582  } else {
583  throw cms::Exception("Bug") << "Bug found in " << __FILE__ << ":" << __LINE__ << ".\n";
584  }
585  return rc;
586 }
587 
589  int i = 0;
590  int err;
591  // static int maxTries = 100;
592  int maxTries = 20;
593  stringstream newFileName_;
594  do {
595  newFileName_.str("");
596  newFileName_ << fileName << "~";
597  if (i > 0)
598  newFileName_ << i;
599  err = link(fileName.c_str(), newFileName_.str().c_str());
600  if (err == 0) {
601  newFileName = newFileName_.str();
602  err = unlink(fileName.c_str());
603  }
604  ++i;
605  } while ((err != 0) && (errno == EEXIST) && (i < maxTries));
606  return err == 0;
607 }
608 
609 LaserSorter::OutStreamList::iterator LaserSorter::createOutStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock) {
610  if (verbosity_)
611  cout << "[LaserSorter " << now() << "] "
612  << "Creating a stream for FED " << fedId << " lumi block " << lumiBlock << ".\n";
613  std::string tmpName;
614  std::string finalName;
615 
616  streamFileName(fedId, lumiBlock, tmpName, finalName);
617 
618  errno = 0;
619 
620  //checks if a file with tmpName name already exists:
621  ofstream* out = new ofstream(tmpName.c_str(), ios::out | ios::in);
622  if (out->is_open()) { //temporary file already exists. Making a backup:
623  string newName;
624  if (!renameAsBackup(tmpName, newName)) {
625  throw cms::Exception("LaserSorter") << "Failed to rename file " << tmpName << " to " << newName << "\n";
626  }
627  if (verbosity_)
628  cout << "[LaserSorter " << now() << "] "
629  << "Already existing File " << tmpName << " renamed to " << newName << "\n";
630  out->close();
631  }
632 
633  out->clear();
634  out->open(tmpName.c_str(), ios::out | ios::trunc);
635 
636  if (out->fail()) { //failed to create file
637  delete out;
638  throw cms::Exception("LaserSorter") << "Failed to create file " << tmpName << " for writing event from FED "
639  << fedId << " lumi block " << lumiBlock << ": " << strerror(errno) << "\n.";
640  }
641 
642  ifstream in(finalName.c_str());
643  bool newFile = true;
644  if (in.good()) { //file already exists with final name.
645  if (verbosity_)
646  cout << "[LaserSorter " << now() << "] "
647  << "File " << finalName << " already exists. It will be updated if needed.\n";
648  //Copying its contents:
649  char buffer[256];
650  streamsize nread = -1;
651  int vers = readFormatVersion(in, finalName);
652  if (vers == -1) {
653  edm::LogWarning("LaserSorter") << "File " << tmpName.c_str() << " is not an LMF file despite its extension or "
654  << "it is corrupted.\n";
655  } else if (vers != formatVersion_) {
656  edm::LogWarning("LaserSorter") << "Cannot include events already in file " << tmpName.c_str()
657  << " because of version "
658  << "mismatch (found version " << (int)vers << " while "
659  << "only version " << (int)formatVersion_ << " is supported).\n";
660  } else {
661  newFile = false;
662  //read index table offset value:
663  const int indexTableOffsetPos8 = 1 * sizeof(uint32_t);
664  uint32_t indexTableOffsetValue = 0;
665  in.clear();
666  in.seekg(indexTableOffsetPos8, ios::beg);
667  in.read((char*)&indexTableOffsetValue, sizeof(indexTableOffsetValue));
668  if (in.fail()) {
669  cout << "[LaserSorter " << now() << "] "
670  << "Failed to read offset of index table "
671  " in the existing file "
672  << finalName << "\n";
673  } else {
674  if (verbosity_ > 2)
675  cout << "[LaserSorter " << now() << "] "
676  << "Index table offset of "
677  "original file "
678  << finalName << ": 0x" << hex << setfill('0') << setw(8) << indexTableOffsetValue << dec << setfill(' ')
679  << "\n";
680  }
681  in.clear();
682  in.seekg(0, ios::beg);
683 
684  //copy legacy file contents except the index table
685  uint32_t toRead = indexTableOffsetValue;
686  cout << "[LaserSorter " << now() << "] "
687  << "Copying " << finalName << " to " << tmpName << endl;
688  while (!in.eof() && (toRead > 0) && (nread = in.readsome(buffer, min(toRead, (uint32_t)sizeof(buffer)))) != 0) {
689  // cout << "Writing " << nread << " bytes to file "
690  // << tmpName.c_str() << "\n";
691  toRead -= nread;
692  // out->seekp(0, ios::end);
693  out->write(buffer, nread);
694  if (out->bad()) {
695  throw cms::Exception("LaserSorter")
696  << "Error while writing to file " << tmpName << ". Check if there is enough "
697  << "space on the device.\n";
698  }
699  }
700 
701  //resets index table offset field:
702  indexTableOffsetValue = 0;
703  out->clear();
704  out->seekp(indexTableOffsetPos8, ios::beg);
705  out->write((char*)&indexTableOffsetValue, sizeof(uint32_t));
706  out->clear();
707  out->seekp(0, ios::end);
708  }
709  }
710 
711 #if 0
712  out->flush();
713  cout << "Press enter... file name was " << tmpName << endl;
714  char c;
715  cin >> c;
716 #endif
717 
718  OutStreamRecord* outRcd = new OutStreamRecord(fedId, lumiBlock, out, tmpName, finalName);
719 
720  if (newFile) {
721  writeFileHeader(*out);
722  } else {
723  std::string errMsg;
724  if (!readIndexTable(in, finalName, *outRcd, &errMsg)) {
725  throw cms::Exception("LaserSorter") << errMsg << "\n";
726  }
727  }
728 
729  return outStreamList_.insert(outStreamList_.end(), outRcd);
730 }
731 
732 void LaserSorter::writeFileHeader(std::ofstream& out) {
733  out.clear();
734 
735  uint32_t id = 'L' | ('M' << 8) | ('F' << 16) | (formatVersion_ << 24);
736 
737  out.write((char*)&id, sizeof(uint32_t));
738 
739  //index position (to be filled at end of writing)
740  uint32_t zero = 0;
741  out.write((char*)&zero, sizeof(uint32_t));
742 
743  if (out.fail()) {
744  throw cms::Exception("LaserSorter") << "Failed to write file header.\n";
745  }
746 }
747 
748 bool LaserSorter::writeEventHeader(std::ofstream& out, const edm::Event& evt, int dtt, unsigned nFeds) {
749  uint32_t data[10];
750  timeval tt = {0, 0};
751  if ((evt.time().value() >> 32)) {
752  tt.tv_usec = evt.time().value() & 0xFFFFFFFF;
753  tt.tv_sec = evt.time().value() >> 32;
754  } else if (orbitZeroTime_.tv_sec) {
755  div_t dt = div(orbit_ * 89.1, 1000 * 1000); //one orbit lasts 89.1 microseconds
756  tt.tv_sec = orbitZeroTime_.tv_sec + dt.quot;
757  tt.tv_usec = orbitZeroTime_.tv_usec + dt.rem;
758  if (tt.tv_usec > 1000 * 1000) {
759  tt.tv_usec -= 1000 * 1000;
760  tt.tv_sec += 1;
761  }
762  }
763 
764  data[0] = tt.tv_usec;
765  data[1] = tt.tv_sec;
766  data[2] = evt.luminosityBlock();
767  data[3] = evt.run();
768  data[4] = orbit_;
769  data[5] = evt.bunchCrossing();
770  data[6] = evt.id().event();
771  data[7] = dtt;
772  data[8] = nFeds;
773  data[9] = 0; //reserved (to be aligned on 64-bits)
774 
775  if (verbosity_ > 1) {
776  cout << "[LaserSorter " << now() << "] "
777  << "Write header of event: "
778  << "Time: " << toString(evt.time().value()) << ", LB: " << evt.luminosityBlock() << ", Run: " << evt.run()
779  << ", Bx: " << evt.bunchCrossing() << ", Event ID: " << evt.id().event() << ", Detailed trigger type: 0x"
780  << hex << dtt << dec << " (" << detailedTrigNames[(dtt >> 8) & 0x7] << ", " << colorNames[(dtt >> 6) & 0x3]
781  << ", DCC " << (dtt & 0x3f) << ", side " << ((dtt >> 10) & 0x1) << ")"
782  << ", number of FEDs: "
783  << "\n";
784  }
785 
786  out.clear();
787  out.write((char*)data, sizeof(data));
788  return !out.bad();
789 }
790 
793  std::string& tmpName,
794  std::string& finalName) {
795  int iFed;
796  if (fedId >= ecalDccFedIdMin_ && fedId <= ecalDccFedIdMax_) {
797  iFed = fedId - ecalDccFedIdMin_ + 1;
798  } else if (fedId < 0) {
799  iFed = -1; //event w/o ECAL data
800  } else {
801  iFed = 0;
802  }
803  if (iFed < -1 || iFed >= (int)fedSubDirs_.size()) {
804  throw cms::Exception("LaserSorter") << "Bug found at " << __FILE__ << ":" << __LINE__
805  << ". FED ID is out of index!";
806  }
807 
808  struct stat fileStat;
809 
810  stringstream buf;
811  buf << outputDir_ << "/" << (iFed < 0 ? "Empty" : fedSubDirs_[iFed]);
812 
813  string dir = buf.str();
814  if (0 == stat(dir.c_str(), &fileStat)) {
815  if (!S_ISDIR(fileStat.st_mode)) {
816  throw cms::Exception("[LaserSorter]") << "File " << dir << " exists but is not a directory "
817  << " as expected.";
818  }
819  } else { //directory does not exists, let's try to create it
820  if (0 != mkdir(dir.c_str(), 0755)) {
821  throw cms::Exception("[LaserSorter]") << "Failed to create directory " << dir << " for writing data.";
822  }
823  }
824 
825  buf.str("");
826  buf << "Run" << runNumber_ << "_LB" << setfill('0') << setw(4) << lumiBlock << ".lmf";
827  string fileName = buf.str();
828  string tmpFileName = fileName + ".part";
829 
830  finalName = dir + "/" + fileName;
831  tmpName = dir + "/" + tmpFileName;
832 
833  if (verbosity_ > 3)
834  cout << "[LaserSorter " << now() << "] "
835  << "File path: " << finalName << "\n";
836 }
837 
838 LaserSorter::OutStreamList::iterator LaserSorter::closeOutStream(LaserSorter::OutStreamList::iterator streamRecord) {
839  if (streamRecord == outStreamList_.end())
840  return outStreamList_.end();
841 
842  if (verbosity_)
843  cout << "[LaserSorter " << now() << "] "
844  << "Writing Index table of file " << streamRecord->finalFileName() << "\n";
845  ofstream& out = *streamRecord->out();
846  out.clear();
847  if (!writeIndexTable(out, *streamRecord->indices())) {
848  cout << "Error while writing index table for file " << streamRecord->finalFileName() << ". "
849  << "Resulting file might be corrupted. "
850  << "The error can be due to a lack of disk space.";
851  }
852 
853  if (verbosity_)
854  cout << "[LaserSorter " << now() << "] "
855  << "Closing file " << streamRecord->finalFileName() << ".\n";
856  out.close();
857 
858  const std::string& tmpFileName = streamRecord->tmpFileName();
859  const std::string& finalFileName = streamRecord->finalFileName();
860 
861  if (verbosity_)
862  cout << "[LaserSorter " << now() << "] "
863  << "Renaming " << tmpFileName << " to " << finalFileName << ".\n";
864 
865  if (0 != rename(tmpFileName.c_str(), finalFileName.c_str())) {
866  cout << "[LaserSorter " << now() << "] "
867  << " Failed to rename output file from " << tmpFileName << " to " << finalFileName << ". " << strerror(errno)
868  << "\n";
869  }
870 
871  if (doOutputList_) {
872  char buf[256];
873  time_t t = time(nullptr);
874  strftime(buf, sizeof(buf), "%F %R:%S", localtime(&t));
875 
876  ifstream f(".watcherfile");
877  string inputFile;
878  f >> inputFile;
879  outputList_ << finalFileName << "\t" << buf << "\t" << inputFile << endl;
880  }
881 
882  return outStreamList_.erase(streamRecord);
883 }
884 
886  //TODO: better treatement of last files:
887  //they might be imcomplete...
888  closeAllStreams();
889 }
890 
892 
893 bool LaserSorter::isDccEventEmpty(const FEDRawData& data, size_t* dccLen, int* nTowerBlocks) const {
894  if (nTowerBlocks)
895  *nTowerBlocks = 0;
896  //DCC event is considered empty if it does not contains any Tower block
897  //( = FE data)
898  bool rc = true;
899  if (dccLen)
900  *dccLen = 0;
901  const unsigned nWord32 = data.size() / sizeof(uint32_t);
902  if (nWord32 == 0) {
903  //cout << "[LaserSorter " << now() << "] " << "FED block completly empty\n";
904  return true;
905  }
906  for (unsigned iWord32 = 0; iWord32 < nWord32; iWord32 += 2) {
907  const uint32_t* data32 = ((const uint32_t*)(data.data())) + iWord32;
908  int dataType = (data32[1] >> 28) & 0xF;
909  // cout << hex << "0x" << setfill('0')
910  // << setw(8) << data32[1] << "'" << setw(8) << data32[0]
911  // << " dataType: 0x" << dataType
912  // << dec << setfill(' ') << "\n";
913  if (0 == (dataType >> 2)) { //in DCC header
914  const int dccHeaderId = (data32[1] >> 24) & 0x3F;
915  if (dccHeaderId == 1) {
916  if (dccLen)
917  *dccLen = ((data32[0] >> 0) & 0xFFFFFF);
918  }
919  }
920  if ((dataType >> 2) == 3) { //Tower block
921  rc = false;
922  if (nTowerBlocks) { //number of tower block must be counted
923  ++(*nTowerBlocks);
924  } else {
925  break;
926  }
927  }
928  }
929  // cout << "[LaserSorter " << now() << "] " << "DCC Len: ";
930 
931  // if(dccLen){
932  // cout << (*dccLen) << " event ";
933  // }
934  // cout << (rc?"":"non") << " empty"
935  // << endl;
936  return rc;
937 }
938 
940  const FEDRawDataCollection& data,
941  std::vector<unsigned>& fedIds) const {
942  fedIds.erase(fedIds.begin(), fedIds.end());
943  for (int id = ecalDccFedIdMin_; id <= ecalDccFedIdMax_; ++id) {
944  size_t dccLen;
945  const FEDRawData& dccEvent = data.FEDData(id);
946  if (!isDccEventEmpty(dccEvent, &dccLen)) {
947  fedIds.push_back(id);
948  }
949  if (dccLen * sizeof(uint64_t) != dccEvent.size()) {
950  edm::LogWarning("LaserSorter") << "Length error in data of FED " << id << " in event " << event.id()
951  << ", Data of this FED dropped.";
952  }
953  }
954  // cout << __FILE__ << ":" << __LINE__ << ": "
955  // << "data.FEDData(" << matacqFedId_ << ").size() = "
956  // << data.FEDData(matacqFedId_).size() << "\n";
957  if (data.FEDData(matacqFedId_).size() > 4) { //matacq block present
958  // cout << __FILE__ << ":" << __LINE__ << ": "
959  // << "Adding matacq to list of FEDs\n";
960  fedIds.push_back(matacqFedId_);
961  }
962 }
963 
965  int nTowers;
966  vector<int> result;
967  for (int fed = ecalDccFedIdMin_; fed <= ecalDccFedIdMax_; ++fed) {
968  const FEDRawData& fedData = data.FEDData(fed);
969  isDccEventEmpty(fedData, nullptr, &nTowers);
970  if (nTowers >= 68)
971  result.push_back(fed);
972  }
973  return result;
974 }
975 
976 bool LaserSorter::writeIndexTable(std::ofstream& out, std::vector<IndexRecord>& indices) {
977  uint32_t indexTablePos = out.tellp();
978  uint32_t nevts = indices.size();
979 
980  out.clear();
981  out.write((char*)&nevts, sizeof(nevts));
982  const uint32_t reserved = 0;
983  out.write((const char*)&reserved, sizeof(reserved));
984 
985  if (out.bad())
986  return false;
987 
988  sort(indices.begin(), indices.end());
989 
990  for (unsigned i = 0; i < indices.size(); ++i) {
991  uint32_t data[2];
992  data[0] = indices[i].orbit;
993  data[1] = indices[i].filePos;
994  out.write((char*)data, sizeof(data));
995  }
996 
997  if (out.bad())
998  return false; //intial 0 valur for index table position
999  // is left to indicate corrupted table.
1000 
1001  //writes index table position:x
1002  out.clear();
1003  out.seekp(indexOffset32_ * sizeof(uint32_t));
1004  // cout << "[LaserSorter] Index table position: 0x" << hex << indexTablePos
1005  // << dec << "\n";
1006  if (!out.bad())
1007  out.write((char*)&indexTablePos, sizeof(uint32_t));
1008 
1009  bool rc = !out.bad();
1010 
1011  //reposition pointer to eof:
1012  out.seekp(0, ios::end);
1013 
1014  return rc;
1015 }
1016 
1017 //beware this method change the pointer position in the ifstream in
1018 bool LaserSorter::readIndexTable(std::ifstream& in, std::string& inName, OutStreamRecord& outRcd, std::string* err) {
1019  stringstream errMsg;
1020 
1021  ifstream* s = &in;
1022 
1023  //streampos pos = s->tellg();
1024  s->clear();
1025  s->seekg(0);
1026 
1027  uint32_t fileHeader[2];
1028  s->read((char*)&fileHeader[0], sizeof(fileHeader));
1029  uint32_t indexTablePos = fileHeader[1];
1030 
1031  if (s->eof()) {
1032  s->clear();
1033  s->seekg(0);
1034  errMsg << "Failed to read header of file " << inName << ".";
1035  if (err)
1036  *err = errMsg.str();
1037  return false;
1038  }
1039 
1040  s->seekg(indexTablePos);
1041 
1042  uint32_t nevts = 0;
1043  s->read((char*)&nevts, sizeof(nevts));
1044  s->ignore(4);
1045  if (s->bad()) {
1046  errMsg << "Failed to read index table from file " << inName << ".";
1047  if (err)
1048  *err = errMsg.str();
1049  return false;
1050  }
1051  if (nevts > maxEvents_) {
1052  errMsg << "Number of events indicated in event index of file " << inName << " (" << nevts << ") "
1053  << "is unexpectively large.";
1054  if (err)
1055  *err = errMsg.str();
1056  return false;
1057  }
1058  outRcd.indices()->resize(nevts);
1059  s->read((char*)&(*outRcd.indices())[0], nevts * sizeof(IndexRecord));
1060  if (s->bad()) {
1061  outRcd.indices()->clear();
1062  errMsg << "Failed to read index table from file " << inName << ".";
1063  if (err)
1064  *err = errMsg.str();
1065  return false;
1066  }
1067  if (nevts > maxEvents_) {
1068  errMsg << "Number of events indicated in event index of file " << inName << " is unexpectively large.";
1069  if (err)
1070  *err = errMsg.str();
1071  outRcd.indices()->clear();
1072  return false;
1073  }
1074 
1075  if (verbosity_ > 1)
1076  cout << "[LaserSorter " << now() << "] "
1077  << "Orbit IDs of events "
1078  << "already contained in the file " << inName << ":";
1079  for (unsigned i = 0; i < outRcd.indices()->size(); ++i) {
1080  if (verbosity_ > 1) {
1081  cout << " " << setw(9) << (*outRcd.indices())[i].orbit;
1082  }
1083  outRcd.excludedOrbit().insert((*outRcd.indices())[i].orbit);
1084  }
1085  if (verbosity_ > 1)
1086  cout << "\n";
1087 
1088  return true;
1089 }
1090 
1092  int vers = -1;
1093  streampos p = in.tellg();
1094 
1095  uint32_t data;
1096 
1097  in.read((char*)&data, sizeof(data));
1098 
1099  char magic[4];
1100 
1101  magic[0] = data & 0xFF;
1102  magic[1] = (data >> 8) & 0xFF;
1103  magic[2] = (data >> 16) & 0xFF;
1104  magic[3] = 0;
1105 
1106  const string lmf = string("LMF");
1107 
1108  if (in.good() && lmf == magic) {
1109  vers = (data >> 24) & 0xFF;
1110  }
1111 
1112  if (lmf != magic) {
1113  edm::LogWarning("LaserSorter") << "File " << fileName << "is not an LMF file.\n";
1114  }
1115 
1116  in.clear();
1117  in.seekg(p);
1118  return vers;
1119 }
1120 
1122  char buf[256];
1123 
1124  time_t tsec = t >> 32;
1125 
1126  uint32_t tusec = t & 0xFFFFFFFF;
1127  strftime(buf, sizeof(buf), "%F %R %S s", localtime(&tsec));
1128  buf[sizeof(buf) - 1] = 0;
1129 
1130  stringstream buf2;
1131  buf2 << (tusec + 500) / 1000;
1132 
1133  return string(buf) + " " + buf2.str() + " ms";
1134 }
1135 
1137  string dummy;
1138  string fileName;
1139 
1140  for (int fedId = ecalDccFedIdMin_ - 2; fedId <= ecalDccFedIdMax_; ++fedId) {
1141  int fedId_;
1142  if (fedId == ecalDccFedIdMin_ - 2)
1143  fedId_ = -1; //stream for event w/o ECAL data
1144  else
1145  fedId_ = fedId;
1146  streamFileName(fedId_, lumiBlock, dummy, fileName);
1147  struct stat s;
1148  //TODO: could be optimized by adding an option to get stream
1149  //to open only existing file: would avoid double call to streamFileName.
1150  if (stat(fileName.c_str(), &s) == 0) { //file exists
1151  getStream(fedId_, lumiBlock);
1152  }
1153  }
1154 }
1155 
1157  // cout << "Run starts at :" << run.runAuxiliary().beginTime().value() << "\n";
1158 }
RunNumber_t run() const
Definition: EventID.h:39
static const char runNumber_[]
void beginJob() override
Definition: LaserSorter.cc:891
edm::InputTag fedRawDataCollectionTag_
Definition: LaserSorter.h:417
EventNumber_t event() const
Definition: EventID.h:41
OutStreamRecord * getStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:474
float dt
Definition: AMPTWrapper.h:126
int lumiBlockSpan_
Definition: LaserSorter.h:415
bool disableOutput_
Definition: LaserSorter.h:335
std::vector< int > getFullyReadoutDccs(const FEDRawDataCollection &data) const
Definition: LaserSorter.cc:964
int maxFullReadoutDccError_
Definition: LaserSorter.h:394
double nRestoredDcc
number of events whose DCC ID was restored based on FED block sizes
Definition: LaserSorter.h:447
static const char *const detailedTrigNames[]
Definition: LaserSorter.cc:44
Definition: rename.py:1
static std::string toString(uint64_t t)
size_t size() const
Definition: Event.cc:233
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:290
static const int indexOffset32_
Definition: LaserSorter.h:426
bool writeIndexTable(std::ofstream &out, std::vector< IndexRecord > &indices)
Definition: LaserSorter.cc:976
bool readIndexTable(std::ifstream &in, std::string &inName, OutStreamRecord &outRcd, std::string *err)
bool writeEvent(OutStreamRecord &out, const edm::Event &event, int detailedTriggerType, const FEDRawDataCollection &data)
Definition: LaserSorter.cc:499
edm::RunNumber_t runNumber_
Definition: LaserSorter.h:339
void writeFileHeader(std::ofstream &out)
Definition: LaserSorter.cc:732
int bunchCrossing() const
Definition: EventBase.h:64
std::ofstream * out() const
Definition: LaserSorter.h:72
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
void streamFileName(int fedId, edm::LuminosityBlockNumber_t lumiBlock, std::string &tmpName, std::string &finalName)
Definition: LaserSorter.cc:791
edm::LuminosityBlockNumber_t lumiBlock_
Definition: LaserSorter.h:306
string newName
Definition: mps_merge.py:86
std::set< uint32_t > & excludedOrbit()
Definition: LaserSorter.h:81
void getOutputFedList(const edm::Event &event, const FEDRawDataCollection &data, std::vector< unsigned > &fedIds) const
Definition: LaserSorter.cc:939
static const int matacqFedId_
Definition: LaserSorter.h:422
OutStreamList::iterator closeOutStream(OutStreamList::iterator streamRecord)
Definition: LaserSorter.cc:838
unsigned int LuminosityBlockNumber_t
std::string finalFileName() const
Definition: LaserSorter.h:73
void closeAllStreams()
Definition: LaserSorter.cc:448
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
std::vector< std::string > fedSubDirs_
Definition: LaserSorter.h:327
struct timeval orbitZeroTime_
Definition: LaserSorter.h:470
edm::LuminosityBlockNumber_t startingLumiBlock() const
Definition: LaserSorter.h:71
void add(const T &value)
Definition: Majority.h:23
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
double nRead
number of events read out
Definition: LaserSorter.h:437
unsigned char formatVersion_
Definition: LaserSorter.h:319
~LaserSorter() override
Definition: LaserSorter.cc:156
std::vector< IndexRecord > * indices()
Definition: LaserSorter.h:75
static const struct timeval nullTime
Definition: LaserSorter.cc:42
RunNumber_t run() const
Definition: Event.h:101
int dcc2Lme(int dccNum, int dccSide)
Definition: LaserSorter.cc:350
std::string outputDir_
Definition: LaserSorter.h:323
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
timeval timer_
Definition: LaserSorter.h:343
bool writeFedBlock(std::ofstream &out, const FEDRawData &data)
Definition: LaserSorter.cc:552
double f[11][100]
std::string outputListFile_
Definition: LaserSorter.h:355
#define end
Definition: vmac.h:39
int getOrbitFromDcc(const edm::Handle< FEDRawDataCollection > &rawdata) const
Definition: LaserSorter.cc:381
T min(T a, T b)
Definition: MathUtil.h:58
std::string timeLogFile_
Definition: LaserSorter.h:331
void beginRun(edm::Run const &, edm::EventSetup const &) override
bool overWriteLumiBlockId_
Definition: LaserSorter.h:453
int iNoEcalDataMess_
Definition: LaserSorter.h:398
static const unsigned maxEvents_
Definition: LaserSorter.h:431
void closeOldStreams(edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:454
static const size_t indexReserve_
Definition: LaserSorter.h:109
static const stats_t stats_init
Definition: LaserSorter.h:449
int getDetailedTriggerType(const edm::Handle< FEDRawDataCollection > &rawdata, double *proba=nullptr)
Definition: LaserSorter.cc:404
LaserSorter(const edm::ParameterSet &)
Definition: LaserSorter.cc:74
int detailedTrigType_
Definition: LaserSorter.h:298
unsigned long long uint64_t
Definition: Time.h:15
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:294
static std::string now()
Definition: LaserSorter.cc:60
std::ofstream outputList_
Definition: LaserSorter.h:367
int readFormatVersion(std::ifstream &in, const std::string &fileName)
std::ofstream logFile_
Definition: LaserSorter.h:302
int orbitCountInALumiBlock_
Definition: LaserSorter.h:459
void endJob() override
Definition: LaserSorter.cc:885
def mkdir(path)
Definition: eostools.py:251
struct LaserSorter::stats_t stats_
static bool inRange(int)
edm::EventID id() const
Definition: EventBase.h:59
HLT enums.
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
bool writeEventHeader(std::ofstream &out, const edm::Event &evt, int fedId, unsigned nFeds)
Definition: LaserSorter.cc:748
time_t getTimeStamp() const
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
OutStreamList::iterator createOutStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:609
edm::LuminosityBlockNumber_t lumiBlockPrev_
Definition: LaserSorter.h:310
int maxNoEcalDataMess_
Definition: LaserSorter.h:402
static const char *const colorNames[]
Definition: LaserSorter.cc:55
int iNoFullReadoutDccError_
Definition: LaserSorter.h:390
void restoreStreamsOfLumiBlock(int lumiBlock)
dbl *** dir
Definition: mlp_gen.cc:35
T result(double *proba) const
Definition: Majority.h:28
bool doOutputList_
Definition: LaserSorter.h:359
double nWritten
number of events written out
Definition: LaserSorter.h:439
edm::EDGetTokenT< FEDRawDataCollection > fedRawDataCollectionToken_
Definition: LaserSorter.h:418
unsigned dccId(DetId const &)
OutStreamList outStreamList_
Definition: LaserSorter.h:315
TimeValue_t value() const
Definition: Timestamp.h:56
std::ofstream timeLog_
Definition: LaserSorter.h:347
edm::Timestamp time() const
Definition: EventBase.h:60
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: LaserSorter.cc:163
Definition: event.py:1
Definition: Run.h:45
bool renameAsBackup(const std::string &fileName, std::string &newFileName)
Definition: LaserSorter.cc:588
bool isDccEventEmpty(const FEDRawData &data, size_t *dccLen=nullptr, int *nTowerBlocks=nullptr) const
Definition: LaserSorter.cc:893