CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
MatacqProducer Class Reference
Inheritance diagram for MatacqProducer:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Classes

struct  MatacqEventId
 
class  PosEstimator
 
struct  stats_t
 

Public Types

enum  calibTrigType_t { laserType = 4, ledType = 5, tpType = 6, pedType = 7 }
 
- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 

Public Member Functions

 MatacqProducer (const edm::ParameterSet &params)
 
void produce (edm::Event &event, const edm::EventSetup &eventSetup) override
 
 ~MatacqProducer () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) 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
 
std::vector< ESProxyIndex > 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
 
bool registeredToConsumeMany (TypeID const &, 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::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Types

typedef FILE * FILE_t
 
typedef off_t filepos_t
 

Private Member Functions

void addMatacqData (edm::Event &event)
 
int getCalibTriggerType (edm::Event &ev) const
 
bool getMatacqEvent (uint32_t runNumber, int32_t orbitId, bool fileChange)
 
bool getMatacqFile (uint32_t runNumber, uint32_t orbitId, bool *fileChange=nullptr)
 
uint32_t getOrbitId (edm::Event &ev) const
 
bool getOrbitRange (uint32_t &firstOrb, uint32_t &lastOrb)
 
uint32_t getRunNumber (edm::Event &ev) const
 
void loadOrbitOffset ()
 
bool mcheck (const std::string &name)
 
void mclose ()
 
bool meof ()
 
bool misOpened ()
 
bool mopen (const std::string &name)
 
bool mread (char *buf, size_t n, const char *mess=nullptr, bool peek=false)
 
bool mrewind ()
 
bool mseek (filepos_t offset, int whence=SEEK_SET, const char *mess=nullptr)
 
bool msize (filepos_t &s)
 
bool mtell (filepos_t &pos)
 
void newRun (int prevRun, int newRun)
 

Static Private Member Functions

static std::string runSubDir (uint32_t runNumber)
 

Private Attributes

std::vector< unsigned char > data_
 
std::string digiInstanceName_
 
bool disabled_
 
bool doOrbitOffset_
 
int eventSkipCounter_
 
int fastRetrievalThresh_
 
std::vector< std::string > fileNames_
 
MatacqDataFormatter formatter_
 
bool ignoreTriggerType_
 
FILE_t inFile_
 
std::string inFileName_
 
edm::InputTag inputRawCollection_
 
edm::EDGetTokenT< FEDRawDataCollectioninputRawCollectionToken_
 
int32_t lastOrb_
 
std::ofstream logFile_
 
std::string logFileName_
 
bool logTiming_
 
MatacqRawEvent matacq_
 
bool mergeRaw_
 
int onErrorDisablingEvtCnt_
 
uint32_t openedFileRunNumber_
 
std::map< uint32_t, uint32_t > orbitOffset_
 
std::string orbitOffsetFile_
 
PosEstimator posEstim_
 
bool produceDigis_
 
bool produceRaw_
 
std::string rawInstanceName_
 
uint32_t runNumber_
 
timeval startTime_
 
struct MatacqProducer::stats_t stats_
 
std::ofstream timeLog_
 
std::string timeLogFile_
 
timeval timer_
 
bool timing_
 
int verbosity_
 

Static Private Attributes

static const int bufferSize = 30000
 
static const int matacqFedId_ = 655
 
static const int orbitTolerance_ = 80
 
static const stats_t stats_init = {0, 0, 0}
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsInputProcessBlocks ()
 
static bool wantsProcessBlocks ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- 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 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<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

Definition at line 37 of file MatacqProducer.cc.

Member Typedef Documentation

◆ FILE_t

typedef FILE* MatacqProducer::FILE_t
private

Definition at line 47 of file MatacqProducer.cc.

◆ filepos_t

typedef off_t MatacqProducer::filepos_t
private

Definition at line 46 of file MatacqProducer.cc.

Member Enumeration Documentation

◆ calibTrigType_t

Enumerator
laserType 
ledType 
tpType 
pedType 

Definition at line 39 of file MatacqProducer.cc.

Constructor & Destructor Documentation

◆ MatacqProducer()

MatacqProducer::MatacqProducer ( const edm::ParameterSet params)
explicit

Constructor

Parameters
paramsseletive readout parameters

Definition at line 372 of file MatacqProducer.cc.

References gather_cfg::cout, digiInstanceName_, doOrbitOffset_, Exception, inputRawCollectionToken_, loadOrbitOffset(), logFile_, logFileName_, logTiming_, now(), orbitOffsetFile_, MillePedeFileConverter_cfg::out, submitPVValidationJobs::params, posEstim_, produceDigis_, produceRaw_, rawInstanceName_, startTime_, timeLog_, timeLogFile_, timer_, MatacqProducer::PosEstimator::verbosity(), and verbosity_.

373  : fileNames_(params.getParameter<std::vector<std::string> >("fileNames")),
374  digiInstanceName_(params.getParameter<string>("digiInstanceName")),
375  rawInstanceName_(params.getParameter<string>("rawInstanceName")),
376  timing_(params.getUntrackedParameter<bool>("timing", false)),
377  disabled_(params.getParameter<bool>("disabled")),
378  verbosity_(params.getUntrackedParameter<int>("verbosity", 0)),
379  produceDigis_(params.getParameter<bool>("produceDigis")),
380  produceRaw_(params.getParameter<bool>("produceRaw")),
381  inputRawCollection_(params.getParameter<edm::InputTag>("inputRawCollection")),
382  mergeRaw_(params.getParameter<bool>("mergeRaw")),
383  ignoreTriggerType_(params.getParameter<bool>("ignoreTriggerType")),
384  matacq_(nullptr, 0),
385  inFile_(nullptr),
386  data_(bufferSize),
388  lastOrb_(0),
390  orbitOffsetFile_(params.getUntrackedParameter<std::string>("orbitOffsetFile", "")),
391  inFileName_(""),
393  logFileName_(params.getUntrackedParameter<std::string>("logFileName", "matacqProducer.log")),
395  onErrorDisablingEvtCnt_(params.getParameter<int>("onErrorDisablingEvtCnt")),
396  timeLogFile_(params.getUntrackedParameter<std::string>("timeLogFile", "")),
397  runNumber_(0) {
398  if (verbosity_ >= 4)
399  cout << "[Matacq " << now() << "] in MatacqProducer ctor" << endl;
400 
401  gettimeofday(&timer_, nullptr);
402 
403  if (!timeLogFile_.empty()) {
404  timeLog_.open(timeLogFile_.c_str());
405  if (timeLog_.fail()) {
406  cout << "[LaserSorter " << now() << "] "
407  << "Failed to open file " << timeLogFile_ << " to log timing.\n";
408  logTiming_ = false;
409  } else {
410  logTiming_ = true;
411  }
412  }
413 
415 
416  logFile_.open(logFileName_.c_str(), ios::app | ios::out);
417 
418  if (logFile_.bad()) {
419  throw cms::Exception("FileOpen") << "Failed to open file " << logFileName_ << " for logging.\n";
420  }
421 
422  inputRawCollectionToken_ = consumes<FEDRawDataCollection>(params.getParameter<InputTag>("inputRawCollection"));
423 
424  if (produceDigis_) {
425  if (verbosity_ > 0)
426  cout << "[Matacq " << now()
427  << "] registering new "
428  "EcalMatacqDigiCollection product with instance name '"
429  << digiInstanceName_ << "'\n";
430  produces<EcalMatacqDigiCollection>(digiInstanceName_);
431  }
432 
433  if (produceRaw_) {
434  if (verbosity_ > 0)
435  cout << "[Matacq " << now()
436  << "] registering new FEDRawDataCollection "
437  "product with instance name '"
438  << rawInstanceName_ << "'\n";
439  produces<FEDRawDataCollection>(rawInstanceName_);
440  }
441 
442  startTime_.tv_sec = startTime_.tv_usec = 0;
443  if (!orbitOffsetFile_.empty()) {
444  doOrbitOffset_ = true;
445  loadOrbitOffset();
446  } else {
447  doOrbitOffset_ = false;
448  }
449  if (verbosity_ >= 4)
450  cout << "[Matacq " << now() << "] exiting MatacqProducer ctor" << endl;
451 }
std::string inFileName_
std::ofstream logFile_
std::ofstream timeLog_
std::vector< std::string > fileNames_
std::string digiInstanceName_
struct MatacqProducer::stats_t stats_
edm::EDGetTokenT< FEDRawDataCollection > inputRawCollectionToken_
edm::InputTag inputRawCollection_
std::string orbitOffsetFile_
std::string timeLogFile_
uint32_t openedFileRunNumber_
PosEstimator posEstim_
static const int bufferSize
static std::string now()
MatacqRawEvent matacq_
std::string rawInstanceName_
std::string logFileName_
std::vector< unsigned char > data_
static const stats_t stats_init

◆ ~MatacqProducer()

MatacqProducer::~MatacqProducer ( )
override

Destructor

Definition at line 1131 of file MatacqProducer.cc.

References gather_cfg::cout, logTiming_, mclose(), now(), startTime_, and submitPVValidationJobs::t.

1131  {
1132  mclose();
1133  timeval t;
1134  gettimeofday(&t, nullptr);
1135  if (logTiming_ && startTime_.tv_sec != 0) {
1136  //not using logger, to allow timing with different logging options
1137  cout << "[Matacq " << now()
1138  << "] Time elapsed between first event and "
1139  "destruction of MatacqProducer: "
1140  << ((t.tv_sec - startTime_.tv_sec) * 1. + (t.tv_usec - startTime_.tv_usec) * 1.e-6) << "s\n";
1141  }
1142 }
static std::string now()

Member Function Documentation

◆ addMatacqData()

void MatacqProducer::addMatacqData ( edm::Event event)
private

Add matacq digi to the event

Parameters
eventthe event
digiInstanceName_name to give to the matacq digi instance

Definition at line 484 of file MatacqProducer.cc.

References bufferSize, filterCSVwithJSON::copy, gather_cfg::cout, data_, DigiToRawDM_cff::digiColl, digiInstanceName_, doOrbitOffset_, eventSkipCounter_, FEDRawDataCollection::FEDData(), formatter_, getCalibTriggerType(), MatacqRawEvent::getDccLen(), getMatacqEvent(), getMatacqFile(), getOrbitId(), MatacqRawEvent::getOrbitId(), MatacqRawEvent::getParsedLen(), getRunNumber(), ignoreTriggerType_, inputRawCollectionToken_, MatacqDataFormatter::interpretRawData(), laserType, matacq_, matacqFedId_, mergeRaw_, eostools::move(), MatacqProducer::stats_t::nLaserEventsWithMatacq, MatacqProducer::stats_t::nNonLaserEventsWithMatacq, now(), orbitOffset_, produceDigis_, produceRaw_, rawInstanceName_, convertSQLiteXML::runNumber, FEDRawData::size(), stats_, and verbosity_.

Referenced by produce().

484  {
486  event.getByToken(inputRawCollectionToken_, sourceColl);
487 
488  std::unique_ptr<FEDRawDataCollection> rawColl;
489  if (produceRaw_) {
490  if (mergeRaw_) {
491  rawColl = std::make_unique<FEDRawDataCollection>(*sourceColl);
492  } else {
493  rawColl = std::make_unique<FEDRawDataCollection>();
494  }
495  }
496 
497  auto digiColl = std::make_unique<EcalMatacqDigiCollection>();
498 
499  if (eventSkipCounter_ == 0) {
500  if (sourceColl->FEDData(matacqFedId_).size() > 4 && !produceRaw_) {
501  //input raw data collection already contains matacqData
503  } else {
504  bool isLaserEvent = (getCalibTriggerType(event) == laserType);
505 
506  // cout << "---> " << (ignoreTriggerType_?"yes":"no") << " " << getCalibTriggerType(event) << endl;
507 
508  if (isLaserEvent || ignoreTriggerType_) {
509  const uint32_t runNumber = getRunNumber(event);
510  const uint32_t orbitId = getOrbitId(event);
511 
512  LogInfo("Matacq") << "Run " << runNumber << "\t Orbit " << orbitId << "\n";
513 
514  bool fileChange;
515  if (doOrbitOffset_) {
516  map<uint32_t, uint32_t>::iterator it = orbitOffset_.find(runNumber);
517  if (it == orbitOffset_.end()) {
518  LogWarning("Matacq") << "Orbit offset not found for run " << runNumber
519  << ". No orbit correction will be applied.";
520  }
521  }
522 
523  if (getMatacqFile(runNumber, orbitId, &fileChange)) {
524  //matacq file retrieval succeeded
525  LogInfo("Matacq") << "Matacq data file found for "
526  << "run " << runNumber << " orbit " << orbitId;
527  if (getMatacqEvent(runNumber, orbitId, fileChange)) {
528  if (produceDigis_) {
530  }
531  if (produceRaw_) {
532  uint32_t dataLen64 = matacq_.getParsedLen();
533  if (dataLen64 > bufferSize * 8 || matacq_.getDccLen() != dataLen64) {
534  LogWarning("Matacq") << " Error in Matacq event fragment length! "
535  << "DCC len: " << matacq_.getDccLen()
536  << "*8 Bytes, Parsed len: " << matacq_.getParsedLen() << "*8 Bytes. "
537  << "Matacq data will not be included for this event.\n";
538  } else {
539  rawColl->FEDData(matacqFedId_).resize(dataLen64 * 8);
540  copy(data_.begin(), data_.begin() + dataLen64 * 8, rawColl->FEDData(matacqFedId_).data());
541  }
542  }
543  LogInfo("Matacq") << "Associating matacq data with orbit id " << matacq_.getOrbitId()
544  << " to dcc event with orbit id " << orbitId << std::endl;
545  if (isLaserEvent) {
547  } else {
549  }
550  } else {
551  if (isLaserEvent) {
552  LogWarning("Matacq") << "No matacq data found for laser event "
553  << "of run " << runNumber << " orbit " << orbitId;
554  }
555  }
556  } else {
557  LogWarning("Matacq") << "No matacq file found for event " << event.id();
558  }
559  }
560  }
561  if (eventSkipCounter_ > 0) { //error occured for this events
562  // and some events will be skipped following
563  // to this error.
564  LogInfo("Matacq") << " [" << now() << "] " << eventSkipCounter_
565  << " next events will be skipped, following to an "
566  << "error on the last processed event, "
567  << "which is expected to be persistant.";
568  }
569  } else {
571  }
572 
573  if (produceRaw_) {
574  if (verbosity_ > 1)
575  cout << "[Matacq " << now() << "] "
576  << "Adding FEDRawDataCollection collection "
577  << " to event.\n";
578  event.put(std::move(rawColl), rawInstanceName_);
579  }
580 
581  if (produceDigis_) {
582  if (verbosity_ > 1)
583  cout << "[Matacq " << now() << "] "
584  << "Adding EcalMatacqDigiCollection collection "
585  << " to event.\n";
586  event.put(std::move(digiColl), digiInstanceName_);
587  }
588 }
int getCalibTriggerType(edm::Event &ev) const
static const int matacqFedId_
bool getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool *fileChange=nullptr)
uint32_t getRunNumber(edm::Event &ev) const
static unsigned getOrbitId(unsigned char *data, size_t size)
unsigned getDccLen() const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
std::string digiInstanceName_
struct MatacqProducer::stats_t stats_
std::map< uint32_t, uint32_t > orbitOffset_
edm::EDGetTokenT< FEDRawDataCollection > inputRawCollectionToken_
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Log< level::Info, false > LogInfo
MatacqDataFormatter formatter_
uint32_t getOrbitId(edm::Event &ev) const
static const int bufferSize
static std::string now()
MatacqRawEvent matacq_
std::string rawInstanceName_
void interpretRawData(const FEDRawData &data, EcalMatacqDigiCollection &matacqDigiCollection)
Log< level::Warning, false > LogWarning
std::vector< unsigned char > data_
def move(src, dest)
Definition: eostools.py:511
Definition: event.py:1
bool getMatacqEvent(uint32_t runNumber, int32_t orbitId, bool fileChange)

