CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
LaserSorter Class Reference

#include <LaserSorter.h>

Inheritance diagram for LaserSorter:
edm::EDAnalyzer edm::EDConsumerBase

Classes

struct  IndexRecord
 
class  OutStreamRecord
 
struct  stats_t
 

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void beginRun (edm::Run const &, edm::EventSetup const &)
 
virtual void endJob ()
 
 LaserSorter (const edm::ParameterSet &)
 
 ~LaserSorter ()
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (const std::string &iProcessName, std::vector< const char * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Private Types

typedef boost::ptr_list
< OutStreamRecord
OutStreamList
 

Private Member Functions

void closeAllStreams ()
 
void closeOldStreams (edm::LuminosityBlockNumber_t lumiBlock)
 
OutStreamList::iterator closeOutStream (OutStreamList::iterator streamRecord)
 
OutStreamList::iterator createOutStream (int fedId, edm::LuminosityBlockNumber_t lumiBlock)
 
int dcc2Lme (int dccNum, int dccSide)
 
int getDetailedTriggerType (const edm::Handle< FEDRawDataCollection > &rawdata, double *proba=0)
 
std::vector< int > getFullyReadoutDccs (const FEDRawDataCollection &data) const
 
int getOrbitFromDcc (const edm::Handle< FEDRawDataCollection > &rawdata) const
 
void getOutputFedList (const edm::Event &event, const FEDRawDataCollection &data, std::vector< unsigned > &fedIds) const
 
OutStreamRecordgetStream (int fedId, edm::LuminosityBlockNumber_t lumiBlock)
 
bool isDccEventEmpty (const FEDRawData &data, size_t *dccLen=0, int *nTowerBlocks=0) const
 
int readFormatVersion (std::ifstream &in, const std::string &fileName)
 
bool readIndexTable (std::ifstream &in, std::string &inName, OutStreamRecord &outRcd, std::string *err)
 
bool renameAsBackup (const std::string &fileName, std::string &newFileName)
 
void restoreStreamsOfLumiBlock (int lumiBlock)
 
void streamFileName (int fedId, edm::LuminosityBlockNumber_t lumiBlock, std::string &tmpName, std::string &finalName)
 
bool writeEvent (OutStreamRecord &out, const edm::Event &event, int detailedTriggerType, const FEDRawDataCollection &data)
 
bool writeEventHeader (std::ofstream &out, const edm::Event &evt, int fedId, unsigned nFeds)
 
bool writeFedBlock (std::ofstream &out, const FEDRawData &data)
 
void writeFileHeader (std::ofstream &out)
 
bool writeIndexTable (std::ofstream &out, std::vector< IndexRecord > &indices)
 

Static Private Member Functions

static std::string toString (uint64_t t)
 

Private Attributes

int detailedTrigType_
 
bool disableOutput_
 
bool doOutputList_
 
edm::InputTag fedRawDataCollectionTag_
 
edm::EDGetTokenT
< FEDRawDataCollection
fedRawDataCollectionToken_
 
std::vector< std::string > fedSubDirs_
 
unsigned char formatVersion_
 
int iNoEcalDataMess_
 
int iNoFullReadoutDccError_
 
std::ofstream logFile_
 
edm::LuminosityBlockNumber_t lumiBlock_
 
edm::LuminosityBlockNumber_t lumiBlockPrev_
 
int lumiBlockSpan_
 
int maxFullReadoutDccError_
 
int maxNoEcalDataMess_
 
int orbit_
 
int orbitCountInALumiBlock_
 
struct timeval orbitZeroTime_
 
std::string outputDir_
 
std::ofstream outputList_
 
std::string outputListFile_
 
OutStreamList outStreamList_
 
bool overWriteLumiBlockId_
 
edm::RunNumber_t runNumber_
 
struct LaserSorter::stats_t stats_
 
std::ofstream timeLog_
 
std::string timeLogFile_
 
timeval timer_
 
bool timing_
 
int verbosity_
 

Static Private Attributes

static const int ecalDccFedIdMax_ = 654
 
static const int ecalDccFedIdMin_ = 601
 
static const int indexOffset32_ = 1
 
static const int matacqFedId_ = 655
 
static const unsigned maxEvents_ = 1<<20
 
static const stats_t stats_init = {0, 0, 0, 0, 0}
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

This module is used to classify events of laser sequence acquired in a global run. Sorting: Events are grouped by bunch of consecutive events from the same FED. A file of such a bunch of events is identified by the FED or ECAL sector and the luminosity block id of the first event.

Sorting strategy: It is assumes that:

File completion: while being feeding, .part is appended at the end of the each output file.Once a file is completed (see above), it is renamed without the enclosing .part suffix.

Definition at line 44 of file LaserSorter.h.

Member Typedef Documentation

typedef boost::ptr_list<OutStreamRecord> LaserSorter::OutStreamList
private

Definition at line 117 of file LaserSorter.h.

Constructor & Destructor Documentation

LaserSorter::LaserSorter ( const edm::ParameterSet pset)

Definition at line 80 of file LaserSorter.cc.

References gather_cfg::cout, doOutputList_, Exception, fedRawDataCollectionTag_, fedRawDataCollectionToken_, fedSubDirs_, logFile_, eostools::mkdir(), now(), dbtoconf::out, outputDir_, outputList_, outputListFile_, timeLog_, timeLogFile_, timer_, and timing_.

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)),
93  maxFullReadoutDccError_(pset.getParameter<int>("maxFullReadoutDccError")),
95  maxNoEcalDataMess_(pset.getParameter<int>("maxNoEcalDataMess")),
96  lumiBlockSpan_(pset.getParameter<int>("lumiBlockSpan")),
97  fedRawDataCollectionTag_(pset.getParameter<edm::InputTag>("fedRawDataCollectionTag")),
99  overWriteLumiBlockId_(pset.getParameter<bool>("overWriteLumiBlockId")),
100  orbitCountInALumiBlock_(pset.getParameter<int>("orbitCountInALumiBlock")),
101  orbit_(-1),
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 }
edm::InputTag fedRawDataCollectionTag_
Definition: LaserSorter.h:441
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int lumiBlockSpan_
Definition: LaserSorter.h:439
bool disableOutput_
Definition: LaserSorter.h:357
int maxFullReadoutDccError_
Definition: LaserSorter.h:417
edm::RunNumber_t runNumber_
Definition: LaserSorter.h:361
edm::LuminosityBlockNumber_t lumiBlock_
Definition: LaserSorter.h:328
std::vector< std::string > fedSubDirs_
Definition: LaserSorter.h:349
struct timeval orbitZeroTime_
Definition: LaserSorter.h:495
unsigned char formatVersion_
Definition: LaserSorter.h:341
static struct timeval nullTime
Definition: LaserSorter.cc:43
std::string outputDir_
Definition: LaserSorter.h:345
timeval timer_
Definition: LaserSorter.h:365
std::string outputListFile_
Definition: LaserSorter.h:377
std::string timeLogFile_
Definition: LaserSorter.h:353
bool overWriteLumiBlockId_
Definition: LaserSorter.h:477
int iNoEcalDataMess_
Definition: LaserSorter.h:422
tuple out
Definition: dbtoconf.py:99
static const stats_t stats_init
Definition: LaserSorter.h:473
static std::string now()
Definition: LaserSorter.cc:66
std::ofstream outputList_
Definition: LaserSorter.h:389
std::ofstream logFile_
Definition: LaserSorter.h:324
int orbitCountInALumiBlock_
Definition: LaserSorter.h:484
struct LaserSorter::stats_t stats_
def mkdir
Definition: eostools.py:250
edm::LuminosityBlockNumber_t lumiBlockPrev_
Definition: LaserSorter.h:332
tuple cout
Definition: gather_cfg.py:121
int maxNoEcalDataMess_
Definition: LaserSorter.h:426
int iNoFullReadoutDccError_
Definition: LaserSorter.h:412
bool doOutputList_
Definition: LaserSorter.h:381
edm::EDGetTokenT< FEDRawDataCollection > fedRawDataCollectionToken_
Definition: LaserSorter.h:442
std::ofstream timeLog_
Definition: LaserSorter.h:369
LaserSorter::~LaserSorter ( )

