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::one::EDAnalyzer< edm::one::WatchRuns > edm::one::EDAnalyzerBase 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
 
void endRun (edm::Run const &, edm::EventSetup const &) override
 
 LaserSorter (const edm::ParameterSet &)
 
 ~LaserSorter () override
 
- Public Member Functions inherited from edm::one::EDAnalyzer< edm::one::WatchRuns >
 EDAnalyzer ()=default
 
 EDAnalyzer (const EDAnalyzer &)=delete
 
SerialTaskQueueglobalLuminosityBlocksQueue () final
 
SerialTaskQueueglobalRunsQueue () final
 
const EDAnalyzeroperator= (const EDAnalyzer &)=delete
 
bool wantsGlobalLuminosityBlocks () const final
 
bool wantsGlobalRuns () const final
 
bool wantsInputProcessBlocks () const final
 
bool wantsProcessBlocks () const final
 
- Public Member Functions inherited from edm::one::EDAnalyzerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 EDAnalyzerBase ()
 
ModuleDescription const & moduleDescription () const
 
bool wantsStreamLuminosityBlocks () const
 
bool wantsStreamRuns () const
 
 ~EDAnalyzerBase () 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
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (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::array< std::vector< ModuleDescription const *> *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, 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
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Types

typedef std::list< std::unique_ptr< 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=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
 
const std::unique_ptr< OutStreamRecord > & getStream (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::one::EDAnalyzerBase
typedef EDAnalyzerBase ModuleType
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::one::EDAnalyzerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
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)
 
void resetItemsToGetFrom (BranchType iType)
 

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

◆ OutStreamList

typedef std::list<std::unique_ptr<OutStreamRecord> > LaserSorter::OutStreamList
private

Definition at line 114 of file LaserSorter.h.

Constructor & Destructor Documentation

◆ LaserSorter()

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

Definition at line 72 of file LaserSorter.cc.

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

73  : lumiBlock_(0),
74  lumiBlockPrev_(0),
75  formatVersion_(5),
76  outputDir_(pset.getParameter<std::string>("outputDir")),
77  fedSubDirs_(pset.getParameter<std::vector<std::string> >("fedSubDirs")),
78  timeLogFile_(pset.getUntrackedParameter<std::string>("timeLogFile", "")),
79  disableOutput_(pset.getUntrackedParameter<bool>("disableOutput", false)),
80  runNumber_(0),
81  outputListFile_(pset.getUntrackedParameter<string>("outputListFile", "")),
82  doOutputList_(false),
83  verbosity_(pset.getUntrackedParameter<int>("verbosity", 0)),
85  maxFullReadoutDccError_(pset.getParameter<int>("maxFullReadoutDccError")),
87  maxNoEcalDataMess_(pset.getParameter<int>("maxNoEcalDataMess")),
88  lumiBlockSpan_(pset.getParameter<int>("lumiBlockSpan")),
89  fedRawDataCollectionTag_(pset.getParameter<edm::InputTag>("fedRawDataCollectionTag")),
91  overWriteLumiBlockId_(pset.getParameter<bool>("overWriteLumiBlockId")),
92  orbitCountInALumiBlock_(pset.getParameter<int>("orbitCountInALumiBlock")),
93  orbit_(-1),
95  gettimeofday(&timer_, nullptr);
96  logFile_.open("eventSelect.log", ios::app | ios::out);
97 
98  const unsigned nEcalFeds = 54;
99  if (fedSubDirs_.size() != nEcalFeds + 1) {
100  throw cms::Exception("LaserSorter") << "Configuration error: "
101  << "fedSubDirs parameter must be a vector "
102  << " of " << nEcalFeds << " strings"
103  << " (subdirectory for unknown triggered FED followed by "
104  "subdirectories for FED ID 601 "
105  "to FED ID 654 in increasing FED ID order)";
106  }
107 
108  fedRawDataCollectionToken_ = consumes<FEDRawDataCollection>(fedRawDataCollectionTag_);
109 
110  if (!outputListFile_.empty()) {
111  outputList_.open(outputListFile_.c_str(), ios::app);
112  if (outputList_.bad()) {
113  throw cms::Exception("FileOpen") << "Failed to open file '" << outputListFile_
114  << "' for logging of output file path list.";
115  }
116  doOutputList_ = true;
117  }
118 
119  if (!timeLogFile_.empty()) {
120  timeLog_.open(timeLogFile_.c_str());
121  if (timeLog_.fail()) {
122  cout << "[LaserSorter " << now() << "] "
123  << "Failed to open file " << timeLogFile_ << " to log timing.\n";
124  timing_ = false;
125  } else {
126  timing_ = true;
127  }
128  }
129 
130  struct stat fileStat;
131  if (0 == stat(outputDir_.c_str(), &fileStat)) {
132  if (!S_ISDIR(fileStat.st_mode)) {
133  throw cms::Exception("[LaserSorter]") << "File " << outputDir_ << " exists but is not a directory "
134  << " as expected.";
135  }
136  } else { //directory does not exists, let's try to create it
137  if (0 != mkdir(outputDir_.c_str(), 0755)) {
138  throw cms::Exception("[LaserSorter]") << "Failed to create directory " << outputDir_ << " for writing data.";
139  }
140  }
141 
142  logFile_ << "# "
143  "run\t"
144  "LB\t"
145  "event\t"
146  "trigType\t"
147  "FED\t"
148  "side\t"
149  "LB out\t"
150  "Written\t"
151  "ECAL data\n";
152 }
edm::InputTag fedRawDataCollectionTag_
Definition: LaserSorter.h:418
int lumiBlockSpan_
Definition: LaserSorter.h:416
bool disableOutput_
Definition: LaserSorter.h:336
int maxFullReadoutDccError_
Definition: LaserSorter.h:395
edm::RunNumber_t runNumber_
Definition: LaserSorter.h:340
edm::LuminosityBlockNumber_t lumiBlock_
Definition: LaserSorter.h:307
std::vector< std::string > fedSubDirs_
Definition: LaserSorter.h:328
struct timeval orbitZeroTime_
Definition: LaserSorter.h:471
unsigned char formatVersion_
Definition: LaserSorter.h:320
static const struct timeval nullTime
Definition: LaserSorter.cc:40
std::string outputDir_
Definition: LaserSorter.h:324
timeval timer_
Definition: LaserSorter.h:344
std::string outputListFile_
Definition: LaserSorter.h:356
std::string timeLogFile_
Definition: LaserSorter.h:332
bool overWriteLumiBlockId_
Definition: LaserSorter.h:454
int iNoEcalDataMess_
Definition: LaserSorter.h:399
static const stats_t stats_init
Definition: LaserSorter.h:450
static std::string now()
Definition: LaserSorter.cc:58
std::ofstream outputList_
Definition: LaserSorter.h:368
std::ofstream logFile_
Definition: LaserSorter.h:303
int orbitCountInALumiBlock_
Definition: LaserSorter.h:460
def mkdir(path)
Definition: eostools.py:251
struct LaserSorter::stats_t stats_
edm::LuminosityBlockNumber_t lumiBlockPrev_
Definition: LaserSorter.h:311
int maxNoEcalDataMess_
Definition: LaserSorter.h:403
int iNoFullReadoutDccError_
Definition: LaserSorter.h:391
bool doOutputList_
Definition: LaserSorter.h:360
edm::EDGetTokenT< FEDRawDataCollection > fedRawDataCollectionToken_
Definition: LaserSorter.h:419
std::ofstream timeLog_
Definition: LaserSorter.h:348