◆ getCalibTriggerType()

int MatacqProducer::getCalibTriggerType ( edm::Event ev) const
private

Definition at line 1002 of file MatacqProducer.cc.

References data, makeMEIFBenchmarkPlots::ev, Exception, FEDRawDataCollection::FEDData(), triggerObjects_cff::id, inputRawCollectionToken_, FEDNumbering::inRange(), edm::HandleBase::isValid(), AlCaHLTBitMon_ParallelJobs::p, and edm_modernize_messagelogger::stat.

Referenced by addMatacqData().

1002  {
1004  ev.getByToken(inputRawCollectionToken_, rawdata);
1005  if (!(rawdata.isValid())) {
1006  throw cms::Exception("NotFound") << "No FED raw data collection found. ECAL raw data are "
1007  "required to retrieve the trigger type";
1008  }
1009 
1011  for (int id = 601; id <= 654; ++id) {
1012  if (!FEDNumbering::inRange(id))
1013  continue;
1014  const FEDRawData& data = rawdata->FEDData(id);
1015  const int detailedTrigger32 = 5;
1016  if (data.size() >= 4 * (detailedTrigger32 + 1)) {
1017  const unsigned char* pTType = data.data() + detailedTrigger32 * 4;
1018  int tType = pTType[1] & 0x7;
1019  stat.add(tType);
1020  }
1021  }
1022  double p;
1023  int tType = stat.result(&p);
1024  if (p < 0) {
1025  //throw cms::Exception("NotFound") << "No ECAL DCC data found\n";
1026  LogWarning("NotFound") << "No ECAL DCC data found\n";
1027  tType = -1;
1028  }
1029  if (p < .8) {
1030  //throw cms::Exception("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
1031  LogWarning("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
1032  tType = -1;
1033  }
1034  return tType;
1035 }
edm::EDGetTokenT< FEDRawDataCollection > inputRawCollectionToken_
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
bool isValid() const
Definition: HandleBase.h:70
static bool inRange(int)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
Log< level::Warning, false > LogWarning

◆ getMatacqEvent()

bool MatacqProducer::getMatacqEvent ( uint32_t  runNumber,
int32_t  orbitId,
bool  fileChange 
)
private

Definition at line 636 of file MatacqProducer.cc.

References funct::abs(), gather_cfg::cout, data_, MatacqProducer::PosEstimator::eventLength(), Exception, runEdmFileComparison::failed, fastRetrievalThresh_, newFWLiteAna::found, MatacqRawEvent::getDccLen(), MatacqRawEvent::getOrbitId(), MatacqRawEvent::getRunNum(), inFileName_, createfilelist::int, MatacqProducer::PosEstimator::invalid(), lastOrb_, matacq_, mread(), mrewind(), mseek(), msize(), mtell(), now(), hltrates_dqm_sourceclient-live_cfg::offset, orbitTolerance_, MatacqProducer::PosEstimator::pos(), posEstim_, writedatasetfile::run, convertSQLiteXML::runNumber, and verbosity_.

Referenced by addMatacqData().

636  {
637  filepos_t startPos;
638  if (!mtell(startPos))
639  return false;
640 
641  int32_t startOrb = -1;
642  const size_t headerSize = 8 * 8;
643  if (mread((char*)&data_[0], headerSize, "Reading matacq header", true)) {
644  startOrb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
645  if (startOrb < 0)
646  startOrb = 0;
647  } else {
648  if (verbosity_ > 2) {
649  cout << "[Matacq " << now()
650  << "] Failed to read matacq header. Moved to start of "
651  " the file.\n";
652  }
653  mrewind();
654  if (mread((char*)&data_[0], headerSize, "Reading matacq header", true)) {
655  startPos = 0;
656  startOrb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
657  } else {
658  if (verbosity_ > 2)
659  cout << "[Matacq " << now() << "] Looks like matacq file is empty"
660  << "\n";
661  return false;
662  }
663  }
664 
665  if (verbosity_ > 2)
666  cout << "[Matacq " << now() << "] Last read orbit: " << lastOrb_ << " looking for orbit " << orbitId
667  << ". Current file position: " << startPos << " Orbit at current position: " << startOrb << "\n";
668 
669  // f.clear();
670  bool didCoarseMove = false;
671 
672  //FIXME: case where posEtim_.invalid() is false
673  if (!posEstim_.invalid() && (abs(lastOrb_ - orbitId) > fastRetrievalThresh_)) {
674  filepos_t pos = posEstim_.pos(orbitId);
675 
676  // struct stat st;
677  filepos_t fsize = -1;
678  // if(0==stat(inFileName_.c_str(), &st)){
679  if (msize(fsize)) {
680  // const int64_t fsize = st.st_size;
681  if (0 != posEstim_.eventLength() && pos > fsize) {
682  //estimated position is beyong end of file
683  //-> move to beginning of last event:
684  int64_t evtSize = posEstim_.eventLength() * sizeof(uint64_t);
685  pos = ((int64_t)fsize / evtSize - 1) * evtSize;
686  if (verbosity_ > 2) {
687  cout << "[Matacq " << now()
688  << "] Estimated position was beyond end of file. "
689  "Changed to "
690  << pos << "\n";
691  }
692  }
693  } else {
694  LogWarning("Matacq") << "Failed to access file " << inFileName_ << ".";
695  }
696  if (pos >= 0) {
697  if (verbosity_ > 2)
698  cout << "[Matacq " << now() << "] jumping to estimated position " << pos << "\n";
699  mseek(pos, SEEK_SET, "Jumping to estimated event position");
700  if (mread((char*)&data_[0], headerSize, "Reading matacq header", true)) {
701  didCoarseMove = true;
702  } else {
703  //estimated position might have been beyond the end of the file,
704  //try, with original position:
705  didCoarseMove = false;
706  if (!mread((char*)&data_[0], headerSize, "Reading event header", true)) {
707  return false;
708  }
709  }
710  } else {
711  if (verbosity_)
712  cout << "[Matacq " << now()
713  << "] Event orbit outside of orbit range "
714  "of matacq data file events\n";
715  return false;
716  }
717  }
718 
719  int32_t orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
720 
721  if (didCoarseMove) {
722  //autoadjustement of threshold for coarse move:
723  if (abs(orb - orbitId) > fastRetrievalThresh_) {
724  if (verbosity_ > 2)
725  cout << "[Matacq " << now() << "] Fast retrieval threshold increased from " << fastRetrievalThresh_;
726  fastRetrievalThresh_ = 2 * abs(orb - orbitId);
727  if (verbosity_ > 2)
728  cout << " to " << fastRetrievalThresh_ << "\n";
729  }
730 
731  //if coarse move did not improve situation, rolls back:
732  if (startOrb > 0 && (abs(orb - orbitId) > abs(startOrb - orbitId))) {
733  if (verbosity_ > 2)
734  cout << "[Matacq " << now() << "] Estimation (-> orbit " << orb
735  << ") "
736  "was worst than original position (-> orbit "
737  << startOrb << "). Restoring position (" << startPos << ").\n";
738  mseek(startPos, SEEK_SET);
739  mread((char*)&data_[0], headerSize, "Reading event header", true);
740  orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
741  }
742  }
743 
744  bool searchBackward = (orb > orbitId) ? true : false;
745  //BEWARE: len must be signed, because we are using latter in the code (-len)
746  //expression
747  int len = (int)MatacqRawEvent::getDccLen(&data_[0], headerSize);
748 
749  if (len == 0) {
750  cout << "[Matacq " << now() << "] read DCC length is null! Cancels matacq event search "
751  << " and move matacq file pointer to beginning of the file. "
752  << "(" << __FILE__ << ":" << __LINE__ << ")."
753  << "\n";
754  //rewind(f);
755  mrewind();
756  return false;
757  }
758 
759  enum state_t { searching, found, failed } state = searching;
760 
761  while (state == searching) {
762  orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
763  len = (int)MatacqRawEvent::getDccLen(&data_[0], headerSize);
764  uint32_t run = MatacqRawEvent::getRunNum(&data_[0], headerSize);
765  if (verbosity_ > 3) {
766  filepos_t pos = -1;
767  mtell(pos);
768  cout << "[Matacq " << now() << "] Header read at file position " << pos << ": orbit = " << orb
769  << " len = " << len << "x8 Byte"
770  << " run = " << run << "\n";
771  }
772  if ((abs(orb - orbitId) < orbitTolerance_) && (runNumber == 0 || runNumber == run)) {
773  state = found;
774  lastOrb_ = orb;
775  //reads the rest of the event:
776  if ((int)data_.size() < len * 8) {
777  throw cms::Exception("Matacq") << "Buffer overflow";
778  }
779  if (verbosity_ > 2)
780  cout << "[Matacq " << now()
781  << "] Event found. Reading "
782  " matacq event."
783  << "\n";
784  if (!mread((char*)&data_[0], len * 8, "Reading matacq event")) {
785  if (verbosity_ > 2)
786  cout << "[Matacq " << now() << "] Failed to read matacq event."
787  << "\n";
788  state = failed;
789  }
790  matacq_ = MatacqRawEvent((unsigned char*)&data_[0], len * 8);
791  } else {
792  if ((searchBackward && (orb < orbitId)) || (!searchBackward && (orb > orbitId))) { //search ended
793  lastOrb_ = orb;
794  state = failed;
795  if (verbosity_ > 2)
796  cout << "[Matacq " << now() << "] No matacq data found for run " << run << ", orbit ID " << orbitId << "."
797  << "\n";
798  } else {
799  off_t offset = (searchBackward ? -len : len) * 8;
800  lastOrb_ = orb;
801  if (verbosity_ > 3) {
802  cout << "[Matacq " << now() << "] In matacq file, moving " << abs(offset) << " byte "
803  << (offset > 0 ? "forward" : "backward") << ".\n";
804  }
805 
806  if (mseek(offset, SEEK_CUR, (searchBackward ? "Moving to previous event" : "Moving to next event")) &&
807  mread((char*)&data_[0], headerSize, "Reading event header", true)) {
808  } else {
809  if (!searchBackward)
810  mseek(-len * 8, SEEK_CUR, "Moving to start of last complete event");
811  state = failed;
812  }
813  }
814  }
815  }
816 
817  if (state == found) {
818  filepos_t pos = -1;
819  filepos_t fsize = -1;
820  mtell(pos);
821  msize(fsize);
822  if (pos == fsize - 1) { //last byte.
823  if (verbosity_ > 2) {
824  cout << "[Matacq " << now()
825  << "] Event found was at the end of the file. Moving "
826  "stream position to beginning of this event."
827  << "\n";
828  }
829  mseek(-(int)len * 8 - 1, SEEK_CUR, "Moving to beginning of last matacq event");
830  }
831  }
832  return (state == found);
833 }
std::string inFileName_
static const int orbitTolerance_
bool mseek(filepos_t offset, int whence=SEEK_SET, const char *mess=nullptr)
unsigned getDccLen() const
int64_t pos(int orb) const
bool mread(char *buf, size_t n, const char *mess=nullptr, bool peek=false)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
unsigned long long uint64_t
Definition: Time.h:13
PosEstimator posEstim_
bool mtell(filepos_t &pos)
static std::string now()
MatacqRawEvent matacq_
unsigned getRunNum() const
uint32_t getOrbitId() const
Log< level::Warning, false > LogWarning
bool msize(filepos_t &s)
std::vector< unsigned char > data_

◆ getMatacqFile()

bool MatacqProducer::getMatacqFile ( uint32_t  runNumber,
uint32_t  orbitId,
bool *  fileChange = nullptr 
)
private

Retrieve the file containing a given matacq event

Parameters
runNumberNumber of the run the matacq event is looking from
orbitIdId of the orbit of the matacq event
fileChangeif not null pointer, set to true if the file changed.
Returns
true if file retrieval succeeded, false otherwise. found.

Definition at line 835 of file MatacqProducer.cc.

References gather_cfg::cout, eventSkipCounter_, fileNames_, alignmentValidation::fname, newFWLiteAna::found, g, getOrbitRange(), mps_fire::i, MatacqProducer::PosEstimator::init(), lastOrb_, misOpened(), mopen(), now(), onErrorDisablingEvtCnt_, openedFileRunNumber_, posEstim_, convertSQLiteXML::runNumber, runSubDir(), and verbosity_.

Referenced by addMatacqData().

835  {
837  uint32_t firstOrb, lastOrb;
838  bool goodRange = getOrbitRange(firstOrb, lastOrb);
839  // if(orbitId < firstOrb || orbitId > lastOrb) continue;
840  if (goodRange && firstOrb <= orbitId && orbitId <= lastOrb) {
841  if (fileChange != nullptr)
842  *fileChange = false;
843  return misOpened();
844  }
845  }
846 
847  if (fileNames_.empty())
848  return false;
849 
850  const string runNumberFormat = "%08d{,_*}";
851  string sRunNumber = fmt::sprintf(runNumberFormat, runNumber);
852  //cout << "Run number string: " << sRunNumber << "\n";
853  bool found = false;
854  string fname;
855  uint32_t maxOrb = 0;
856  //we make two iterations to handle the case where the event is procesed
857  //before the matacq data are available. In such case we would have
858  //orbitId > maxOrb (maxOrb: orbit of last written matacq event)
859  // for(int itry = 0; itry < 2 && (orbitId > maxOrb); ++itry){
860  for (int itry = 0; itry < 1 && (orbitId > maxOrb); ++itry) {
861  if (itry > 0) {
862  int n_sec = 1;
863  std::cout << "[Matacq " << now() << "] Event orbit id (" << orbitId
864  << ") goes "
865  "beyound the range of available one. Waiting for "
866  << n_sec
867  << " seconds in case "
868  "it was not written yet to disk.";
869  sleep(n_sec);
870  }
871 
872  for (unsigned i = 0; i < fileNames_.size() && !found; ++i) {
873  fname = fileNames_[i];
874  boost::algorithm::replace_all(fname, "%run_subdir%", runSubDir(runNumber));
875  boost::algorithm::replace_all(fname, "%run_number%", sRunNumber);
876 
877  glob_t g;
878  int rc = glob(fname.c_str(), GLOB_BRACE, nullptr, &g);
879  if (rc) {
880  if (verbosity_ > 1) {
881  switch (rc) {
882  case GLOB_NOSPACE:
883  std::cout << "[Matacq " << now()
884  << "] Running out of memory while calling glob function to look for matacq file paths\n";
885  break;
886  case GLOB_ABORTED:
887  std::cout << "[Matacq " << now()
888  << "] Read error while calling glob function to look for matacq file paths\n";
889  break;
890  case GLOB_NOMATCH:
891  //ok. No message to report.
892  break;
893  }
894  continue;
895  }
896  } //rc
897  for (unsigned iglob = 0; iglob < g.gl_pathc; ++iglob) {
898  char* thePath = g.gl_pathv[iglob];
899  //FIXME: add sanity check on the path
900  static std::atomic<int> nOpenErrors{0};
901  const int maxOpenErrors = 50;
902  if (!mopen(thePath) && nOpenErrors < maxOpenErrors) {
903  std::cout << "[Matacq " << now() << "] Failed to open file " << thePath;
904  ++nOpenErrors;
905  if (nOpenErrors == maxOpenErrors) {
906  std::cout << nOpenErrors << "This is the " << maxOpenErrors
907  << "th occurence of this error. Report of this error is now disabled.\n";
908  } else {
909  std::cout << "\n";
910  }
911  }
912  uint32_t firstOrb;
913  uint32_t lastOrb;
914  bool goodRange = getOrbitRange(firstOrb, lastOrb);
915  std::cout << "Get orbit range " << (goodRange ? "succeeded" : "failed") << ". Range: " << firstOrb << "..."
916  << lastOrb << "\n";
917  if (goodRange && lastOrb > maxOrb)
918  maxOrb = lastOrb;
919  if (goodRange && firstOrb <= orbitId && orbitId <= lastOrb) {
920  found = true;
921  //continue;
922  fname = thePath;
923  if (verbosity_ > 1)
924  std::cout << "[Matacq " << now() << "] Switching to file " << fname << "\n";
925  break;
926  }
927  } //next iglob
928  globfree(&g);
929  } //next filenames
930  } //next itry
931 
932  if (found) {
933  LogInfo("Matacq") << "Uses matacq data file: '" << fname << "'\n";
934  } else {
935  if (verbosity_ >= 0)
936  cout << "[Matacq " << now()
937  << "] no matacq file found "
938  "for run "
939  << runNumber << ", orbit " << orbitId << "\n";
942  if (fileChange != nullptr)
943  *fileChange = false;
944  return false;
945  }
946 
947  if (found) {
949  lastOrb_ = 0;
950  posEstim_.init(this);
951  if (fileChange != nullptr)
952  *fileChange = true;
953  return true;
954  } else {
955  return false;
956  }
957 }
bool getOrbitRange(uint32_t &firstOrb, uint32_t &lastOrb)
std::vector< std::string > fileNames_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
static std::string runSubDir(uint32_t runNumber)
Log< level::Info, false > LogInfo
uint32_t openedFileRunNumber_
PosEstimator posEstim_
void init(MatacqProducer *mp)
string fname
main script
static std::string now()
bool mopen(const std::string &name)