Definition at line 169 of file LaserSorter.cc.

References logFile_, LaserSorter::stats_t::nInvalidDccStrict, LaserSorter::stats_t::nInvalidDccWeak, LaserSorter::stats_t::nRead, LaserSorter::stats_t::nRestoredDcc, LaserSorter::stats_t::nWritten, and stats_.

169  {
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 }
double nRestoredDcc
number of events whose DCC ID was restored based on FED block sizes
Definition: LaserSorter.h:471
double nRead
number of events read out
Definition: LaserSorter.h:461
std::ofstream logFile_
Definition: LaserSorter.h:324
struct LaserSorter::stats_t stats_
double nWritten
number of events written out
Definition: LaserSorter.h:463

Member Function Documentation

void LaserSorter::analyze ( const edm::Event event,
const edm::EventSetup es 
)
virtual

Implements edm::EDAnalyzer.

Definition at line 181 of file LaserSorter.cc.

References closeAllStreams(), closeOldStreams(), create_public_lumi_plots::color, colorNames, gather_cfg::cout, ecaldqm::dccId(), detailedTrigNames, detailedTrigType_, disableOutput_, ecalDccFedIdMax_, ecalDccFedIdMin_, LaserSorter::OutStreamRecord::excludedOrbit(), fedRawDataCollectionToken_, LaserSorter::OutStreamRecord::finalFileName(), getDetailedTriggerType(), getFullyReadoutDccs(), getOrbitFromDcc(), getStream(), i, edm::EventBase::id(), iNoEcalDataMess_, iNoFullReadoutDccError_, logFile_, lumiBlock_, lumiBlockPrev_, lumiBlockSpan_, maxFullReadoutDccError_, csvLumiCalc::maxLumi, csvLumiCalc::minLumi, LaserSorter::stats_t::nInvalidDccStrict, LaserSorter::stats_t::nInvalidDccWeak, now(), LaserSorter::stats_t::nRead, LaserSorter::stats_t::nRestoredDcc, LaserSorter::stats_t::nWritten, orbit_, orbitCountInALumiBlock_, dbtoconf::out, overWriteLumiBlockId_, lumiPlot::rawdata, restoreStreamsOfLumiBlock(), edm::EventID::run(), runNumber_, LaserSorter::OutStreamRecord::startingLumiBlock(), stats_, lumiQTWidget::t, timeLog_, timer_, timing_, verbosity_, and writeEvent().