◆ ~LaserSorter()

LaserSorter::~LaserSorter ( )
override

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

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

Member Function Documentation

◆ analyze()

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

Implements edm::one::EDAnalyzerBase.

Definition at line 161 of file LaserSorter.cc.

References closeAllStreams(), closeOldStreams(), colorNames, gather_cfg::cout, ecaldqm::dccId(), detailedTrigNames, detailedTrigType_, disableOutput_, ecalDccFedIdMax_, fedRawDataCollectionToken_, getDetailedTriggerType(), getFullyReadoutDccs(), getOrbitFromDcc(), getStream(), mps_fire::i, iNoEcalDataMess_, iNoFullReadoutDccError_, logFile_, lumiBlock_, lumiBlockPrev_, lumiBlockSpan_, maxFullReadoutDccError_, 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_, restoreStreamsOfLumiBlock(), runNumber_, stats_, submitPVValidationJobs::t, timeLog_, timer_, timing_, verbosity_, writeEvent(), and testProducerWithPsetDescEmpty_cfi::x1.

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

◆ beginJob()

void LaserSorter::beginJob ( )
overridevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 892 of file LaserSorter.cc.

892 {}

◆ beginRun()

void LaserSorter::beginRun ( edm::Run const &  run,
edm::EventSetup const &  es 
)
override