◆ getOrbitId()

uint32_t MatacqProducer::getOrbitId ( edm::Event ev) const
private

Definition at line 961 of file MatacqProducer.cc.

References funct::abs(), data, makeMEIFBenchmarkPlots::ev, Exception, FEDRawDataCollection::FEDData(), triggerObjects_cff::id, inputRawCollectionToken_, FEDNumbering::inRange(), edm::HandleBase::isValid(), and orbitTolerance_.

Referenced by addMatacqData().

961  {
962  //on CVS HEAD (June 4, 08), class Event has a method orbitNumber()
963  //we could use here. The code would be shorten to:
964  //return ev.orbitNumber();
965  //we have to deal with what we have in current CMSSW releases:
967  ev.getByToken(inputRawCollectionToken_, rawdata);
968  if (!(rawdata.isValid())) {
969  throw cms::Exception("NotFound") << "No FED raw data collection found. ECAL raw data are "
970  "required to retrieve the orbit ID";
971  }
972 
973  int orbit = 0;
974  for (int id = 601; id <= 654; ++id) {
975  if (!FEDNumbering::inRange(id))
976  continue;
977  const FEDRawData& data = rawdata->FEDData(id);
978  const int orbitIdOffset64 = 3;
979  if (data.size() >= 8 * (orbitIdOffset64 + 1)) { //orbit id is in 4th 64-bit word
980  const unsigned char* pOrbit = data.data() + orbitIdOffset64 * 8;
981  int thisOrbit = pOrbit[0] | (pOrbit[1] << 8) | (pOrbit[2] << 16) | (pOrbit[3] << 24);
982  if (orbit != 0 && thisOrbit != 0 && abs(orbit - thisOrbit) > orbitTolerance_) {
983  //throw cms::Exception("EventCorruption")
984  // << "Orbit ID inconsitency in DCC headers";
985  LogWarning("EventCorruption") << "Orbit ID inconsitency in DCC headers";
986  orbit = 0;
987  break;
988  }
989  if (thisOrbit != 0)
990  orbit = thisOrbit;
991  }
992  }
993 
994  if (orbit == 0) {
995  // throw cms::Exception("NotFound")
996  // << "Failed to retrieve orbit ID of event "<< ev.id();
997  LogWarning("NotFound") << "Failed to retrieve orbit ID of event " << ev.id();
998  }
999  return orbit;
1000 }
static const int orbitTolerance_
edm::EDGetTokenT< FEDRawDataCollection > inputRawCollectionToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
bool isValid() const
Definition: HandleBase.h:70
static bool inRange(int)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
Log< level::Warning, false > LogWarning

