CMS 3D CMS Logo

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

void analyze (const edm::Event &, const edm::EventSetup &) override
 
void beginJob () override
 
void beginRun (edm::Run const &, edm::EventSetup const &) override
 
void endJob () override
 
 LaserSorter (const edm::ParameterSet &)
 
 ~LaserSorter () override
 
- Public Member Functions inherited from edm::EDAnalyzer
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
std::string workerType () const
 
 ~EDAnalyzer () override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Types

typedef boost::ptr_list< OutStreamRecordOutStreamList
 

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=nullptr)
 
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=nullptr, int *nTowerBlocks=nullptr) 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< FEDRawDataCollectionfedRawDataCollectionToken_
 
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 &)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- 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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
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 114 of file LaserSorter.h.

Constructor & Destructor Documentation

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

Definition at line 74 of file LaserSorter.cc.

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

75  : lumiBlock_(0),
76  lumiBlockPrev_(0),
77  formatVersion_(5),
78  outputDir_(pset.getParameter<std::string>("outputDir")),
79  fedSubDirs_(pset.getParameter<std::vector<std::string> >("fedSubDirs")),
80  timeLogFile_(pset.getUntrackedParameter<std::string>("timeLogFile", "")),
81  disableOutput_(pset.getUntrackedParameter<bool>("disableOutput", false)),
82  runNumber_(0),
83  outputListFile_(pset.getUntrackedParameter<string>("outputListFile", "")),
84  doOutputList_(false),
85  verbosity_(pset.getUntrackedParameter<int>("verbosity", 0)),
87  maxFullReadoutDccError_(pset.getParameter<int>("maxFullReadoutDccError")),
89  maxNoEcalDataMess_(pset.getParameter<int>("maxNoEcalDataMess")),
90  lumiBlockSpan_(pset.getParameter<int>("lumiBlockSpan")),
91  fedRawDataCollectionTag_(pset.getParameter<edm::InputTag>("fedRawDataCollectionTag")),
93  overWriteLumiBlockId_(pset.getParameter<bool>("overWriteLumiBlockId")),
94  orbitCountInALumiBlock_(pset.getParameter<int>("orbitCountInALumiBlock")),
95  orbit_(-1),
97  gettimeofday(&timer_, nullptr);
98  logFile_.open("eventSelect.log", ios::app | ios::out);
99 
100  const unsigned nEcalFeds = 54;
101  if (fedSubDirs_.size() != nEcalFeds + 1) {
102  throw cms::Exception("LaserSorter") << "Configuration error: "
103  << "fedSubDirs parameter must be a vector "
104  << " of " << nEcalFeds << " strings"
105  << " (subdirectory for unknown triggered FED followed by "
106  "subdirectories for FED ID 601 "
107  "to FED ID 654 in increasing FED ID order)";
108  }
109 
110  fedRawDataCollectionToken_ = consumes<FEDRawDataCollection>(fedRawDataCollectionTag_);
111 
112  if (!outputListFile_.empty()) {
113  outputList_.open(outputListFile_.c_str(), ios::app);
114  if (outputList_.bad()) {
115  throw cms::Exception("FileOpen") << "Failed to open file '" << outputListFile_
116  << "' for logging of output file path list.";
117  }
118  doOutputList_ = true;
119  }
120 
121  if (!timeLogFile_.empty()) {
122  timeLog_.open(timeLogFile_.c_str());
123  if (timeLog_.fail()) {
124  cout << "[LaserSorter " << now() << "] "
125  << "Failed to open file " << timeLogFile_ << " to log timing.\n";
126  timing_ = false;
127  } else {
128  timing_ = true;
129  }
130  }
131 
132  struct stat fileStat;
133  if (0 == stat(outputDir_.c_str(), &fileStat)) {
134  if (!S_ISDIR(fileStat.st_mode)) {
135  throw cms::Exception("[LaserSorter]") << "File " << outputDir_ << " exists but is not a directory "
136  << " as expected.";
137  }
138  } else { //directory does not exists, let's try to create it
139  if (0 != mkdir(outputDir_.c_str(), 0755)) {
140  throw cms::Exception("[LaserSorter]") << "Failed to create directory " << outputDir_ << " for writing data.";
141  }
142  }
143 
144  logFile_ << "# "
145  "run\t"
146  "LB\t"
147  "event\t"
148  "trigType\t"
149  "FED\t"
150  "side\t"
151  "LB out\t"
152  "Written\t"
153  "ECAL data\n";
154 }
edm::InputTag fedRawDataCollectionTag_
Definition: LaserSorter.h:417
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int lumiBlockSpan_
Definition: LaserSorter.h:415
bool disableOutput_
Definition: LaserSorter.h:335
int maxFullReadoutDccError_
Definition: LaserSorter.h:394
edm::RunNumber_t runNumber_
Definition: LaserSorter.h:339
edm::LuminosityBlockNumber_t lumiBlock_
Definition: LaserSorter.h:306
std::vector< std::string > fedSubDirs_
Definition: LaserSorter.h:327
struct timeval orbitZeroTime_
Definition: LaserSorter.h:470
unsigned char formatVersion_
Definition: LaserSorter.h:319
static const struct timeval nullTime
Definition: LaserSorter.cc:42
std::string outputDir_
Definition: LaserSorter.h:323
timeval timer_
Definition: LaserSorter.h:343
std::string outputListFile_
Definition: LaserSorter.h:355
std::string timeLogFile_
Definition: LaserSorter.h:331
bool overWriteLumiBlockId_
Definition: LaserSorter.h:453
int iNoEcalDataMess_
Definition: LaserSorter.h:398
static const stats_t stats_init
Definition: LaserSorter.h:449
static std::string now()
Definition: LaserSorter.cc:60
std::ofstream outputList_
Definition: LaserSorter.h:367
std::ofstream logFile_
Definition: LaserSorter.h:302
int orbitCountInALumiBlock_
Definition: LaserSorter.h:459
def mkdir(path)
Definition: eostools.py:251
struct LaserSorter::stats_t stats_
edm::LuminosityBlockNumber_t lumiBlockPrev_
Definition: LaserSorter.h:310
int maxNoEcalDataMess_
Definition: LaserSorter.h:402
int iNoFullReadoutDccError_
Definition: LaserSorter.h:390
bool doOutputList_
Definition: LaserSorter.h:359
edm::EDGetTokenT< FEDRawDataCollection > fedRawDataCollectionToken_
Definition: LaserSorter.h:418
std::ofstream timeLog_
Definition: LaserSorter.h:347
LaserSorter::~LaserSorter ( )
override

Definition at line 156 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_.

156  {
157  logFile_ << "Summary. Event count: " << stats_.nRead << " processed, " << stats_.nWritten << " written, "
158  << stats_.nInvalidDccStrict << " with errors in DCC ID values, " << stats_.nInvalidDccWeak
159  << " with unusable DCC ID values, " << stats_.nRestoredDcc << " restored DCC ID based on DCC block size\n";
160 }
double nRestoredDcc
number of events whose DCC ID was restored based on FED block sizes
Definition: LaserSorter.h:447
double nRead
number of events read out
Definition: LaserSorter.h:437
std::ofstream logFile_
Definition: LaserSorter.h:302
struct LaserSorter::stats_t stats_
double nWritten
number of events written out
Definition: LaserSorter.h:439

Member Function Documentation

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

Definition at line 163 of file LaserSorter.cc.