Definition at line 1157 of file LaserSorter.cc.

1157 {}

◆ closeAllStreams()

void LaserSorter::closeAllStreams ( )
private

Closes all opened output streams.

Definition at line 446 of file LaserSorter.cc.

References closeOutStream(), and outStreamList_.

Referenced by analyze(), and endJob().

446  {
447  for (OutStreamList::iterator it = outStreamList_.begin(); it != outStreamList_.end(); /*NOOP*/) {
448  it = closeOutStream(it);
449  }
450 }
OutStreamList::iterator closeOutStream(OutStreamList::iterator streamRecord)
Definition: LaserSorter.cc:839
OutStreamList outStreamList_
Definition: LaserSorter.h:316

◆ closeOldStreams()

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 452 of file LaserSorter.cc.

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

Referenced by analyze().

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

◆ closeOutStream()

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 839 of file LaserSorter.cc.

References visDQMUpload::buf, gather_cfg::cout, doOutputList_, f, makeListRunsInFiles::inputFile, now(), MillePedeFileConverter_cfg::out, outputList_, outStreamList_, AlCaHLTBitMon_QueryRunRegistry::string, submitPVValidationJobs::t, hcalRecHitTable_cff::time, verbosity_, and writeIndexTable().

Referenced by closeAllStreams(), and closeOldStreams().

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

◆ createOutStream()

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 610 of file LaserSorter.cc.

References edmScanValgrind::buffer, HltBtagPostValidation_cff::c, gather_cfg::cout, TauDecayModes::dec, mps_fire::end, Exception, l1tstage2_dqm_sourceclient-live_cfg::fedId, formatVersion_, recoMuon::in, createfilelist::int, SiStripPI::min, mps_merge::newName, now(), MillePedeFileConverter_cfg::out, outStreamList_, readFormatVersion(), readIndexTable(), renameAsBackup(), streamFileName(), AlCaHLTBitMon_QueryRunRegistry::string, pileupReCalc_HLTpaths::trunc, verbosity_, and writeFileHeader().

Referenced by getStream().

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

◆ dcc2Lme()

int LaserSorter::dcc2Lme ( int  dccNum,
int  dccSide 
)
private

Definition at line 348 of file LaserSorter.cc.

References PixelSLinkDataInputSource_cfi::fedid, and SiStripPI::min.

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

◆ endJob()

void LaserSorter::endJob ( void  )
overridevirtual

Reimplemented from edm::one::EDAnalyzerBase.

Definition at line 886 of file LaserSorter.cc.

References closeAllStreams().

Referenced by o2olib.O2ORunMgr::executeJob().

886  {
887  //TODO: better treatement of last files:
888  //they might be imcomplete...
889  closeAllStreams();
890 }
void closeAllStreams()
Definition: LaserSorter.cc:446

◆ endRun()

void LaserSorter::endRun ( edm::Run const &  run,
edm::EventSetup const &  es 
)
override

Definition at line 1159 of file LaserSorter.cc.

1159 {}

◆ getDetailedTriggerType()

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 402 of file LaserSorter.cc.

References gather_cfg::cout, data, ecalDccFedIdMax_, ecalDccFedIdMin_, FEDRawDataCollection::FEDData(), l1ctLayer2EG_cff::id, iNoEcalDataMess_, FEDNumbering::inRange(), maxNoEcalDataMess_, now(), AlCaHLTBitMon_ParallelJobs::p, edm_modernize_messagelogger::stat, and verbosity_.