◆ getOrbitRange()

bool MatacqProducer::getOrbitRange ( uint32_t &  firstOrb,
uint32_t &  lastOrb 
)
private

Definition at line 1443 of file MatacqProducer.cc.

References MatacqRawEvent::getDccLen(), MatacqRawEvent::getOrbitId(), RecoTauValidation_cfi::header, createfilelist::int, mread(), mseek(), msize(), mtell(), nEvts, and createJobs::tmp.

Referenced by getMatacqFile().

1443  {
1444  filepos_t pos = -1;
1445  filepos_t fsize = -1;
1446  mtell(pos);
1447  msize(fsize);
1448  const unsigned headerSize = 8 * 8;
1449  unsigned char header[headerSize];
1450  //FIXME: Don't we need here to rewind?
1451  mseek(0);
1452  if (!mread((char*)header, headerSize, nullptr, false))
1453  return false;
1454  firstOrb = MatacqRawEvent::getOrbitId(header, headerSize);
1455  int len = (int)MatacqRawEvent::getDccLen(header, headerSize);
1456  //number of complete events. If last event is partially written,
1457  //it won't be included in the count.
1458  unsigned nEvts = fsize / (len * 8);
1459  //Position of last complete event:
1460  filepos_t lastEvtPos = (filepos_t)(nEvts - 1) * len * 8;
1461  // std::cout << "Move to position : " << lastEvtPos
1462  // << "(" << (nEvts - 1) << "*" << len << "*" << 64 << ")"
1463  //<< "\n";
1464  mseek(lastEvtPos);
1465  filepos_t tmp;
1466  mtell(tmp);
1467  //std::cout << "New position, sizeof(tmp): " << tmp << "," << sizeof(tmp) << "\n";
1468  mread((char*)header, headerSize, nullptr, false);
1469  lastOrb = MatacqRawEvent::getOrbitId(header, headerSize);
1470 
1471  //restore file position:
1472  mseek(pos);
1473 
1474  return true;
1475 }
bool mseek(filepos_t offset, int whence=SEEK_SET, const char *mess=nullptr)
unsigned getDccLen() const
bool mread(char *buf, size_t n, const char *mess=nullptr, bool peek=false)
const int nEvts
bool mtell(filepos_t &pos)
uint32_t getOrbitId() const
bool msize(filepos_t &s)
tmp
align.sh
Definition: createJobs.py:716