181  {
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 }
RunNumber_t run() const
Definition: EventID.h:39
OutStreamRecord * getStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:500
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 const int ecalDccFedIdMin_
Definition: LaserSorter.h:312
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
edm::LuminosityBlockNumber_t lumiBlock_
Definition: LaserSorter.h:328
unsigned int LuminosityBlockNumber_t
void closeAllStreams()
Definition: LaserSorter.cc:468
double nRead
number of events read out
Definition: LaserSorter.h:461
timeval timer_
Definition: LaserSorter.h:365
int getOrbitFromDcc(const edm::Handle< FEDRawDataCollection > &rawdata) const
Definition: LaserSorter.cc:405
bool overWriteLumiBlockId_
Definition: LaserSorter.h:477
int iNoEcalDataMess_
Definition: LaserSorter.h:422
void closeOldStreams(edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:475
tuple out
Definition: dbtoconf.py:99
int getDetailedTriggerType(const edm::Handle< FEDRawDataCollection > &rawdata, double *proba=0)
Definition: LaserSorter.cc:427
int detailedTrigType_
Definition: LaserSorter.h:320
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:316
static std::string now()
Definition: LaserSorter.cc:66
std::ofstream logFile_
Definition: LaserSorter.h:324
int orbitCountInALumiBlock_
Definition: LaserSorter.h:484
struct LaserSorter::stats_t stats_
edm::EventID id() const
Definition: EventBase.h:60
edm::LuminosityBlockNumber_t lumiBlockPrev_
Definition: LaserSorter.h:332
tuple cout
Definition: gather_cfg.py:121
static const char *const colorNames[]
Definition: LaserSorter.cc:56
int iNoFullReadoutDccError_
Definition: LaserSorter.h:412
void restoreStreamsOfLumiBlock(int lumiBlock)
dictionary rawdata
Definition: lumiPlot.py:393
double nWritten
number of events written out
Definition: LaserSorter.h:463
edm::EDGetTokenT< FEDRawDataCollection > fedRawDataCollectionToken_
Definition: LaserSorter.h:442
unsigned dccId(DetId const &)
std::ofstream timeLog_
Definition: LaserSorter.h:369
void LaserSorter::beginJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 951 of file LaserSorter.cc.

951  {
952 }
void LaserSorter::beginRun ( edm::Run const &  run,
edm::EventSetup const &  es 
)
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 1217 of file LaserSorter.cc.

1217  {
1218  // cout << "Run starts at :" << run.runAuxiliary().beginTime().value() << "\n";
1219 }
void LaserSorter::closeAllStreams ( )
private

Closes all opened output streams.

Definition at line 468 of file LaserSorter.cc.

References closeOutStream(), and outStreamList_.

Referenced by analyze(), and endJob().

468  {
469  for(OutStreamList::iterator it = outStreamList_.begin();
470  it != outStreamList_.end();/*NOOP*/){
471  it = closeOutStream(it);
472  }
473 }
OutStreamList::iterator closeOutStream(OutStreamList::iterator streamRecord)
Definition: LaserSorter.cc:897
OutStreamList outStreamList_
Definition: LaserSorter.h:337
void LaserSorter::closeOldStreams ( edm::LuminosityBlockNumber_t  lumiBlock)
private

Closes output stream 2 lumi block older than the input 'lumiBlock' ID.

Parameters
lumiBlockID of the reference luminosity block.

Definition at line 475 of file LaserSorter.cc.

References closeOutStream(), gather_cfg::cout, lumiBlockSpan_, now(), outStreamList_, and verbosity_.

Referenced by analyze().

475  {
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 }
int lumiBlockSpan_
Definition: LaserSorter.h:439
OutStreamList::iterator closeOutStream(OutStreamList::iterator streamRecord)
Definition: LaserSorter.cc:897
unsigned int LuminosityBlockNumber_t
static std::string now()
Definition: LaserSorter.cc:66
tuple cout
Definition: gather_cfg.py:121
OutStreamList outStreamList_
Definition: LaserSorter.h:337
LaserSorter::OutStreamList::iterator LaserSorter::closeOutStream ( OutStreamList::iterator  streamRecord)
private

Closes an output stream and removed it from opened stream records. Beware: this methode modifies outStreamList_.

Parameters
streamRecordrecord of the output stream to close.
Returns
iterator to element next to the deleted one.

Definition at line 897 of file LaserSorter.cc.

References gather_cfg::cout, doOutputList_, f, analyzePatCleaning_cfg::inputFile, now(), outputList_, outStreamList_, AlCaHLTBitMon_QueryRunRegistry::string, lumiQTWidget::t, cond::rpcobgas::time, verbosity_, and writeIndexTable().

Referenced by closeAllStreams(), and closeOldStreams().

898  {
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 }
bool writeIndexTable(std::ofstream &out, std::vector< IndexRecord > &indices)
double f[11][100]
tuple out
Definition: dbtoconf.py:99
static std::string now()
Definition: LaserSorter.cc:66
std::ofstream outputList_
Definition: LaserSorter.h:389
tuple cout
Definition: gather_cfg.py:121
bool doOutputList_
Definition: LaserSorter.h:381
OutStreamList outStreamList_
Definition: LaserSorter.h:337
LaserSorter::OutStreamList::iterator LaserSorter::createOutStream ( int  fedId,
edm::LuminosityBlockNumber_t  lumiBlock 
)
private

Creates an output stream. It must be ensured before calling this method that the output stream is not already opened (See outStreamList_).

Parameters
fedIdFED ID of the event to stream out.
lumiBlockstarting lumi block of the event group to write to the stream.
Returns
iterator to the new stream record. outStreamList_.end() in case of failure.

Definition at line 640 of file LaserSorter.cc.

References EnergyCorrector::c, gather_cfg::cout, TauDecayModes::dec, end, Exception, formatVersion_, recoMuon::in, min(), now(), dbtoconf::out, outStreamList_, readFormatVersion(), readIndexTable(), renameAsBackup(), streamFileName(), AlCaHLTBitMon_QueryRunRegistry::string, estimatePileup_makeJSON::trunc, verbosity_, and writeFileHeader().

Referenced by getStream().

641  {
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 }
bool readIndexTable(std::ifstream &in, std::string &inName, OutStreamRecord &outRcd, std::string *err)
void writeFileHeader(std::ofstream &out)
Definition: LaserSorter.cc:776
void streamFileName(int fedId, edm::LuminosityBlockNumber_t lumiBlock, std::string &tmpName, std::string &finalName)
Definition: LaserSorter.cc:843
unsigned char formatVersion_
Definition: LaserSorter.h:341
#define end
Definition: vmac.h:37
T min(T a, T b)
Definition: MathUtil.h:58
tuple out
Definition: dbtoconf.py:99
static std::string now()
Definition: LaserSorter.cc:66
int readFormatVersion(std::ifstream &in, const std::string &fileName)
tuple cout
Definition: gather_cfg.py:121
OutStreamList outStreamList_
Definition: LaserSorter.h:337
bool renameAsBackup(const std::string &fileName, std::string &newFileName)
Definition: LaserSorter.cc:618
int LaserSorter::dcc2Lme ( int  dccNum,
int  dccSide 
)
private

Definition at line 374 of file LaserSorter.cc.

References min().

374  {
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 }
T min(T a, T b)
Definition: MathUtil.h:58
void LaserSorter::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 945 of file LaserSorter.cc.

References closeAllStreams().

945  {
946  //TODO: better treatement of last files:
947  //they might be imcomplete...
948  closeAllStreams();
949 }
void closeAllStreams()
Definition: LaserSorter.cc:468
int LaserSorter::getDetailedTriggerType ( const edm::Handle< FEDRawDataCollection > &  rawdata,
double *  proba = 0 
)
private

Retrieve detailed trigger type (trigger type, DCC, side) from raw event

Parameters
rawdataFED data collection
probaif not null used to store the maximum of occurence frequency of the detailed trigger types (DTT) appearing in each DCC block. In normal condition every DCC indicated the same DTT and this value is 1.
Returns
detailed trigger type. In case of descripancy between the DCCs, the most frequent value is returned if it covers more than 80% of the present DCC blocks, -1 is returned otherwise. If event does not contain any ECAL data -2 is returned.

Definition at line 427 of file LaserSorter.cc.

References Majority< T >::add(), gather_cfg::cout, FEDRawData::data(), data, ecalDccFedIdMax_, ecalDccFedIdMin_, iNoEcalDataMess_, FEDNumbering::inRange(), maxNoEcalDataMess_, now(), AlCaHLTBitMon_ParallelJobs::p, Majority< T >::result(), FEDRawData::size(), and verbosity_.

Referenced by analyze().

428  {
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 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:312
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void add(const T &value)
Definition: Majority.h:24
int iNoEcalDataMess_
Definition: LaserSorter.h:422
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:316
static std::string now()
Definition: LaserSorter.cc:66
static bool inRange(int)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
tuple cout
Definition: gather_cfg.py:121
int maxNoEcalDataMess_
Definition: LaserSorter.h:426
T result(double *proba) const
Definition: Majority.h:29
std::vector< int > LaserSorter::getFullyReadoutDccs ( const FEDRawDataCollection data) const
private

Retrieves DCCs which were fully read out (>=68 readout channels).

Parameters
dataDCC data collection
Returns
FED ids.

Definition at line 1025 of file LaserSorter.cc.

References ecalDccFedIdMax_, ecalDccFedIdMin_, FEDRawDataCollection::FEDData(), isDccEventEmpty(), ecaldqm::nTowers, and query::result.

Referenced by analyze().

1025  {
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 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:312
bool isDccEventEmpty(const FEDRawData &data, size_t *dccLen=0, int *nTowerBlocks=0) const
Definition: LaserSorter.cc:954
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
tuple result
Definition: query.py:137
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:316
int LaserSorter::getOrbitFromDcc ( const edm::Handle< FEDRawDataCollection > &  rawdata) const
private

Retrieves the orbit ID from DCC headers. The first header found is used. the raw data where to read the orbit id.

Returns
the event orbit ID or -1 if it was not found

Definition at line 405 of file LaserSorter.cc.

References FEDRawData::data(), data, ecalDccFedIdMax_, ecalDccFedIdMin_, FEDNumbering::inRange(), and FEDRawData::size().

Referenced by analyze().

405  {
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 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:312
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:316
static bool inRange(int)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
void LaserSorter::getOutputFedList ( const edm::Event event,
const FEDRawDataCollection data,
std::vector< unsigned > &  fedIds 
) const
private

Computes the list of FEDs which data must be written out.

Parameters
dataCMS raw event
fedIds[out] list of FEDs to keep

Definition at line 997 of file LaserSorter.cc.

References ecalDccFedIdMax_, ecalDccFedIdMin_, FEDRawDataCollection::FEDData(), isDccEventEmpty(), matacqFedId_, and FEDRawData::size().

Referenced by writeEvent().

999  {
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 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:312
bool isDccEventEmpty(const FEDRawData &data, size_t *dccLen=0, int *nTowerBlocks=0) const
Definition: LaserSorter.cc:954
static const int matacqFedId_
Definition: LaserSorter.h:446
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
unsigned long long uint64_t
Definition: Time.h:15
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:316
LaserSorter::OutStreamRecord * LaserSorter::getStream ( int  fedId,
edm::LuminosityBlockNumber_t  lumiBlock 
)
private

Gets and eventually creates the output stream for writing the events of a given FED and luminosity block.

Parameters
fedIdID of the FED the event is issued from
lumiBlockluminositu block of the event
Returns
pointer of the output stream record or null if not found.

Definition at line 500 of file LaserSorter.cc.

References funct::abs(), gather_cfg::cout, createOutStream(), ecalDccFedIdMax_, lumiBlockSpan_, now(), outStreamList_, and verbosity_.

Referenced by analyze(), and restoreStreamsOfLumiBlock().

501  {
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 }
int lumiBlockSpan_
Definition: LaserSorter.h:439
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:316
static std::string now()
Definition: LaserSorter.cc:66
OutStreamList::iterator createOutStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:640
tuple cout
Definition: gather_cfg.py:121
OutStreamList outStreamList_
Definition: LaserSorter.h:337
bool LaserSorter::isDccEventEmpty ( const FEDRawData data,
size_t *  dccLen = 0,
int *  nTowerBlocks = 0 
) const
private

Checks if an ECAL DCC event is empty. It is considered as empty if it does not contains FE data ("tower" block). So an event containing SRP or TCC data can be tagged as empty by this method. , if not null filled with the event length read from the DCC header. if not null, filled with number of tower blocks

Returns
true if event is empty, false otherwise

Definition at line 954 of file LaserSorter.cc.

References FEDRawData::data(), dtTPAnalyzer_cfg::dataType, and FEDRawData::size().

Referenced by getFullyReadoutDccs(), and getOutputFedList().

955  {
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 }
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
int LaserSorter::readFormatVersion ( std::ifstream &  in,
const std::string &  fileName 
)
private

Gets format version of an LMF file. Position of file is preserved.

Parameters
instream to read the file
fileNamename of the file. Used in error message.
Returns
version or -1 in case of error.

Definition at line 1151 of file LaserSorter.cc.

References data, AlCaHLTBitMon_ParallelJobs::p, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by createOutStream().

1152  {
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 }
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
bool LaserSorter::readIndexTable ( std::ifstream &  in,
std::string &  inName,
OutStreamRecord outRcd,
std::string *  err 
)
private

Read index table of an LMF file.

Parameters
inLMF file whose index table must be read.
inNamename of the in file
outRcdrecord of the output file. whose the index table must be copied to.
errif not nul, in case of failure filled with the error message.
Returns
true in case of success, false otherwise

Definition at line 1077 of file LaserSorter.cc.

References gather_cfg::cout, LaserSorter::OutStreamRecord::excludedOrbit(), i, recoMuon::in, LaserSorter::OutStreamRecord::indices(), maxEvents_, jetmet_cfg::nevts, now(), alignCSCRings::s, and verbosity_.

Referenced by createOutStream().

1080  {
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 }
int i
Definition: DBlmapReader.cc:9
static const unsigned maxEvents_
Definition: LaserSorter.h:455
static std::string now()
Definition: LaserSorter.cc:66
tuple cout
Definition: gather_cfg.py:121
int nevts
Definition: jetmet_cfg.py:3
bool LaserSorter::renameAsBackup ( const std::string &  fileName,
std::string &  newFileName 
)
private

Definition at line 618 of file LaserSorter.cc.

References i, and MainPageGenerator::link.

Referenced by createOutStream().

619  {
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 }
int i
Definition: DBlmapReader.cc:9
void LaserSorter::restoreStreamsOfLumiBlock ( int  lumiBlock)
private

Opens output streams associated to a lumi block according to already existing files. To be used when previously processed luminosity block is not

Parameters
lumiBlockID of the luminosity block whose output streams must be reopened.

Definition at line 1199 of file LaserSorter.cc.

References ecalDccFedIdMax_, ecalDccFedIdMin_, HLT_25ns14e33_v1_cff::fedId, MillePedeFileConverter_cfg::fileName, getStream(), alignCSCRings::s, and streamFileName().

Referenced by analyze().

1199  {
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 }
OutStreamRecord * getStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:500
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:312
void streamFileName(int fedId, edm::LuminosityBlockNumber_t lumiBlock, std::string &tmpName, std::string &finalName)
Definition: LaserSorter.cc:843
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:316
void LaserSorter::streamFileName ( int  fedId,
edm::LuminosityBlockNumber_t  lumiBlock,
std::string &  tmpName,
std::string &  finalName 
)
private

Builds the file names for the group of event corresponding to a FED and a starting lumi block.

Parameters
fedIdFED ID of the event set
lumiBlockstarting luminoisty block of the event set
[out]tmpNamename of the file to use when filling it.
[out]finalNamename of the file once completed.

Definition at line 843 of file LaserSorter.cc.

References gather_cfg::cout, dir, ecalDccFedIdMax_, ecalDccFedIdMin_, Exception, fedSubDirs_, MillePedeFileConverter_cfg::fileName, eostools::mkdir(), now(), outputDir_, runNumber_, and verbosity_.

Referenced by createOutStream(), and restoreStreamsOfLumiBlock().

845  {
846  int iFed;
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 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:312
edm::RunNumber_t runNumber_
Definition: LaserSorter.h:361
std::vector< std::string > fedSubDirs_
Definition: LaserSorter.h:349
std::string outputDir_
Definition: LaserSorter.h:345
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:316
static std::string now()
Definition: LaserSorter.cc:66
def mkdir
Definition: eostools.py:250
tuple cout
Definition: gather_cfg.py:121
dbl *** dir
Definition: mlp_gen.cc:35
std::string LaserSorter::toString ( uint64_t  t)
staticprivate

Help function to format a date

Definition at line 1184 of file LaserSorter.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by writeEventHeader().

1184  {
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 }
bool LaserSorter::writeEvent ( OutStreamRecord out,
const edm::Event event,
int  detailedTriggerType,
const FEDRawDataCollection data 
)
private

Writes a monitoring events to an output stream.

Parameters
outstream to write the event out
eventEDM event, used to retrieve meta information like timestamp and ID.
IDof the unique FED block of the event
dataDCC data
Returns
true on success, false on failure
See Also
getStream(int, edm::LuminosityBlockNumber_t)

Definition at line 530 of file LaserSorter.cc.

References gather_cfg::cout, FEDRawData::data(), dt, FEDRawDataCollection::FEDData(), getOutputFedList(), MatacqRawEvent::getTimeStamp(), LaserSorter::OutStreamRecord::indices(), matacqFedId_, now(), orbit_, orbitZeroTime_, LaserSorter::OutStreamRecord::out(), dbtoconf::out, FEDRawData::size(), edm::Event::size(), verbosity_, writeEventHeader(), and writeFedBlock().

Referenced by analyze().

532  {
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 }
float dt
Definition: AMPTWrapper.h:126
size_t size() const
Definition: Event.cc:197
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
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
struct timeval orbitZeroTime_
Definition: LaserSorter.h:495
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
bool writeFedBlock(std::ofstream &out, const FEDRawData &data)
Definition: LaserSorter.cc:581
tuple out
Definition: dbtoconf.py:99
static std::string now()
Definition: LaserSorter.cc:66
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
tuple cout
Definition: gather_cfg.py:121
bool LaserSorter::writeEventHeader ( std::ofstream &  out,
const edm::Event evt,
int  fedId,
unsigned  nFeds 
)
private

Write event header with event identification and timestamp.

Parameters
outoutput stream to write to
evtevent
Returns
false in case of write failure

Definition at line 793 of file LaserSorter.cc.

References edm::EventBase::bunchCrossing(), colorNames, gather_cfg::cout, TauDecayModes::dec, detailedTrigNames, dt, edm::EventID::event(), edm::EventBase::id(), edm::EventBase::luminosityBlock(), now(), orbit_, orbitZeroTime_, edm::Event::run(), edm::EventBase::time(), toString(), groupFilesInBlocks::tt, edm::Timestamp::value(), and verbosity_.

Referenced by writeEvent().

796  {
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 }
EventNumber_t event() const
Definition: EventID.h:41
float dt
Definition: AMPTWrapper.h:126
static const char *const detailedTrigNames[]
Definition: LaserSorter.cc:45
static std::string toString(uint64_t t)
int bunchCrossing() const
Definition: EventBase.h:66
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
struct timeval orbitZeroTime_
Definition: LaserSorter.h:495
RunNumber_t run() const
Definition: Event.h:92
tuple out
Definition: dbtoconf.py:99
static std::string now()
Definition: LaserSorter.cc:66
edm::EventID id() const
Definition: EventBase.h:60
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
tuple cout
Definition: gather_cfg.py:121
static const char *const colorNames[]
Definition: LaserSorter.cc:56
TimeValue_t value() const
Definition: Timestamp.h:56
edm::Timestamp time() const
Definition: EventBase.h:61
bool LaserSorter::writeFedBlock ( std::ofstream &  out,
const FEDRawData data 
)
private

Writes out data of a FED

Parameters
outstream to write the event out
dataFED data
Returns
true on success, false on failure

Definition at line 581 of file LaserSorter.cc.

References gather_cfg::cout, FEDRawData::data(), Exception, now(), FEDRawData::size(), and verbosity_.

Referenced by writeEvent().

582  {
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 }
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
tuple out
Definition: dbtoconf.py:99
unsigned long long uint64_t
Definition: Time.h:15
static std::string now()
Definition: LaserSorter.cc:66
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
tuple cout
Definition: gather_cfg.py:121
void LaserSorter::writeFileHeader ( std::ofstream &  out)
private

Writing file header for an LMF binary file

Parameters
outstream of the output file

Definition at line 776 of file LaserSorter.cc.

References Exception, and formatVersion_.

Referenced by createOutStream().

776  {
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 }
unsigned char formatVersion_
Definition: LaserSorter.h:341
tuple out
Definition: dbtoconf.py:99
bool LaserSorter::writeIndexTable ( std::ofstream &  out,
std::vector< IndexRecord > &  indices 
)
private

Writes index table in LMF output file. stream must be positionned to the place for the index table (end of file).

Parameters
outstream of output file.
indicesindex table

Definition at line 1037 of file LaserSorter.cc.

References end, i, indexOffset32_, jetmet_cfg::nevts, and python.multivaluedict::sort().

Referenced by closeOutStream().

1038  {
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 }
int i
Definition: DBlmapReader.cc:9
static const int indexOffset32_
Definition: LaserSorter.h:450
#define end
Definition: vmac.h:37
tuple out
Definition: dbtoconf.py:99
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
int nevts
Definition: jetmet_cfg.py:3

Member Data Documentation

int LaserSorter::detailedTrigType_
private

Trigger type of calibration event. -1 if unkown.

Definition at line 320 of file LaserSorter.h.

Referenced by analyze().

bool LaserSorter::disableOutput_
private

Switch to disable writing output file (for test purpose).

Definition at line 357 of file LaserSorter.h.

Referenced by analyze().

bool LaserSorter::doOutputList_
private

Switch for logging paths of the output files

Definition at line 381 of file LaserSorter.h.

Referenced by closeOutStream(), and LaserSorter().

const int LaserSorter::ecalDccFedIdMax_ = 654
staticprivate
const int LaserSorter::ecalDccFedIdMin_ = 601
staticprivate
edm::InputTag LaserSorter::fedRawDataCollectionTag_
private

Definition at line 441 of file LaserSorter.h.

Referenced by LaserSorter().

edm::EDGetTokenT<FEDRawDataCollection> LaserSorter::fedRawDataCollectionToken_
private

Definition at line 442 of file LaserSorter.h.

Referenced by analyze(), and LaserSorter().

std::vector<std::string> LaserSorter::fedSubDirs_
private

Subdirectories for output file of each FED

Definition at line 349 of file LaserSorter.h.

Referenced by LaserSorter(), and streamFileName().

unsigned char LaserSorter::formatVersion_
private

Data format version of lmf output file

Definition at line 341 of file LaserSorter.h.

Referenced by createOutStream(), and writeFileHeader().

const int LaserSorter::indexOffset32_ = 1
staticprivate

Definition at line 450 of file LaserSorter.h.

Referenced by writeIndexTable().

int LaserSorter::iNoEcalDataMess_
private

number of "ECAL DCC data" message in a run

Definition at line 422 of file LaserSorter.h.

Referenced by analyze(), and getDetailedTriggerType().

int LaserSorter::iNoFullReadoutDccError_
private

Number of "No fully readout DCC error"

Definition at line 412 of file LaserSorter.h.

Referenced by analyze().

std::ofstream LaserSorter::logFile_
private

File for logging

Definition at line 324 of file LaserSorter.h.

Referenced by analyze(), LaserSorter(), and ~LaserSorter().

edm::LuminosityBlockNumber_t LaserSorter::lumiBlock_
private

Luminosity block of event under processing

Definition at line 328 of file LaserSorter.h.

Referenced by analyze().

edm::LuminosityBlockNumber_t LaserSorter::lumiBlockPrev_
private

Luminosity block of previous processed event

Definition at line 332 of file LaserSorter.h.

Referenced by analyze().

int LaserSorter::lumiBlockSpan_
private

Tolerance on lumi block spanning of a FED sequence. Subsequent events of a same FED must span at most on 2*lumiBlockSpan_+1 luminosity blocks.

  • It is important that the laser sequence scane does not pass twice on the same FED within the 2*lumiBlockSpan_+1. Failing this requirement will result mixing event of different passes in the same output file.
  • The number of input files opened simultinuously is proportional to 2*lumiBlockSpan_+1. So increasing lumiBlockSpan_ will also increase the number of opened files and may have some impact of sorting time performances.

Definition at line 439 of file LaserSorter.h.

Referenced by analyze(), closeOldStreams(), and getStream().

const int LaserSorter::matacqFedId_ = 655
staticprivate

FED ID associated to Matacq data

Definition at line 446 of file LaserSorter.h.

Referenced by getOutputFedList(), and writeEvent().

const unsigned LaserSorter::maxEvents_ = 1<<20
staticprivate

Limit of number of events to prevent exhausting memory with indexTable_ in case of file corruption.

Definition at line 455 of file LaserSorter.h.

Referenced by readIndexTable().

int LaserSorter::maxFullReadoutDccError_
private

Maximum number of "No fully readout DCC error" message in a run

Definition at line 417 of file LaserSorter.h.

Referenced by analyze().

int LaserSorter::maxNoEcalDataMess_
private

Maximum number of "ECAL DCC data" message in a run

Definition at line 426 of file LaserSorter.h.

Referenced by getDetailedTriggerType().

int LaserSorter::orbit_
private

Definition at line 486 of file LaserSorter.h.

Referenced by analyze(), writeEvent(), and writeEventHeader().

int LaserSorter::orbitCountInALumiBlock_
private

Length of a lumi block in number of orbits used when overWriteLumiBlockId is set to true; LB = orbit_id / orbitCountInALumiBlock_

Definition at line 484 of file LaserSorter.h.

Referenced by analyze().

struct timeval LaserSorter::orbitZeroTime_
private

Time stamp offset to use to calculate calibration time from the orbit id. It is obtained from the matacq block (time originates from the PC hosting the laser supervisor). and used in case the event is missing timestamp, in principle for data acquired with the minidaq Calibration event time = orbitZeroTime_ + orbit_ * (89.1 microsec).

Definition at line 495 of file LaserSorter.h.

Referenced by writeEvent(), and writeEventHeader().

std::string LaserSorter::outputDir_
private

Top directory for output files

Definition at line 345 of file LaserSorter.h.

Referenced by LaserSorter(), batchmanager.BatchManager::PrepareJob(), valtools.webpage::readCaptions(), and streamFileName().

std::ofstream LaserSorter::outputList_
private

stream where list of output file is listed to

Definition at line 389 of file LaserSorter.h.

Referenced by closeOutStream(), and LaserSorter().

std::string LaserSorter::outputListFile_
private

name of file where list of output file is listed to

Definition at line 377 of file LaserSorter.h.

Referenced by LaserSorter().

OutStreamList LaserSorter::outStreamList_
private

List of output stream to write sorted data

Definition at line 337 of file LaserSorter.h.

Referenced by closeAllStreams(), closeOldStreams(), closeOutStream(), createOutStream(), and getStream().

bool LaserSorter::overWriteLumiBlockId_
private

Switch to recompute and overwrite the lumi block ID

Definition at line 477 of file LaserSorter.h.

Referenced by analyze().

edm::RunNumber_t LaserSorter::runNumber_
private

Run number of event under process

Definition at line 361 of file LaserSorter.h.

Referenced by analyze(), and streamFileName().

struct LaserSorter::stats_t LaserSorter::stats_
private

Referenced by analyze(), and ~LaserSorter().

const LaserSorter::stats_t LaserSorter::stats_init = {0, 0, 0, 0, 0}
staticprivate

Definition at line 473 of file LaserSorter.h.

std::ofstream LaserSorter::timeLog_
private

Output stream to log code timing

Definition at line 369 of file LaserSorter.h.

Referenced by analyze(), and LaserSorter().

std::string LaserSorter::timeLogFile_
private

Name of the file to log the processing time

Definition at line 353 of file LaserSorter.h.

Referenced by LaserSorter().

timeval LaserSorter::timer_
private

Buffer for timing

Definition at line 365 of file LaserSorter.h.

Referenced by analyze(), and LaserSorter().

bool LaserSorter::timing_
private

Switch for code timing.

Definition at line 373 of file LaserSorter.h.

Referenced by analyze(), and LaserSorter().

int LaserSorter::verbosity_
private