Referenced by analyze().

402  {
404  bool ecalData = false;
405  for (int id = ecalDccFedIdMin_; id <= ecalDccFedIdMax_; ++id) {
406  if (!FEDNumbering::inRange(id))
407  continue;
408  const FEDRawData& data = rawdata->FEDData(id);
409  const int detailedTrigger32 = 5;
410  if (verbosity_ > 3)
411  cout << "[LaserSorter " << now() << "] "
412  << "FED " << id << " data size: " << data.size() << "\n";
413  if (data.size() >= 4 * (detailedTrigger32 + 1)) {
414  ecalData = true;
415  const uint32_t* pData32 = (const uint32_t*)data.data();
416  int tType = pData32[detailedTrigger32] & 0xFFF;
417  if (verbosity_ > 3)
418  cout << "[LaserSorter " << now() << "] "
419  << "Trigger type " << tType << "\n";
420  stat.add(tType);
421  }
422  }
423  if (!ecalData)
424  return -2;
425  double p;
426  int tType = stat.result(&p);
427  if (p < 0) {
428  //throw cms::Exception("NotFound") << "No ECAL DCC data found\n";
430  edm::LogWarning("NotFound") << "No ECAL DCC data found. "
431  "(This warning will be disabled for the current run after "
432  << maxNoEcalDataMess_ << " occurences.)";
434  }
435  tType = -1;
436  } else if (p < .8) {
437  //throw cms::Exception("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
438  edm::LogWarning("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
439  tType = -1;
440  }
441  if (proba)
442  *proba = p;
443  return tType;
444 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:291
int iNoEcalDataMess_
Definition: LaserSorter.h:399
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:295
static std::string now()
Definition: LaserSorter.cc:58
static bool inRange(int)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
int maxNoEcalDataMess_
Definition: LaserSorter.h:403
Log< level::Warning, false > LogWarning

◆ getFullyReadoutDccs()

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 965 of file LaserSorter.cc.

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

Referenced by analyze().

965  {
966  int nTowers;
967  vector<int> result;
968  for (int fed = ecalDccFedIdMin_; fed <= ecalDccFedIdMax_; ++fed) {
969  const FEDRawData& fedData = data.FEDData(fed);
970  isDccEventEmpty(fedData, nullptr, &nTowers);
971  if (nTowers >= 68)
972  result.push_back(fed);
973  }
974  return result;
975 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:291
bool isDccEventEmpty(const FEDRawData &data, size_t *dccLen=nullptr, int *nTowerBlocks=nullptr) const
Definition: LaserSorter.cc:894
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:295
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80

◆ getOrbitFromDcc()

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 379 of file LaserSorter.cc.

References data, ecalDccFedIdMax_, ecalDccFedIdMin_, FEDRawDataCollection::FEDData(), l1ctLayer2EG_cff::id, and FEDNumbering::inRange().

Referenced by analyze().

379  {
380  const int orbit32 = 6;
381  for (int id = ecalDccFedIdMin_; id <= ecalDccFedIdMax_; ++id) {
382  if (!FEDNumbering::inRange(id))
383  continue;
384  const FEDRawData& data = rawdata->FEDData(id);
385  if (data.size() >= 4 * (orbit32 + 1)) {
386  const uint32_t* pData32 = (const uint32_t*)data.data();
387  // cout << "Found a DCC header: "
388  // << pData32[0] << " "
389  // << pData32[1] << " "
390  // << pData32[2] << " "
391  // << pData32[3] << " "
392  // << pData32[4] << " "
393  // << pData32[5] << " "
394  // << pData32[6] << " "
395  // << "\n";
396  return pData32[orbit32];
397  }
398  }
399  return -1;
400 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:291
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:295
static bool inRange(int)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80

◆ getOutputFedList()

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 940 of file LaserSorter.cc.

References data, ecalDccFedIdMax_, ecalDccFedIdMin_, L1TStage2BMTF_cff::fedIds, l1ctLayer2EG_cff::id, isDccEventEmpty(), matacqFedId_, and FEDRawData::size().

Referenced by writeEvent().

942  {
943  fedIds.erase(fedIds.begin(), fedIds.end());
944  for (int id = ecalDccFedIdMin_; id <= ecalDccFedIdMax_; ++id) {
945  size_t dccLen;
946  const FEDRawData& dccEvent = data.FEDData(id);
947  if (!isDccEventEmpty(dccEvent, &dccLen)) {
948  fedIds.push_back(id);
949  }
950  if (dccLen * sizeof(uint64_t) != dccEvent.size()) {
951  edm::LogWarning("LaserSorter") << "Length error in data of FED " << id << " in event " << event.id()
952  << ", Data of this FED dropped.";
953  }
954  }
955  // cout << __FILE__ << ":" << __LINE__ << ": "
956  // << "data.FEDData(" << matacqFedId_ << ").size() = "
957  // << data.FEDData(matacqFedId_).size() << "\n";
958  if (data.FEDData(matacqFedId_).size() > 4) { //matacq block present
959  // cout << __FILE__ << ":" << __LINE__ << ": "
960  // << "Adding matacq to list of FEDs\n";
961  fedIds.push_back(matacqFedId_);
962  }
963 }
static const int ecalDccFedIdMin_
Definition: LaserSorter.h:291
bool isDccEventEmpty(const FEDRawData &data, size_t *dccLen=nullptr, int *nTowerBlocks=nullptr) const
Definition: LaserSorter.cc:894
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
static const int matacqFedId_
Definition: LaserSorter.h:423
unsigned long long uint64_t
Definition: Time.h:13
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:295
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
Log< level::Warning, false > LogWarning

◆ getStream()

const std::unique_ptr< 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 472 of file LaserSorter.cc.

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

Referenced by analyze(), and restoreStreamsOfLumiBlock().

473  {
474  const static std::unique_ptr<LaserSorter::OutStreamRecord> streamNotFound(nullptr);
475 
476  if ((fedId != -1) && (fedId < ecalDccFedIdMin_ || fedId > ecalDccFedIdMax_))
477  fedId = -1;
478 
479  if (verbosity_ > 1)
480  cout << "[LaserSorter " << now() << "] "
481  << "Looking for an opened output file for FED " << fedId << " LB " << lumiBlock << "\n";
482 
483  //first look if stream is already open:
484  for (OutStreamList::iterator it = outStreamList_.begin(); it != outStreamList_.end(); ++it) {
485  if ((*it)->fedId() == fedId && (abs((int)(*it)->startingLumiBlock() - (int)lumiBlock) <= lumiBlockSpan_)) {
486  //stream found!
487  return (*it);
488  }
489  }
490  //stream was not found. Let's create one
491 
492  if (verbosity_)
493  cout << "[LaserSorter " << now() << "] "
494  << "File not yet opened. Opening it.\n";
495 
496  OutStreamList::iterator streamRecord = createOutStream(fedId, lumiBlock);
497  return streamRecord != outStreamList_.end() ? (*streamRecord) : streamNotFound;
498 }
int lumiBlockSpan_
Definition: LaserSorter.h:416
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const int ecalDccFedIdMax_
Definition: LaserSorter.h:295
static std::string now()
Definition: LaserSorter.cc:58
OutStreamList::iterator createOutStream(int fedId, edm::LuminosityBlockNumber_t lumiBlock)
Definition: LaserSorter.cc:610
OutStreamList outStreamList_
Definition: LaserSorter.h:316

◆ isDccEventEmpty()

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 894 of file LaserSorter.cc.

References data, and DTskim_cfg::dataType.

Referenced by getFullyReadoutDccs(), and getOutputFedList().

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

◆ readFormatVersion()

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 1092 of file LaserSorter.cc.

References data, MillePedeFileConverter_cfg::fileName, recoMuon::in, AlCaHLTBitMon_ParallelJobs::p, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by createOutStream().

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

◆ readIndexTable()

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 1019 of file LaserSorter.cc.

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

Referenced by createOutStream().

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

◆ renameAsBackup()

bool LaserSorter::renameAsBackup ( const std::string &  fileName,
std::string &  newFileName 
)
private

Definition at line 589 of file LaserSorter.cc.

References submitPVResolutionJobs::err, MillePedeFileConverter_cfg::fileName, mps_fire::i, and cmssw_fix_interface::newFileName.

Referenced by createOutStream().

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

◆ restoreStreamsOfLumiBlock()

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 1137 of file LaserSorter.cc.

References ecalDccFedIdMax_, ecalDccFedIdMin_, l1tstage2_dqm_sourceclient-live_cfg::fedId, MillePedeFileConverter_cfg::fileName, getStream(), alignCSCRings::s, edm_modernize_messagelogger::stat, and streamFileName().

Referenced by analyze().

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

◆ streamFileName()

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 792 of file LaserSorter.cc.

References visDQMUpload::buf, gather_cfg::cout, DeadROC_duringRun::dir, ecalDccFedIdMax_, ecalDccFedIdMin_, Exception, l1tstage2_dqm_sourceclient-live_cfg::fedId, fedSubDirs_, MillePedeFileConverter_cfg::fileName, eostools::mkdir(), now(), outputDir_, runNumber_, edm_modernize_messagelogger::stat, and verbosity_.

Referenced by createOutStream(), and restoreStreamsOfLumiBlock().

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

◆ toString()

std::string LaserSorter::toString ( uint64_t  t)
staticprivate

Help function to format a date

Definition at line 1122 of file LaserSorter.cc.

References visDQMUpload::buf, AlCaHLTBitMon_QueryRunRegistry::string, and submitPVValidationJobs::t.

Referenced by writeEventHeader().

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

◆ writeEvent()

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 500 of file LaserSorter.cc.

References gather_cfg::cout, data, dt, L1TStage2BMTF_cff::fedIds, getOutputFedList(), MatacqRawEvent::getTimeStamp(), dqmdumpme::indices, LaserSorter::OutStreamRecord::indices(), matacqFedId_, now(), orbit_, orbitZeroTime_, MillePedeFileConverter_cfg::out, LaserSorter::OutStreamRecord::out(), verbosity_, writeEventHeader(), and writeFedBlock().

Referenced by analyze().

503  {
504  ofstream& out = *outRcd.out();
505  bool rc = true;
506  vector<unsigned> fedIds;
508 
509  out.clear();
510  uint32_t evtStart = out.tellp();
511  if (out.bad())
512  evtStart = 0;
513  rc &= writeEventHeader(out, event, dtt, fedIds.size());
514 
515  if (orbitZeroTime_.tv_sec == 0 && data.FEDData(matacqFedId_).size() != 0) {
516  struct timeval ts = {0, 0};
517  MatacqRawEvent mre(data.FEDData(matacqFedId_).data(), data.FEDData(matacqFedId_).size());
518  mre.getTimeStamp(ts);
519  uint32_t orb = mre.getOrbitId();
520  if (ts.tv_sec != 0) {
521  div_t dt = div(orb * 89.1, 1000 * 1000); //an orbit lasts 89.1 microseconds
522  orbitZeroTime_.tv_sec = ts.tv_sec - dt.quot;
523  orbitZeroTime_.tv_usec = ts.tv_usec - dt.rem;
524  if (orbitZeroTime_.tv_usec < 0) {
525  orbitZeroTime_.tv_usec += 1000 * 1000;
526  orbitZeroTime_.tv_sec -= 1;
527  }
528  }
529  }
530 
531  for (unsigned iFed = 0; iFed < fedIds.size() && rc; ++iFed) {
532  if (verbosity_ > 3)
533  cout << "[LaserSorter " << now() << "] "
534  << "Writing data block of FED " << fedIds[iFed] << ". Data size: " << data.FEDData(fedIds[iFed]).size()
535  << "\n";
536  rc &= writeFedBlock(out, data.FEDData(fedIds[iFed]));
537  }
538 
539  if (rc) {
540  //update index table for this file:
541  vector<IndexRecord>& indices = *outRcd.indices();
542  if (verbosity_ > 2) {
543  std::cout << "Event "
544  << " written successfully. "
545  << "Orbit: " << orbit_ << "\tFile index: " << evtStart << "\n";
546  }
547  IndexRecord indexRcd = {(uint32_t)orbit_, evtStart};
548  indices.push_back(indexRcd);
549  }
550  return rc;
551 }
float dt
Definition: AMPTWrapper.h:136
void getOutputFedList(const edm::Event &event, const FEDRawDataCollection &data, std::vector< unsigned > &fedIds) const
Definition: LaserSorter.cc:940
time_t getTimeStamp() const
static const int matacqFedId_
Definition: LaserSorter.h:423
struct timeval orbitZeroTime_
Definition: LaserSorter.h:471
bool writeFedBlock(std::ofstream &out, const FEDRawData &data)
Definition: LaserSorter.cc:553
static std::string now()
Definition: LaserSorter.cc:58
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
bool writeEventHeader(std::ofstream &out, const edm::Event &evt, int fedId, unsigned nFeds)
Definition: LaserSorter.cc:749
Definition: event.py:1

◆ writeEventHeader()

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 749 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_, MillePedeFileConverter_cfg::out, edm::Event::run(), edm::EventBase::time(), toString(), edm::Timestamp::value(), and verbosity_.

Referenced by writeEvent().

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

◆ writeFedBlock()

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 553 of file LaserSorter.cc.

References gather_cfg::cout, data, Exception, now(), MillePedeFileConverter_cfg::out, and verbosity_.

Referenced by writeEvent().

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

◆ writeFileHeader()

void LaserSorter::writeFileHeader ( std::ofstream &  out)
private

Writing file header for an LMF binary file

Parameters
outstream of the output file

Definition at line 733 of file LaserSorter.cc.

References Exception, formatVersion_, MillePedeFileConverter_cfg::out, and SiPixelPI::zero.

Referenced by createOutStream().

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

◆ writeIndexTable()

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 977 of file LaserSorter.cc.

References data, mps_fire::end, mps_fire::i, indexOffset32_, dqmdumpme::indices, jetmet_cfg::nevts, MillePedeFileConverter_cfg::out, and jetUpdater_cfi::sort.

Referenced by closeOutStream().

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

Member Data Documentation

◆ detailedTrigType_

int LaserSorter::detailedTrigType_
private

Trigger type of calibration event. -1 if unkown.

Definition at line 299 of file LaserSorter.h.

Referenced by analyze().

◆ disableOutput_

bool LaserSorter::disableOutput_
private

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

Definition at line 336 of file LaserSorter.h.

Referenced by analyze().

◆ doOutputList_

bool LaserSorter::doOutputList_
private

Switch for logging paths of the output files

Definition at line 360 of file LaserSorter.h.

Referenced by closeOutStream(), and LaserSorter().

◆ ecalDccFedIdMax_

const int LaserSorter::ecalDccFedIdMax_ = 654
staticprivate

◆ ecalDccFedIdMin_

const int LaserSorter::ecalDccFedIdMin_ = 601
staticprivate

◆ fedRawDataCollectionTag_

edm::InputTag LaserSorter::fedRawDataCollectionTag_
private

Definition at line 418 of file LaserSorter.h.

Referenced by LaserSorter().

◆ fedRawDataCollectionToken_

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

Definition at line 419 of file LaserSorter.h.

Referenced by analyze(), and LaserSorter().

◆ fedSubDirs_

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

Subdirectories for output file of each FED

Definition at line 328 of file LaserSorter.h.

Referenced by LaserSorter(), and streamFileName().

◆ formatVersion_

unsigned char LaserSorter::formatVersion_
private

Data format version of lmf output file

Definition at line 320 of file LaserSorter.h.

Referenced by createOutStream(), and writeFileHeader().

◆ indexOffset32_

const int LaserSorter::indexOffset32_ = 1
staticprivate

Definition at line 427 of file LaserSorter.h.

Referenced by writeIndexTable().

◆ iNoEcalDataMess_

int LaserSorter::iNoEcalDataMess_
private

number of "ECAL DCC data" message in a run

Definition at line 399 of file LaserSorter.h.

Referenced by analyze(), and getDetailedTriggerType().

◆ iNoFullReadoutDccError_

int LaserSorter::iNoFullReadoutDccError_
private

Number of "No fully readout DCC error"

Definition at line 391 of file LaserSorter.h.

Referenced by analyze().

◆ logFile_

std::ofstream LaserSorter::logFile_
private

File for logging

Definition at line 303 of file LaserSorter.h.

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

◆ lumiBlock_

edm::LuminosityBlockNumber_t LaserSorter::lumiBlock_
private

Luminosity block of event under processing

Definition at line 307 of file LaserSorter.h.

Referenced by analyze().

◆ lumiBlockPrev_

edm::LuminosityBlockNumber_t LaserSorter::lumiBlockPrev_
private

Luminosity block of previous processed event

Definition at line 311 of file LaserSorter.h.

Referenced by analyze().

◆ lumiBlockSpan_

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 416 of file LaserSorter.h.

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

◆ matacqFedId_

const int LaserSorter::matacqFedId_ = 655
staticprivate

FED ID associated to Matacq data

Definition at line 423 of file LaserSorter.h.

Referenced by getOutputFedList(), and writeEvent().

◆ maxEvents_

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 432 of file LaserSorter.h.

Referenced by readIndexTable().

◆ maxFullReadoutDccError_

int LaserSorter::maxFullReadoutDccError_
private

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

Definition at line 395 of file LaserSorter.h.

Referenced by analyze().

◆ maxNoEcalDataMess_

int LaserSorter::maxNoEcalDataMess_
private

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

Definition at line 403 of file LaserSorter.h.

Referenced by getDetailedTriggerType().

◆ orbit_

int LaserSorter::orbit_
private

Definition at line 462 of file LaserSorter.h.

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

◆ orbitCountInALumiBlock_

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 460 of file LaserSorter.h.

Referenced by analyze().

◆ orbitZeroTime_

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 471 of file LaserSorter.h.

Referenced by writeEvent(), and writeEventHeader().

◆ outputDir_

std::string LaserSorter::outputDir_
private

Top directory for output files

Definition at line 324 of file LaserSorter.h.

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

◆ outputList_

std::ofstream LaserSorter::outputList_
private

stream where list of output file is listed to

Definition at line 368 of file LaserSorter.h.

Referenced by closeOutStream(), and LaserSorter().

◆ outputListFile_

std::string LaserSorter::outputListFile_
private

name of file where list of output file is listed to

Definition at line 356 of file LaserSorter.h.

Referenced by LaserSorter().

◆ outStreamList_

OutStreamList LaserSorter::outStreamList_
private

List of output stream to write sorted data

Definition at line 316 of file LaserSorter.h.

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

◆ overWriteLumiBlockId_

bool LaserSorter::overWriteLumiBlockId_
private

Switch to recompute and overwrite the lumi block ID

Definition at line 454 of file LaserSorter.h.

Referenced by analyze().

◆ runNumber_

edm::RunNumber_t LaserSorter::runNumber_
private

Run number of event under process

Definition at line 340 of file LaserSorter.h.

Referenced by analyze(), and streamFileName().

◆ stats_

struct LaserSorter::stats_t LaserSorter::stats_
private

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

◆ stats_init

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

Definition at line 450 of file LaserSorter.h.

◆ timeLog_

std::ofstream LaserSorter::timeLog_
private

Output stream to log code timing

Definition at line 348 of file LaserSorter.h.

Referenced by analyze(), and LaserSorter().

◆ timeLogFile_

std::string LaserSorter::timeLogFile_
private

Name of the file to log the processing time

Definition at line 332 of file LaserSorter.h.

Referenced by LaserSorter().

◆ timer_

timeval LaserSorter::timer_
private

Buffer for timing

Definition at line 344 of file LaserSorter.h.

Referenced by analyze(), and LaserSorter().

◆ timing_

bool LaserSorter::timing_
private

Switch for code timing.

Definition at line 352 of file LaserSorter.h.

Referenced by analyze(), and LaserSorter().

◆ verbosity_

int LaserSorter::verbosity_
private