◆ getRunNumber()

uint32_t MatacqProducer::getRunNumber ( edm::Event ev) const
private

Definition at line 959 of file MatacqProducer.cc.

References makeMEIFBenchmarkPlots::ev.

Referenced by addMatacqData(), and produce().

959 { return ev.run(); }

◆ loadOrbitOffset()

void MatacqProducer::loadOrbitOffset ( )
private

Loading orbit correction table from file.

See also
orbitOffsetFile_

Definition at line 1144 of file MatacqProducer.cc.

References visDQMUpload::buf, gather_cfg::cout, Exception, f, ntuplemaker::iline, SiStripPI::max, now(), orbitOffset_, orbitOffsetFile_, writedatasetfile::run, and alignCSCRings::s.

Referenced by MatacqProducer().

1144  {
1145  std::ifstream f(orbitOffsetFile_.c_str());
1146  if (f.bad()) {
1147  throw cms::Exception("Matacq") << "Failed to open orbit ID correction file '" << orbitOffsetFile_ << "'\n";
1148  }
1149 
1150  cout << "[Matacq " << now() << "] "
1151  << "Offset to substract to Matacq events Orbit ID: \n"
1152  << "#Run Number\t Offset\n";
1153 
1154  int iline = 0;
1155  string s;
1156  stringstream buf;
1157  while (f.eof()) {
1158  getline(f, s);
1159  ++iline;
1160  if (s[0] == '#') { //comment
1161  //skip line:
1162  f.ignore(numeric_limits<streamsize>::max(), '\n');
1163  continue;
1164  }
1165  buf.str("");
1166  buf << s;
1167  int run;
1168  int orbit;
1169  buf >> run;
1170  buf >> orbit;
1171  if (buf.bad()) {
1172  throw cms::Exception("Matacq") << "Syntax error in Orbit offset file '" << orbitOffsetFile_ << "'";
1173  }
1174  cout << run << "\t" << orbit << "\n";
1175  orbitOffset_.insert(pair<int, int>(run, orbit));
1176  }
1177 }
std::map< uint32_t, uint32_t > orbitOffset_
double f[11][100]
std::string orbitOffsetFile_
static std::string now()

