CMS 3D CMS Logo

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