References closeAllStreams(), closeOldStreams(), create_public_lumi_plots::color, colorNames, gather_cfg::cout, ecaldqm::dccId(), detailedTrigNames, detailedTrigType_, disableOutput_, ecalDccFedIdMax_, LaserSorter::OutStreamRecord::excludedOrbit(), fedRawDataCollectionToken_, LaserSorter::OutStreamRecord::finalFileName(), getDetailedTriggerType(), getFullyReadoutDccs(), getOrbitFromDcc(), getStream(), mps_fire::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_, MillePedeFileConverter_cfg::out, overWriteLumiBlockId_, matplotRender::rawdata, restoreStreamsOfLumiBlock(), edm::EventID::run(), runNumber_, LaserSorter::OutStreamRecord::startingLumiBlock(), stats_, lumiQTWidget::t, timeLog_, timer_, timing_, verbosity_, writeEvent(), and globals_cff::x1.

163  {
164  if (timing_) {
165  timeval t;
166  gettimeofday(&t, nullptr);
167  timeLog_ << t.tv_sec << "." << setfill('0') << setw(3) << (t.tv_usec + 500) / 1000 << setfill(' ') << "\t"
168  << (t.tv_usec - timer_.tv_usec) * 1. + (t.tv_sec - timer_.tv_sec) * 1.e6 << "\t";
169  timer_ = t;
170  }
171 
172  ++stats_.nRead;
173 
174  if (event.id().run() != runNumber_) { //run changed or first event
175  //for a new run, starts with a new output stream set.
176  closeAllStreams();
177  runNumber_ = event.id().run();
179  iNoEcalDataMess_ = 0;
180  lumiBlockPrev_ = 0;
181  lumiBlock_ = 0;
182  }
183 
185  event.getByToken(fedRawDataCollectionToken_, rawdata);
186 
187  //orbit number
188  //FIXME: orbit from edm Event is currently wrong. Forcing to use of CMS orbit until
189  //it is fixed. See https://hypernews.cern.ch/HyperNews/CMS/get/commissioning/5343/2.html
190 #if 0
191  orbit_ = event.orbitNumber();
192 #else
193  orbit_ = -1;
194 #endif
195 
196  // std::cerr << "Orbit ID CMS, ECAL: " << orbit_ << "\t" << getOrbitFromDcc(rawdata) << "\n";
197 
198  if (orbit_ < 0) { //For local run CMSSW failed to find the orbit number
199  // cout << "Look for orbit from DCC headers....\n";
200  orbit_ = getOrbitFromDcc(rawdata);
201  }
202 
203  //The "detailed trigger type DCC field content:
204  double dttProba = 0;
205  int dtt = getDetailedTriggerType(rawdata, &dttProba);
206 
207  if (overWriteLumiBlockId_) {
210  if (lb != lumiBlock_) {
211  std::cout << "[LaserSorter " << now() << "] Overwrite LB mode. LB number changed from: " << lb << " to "
212  << lumiBlock_ << "\n";
213  }
214  } else {
216  lumiBlock_ = event.luminosityBlock();
217  if (lb != lumiBlock_) {
218  std::cout << "[LaserSorter " << now() << "] Standard LB mode. LB number changed from: " << lb << " to "
219  << lumiBlock_ << "\n";
220  }
221  }
222 
223  detailedTrigType_ = dtt;
224  const int trigType = (detailedTrigType_ >> 8) & 0x7;
225  const int color = (detailedTrigType_ >> 6) & 0x3;
226  const int dccId = (detailedTrigType_ >> 0) & 0x3F;
227  int triggeredFedId = (detailedTrigType_ == -2) ? -1 : (600 + dccId);
228  const int side = (detailedTrigType_ >> 11) & 0x1;
229  //monitoring region extended id:
230  // const int lme = dcc2Lme(dccId, side);
231 
232  if (detailedTrigType_ > -2) {
233  if (dttProba < 1. || triggeredFedId < ecalDccFedIdMin_ || triggeredFedId > ecalDccFedIdMax_) {
235  }
236 
237  if (triggeredFedId < ecalDccFedIdMin_ || triggeredFedId > ecalDccFedIdMax_) {
238  if (verbosity_)
239  cout << "[LaserSorter " << now() << "] "
240  << "DCC ID (" << dccId << ") found in trigger type is out of range.";
242  vector<int> ids = getFullyReadoutDccs(*rawdata);
243  if (ids.empty()) {
245  cout << " No fully read-out DCC found\n";
247  }
248  } else if (ids.size() == 1) {
249  triggeredFedId = ids[0];
250  if (verbosity_)
251  cout << " ID guessed from DCC payloads\n";
253  } else { //ids.size()>1
254  if (verbosity_) {
255  cout << " Several fully read-out Dccs:";
256  for (unsigned i = 0; i < ids.size(); ++i)
257  cout << " " << ids[i];
258  cout << "\n";
259  }
260  }
261  }
262 
263  if (verbosity_ > 1)
264  cout << "\n----------------------------------------------------------------------\n"
265  << "Event id: "
266  << " " << event.id() << "\n"
267  << "Lumin block: " << lumiBlock_ << "\n"
268  << "TrigType: " << detailedTrigNames[trigType & 0x7] << " Color: " << colorNames[color & 0x3]
269  << " FED: " << triggeredFedId << " side:" << side << "\n"
270  << "\n----------------------------------------------------------------------\n";
271 
272  } else { //NO ECAL DATA
273  if (verbosity_ > 1)
274  cout << "\n----------------------------------------------------------------------\n"
275  << "Event id: "
276  << " " << event.id() << "\n"
277  << "Lumin block: " << lumiBlock_ << "\n"
278  << "No ECAL data\n"
279  << "\n----------------------------------------------------------------------\n";
280  }
281 
282  logFile_ << event.id().run() << "\t" << lumiBlock_ << "\t" << event.id().event() << "\t" << trigType << "\t"
283  << triggeredFedId << "\t" << side;
284 
285  bool written = false;
286  int assignedLB = -1;
287 
288  if (lumiBlock_ != lumiBlockPrev_) {
289  //lumi block change => need for stream garbage collection
290  const int lb = lumiBlock_;
291  closeOldStreams(lb);
294  for (int lb1 = minLumi; lb1 <= maxLumi; ++lb1) {
296  }
297  }
298 
299  // if(lumiBlock_ < lumiBlockPrev_){
300  // throw cms::Exception("LaserSorter")
301  // << "Process event has a lumi block (" << lumiBlock_ << ")"
302  // << "older than previous one (" << lumiBlockPrev_ << "). "
303  // << "This can be due by wrong input file ordering or bad luminosity "
304  // << "block indication is the event header. "
305  // << "Event cannot be processed";
306  // }
307 
308  if (disableOutput_) {
309  /* NO OP*/
310  } else {
311  OutStreamRecord* out = getStream(triggeredFedId, lumiBlock_);
312 
313  if (out != nullptr) {
314  assignedLB = out->startingLumiBlock();
315  if (out->excludedOrbit().find(orbit_) == out->excludedOrbit().end()) {
316  if (verbosity_ > 1)
317  cout << "[LaserSorter " << now() << "] "
318  << "Writing out event from FED " << triggeredFedId << " LB " << lumiBlock_ << " orbit " << orbit_
319  << "\n";
320  int dtt = (detailedTrigType_ >= 0) ? detailedTrigType_ : -1; //shall we use -1 or 0 for undefined value?
321  written = written || writeEvent(*out, event, dtt, *rawdata);
322  ++stats_.nWritten;
323  } else {
324  if (verbosity_)
325  cout << "[LaserSorter " << now() << "] "
326  << "File " << out->finalFileName() << " "
327  << "already contains calibration event from FED " << triggeredFedId << ", LB = " << lumiBlock_
328  << " with orbit ID " << orbit_ << ". Event skipped.\n";
329  }
330  }
331  }
333 
334  logFile_ << "\t";
335  if (assignedLB >= 0)
336  logFile_ << assignedLB;
337  else
338  logFile_ << "-";
339  logFile_ << "\t" << (written ? "Y" : "N") << "\n";
340  logFile_ << "\t" << (detailedTrigType_ == -2 ? "N" : "Y") << "\n";
341 
342  if (timing_) {
343  timeval t;
344  gettimeofday(&t, nullptr);
345  timeLog_ << (t.tv_usec - timer_.tv_usec) * 1. + (t.tv_sec - timer_.tv_sec) * 1.e6 << "\n";
346  timer_ = t;
347  }
348 }
RunNumber_t run() const
Definition: EventID.h:39
OutStreamRecord * getStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:474
int lumiBlockSpan_
Definition: LaserSorter.h:415
bool disableOutput_
Definition: LaserSorter.h:335
std::vector< int > getFullyReadoutDccs(const FEDRawDataCollection &data) const
Definition: LaserSorter.cc:964
int maxFullReadoutDccError_
Definition: LaserSorter.h:394
double nRestoredDcc
number of events whose DCC ID was restored based on FED block sizes
Definition: LaserSorter.h:447
static const char *const detailedTrigNames[]
Definition: LaserSorter.cc:44
bool writeEvent(OutStreamRecord &out, const edm::Event &event, int detailedTriggerType, const FEDRawDataCollection &data)
Definition: LaserSorter.cc:499
edm::RunNumber_t runNumber_
Definition: LaserSorter.h:339
edm::LuminosityBlockNumber_t lumiBlock_
Definition: LaserSorter.h:306
unsigned int LuminosityBlockNumber_t
void closeAllStreams()
Definition: LaserSorter.cc:448
double nRead
number of events read out
Definition: LaserSorter.h:437
timeval timer_
Definition: LaserSorter.h:343
int getOrbitFromDcc(const edm::Handle< FEDRawDataCollection > &rawdata) const
Definition: LaserSorter.cc:381
bool overWriteLumiBlockId_
Definition: LaserSorter.h:453
int iNoEcalDataMess_
Definition: LaserSorter.h:398
void closeOldStreams(edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:454
int getDetailedTriggerType(const edm::Handle< FEDRawDataCollection > &rawdata, double *proba=nullptr)
Definition: LaserSorter.cc:404
int detailedTrigType_
Definition: LaserSorter.h:298
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:294
static std::string now()
Definition: LaserSorter.cc:60
std::ofstream logFile_
Definition: LaserSorter.h:302
int orbitCountInALumiBlock_
Definition: LaserSorter.h:459
struct LaserSorter::stats_t stats_
edm::EventID id() const
Definition: EventBase.h:59
edm::LuminosityBlockNumber_t lumiBlockPrev_
Definition: LaserSorter.h:310
static const char *const colorNames[]
Definition: LaserSorter.cc:55
int iNoFullReadoutDccError_
Definition: LaserSorter.h:390
void restoreStreamsOfLumiBlock(int lumiBlock)
double nWritten
number of events written out
Definition: LaserSorter.h:439
edm::EDGetTokenT< FEDRawDataCollection > fedRawDataCollectionToken_
Definition: LaserSorter.h:418
unsigned dccId(DetId const &)
std::ofstream timeLog_
Definition: LaserSorter.h:347
void LaserSorter::beginJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 891 of file LaserSorter.cc.

891 {}
void LaserSorter::beginRun ( edm::Run const &  run,
edm::EventSetup const &  es 
)
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 1156 of file LaserSorter.cc.

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

Closes all opened output streams.

Definition at line 448 of file LaserSorter.cc.

References closeOutStream(), and outStreamList_.

Referenced by analyze(), and endJob().

448  {
449  for (OutStreamList::iterator it = outStreamList_.begin(); it != outStreamList_.end(); /*NOOP*/) {
450  it = closeOutStream(it);
451  }
452 }
OutStreamList::iterator closeOutStream(OutStreamList::iterator streamRecord)
Definition: LaserSorter.cc:838
OutStreamList outStreamList_
Definition: LaserSorter.h:315
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 454 of file LaserSorter.cc.

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

Referenced by analyze().

454  {
455  const edm::LuminosityBlockNumber_t minLumiBlock = lumiBlock - lumiBlockSpan_;
456  const edm::LuminosityBlockNumber_t maxLumiBlock = lumiBlock + lumiBlockSpan_;
457  //If container type is ever changed, beware that
458  //closeOutStream call in the loop removes it from outStreamList
459  for (boost::ptr_list<OutStreamRecord>::iterator it = outStreamList_.begin(); it != outStreamList_.end();
460  /*NOOP*/) {
461  if (it->startingLumiBlock() < minLumiBlock || it->startingLumiBlock() > maxLumiBlock) {
462  //event older than 2 lumi block => stream can be closed
463  if (verbosity_)
464  cout << "[LaserSorter " << now() << "] "
465  << "Closing file for "
466  << "FED " << it->fedId() << " LB " << it->startingLumiBlock() << "\n";
467  it = closeOutStream(it);
468  } else {
469  ++it;
470  }
471  }
472 }
int lumiBlockSpan_
Definition: LaserSorter.h:415
OutStreamList::iterator closeOutStream(OutStreamList::iterator streamRecord)
Definition: LaserSorter.cc:838
unsigned int LuminosityBlockNumber_t
static std::string now()
Definition: LaserSorter.cc:60
OutStreamList outStreamList_
Definition: LaserSorter.h:315
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 838 of file LaserSorter.cc.

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

Referenced by closeAllStreams(), and closeOldStreams().

838  {
839  if (streamRecord == outStreamList_.end())
840  return outStreamList_.end();
841 
842  if (verbosity_)
843  cout << "[LaserSorter " << now() << "] "
844  << "Writing Index table of file " << streamRecord->finalFileName() << "\n";
845  ofstream& out = *streamRecord->out();
846  out.clear();
847  if (!writeIndexTable(out, *streamRecord->indices())) {
848  cout << "Error while writing index table for file " << streamRecord->finalFileName() << ". "
849  << "Resulting file might be corrupted. "
850  << "The error can be due to a lack of disk space.";
851  }
852 
853  if (verbosity_)
854  cout << "[LaserSorter " << now() << "] "
855  << "Closing file " << streamRecord->finalFileName() << ".\n";
856  out.close();
857 
858  const std::string& tmpFileName = streamRecord->tmpFileName();
859  const std::string& finalFileName = streamRecord->finalFileName();
860 
861  if (verbosity_)
862  cout << "[LaserSorter " << now() << "] "
863  << "Renaming " << tmpFileName << " to " << finalFileName << ".\n";
864 
865  if (0 != rename(tmpFileName.c_str(), finalFileName.c_str())) {
866  cout << "[LaserSorter " << now() << "] "
867  << " Failed to rename output file from " << tmpFileName << " to " << finalFileName << ". " << strerror(errno)
868  << "\n";
869  }
870 
871  if (doOutputList_) {
872  char buf[256];
873  time_t t = time(nullptr);
874  strftime(buf, sizeof(buf), "%F %R:%S", localtime(&t));
875 
876  ifstream f(".watcherfile");
877  string inputFile;
878  f >> inputFile;
879  outputList_ << finalFileName << "\t" << buf << "\t" << inputFile << endl;
880  }
881 
882  return outStreamList_.erase(streamRecord);
883 }
Definition: rename.py:1
bool writeIndexTable(std::ofstream &out, std::vector< IndexRecord > &indices)
Definition: LaserSorter.cc:976
double f[11][100]
static std::string now()
Definition: LaserSorter.cc:60
std::ofstream outputList_
Definition: LaserSorter.h:367
bool doOutputList_
Definition: LaserSorter.h:359
OutStreamList outStreamList_
Definition: LaserSorter.h:315
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 609 of file LaserSorter.cc.

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

Referenced by getStream().

609  {
610  if (verbosity_)
611  cout << "[LaserSorter " << now() << "] "
612  << "Creating a stream for FED " << fedId << " lumi block " << lumiBlock << ".\n";
613  std::string tmpName;
614  std::string finalName;
615 
616  streamFileName(fedId, lumiBlock, tmpName, finalName);
617 
618  errno = 0;
619 
620  //checks if a file with tmpName name already exists:
621  ofstream* out = new ofstream(tmpName.c_str(), ios::out | ios::in);
622  if (out->is_open()) { //temporary file already exists. Making a backup:
623  string newName;
624  if (!renameAsBackup(tmpName, newName)) {
625  throw cms::Exception("LaserSorter") << "Failed to rename file " << tmpName << " to " << newName << "\n";
626  }
627  if (verbosity_)
628  cout << "[LaserSorter " << now() << "] "
629  << "Already existing File " << tmpName << " renamed to " << newName << "\n";
630  out->close();
631  }
632 
633  out->clear();
634  out->open(tmpName.c_str(), ios::out | ios::trunc);
635 
636  if (out->fail()) { //failed to create file
637  delete out;
638  throw cms::Exception("LaserSorter") << "Failed to create file " << tmpName << " for writing event from FED "
639  << fedId << " lumi block " << lumiBlock << ": " << strerror(errno) << "\n.";
640  }
641 
642  ifstream in(finalName.c_str());
643  bool newFile = true;
644  if (in.good()) { //file already exists with final name.
645  if (verbosity_)
646  cout << "[LaserSorter " << now() << "] "
647  << "File " << finalName << " already exists. It will be updated if needed.\n";
648  //Copying its contents:
649  char buffer[256];
650  streamsize nread = -1;
651  int vers = readFormatVersion(in, finalName);
652  if (vers == -1) {
653  edm::LogWarning("LaserSorter") << "File " << tmpName.c_str() << " is not an LMF file despite its extension or "
654  << "it is corrupted.\n";
655  } else if (vers != formatVersion_) {
656  edm::LogWarning("LaserSorter") << "Cannot include events already in file " << tmpName.c_str()
657  << " because of version "
658  << "mismatch (found version " << (int)vers << " while "
659  << "only version " << (int)formatVersion_ << " is supported).\n";
660  } else {
661  newFile = false;
662  //read index table offset value:
663  const int indexTableOffsetPos8 = 1 * sizeof(uint32_t);
664  uint32_t indexTableOffsetValue = 0;
665  in.clear();
666  in.seekg(indexTableOffsetPos8, ios::beg);
667  in.read((char*)&indexTableOffsetValue, sizeof(indexTableOffsetValue));
668  if (in.fail()) {
669  cout << "[LaserSorter " << now() << "] "
670  << "Failed to read offset of index table "
671  " in the existing file "
672  << finalName << "\n";
673  } else {
674  if (verbosity_ > 2)
675  cout << "[LaserSorter " << now() << "] "
676  << "Index table offset of "
677  "original file "
678  << finalName << ": 0x" << hex << setfill('0') << setw(8) << indexTableOffsetValue << dec << setfill(' ')
679  << "\n";
680  }
681  in.clear();
682  in.seekg(0, ios::beg);
683 
684  //copy legacy file contents except the index table
685  uint32_t toRead = indexTableOffsetValue;
686  cout << "[LaserSorter " << now() << "] "
687  << "Copying " << finalName << " to " << tmpName << endl;
688  while (!in.eof() && (toRead > 0) && (nread = in.readsome(buffer, min(toRead, (uint32_t)sizeof(buffer)))) != 0) {
689  // cout << "Writing " << nread << " bytes to file "
690  // << tmpName.c_str() << "\n";
691  toRead -= nread;
692  // out->seekp(0, ios::end);
693  out->write(buffer, nread);
694  if (out->bad()) {
695  throw cms::Exception("LaserSorter")
696  << "Error while writing to file " << tmpName << ". Check if there is enough "
697  << "space on the device.\n";
698  }
699  }
700 
701  //resets index table offset field:
702  indexTableOffsetValue = 0;
703  out->clear();
704  out->seekp(indexTableOffsetPos8, ios::beg);
705  out->write((char*)&indexTableOffsetValue, sizeof(uint32_t));
706  out->clear();
707  out->seekp(0, ios::end);
708  }
709  }
710 
711 #if 0
712  out->flush();
713  cout << "Press enter... file name was " << tmpName << endl;
714  char c;
715  cin >> c;
716 #endif
717 
718  OutStreamRecord* outRcd = new OutStreamRecord(fedId, lumiBlock, out, tmpName, finalName);
719 
720  if (newFile) {
721  writeFileHeader(*out);
722  } else {
723  std::string errMsg;
724  if (!readIndexTable(in, finalName, *outRcd, &errMsg)) {
725  throw cms::Exception("LaserSorter") << errMsg << "\n";
726  }
727  }
728 
729  return outStreamList_.insert(outStreamList_.end(), outRcd);
730 }
bool readIndexTable(std::ifstream &in, std::string &inName, OutStreamRecord &outRcd, std::string *err)
void writeFileHeader(std::ofstream &out)
Definition: LaserSorter.cc:732
void streamFileName(int fedId, edm::LuminosityBlockNumber_t lumiBlock, std::string &tmpName, std::string &finalName)
Definition: LaserSorter.cc:791
string newName
Definition: mps_merge.py:86
unsigned char formatVersion_
Definition: LaserSorter.h:319
#define end
Definition: vmac.h:39
T min(T a, T b)
Definition: MathUtil.h:58
static std::string now()
Definition: LaserSorter.cc:60
int readFormatVersion(std::ifstream &in, const std::string &fileName)
OutStreamList outStreamList_
Definition: LaserSorter.h:315
bool renameAsBackup(const std::string &fileName, std::string &newFileName)
Definition: LaserSorter.cc:588
int LaserSorter::dcc2Lme ( int  dccNum,
int  dccSide 
)
private

Definition at line 350 of file LaserSorter.cc.

References min().

350  {
351  int fedid = (dcc % 600) + 600; //to handle both FED and DCC id.
352  vector<int> lmes;
353  // EE -
354  if (fedid <= 609) {
355  if (fedid <= 607) {
356  lmes.push_back(fedid - 601 + 83);
357  } else if (fedid == 608) {
358  lmes.push_back(90);
359  lmes.push_back(91);
360  } else if (fedid == 609) {
361  lmes.push_back(92);
362  }
363  } //EB
364  else if (fedid >= 610 && fedid <= 645) {
365  lmes.push_back(2 * (fedid - 610) + 1);
366  lmes.push_back(lmes[0] + 1);
367  } // EE+
368  else if (fedid >= 646) {
369  if (fedid <= 652) {
370  lmes.push_back(fedid - 646 + 73);
371  } else if (fedid == 653) {
372  lmes.push_back(80);
373  lmes.push_back(81);
374  } else if (fedid == 654) {
375  lmes.push_back(82);
376  }
377  }
378  return lmes.empty() ? -1 : lmes[min(lmes.size(), (size_t)side)];
379 }
T min(T a, T b)
Definition: MathUtil.h:58
void LaserSorter::endJob ( void  )
overridevirtual

Reimplemented from edm::EDAnalyzer.

Definition at line 885 of file LaserSorter.cc.

References closeAllStreams().

Referenced by o2olib.O2ORunMgr::executeJob().

885  {
886  //TODO: better treatement of last files:
887  //they might be imcomplete...
888  closeAllStreams();
889 }
void closeAllStreams()
Definition: LaserSorter.cc:448
int LaserSorter::getDetailedTriggerType ( const edm::Handle< FEDRawDataCollection > &  rawdata,
double *  proba = nullptr 
)
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 404 of file LaserSorter.cc.

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

Referenced by analyze().

404  {
406  bool ecalData = false;
407  for (int id = ecalDccFedIdMin_; id <= ecalDccFedIdMax_; ++id) {
408  if (!FEDNumbering::inRange(id))
409  continue;
410  const FEDRawData& data = rawdata->FEDData(id);
411  const int detailedTrigger32 = 5;
412  if (verbosity_ > 3)
413  cout << "[LaserSorter " << now() << "] "
414  << "FED " << id << " data size: " << data.size() << "\n";
415  if (data.size() >= 4 * (detailedTrigger32 + 1)) {
416  ecalData = true;
417  const uint32_t* pData32 = (const uint32_t*)data.data();
418  int tType = pData32[detailedTrigger32] & 0xFFF;
419  if (verbosity_ > 3)
420  cout << "[LaserSorter " << now() << "] "
421  << "Trigger type " << tType << "\n";
422  stat.add(tType);
423  }
424  }
425  if (!ecalData)
426  return -2;
427  double p;
428  int tType = stat.result(&p);
429  if (p < 0) {
430  //throw cms::Exception("NotFound") << "No ECAL DCC data found\n";
432  edm::LogWarning("NotFound") << "No ECAL DCC data found. "
433  "(This warning will be disabled for the current run after "
434  << maxNoEcalDataMess_ << " occurences.)";
436  }
437  tType = -1;
438  } else if (p < .8) {
439  //throw cms::Exception("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
440  edm::LogWarning("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
441  tType = -1;
442  }
443  if (proba)
444  *proba = p;
445  return tType;
446 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:290
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void add(const T &value)
Definition: Majority.h:23
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
int iNoEcalDataMess_
Definition: LaserSorter.h:398
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:294
static std::string now()
Definition: LaserSorter.cc:60
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
int maxNoEcalDataMess_
Definition: LaserSorter.h:402
T result(double *proba) const
Definition: Majority.h:28
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 964 of file LaserSorter.cc.

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

Referenced by analyze().

964  {
965  int nTowers;
966  vector<int> result;
967  for (int fed = ecalDccFedIdMin_; fed <= ecalDccFedIdMax_; ++fed) {
968  const FEDRawData& fedData = data.FEDData(fed);
969  isDccEventEmpty(fedData, nullptr, &nTowers);
970  if (nTowers >= 68)
971  result.push_back(fed);
972  }
973  return result;
974 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:290
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:294
bool isDccEventEmpty(const FEDRawData &data, size_t *dccLen=nullptr, int *nTowerBlocks=nullptr) const
Definition: LaserSorter.cc:893
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 381 of file LaserSorter.cc.

References FEDRawData::data(), data, ecalDccFedIdMax_, ecalDccFedIdMin_, FEDRawDataCollection::FEDData(), triggerObjects_cff::id, FEDNumbering::inRange(), and FEDRawData::size().

Referenced by analyze().

381  {
382  const int orbit32 = 6;
383  for (int id = ecalDccFedIdMin_; id <= ecalDccFedIdMax_; ++id) {
384  if (!FEDNumbering::inRange(id))
385  continue;
386  const FEDRawData& data = rawdata->FEDData(id);
387  if (data.size() >= 4 * (orbit32 + 1)) {
388  const uint32_t* pData32 = (const uint32_t*)data.data();
389  // cout << "Found a DCC header: "
390  // << pData32[0] << " "
391  // << pData32[1] << " "
392  // << pData32[2] << " "
393  // << pData32[3] << " "
394  // << pData32[4] << " "
395  // << pData32[5] << " "
396  // << pData32[6] << " "
397  // << "\n";
398  return pData32[orbit32];
399  }
400  }
401  return -1;
402 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:290
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
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:294
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 939 of file LaserSorter.cc.

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

Referenced by writeEvent().

941  {
942  fedIds.erase(fedIds.begin(), fedIds.end());
943  for (int id = ecalDccFedIdMin_; id <= ecalDccFedIdMax_; ++id) {
944  size_t dccLen;
945  const FEDRawData& dccEvent = data.FEDData(id);
946  if (!isDccEventEmpty(dccEvent, &dccLen)) {
947  fedIds.push_back(id);
948  }
949  if (dccLen * sizeof(uint64_t) != dccEvent.size()) {
950  edm::LogWarning("LaserSorter") << "Length error in data of FED " << id << " in event " << event.id()
951  << ", Data of this FED dropped.";
952  }
953  }
954  // cout << __FILE__ << ":" << __LINE__ << ": "
955  // << "data.FEDData(" << matacqFedId_ << ").size() = "
956  // << data.FEDData(matacqFedId_).size() << "\n";
957  if (data.FEDData(matacqFedId_).size() > 4) { //matacq block present
958  // cout << __FILE__ << ":" << __LINE__ << ": "
959  // << "Adding matacq to list of FEDs\n";
960  fedIds.push_back(matacqFedId_);
961  }
962 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:290
static const int matacqFedId_
Definition: LaserSorter.h:422
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:294
bool isDccEventEmpty(const FEDRawData &data, size_t *dccLen=nullptr, int *nTowerBlocks=nullptr) const
Definition: LaserSorter.cc:893
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 474 of file LaserSorter.cc.

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

Referenced by analyze(), and restoreStreamsOfLumiBlock().

474  {
475  if ((fedId != -1) && (fedId < ecalDccFedIdMin_ || fedId > ecalDccFedIdMax_))
476  fedId = -1;
477 
478  if (verbosity_ > 1)
479  cout << "[LaserSorter " << now() << "] "
480  << "Looking for an opened output file for FED " << fedId << " LB " << lumiBlock << "\n";
481 
482  //first look if stream is already open:
483  for (OutStreamList::iterator it = outStreamList_.begin(); it != outStreamList_.end(); ++it) {
484  if (it->fedId() == fedId && (abs((int)it->startingLumiBlock() - (int)lumiBlock) <= lumiBlockSpan_)) {
485  //stream found!
486  return &(*it);
487  }
488  }
489  //stream was not found. Let's create one
490 
491  if (verbosity_)
492  cout << "[LaserSorter " << now() << "] "
493  << "File not yet opened. Opening it.\n";
494 
495  OutStreamList::iterator streamRecord = createOutStream(fedId, lumiBlock);
496  return streamRecord != outStreamList_.end() ? &(*streamRecord) : nullptr;
497 }
int lumiBlockSpan_
Definition: LaserSorter.h:415
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:294
static std::string now()
Definition: LaserSorter.cc:60
OutStreamList::iterator createOutStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:609
OutStreamList outStreamList_
Definition: LaserSorter.h:315
bool LaserSorter::isDccEventEmpty ( const FEDRawData data,
size_t *  dccLen = nullptr,
int *  nTowerBlocks = nullptr 
) 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 893 of file LaserSorter.cc.

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

Referenced by getFullyReadoutDccs(), and getOutputFedList().

893  {
894  if (nTowerBlocks)
895  *nTowerBlocks = 0;
896  //DCC event is considered empty if it does not contains any Tower block
897  //( = FE data)
898  bool rc = true;
899  if (dccLen)
900  *dccLen = 0;
901  const unsigned nWord32 = data.size() / sizeof(uint32_t);
902  if (nWord32 == 0) {
903  //cout << "[LaserSorter " << now() << "] " << "FED block completly empty\n";
904  return true;
905  }
906  for (unsigned iWord32 = 0; iWord32 < nWord32; iWord32 += 2) {
907  const uint32_t* data32 = ((const uint32_t*)(data.data())) + iWord32;
908  int dataType = (data32[1] >> 28) & 0xF;
909  // cout << hex << "0x" << setfill('0')
910  // << setw(8) << data32[1] << "'" << setw(8) << data32[0]
911  // << " dataType: 0x" << dataType
912  // << dec << setfill(' ') << "\n";
913  if (0 == (dataType >> 2)) { //in DCC header
914  const int dccHeaderId = (data32[1] >> 24) & 0x3F;
915  if (dccHeaderId == 1) {
916  if (dccLen)
917  *dccLen = ((data32[0] >> 0) & 0xFFFFFF);
918  }
919  }
920  if ((dataType >> 2) == 3) { //Tower block
921  rc = false;
922  if (nTowerBlocks) { //number of tower block must be counted
923  ++(*nTowerBlocks);
924  } else {
925  break;
926  }
927  }
928  }
929  // cout << "[LaserSorter " << now() << "] " << "DCC Len: ";
930 
931  // if(dccLen){
932  // cout << (*dccLen) << " event ";
933  // }
934  // cout << (rc?"":"non") << " empty"
935  // << endl;
936  return rc;
937 }
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 1091 of file LaserSorter.cc.

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

Referenced by createOutStream().

1091  {
1092  int vers = -1;
1093  streampos p = in.tellg();
1094 
1095  uint32_t data;
1096 
1097  in.read((char*)&data, sizeof(data));
1098 
1099  char magic[4];
1100 
1101  magic[0] = data & 0xFF;
1102  magic[1] = (data >> 8) & 0xFF;
1103  magic[2] = (data >> 16) & 0xFF;
1104  magic[3] = 0;
1105 
1106  const string lmf = string("LMF");
1107 
1108  if (in.good() && lmf == magic) {
1109  vers = (data >> 24) & 0xFF;
1110  }
1111 
1112  if (lmf != magic) {
1113  edm::LogWarning("LaserSorter") << "File " << fileName << "is not an LMF file.\n";
1114  }
1115 
1116  in.clear();
1117  in.seekg(p);
1118  return vers;
1119 }
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 1018 of file LaserSorter.cc.

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

Referenced by createOutStream().

1018  {
1019  stringstream errMsg;
1020 
1021  ifstream* s = &in;
1022 
1023  //streampos pos = s->tellg();
1024  s->clear();
1025  s->seekg(0);
1026 
1027  uint32_t fileHeader[2];
1028  s->read((char*)&fileHeader[0], sizeof(fileHeader));
1029  uint32_t indexTablePos = fileHeader[1];
1030 
1031  if (s->eof()) {
1032  s->clear();
1033  s->seekg(0);
1034  errMsg << "Failed to read header of file " << inName << ".";
1035  if (err)
1036  *err = errMsg.str();
1037  return false;
1038  }
1039 
1040  s->seekg(indexTablePos);
1041 
1042  uint32_t nevts = 0;
1043  s->read((char*)&nevts, sizeof(nevts));
1044  s->ignore(4);
1045  if (s->bad()) {
1046  errMsg << "Failed to read index table from file " << inName << ".";
1047  if (err)
1048  *err = errMsg.str();
1049  return false;
1050  }
1051  if (nevts > maxEvents_) {
1052  errMsg << "Number of events indicated in event index of file " << inName << " (" << nevts << ") "
1053  << "is unexpectively large.";
1054  if (err)
1055  *err = errMsg.str();
1056  return false;
1057  }
1058  outRcd.indices()->resize(nevts);
1059  s->read((char*)&(*outRcd.indices())[0], nevts * sizeof(IndexRecord));
1060  if (s->bad()) {
1061  outRcd.indices()->clear();
1062  errMsg << "Failed to read index table from file " << inName << ".";
1063  if (err)
1064  *err = errMsg.str();
1065  return false;
1066  }
1067  if (nevts > maxEvents_) {
1068  errMsg << "Number of events indicated in event index of file " << inName << " is unexpectively large.";
1069  if (err)
1070  *err = errMsg.str();
1071  outRcd.indices()->clear();
1072  return false;
1073  }
1074 
1075  if (verbosity_ > 1)
1076  cout << "[LaserSorter " << now() << "] "
1077  << "Orbit IDs of events "
1078  << "already contained in the file " << inName << ":";
1079  for (unsigned i = 0; i < outRcd.indices()->size(); ++i) {
1080  if (verbosity_ > 1) {
1081  cout << " " << setw(9) << (*outRcd.indices())[i].orbit;
1082  }
1083  outRcd.excludedOrbit().insert((*outRcd.indices())[i].orbit);
1084  }
1085  if (verbosity_ > 1)
1086  cout << "\n";
1087 
1088  return true;
1089 }
static const unsigned maxEvents_
Definition: LaserSorter.h:431
static std::string now()
Definition: LaserSorter.cc:60
bool LaserSorter::renameAsBackup ( const std::string &  fileName,
std::string &  newFileName 
)
private

Definition at line 588 of file LaserSorter.cc.

References mps_fire::i.

Referenced by createOutStream().

588  {
589  int i = 0;
590  int err;
591  // static int maxTries = 100;
592  int maxTries = 20;
593  stringstream newFileName_;
594  do {
595  newFileName_.str("");
596  newFileName_ << fileName << "~";
597  if (i > 0)
598  newFileName_ << i;
599  err = link(fileName.c_str(), newFileName_.str().c_str());
600  if (err == 0) {
601  newFileName = newFileName_.str();
602  err = unlink(fileName.c_str());
603  }
604  ++i;
605  } while ((err != 0) && (errno == EEXIST) && (i < maxTries));
606  return err == 0;
607 }
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 1136 of file LaserSorter.cc.

References ecalDccFedIdMax_, ecalDccFedIdMin_, l1t::stage2::layer2::fedId, MillePedeFileConverter_cfg::fileName, getStream(), alignCSCRings::s, trackingPlots::stat, and streamFileName().

Referenced by analyze().

1136  {
1137  string dummy;
1138  string fileName;
1139 
1140  for (int fedId = ecalDccFedIdMin_ - 2; fedId <= ecalDccFedIdMax_; ++fedId) {
1141  int fedId_;
1142  if (fedId == ecalDccFedIdMin_ - 2)
1143  fedId_ = -1; //stream for event w/o ECAL data
1144  else
1145  fedId_ = fedId;
1146  streamFileName(fedId_, lumiBlock, dummy, fileName);
1147  struct stat s;
1148  //TODO: could be optimized by adding an option to get stream
1149  //to open only existing file: would avoid double call to streamFileName.
1150  if (stat(fileName.c_str(), &s) == 0) { //file exists
1151  getStream(fedId_, lumiBlock);
1152  }
1153  }
1154 }
OutStreamRecord * getStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:474
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:290
void streamFileName(int fedId, edm::LuminosityBlockNumber_t lumiBlock, std::string &tmpName, std::string &finalName)
Definition: LaserSorter.cc:791
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:294
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 791 of file LaserSorter.cc.

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

Referenced by createOutStream(), and restoreStreamsOfLumiBlock().

794  {
795  int iFed;
797  iFed = fedId - ecalDccFedIdMin_ + 1;
798  } else if (fedId < 0) {
799  iFed = -1; //event w/o ECAL data
800  } else {
801  iFed = 0;
802  }
803  if (iFed < -1 || iFed >= (int)fedSubDirs_.size()) {
804  throw cms::Exception("LaserSorter") << "Bug found at " << __FILE__ << ":" << __LINE__
805  << ". FED ID is out of index!";
806  }
807 
808  struct stat fileStat;
809 
810  stringstream buf;
811  buf << outputDir_ << "/" << (iFed < 0 ? "Empty" : fedSubDirs_[iFed]);
812 
813  string dir = buf.str();
814  if (0 == stat(dir.c_str(), &fileStat)) {
815  if (!S_ISDIR(fileStat.st_mode)) {
816  throw cms::Exception("[LaserSorter]") << "File " << dir << " exists but is not a directory "
817  << " as expected.";
818  }
819  } else { //directory does not exists, let's try to create it
820  if (0 != mkdir(dir.c_str(), 0755)) {
821  throw cms::Exception("[LaserSorter]") << "Failed to create directory " << dir << " for writing data.";
822  }
823  }
824 
825  buf.str("");
826  buf << "Run" << runNumber_ << "_LB" << setfill('0') << setw(4) << lumiBlock << ".lmf";
827  string fileName = buf.str();
828  string tmpFileName = fileName + ".part";
829 
830  finalName = dir + "/" + fileName;
831  tmpName = dir + "/" + tmpFileName;
832 
833  if (verbosity_ > 3)
834  cout << "[LaserSorter " << now() << "] "
835  << "File path: " << finalName << "\n";
836 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:290
edm::RunNumber_t runNumber_
Definition: LaserSorter.h:339
std::vector< std::string > fedSubDirs_
Definition: LaserSorter.h:327
std::string outputDir_
Definition: LaserSorter.h:323
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:294
static std::string now()
Definition: LaserSorter.cc:60
def mkdir(path)
Definition: eostools.py:251
dbl *** dir
Definition: mlp_gen.cc:35
std::string LaserSorter::toString ( uint64_t  t)
staticprivate

Help function to format a date

Definition at line 1121 of file LaserSorter.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by writeEventHeader().

1121  {
1122  char buf[256];
1123 
1124  time_t tsec = t >> 32;
1125 
1126  uint32_t tusec = t & 0xFFFFFFFF;
1127  strftime(buf, sizeof(buf), "%F %R %S s", localtime(&tsec));
1128  buf[sizeof(buf) - 1] = 0;
1129 
1130  stringstream buf2;
1131  buf2 << (tusec + 500) / 1000;
1132 
1133  return string(buf) + " " + buf2.str() + " ms";
1134 }
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 499 of file LaserSorter.cc.

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

Referenced by analyze().

502  {
503  ofstream& out = *outRcd.out();
504  bool rc = true;
505  vector<unsigned> fedIds;
506  getOutputFedList(event, data, fedIds);
507 
508  out.clear();
509  uint32_t evtStart = out.tellp();
510  if (out.bad())
511  evtStart = 0;
512  rc &= writeEventHeader(out, event, dtt, fedIds.size());
513 
514  if (orbitZeroTime_.tv_sec == 0 && data.FEDData(matacqFedId_).size() != 0) {
515  struct timeval ts = {0, 0};
517  mre.getTimeStamp(ts);
518  uint32_t orb = mre.getOrbitId();
519  if (ts.tv_sec != 0) {
520  div_t dt = div(orb * 89.1, 1000 * 1000); //an orbit lasts 89.1 microseconds
521  orbitZeroTime_.tv_sec = ts.tv_sec - dt.quot;
522  orbitZeroTime_.tv_usec = ts.tv_usec - dt.rem;
523  if (orbitZeroTime_.tv_usec < 0) {
524  orbitZeroTime_.tv_usec += 1000 * 1000;
525  orbitZeroTime_.tv_sec -= 1;
526  }
527  }
528  }
529 
530  for (unsigned iFed = 0; iFed < fedIds.size() && rc; ++iFed) {
531  if (verbosity_ > 3)
532  cout << "[LaserSorter " << now() << "] "
533  << "Writing data block of FED " << fedIds[iFed] << ". Data size: " << data.FEDData(fedIds[iFed]).size()
534  << "\n";
535  rc &= writeFedBlock(out, data.FEDData(fedIds[iFed]));
536  }
537 
538  if (rc) {
539  //update index table for this file:
540  vector<IndexRecord>& indices = *outRcd.indices();
541  if (verbosity_ > 2) {
542  std::cout << "Event "
543  << " written successfully. "
544  << "Orbit: " << orbit_ << "\tFile index: " << evtStart << "\n";
545  }
546  IndexRecord indexRcd = {(uint32_t)orbit_, evtStart};
547  indices.push_back(indexRcd);
548  }
549  return rc;
550 }
float dt
Definition: AMPTWrapper.h:126
size_t size() const
Definition: Event.cc:233
void getOutputFedList(const edm::Event &event, const FEDRawDataCollection &data, std::vector< unsigned > &fedIds) const
Definition: LaserSorter.cc:939
static const int matacqFedId_
Definition: LaserSorter.h:422
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
struct timeval orbitZeroTime_
Definition: LaserSorter.h:470
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
bool writeFedBlock(std::ofstream &out, const FEDRawData &data)
Definition: LaserSorter.cc:552
static std::string now()
Definition: LaserSorter.cc:60
bool writeEventHeader(std::ofstream &out, const edm::Event &evt, int fedId, unsigned nFeds)
Definition: LaserSorter.cc:748
time_t getTimeStamp() const
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
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 748 of file LaserSorter.cc.

References edm::EventBase::bunchCrossing(), colorNames, gather_cfg::cout, data, 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().

748  {
749  uint32_t data[10];
750  timeval tt = {0, 0};
751  if ((evt.time().value() >> 32)) {
752  tt.tv_usec = evt.time().value() & 0xFFFFFFFF;
753  tt.tv_sec = evt.time().value() >> 32;
754  } else if (orbitZeroTime_.tv_sec) {
755  div_t dt = div(orbit_ * 89.1, 1000 * 1000); //one orbit lasts 89.1 microseconds
756  tt.tv_sec = orbitZeroTime_.tv_sec + dt.quot;
757  tt.tv_usec = orbitZeroTime_.tv_usec + dt.rem;
758  if (tt.tv_usec > 1000 * 1000) {
759  tt.tv_usec -= 1000 * 1000;
760  tt.tv_sec += 1;
761  }
762  }
763 
764  data[0] = tt.tv_usec;
765  data[1] = tt.tv_sec;
766  data[2] = evt.luminosityBlock();
767  data[3] = evt.run();
768  data[4] = orbit_;
769  data[5] = evt.bunchCrossing();
770  data[6] = evt.id().event();
771  data[7] = dtt;
772  data[8] = nFeds;
773  data[9] = 0; //reserved (to be aligned on 64-bits)
774 
775  if (verbosity_ > 1) {
776  cout << "[LaserSorter " << now() << "] "
777  << "Write header of event: "
778  << "Time: " << toString(evt.time().value()) << ", LB: " << evt.luminosityBlock() << ", Run: " << evt.run()
779  << ", Bx: " << evt.bunchCrossing() << ", Event ID: " << evt.id().event() << ", Detailed trigger type: 0x"
780  << hex << dtt << dec << " (" << detailedTrigNames[(dtt >> 8) & 0x7] << ", " << colorNames[(dtt >> 6) & 0x3]
781  << ", DCC " << (dtt & 0x3f) << ", side " << ((dtt >> 10) & 0x1) << ")"
782  << ", number of FEDs: "
783  << "\n";
784  }
785 
786  out.clear();
787  out.write((char*)data, sizeof(data));
788  return !out.bad();
789 }
EventNumber_t event() const
Definition: EventID.h:41
float dt
Definition: AMPTWrapper.h:126
static const char *const detailedTrigNames[]
Definition: LaserSorter.cc:44
static std::string toString(uint64_t t)
int bunchCrossing() const
Definition: EventBase.h:64
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
struct timeval orbitZeroTime_
Definition: LaserSorter.h:470
RunNumber_t run() const
Definition: Event.h:101
static std::string now()
Definition: LaserSorter.cc:60
edm::EventID id() const
Definition: EventBase.h:59
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
static const char *const colorNames[]
Definition: LaserSorter.cc:55
TimeValue_t value() const
Definition: Timestamp.h:56
edm::Timestamp time() const
Definition: EventBase.h:60
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 552 of file LaserSorter.cc.

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

Referenced by writeEvent().

552  {
553  bool rc = false;
554  if (data.size() > 4) {
555  const uint32_t* pData = reinterpret_cast<const uint32_t*>(data.data());
556 
557  uint32_t dccLen64 = pData[2] & 0x00FFFFFF; //in 32-byte unit
558 
559  if (data.size() != dccLen64 * sizeof(uint64_t)) {
560  // throw cms::Exception("Bug") << "Bug found in "
561  // << __FILE__ << ":" << __LINE__ << ".";
562  throw cms::Exception("LaserSorter") << "Mismatch between FED fragment size indicated in header "
563  << "(" << dccLen64 << "*8 Byte) "
564  << "and actual size (" << data.size() << " Byte) "
565  << "for FED ID " << ((pData[0] >> 8) & 0xFFF) << "!\n";
566  }
567 
568  if (verbosity_ > 3)
569  cout << "[LaserSorter " << now() << "] "
570  << "Event fragment size: " << data.size() << " Byte"
571  << "\t From Dcc header: " << dccLen64 * 8 << " Byte\n";
572 
573  const size_t nBytes = data.size();
574  // cout << "[LaserSorter " << now() << "] "
575  // << "Writing " << nBytes << " byte from adress "
576  // << (void*) data.data() << " to file.\n";
577  if (out.fail())
578  cout << "[LaserSorter " << now() << "] "
579  << "Problem with stream!\n";
580  out.write((char*)data.data(), nBytes);
581  rc = true;
582  } else {
583  throw cms::Exception("Bug") << "Bug found in " << __FILE__ << ":" << __LINE__ << ".\n";
584  }
585  return rc;
586 }
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
unsigned long long uint64_t
Definition: Time.h:15
static std::string now()
Definition: LaserSorter.cc:60
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
void LaserSorter::writeFileHeader ( std::ofstream &  out)
private

Writing file header for an LMF binary file

Parameters
outstream of the output file

Definition at line 732 of file LaserSorter.cc.

References Exception, and formatVersion_.

Referenced by createOutStream().

732  {
733  out.clear();
734 
735  uint32_t id = 'L' | ('M' << 8) | ('F' << 16) | (formatVersion_ << 24);
736 
737  out.write((char*)&id, sizeof(uint32_t));
738 
739  //index position (to be filled at end of writing)
740  uint32_t zero = 0;
741  out.write((char*)&zero, sizeof(uint32_t));
742 
743  if (out.fail()) {
744  throw cms::Exception("LaserSorter") << "Failed to write file header.\n";
745  }
746 }
unsigned char formatVersion_
Definition: LaserSorter.h:319
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 976 of file LaserSorter.cc.

References data, end, mps_fire::i, and indexOffset32_.

Referenced by closeOutStream().

976  {
977  uint32_t indexTablePos = out.tellp();
978  uint32_t nevts = indices.size();
979 
980  out.clear();
981  out.write((char*)&nevts, sizeof(nevts));
982  const uint32_t reserved = 0;
983  out.write((const char*)&reserved, sizeof(reserved));
984 
985  if (out.bad())
986  return false;
987 
988  sort(indices.begin(), indices.end());
989 
990  for (unsigned i = 0; i < indices.size(); ++i) {
991  uint32_t data[2];
992  data[0] = indices[i].orbit;
993  data[1] = indices[i].filePos;
994  out.write((char*)data, sizeof(data));
995  }
996 
997  if (out.bad())
998  return false; //intial 0 valur for index table position
999  // is left to indicate corrupted table.
1000 
1001  //writes index table position:x
1002  out.clear();
1003  out.seekp(indexOffset32_ * sizeof(uint32_t));
1004  // cout << "[LaserSorter] Index table position: 0x" << hex << indexTablePos
1005  // << dec << "\n";
1006  if (!out.bad())
1007  out.write((char*)&indexTablePos, sizeof(uint32_t));
1008 
1009  bool rc = !out.bad();
1010 
1011  //reposition pointer to eof:
1012  out.seekp(0, ios::end);
1013 
1014  return rc;
1015 }
static const int indexOffset32_
Definition: LaserSorter.h:426
#define end
Definition: vmac.h:39
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82

Member Data Documentation

int LaserSorter::detailedTrigType_
private

Trigger type of calibration event. -1 if unkown.

Definition at line 298 of file LaserSorter.h.

Referenced by analyze().

bool LaserSorter::disableOutput_
private

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

Definition at line 335 of file LaserSorter.h.

Referenced by analyze().

bool LaserSorter::doOutputList_
private

Switch for logging paths of the output files

Definition at line 359 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 417 of file LaserSorter.h.

Referenced by LaserSorter().

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

Definition at line 418 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 327 of file LaserSorter.h.

Referenced by LaserSorter(), and streamFileName().

unsigned char LaserSorter::formatVersion_
private

Data format version of lmf output file

Definition at line 319 of file LaserSorter.h.

Referenced by createOutStream(), and writeFileHeader().

const int LaserSorter::indexOffset32_ = 1
staticprivate

Definition at line 426 of file LaserSorter.h.

Referenced by writeIndexTable().

int LaserSorter::iNoEcalDataMess_
private

number of "ECAL DCC data" message in a run

Definition at line 398 of file LaserSorter.h.

Referenced by analyze(), and getDetailedTriggerType().

int LaserSorter::iNoFullReadoutDccError_
private

Number of "No fully readout DCC error"

Definition at line 390 of file LaserSorter.h.

Referenced by analyze().

std::ofstream LaserSorter::logFile_
private

File for logging

Definition at line 302 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 306 of file LaserSorter.h.

Referenced by analyze().

edm::LuminosityBlockNumber_t LaserSorter::lumiBlockPrev_
private

Luminosity block of previous processed event

Definition at line 310 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 415 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 422 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 431 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 394 of file LaserSorter.h.

Referenced by analyze().

int LaserSorter::maxNoEcalDataMess_
private

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

Definition at line 402 of file LaserSorter.h.

Referenced by getDetailedTriggerType().

int LaserSorter::orbit_
private

Definition at line 461 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 459 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 470 of file LaserSorter.h.

Referenced by writeEvent(), and writeEventHeader().

std::string LaserSorter::outputDir_
private

Top directory for output files

Definition at line 323 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 367 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 355 of file LaserSorter.h.

Referenced by LaserSorter().

OutStreamList LaserSorter::outStreamList_
private

List of output stream to write sorted data

Definition at line 315 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 453 of file LaserSorter.h.

Referenced by analyze().

edm::RunNumber_t LaserSorter::runNumber_
private

Run number of event under process

Definition at line 339 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 449 of file LaserSorter.h.

std::ofstream LaserSorter::timeLog_
private

Output stream to log code timing

Definition at line 347 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 331 of file LaserSorter.h.

Referenced by LaserSorter().

timeval LaserSorter::timer_
private

Buffer for timing

Definition at line 343 of file LaserSorter.h.

Referenced by analyze(), and LaserSorter().

bool LaserSorter::timing_
private

Switch for code timing.

Definition at line 351 of file LaserSorter.h.

Referenced by analyze(), and LaserSorter().

int LaserSorter::verbosity_
private