◆ mcheck()

bool MatacqProducer::mcheck ( const std::string &  name)
private

Definition at line 1380 of file MatacqProducer.cc.

References Skims_PA_cff::name, and edm_modernize_messagelogger::stat.

1380  {
1381  struct stat dummy;
1382  return 0 == stat(name.c_str(), &dummy);
1383  // if(stat(name.c_str(), &dummy)==0){
1384  // return true;
1385  // } else{
1386  // cout << "[Matacq " << now() << "] Failed to stat file '"
1387  // << name.c_str() << "'. "
1388  // << "Error " << errno << ": " << strerror(errno) << "\n";
1389  // return false;
1390  // }
1391 }

◆ mclose()

void MatacqProducer::mclose ( )
private

Definition at line 1406 of file MatacqProducer.cc.

References inFile_.

Referenced by mopen(), and ~MatacqProducer().

1406  {
1407  if (inFile_ != nullptr)
1408  fclose(inFile_);
1409  inFile_ = nullptr;
1410 }

◆ meof()

bool MatacqProducer::meof ( )
private

Definition at line 1414 of file MatacqProducer.cc.

References inFile_.

1414  {
1415  if (nullptr == inFile_)
1416  return true;
1417  return feof(inFile_) == 0;
1418 }

◆ misOpened()

bool MatacqProducer::misOpened ( )
private

Definition at line 1412 of file MatacqProducer.cc.

References inFile_.

Referenced by getMatacqFile().

1412 { return inFile_ != nullptr; }

◆ mopen()

bool MatacqProducer::mopen ( const std::string &  name)
private

Definition at line 1393 of file MatacqProducer.cc.

References inFile_, inFileName_, mclose(), and Skims_PA_cff::name.

Referenced by getMatacqFile().

1393  {
1394  if (inFile_ != nullptr)
1395  mclose();
1396  inFile_ = fopen(name.c_str(), "r");
1397  if (inFile_ != nullptr) {
1398  inFileName_ = name;
1399  return true;
1400  } else {
1401  inFileName_ = "";
1402  return false;
1403  }
1404 }
std::string inFileName_

◆ mread()

bool MatacqProducer::mread ( char *  buf,
size_t  n,
const char *  mess = nullptr,
bool  peek = false 
)
private

Read a data block from input file. On failure file position is restored and if position restoring fails, file is rewind.

Parameters
bufbuffer to store read data
nsize of data block
messtext to insert in the eventual error message.
peekif true file position is restored after the data read
Returns
true on success, false on failure

Definition at line 1329 of file MatacqProducer.cc.

References visDQMUpload::buf, gather_cfg::cout, inFile_, lastOrb_, mrewind(), dqmiodumpmetadata::n, now(), and verbosity_.

Referenced by getMatacqEvent(), getOrbitRange(), and MatacqProducer::PosEstimator::init().

1329  {
1330  if (nullptr == inFile_)
1331  return false;
1332  off_t pos = ftello(inFile_);
1333  bool rc = (pos != -1) && (1 == fread(buf, n, 1, inFile_));
1334  if (!rc) {
1335  if (verbosity_) {
1336  cout << "[Matacq " << now() << "] ";
1337  if (mess)
1338  cout << mess << ". ";
1339  cout << "Read failure from input matacq file.\n";
1340  }
1341  clearerr(inFile_);
1342  }
1343  if (peek || !rc) { //need to restore file position
1344  if (0 != fseeko(inFile_, pos, SEEK_SET)) {
1345  if (verbosity_) {
1346  cout << "[Matacq " << now() << "] ";
1347  if (mess)
1348  cout << mess << ". ";
1349  cout << "Failed to restore file position of "
1350  "before read error. Rewind file.\n";
1351  }
1352  //rewind(inFile_.get());
1353  mrewind();
1354  lastOrb_ = 0;
1355  }
1356  }
1357  return rc;
1358 }
static std::string now()

◆ mrewind()

bool MatacqProducer::mrewind ( )
private

Definition at line 1373 of file MatacqProducer.cc.

References inFile_.

Referenced by getMatacqEvent(), MatacqProducer::PosEstimator::init(), mread(), and mseek().

1373  {
1374  if (nullptr == inFile_)
1375  return false;
1376  clearerr(inFile_);
1377  return fseeko(inFile_, 0, SEEK_SET) != 0;
1378 }

◆ mseek()

bool MatacqProducer::mseek ( filepos_t  offset,
int  whence = SEEK_SET,
const char *  mess = nullptr 
)
private

Move input file read pointer. On failure file is rewind.

Parameters
bufbuffer to store read data
nsize of data block
messtext to insert in the eventual error message.
Returns
true on success, false on failure

Definition at line 1307 of file MatacqProducer.cc.

References gather_cfg::cout, inFile_, mrewind(), now(), hltrates_dqm_sourceclient-live_cfg::offset, and verbosity_.

Referenced by getMatacqEvent(), getOrbitRange(), and MatacqProducer::PosEstimator::init().

1307  {
1308  if (nullptr == inFile_)
1309  return false;
1310  const int rc = fseeko(inFile_, offset, whence);
1311  if (rc != 0 && verbosity_) {
1312  cout << "[Matacq " << now() << "] ";
1313  if (mess)
1314  cout << mess << ". ";
1315  cout << "Random access error on input matacq file. "
1316  "Rewind file.\n";
1317  mrewind();
1318  }
1319  return rc == 0;
1320 }
static std::string now()

◆ msize()

bool MatacqProducer::msize ( filepos_t s)
private

Definition at line 1360 of file MatacqProducer.cc.

References visDQMUpload::buf, inFile_, and alignCSCRings::s.

Referenced by getMatacqEvent(), getOrbitRange(), and MatacqProducer::PosEstimator::init().

1360  {
1361  if (nullptr == inFile_)
1362  return false;
1363  struct stat buf;
1364  if (0 != fstat(fileno(inFile_), &buf)) {
1365  s = 0;
1366  return false;
1367  } else {
1368  s = buf.st_size;
1369  return true;
1370  }
1371 }

◆ mtell()

bool MatacqProducer::mtell ( filepos_t pos)
private

Definition at line 1322 of file MatacqProducer.cc.

References inFile_.

Referenced by getMatacqEvent(), and getOrbitRange().

1322  {
1323  if (nullptr == inFile_)
1324  return false;
1325  pos = ftello(inFile_);
1326  return pos != -1;
1327 }

◆ newRun()

void MatacqProducer::newRun ( int  prevRun,
int  newRun 
)
private

Definition at line 1429 of file MatacqProducer.cc.

References eventSkipCounter_, logFile_, MatacqProducer::stats_t::nEvents, MatacqProducer::stats_t::nLaserEventsWithMatacq, MatacqProducer::stats_t::nNonLaserEventsWithMatacq, now(), runNumber_, and stats_.

Referenced by produce().

1429  {
1430  runNumber_ = newRun;
1431  eventSkipCounter_ = 0;
1432  logFile_ << "[" << now() << "] Event count for run " << runNumber_ << ": "
1433  << "total: " << stats_.nEvents << ", "
1434  << "Laser event with Matacq data: " << stats_.nLaserEventsWithMatacq << ", "
1435  << "Non laser event (according to DCC header) with Matacq data: " << stats_.nNonLaserEventsWithMatacq << "\n"
1436  << flush;
1437 
1438  stats_.nEvents = 0;
1441 }
std::ofstream logFile_
struct MatacqProducer::stats_t stats_
static std::string now()
void newRun(int prevRun, int newRun)

◆ produce()

void MatacqProducer::produce ( edm::Event event,
const edm::EventSetup eventSetup 
)
overridevirtual

Produces the EDM products

Parameters
CMSevent
eventSetupevent conditions

Implements edm::EDProducer.

Definition at line 453 of file MatacqProducer.cc.

References addMatacqData(), gather_cfg::cout, disabled_, getRunNumber(), logTiming_, MatacqProducer::stats_t::nEvents, newRun(), now(), convertSQLiteXML::runNumber, runNumber_, startTime_, stats_, submitPVValidationJobs::t, timeLog_, timer_, and verbosity_.

453  {
454  if (verbosity_ >= 4)
455  cout << "[Matacq " << now() << "] in MatacqProducer::produce" << endl;
456  if (logTiming_) {
457  timeval t;
458  gettimeofday(&t, nullptr);
459 
460  timeLog_ << t.tv_sec << "." << setfill('0') << setw(3) << (t.tv_usec + 500) / 1000 << setfill(' ') << "\t"
461  << (t.tv_usec - timer_.tv_usec) * 1. + (t.tv_sec - timer_.tv_sec) * 1.e6 << "\t";
462  timer_ = t;
463  }
464 
465  if (startTime_.tv_sec == 0)
466  gettimeofday(&startTime_, nullptr);
467  ++stats_.nEvents;
468  if (disabled_)
469  return;
470  const uint32_t runNumber = getRunNumber(event);
471  if (runNumber != runNumber_) {
473  }
475 
476  if (logTiming_) {
477  timeval t;
478  gettimeofday(&t, nullptr);
479  timeLog_ << (t.tv_usec - timer_.tv_usec) * 1. + (t.tv_sec - timer_.tv_sec) * 1.e6 << "\n";
480  timer_ = t;
481  }
482 }
std::ofstream timeLog_
uint32_t getRunNumber(edm::Event &ev) const
struct MatacqProducer::stats_t stats_
void addMatacqData(edm::Event &event)
static std::string now()
void newRun(int prevRun, int newRun)
Definition: event.py:1

◆ runSubDir()

std::string MatacqProducer::runSubDir ( uint32_t  runNumber)
staticprivate

Definition at line 1422 of file MatacqProducer.cc.

References convertSQLiteXML::runNumber, and units().

Referenced by getMatacqFile().

1422  {
1423  int millions = runNumber / (1000 * 1000);
1424  int thousands = (runNumber - millions * 1000 * 1000) / 1000;
1425  int units = runNumber - millions * 1000 * 1000 - thousands * 1000;
1426  return fmt::sprintf("%03d/%03d/%03d", millions, thousands, units);
1427 }
TString units(TString variable, Char_t axis)

Member Data Documentation

◆ bufferSize

const int MatacqProducer::bufferSize = 30000
staticprivate

Definition at line 239 of file MatacqProducer.cc.

Referenced by addMatacqData().

◆ data_

std::vector<unsigned char> MatacqProducer::data_
private

Definition at line 241 of file MatacqProducer.cc.

Referenced by addMatacqData(), and getMatacqEvent().

◆ digiInstanceName_

std::string MatacqProducer::digiInstanceName_
private

Instance name to use for the produced Matacq digi collection

Definition at line 188 of file MatacqProducer.cc.

Referenced by addMatacqData(), and MatacqProducer().

◆ disabled_

bool MatacqProducer::disabled_
private

Parameter to disable matacq data production. For timing purpose.

Definition at line 200 of file MatacqProducer.cc.

Referenced by produce().

◆ doOrbitOffset_

bool MatacqProducer::doOrbitOffset_
private

Switch for orbit ID correction.

See also
orbitOffsetFile_

Definition at line 264 of file MatacqProducer.cc.

Referenced by addMatacqData(), and MatacqProducer().

◆ eventSkipCounter_

int MatacqProducer::eventSkipCounter_
private

counter for event skipping

Definition at line 289 of file MatacqProducer.cc.

Referenced by addMatacqData(), getMatacqFile(), and newRun().

◆ fastRetrievalThresh_

int MatacqProducer::fastRetrievalThresh_
private

Definition at line 246 of file MatacqProducer.cc.

Referenced by getMatacqEvent().

◆ fileNames_

std::vector<std::string> MatacqProducer::fileNames_
private

Definition at line 184 of file MatacqProducer.cc.

Referenced by getMatacqFile().

◆ formatter_

MatacqDataFormatter MatacqProducer::formatter_
private

Definition at line 242 of file MatacqProducer.cc.

Referenced by addMatacqData().

◆ ignoreTriggerType_

bool MatacqProducer::ignoreTriggerType_
private

When true look for matacq data independently of trigger type.

Definition at line 231 of file MatacqProducer.cc.

Referenced by addMatacqData().

◆ inFile_

FILE_t MatacqProducer::inFile_
private

Stream of currently opened matacq file

Definition at line 237 of file MatacqProducer.cc.

Referenced by mclose(), meof(), misOpened(), mopen(), mread(), mrewind(), mseek(), msize(), and mtell().

◆ inFileName_

std::string MatacqProducer::inFileName_
private

Name of currently opened matacq file

Definition at line 268 of file MatacqProducer.cc.

Referenced by getMatacqEvent(), and mopen().

◆ inputRawCollection_

edm::InputTag MatacqProducer::inputRawCollection_
private

Name of the raw data collection the Matacq data must be merge to if merging is enabled.

Definition at line 217 of file MatacqProducer.cc.

◆ inputRawCollectionToken_

edm::EDGetTokenT<FEDRawDataCollection> MatacqProducer::inputRawCollectionToken_
private

EDM token to access the raw data collection the Matacq data must be merge to if merging is enabled.

Definition at line 222 of file MatacqProducer.cc.

Referenced by addMatacqData(), getCalibTriggerType(), getOrbitId(), and MatacqProducer().

◆ lastOrb_

int32_t MatacqProducer::lastOrb_
private

Definition at line 245 of file MatacqProducer.cc.

Referenced by getMatacqEvent(), getMatacqFile(), and mread().

◆ logFile_

std::ofstream MatacqProducer::logFile_
private

Log file

Definition at line 285 of file MatacqProducer.cc.

Referenced by MatacqProducer(), and newRun().

◆ logFileName_

std::string MatacqProducer::logFileName_
private

Log file name

Definition at line 281 of file MatacqProducer.cc.

Referenced by MatacqProducer().

◆ logTiming_

bool MatacqProducer::logTiming_
private

Switch for code timing.

Definition at line 308 of file MatacqProducer.cc.

Referenced by MatacqProducer(), produce(), and ~MatacqProducer().

◆ matacq_

MatacqRawEvent MatacqProducer::matacq_
private

Definition at line 233 of file MatacqProducer.cc.

Referenced by addMatacqData(), and getMatacqEvent().

◆ matacqFedId_

const int MatacqProducer::matacqFedId_ = 655
staticprivate

Definition at line 270 of file MatacqProducer.cc.

Referenced by addMatacqData().

◆ mergeRaw_

bool MatacqProducer::mergeRaw_
private

Switch for merging Matacq raw data with existing raw data collection.

Definition at line 227 of file MatacqProducer.cc.

Referenced by addMatacqData().

◆ onErrorDisablingEvtCnt_

int MatacqProducer::onErrorDisablingEvtCnt_
private

Number of events to skip in case of error

Definition at line 293 of file MatacqProducer.cc.

Referenced by getMatacqFile().

◆ openedFileRunNumber_

uint32_t MatacqProducer::openedFileRunNumber_
private

Definition at line 244 of file MatacqProducer.cc.

Referenced by getMatacqFile().

◆ orbitOffset_

std::map<uint32_t, uint32_t> MatacqProducer::orbitOffset_
private

Orbit offset table.

See also
orbitOffsetFile_

Definition at line 260 of file MatacqProducer.cc.

Referenced by addMatacqData(), and loadOrbitOffset().

◆ orbitOffsetFile_

std::string MatacqProducer::orbitOffsetFile_
private

File name of table with orbit offset between matacq event and DCC. Used to recover data suffering from orbit miss-synchonization

Definition at line 256 of file MatacqProducer.cc.

Referenced by loadOrbitOffset(), and MatacqProducer().

◆ orbitTolerance_

const int MatacqProducer::orbitTolerance_ = 80
staticprivate

Definition at line 243 of file MatacqProducer.cc.

Referenced by getMatacqEvent(), and getOrbitId().

◆ posEstim_

PosEstimator MatacqProducer::posEstim_
private

Definition at line 248 of file MatacqProducer.cc.

Referenced by getMatacqEvent(), getMatacqFile(), and MatacqProducer().

◆ produceDigis_

bool MatacqProducer::produceDigis_
private

Swictch for Matacq digi producion

Definition at line 208 of file MatacqProducer.cc.

Referenced by addMatacqData(), and MatacqProducer().

◆ produceRaw_

bool MatacqProducer::produceRaw_
private

Switch for Matacq FED raw data production

Definition at line 212 of file MatacqProducer.cc.

Referenced by addMatacqData(), and MatacqProducer().

◆ rawInstanceName_

std::string MatacqProducer::rawInstanceName_
private

Instance name to use for the produced Matacq raw data collection

Definition at line 192 of file MatacqProducer.cc.

Referenced by addMatacqData(), and MatacqProducer().

◆ runNumber_

uint32_t MatacqProducer::runNumber_
private

Number of the currently processed run

Definition at line 312 of file MatacqProducer.cc.

Referenced by newRun(), and produce().

◆ startTime_

timeval MatacqProducer::startTime_
private

Definition at line 250 of file MatacqProducer.cc.

Referenced by MatacqProducer(), produce(), and ~MatacqProducer().

◆ stats_

struct MatacqProducer::stats_t MatacqProducer::stats_
private

Referenced by addMatacqData(), newRun(), and produce().

◆ stats_init

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

Definition at line 278 of file MatacqProducer.cc.

◆ timeLog_

std::ofstream MatacqProducer::timeLog_
private

Output stream to log code timing

Definition at line 304 of file MatacqProducer.cc.

Referenced by MatacqProducer(), and produce().

◆ timeLogFile_

std::string MatacqProducer::timeLogFile_
private

Name of file to log timing

Definition at line 297 of file MatacqProducer.cc.

Referenced by MatacqProducer().

◆ timer_

timeval MatacqProducer::timer_
private

Buffer for timing

Definition at line 300 of file MatacqProducer.cc.

Referenced by MatacqProducer(), and produce().

◆ timing_

bool MatacqProducer::timing_
private

Parameter to switch module timing.

Definition at line 196 of file MatacqProducer.cc.

◆ verbosity_

int MatacqProducer::verbosity_
private