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

#include <MatacqProducer.h>

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 &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
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
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
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
 
const static int orbitTolerance_ = 80
 
const static 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<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 declare what type of product will make and with which optional label More...
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
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)
 
template<Transition B>
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 (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
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<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Definition at line 41 of file MatacqProducer.h.

Member Typedef Documentation

◆ FILE_t

typedef FILE* MatacqProducer::FILE_t
private

Definition at line 51 of file MatacqProducer.h.

◆ filepos_t

typedef off_t MatacqProducer::filepos_t
private

Definition at line 50 of file MatacqProducer.h.

Member Enumeration Documentation

◆ calibTrigType_t

Enumerator
laserType 
ledType 
tpType 
pedType 

Definition at line 43 of file MatacqProducer.h.

43 { laserType = 4, ledType = 5, tpType = 6, pedType = 7 };

Constructor & Destructor Documentation

◆ MatacqProducer()

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

Constructor

Parameters
paramsseletive readout parameters

Definition at line 62 of file MatacqProducer.cc.

63  : fileNames_(params.getParameter<std::vector<std::string> >("fileNames")),
64  digiInstanceName_(params.getParameter<string>("digiInstanceName")),
65  rawInstanceName_(params.getParameter<string>("rawInstanceName")),
66  timing_(params.getUntrackedParameter<bool>("timing", false)),
67  disabled_(params.getParameter<bool>("disabled")),
68  verbosity_(params.getUntrackedParameter<int>("verbosity", 0)),
69  produceDigis_(params.getParameter<bool>("produceDigis")),
70  produceRaw_(params.getParameter<bool>("produceRaw")),
71  inputRawCollection_(params.getParameter<edm::InputTag>("inputRawCollection")),
72  mergeRaw_(params.getParameter<bool>("mergeRaw")),
73  ignoreTriggerType_(params.getParameter<bool>("ignoreTriggerType")),
74  matacq_(nullptr, 0),
75  inFile_(nullptr),
78  lastOrb_(0),
80  orbitOffsetFile_(params.getUntrackedParameter<std::string>("orbitOffsetFile", "")),
81  inFileName_(""),
83  logFileName_(params.getUntrackedParameter<std::string>("logFileName", "matacqProducer.log")),
85  onErrorDisablingEvtCnt_(params.getParameter<int>("onErrorDisablingEvtCnt")),
86  timeLogFile_(params.getUntrackedParameter<std::string>("timeLogFile", "")),
87  runNumber_(0) {
88  if (verbosity_ >= 4)
89  cout << "[Matacq " << now() << "] in MatacqProducer ctor" << endl;
90 
91  gettimeofday(&timer_, nullptr);
92 
93  if (!timeLogFile_.empty()) {
94  timeLog_.open(timeLogFile_.c_str());
95  if (timeLog_.fail()) {
96  cout << "[LaserSorter " << now() << "] "
97  << "Failed to open file " << timeLogFile_ << " to log timing.\n";
98  logTiming_ = false;
99  } else {
100  logTiming_ = true;
101  }
102  }
103 
105 
106  logFile_.open(logFileName_.c_str(), ios::app | ios::out);
107 
108  if (logFile_.bad()) {
109  throw cms::Exception("FileOpen") << "Failed to open file " << logFileName_ << " for logging.\n";
110  }
111 
112  inputRawCollectionToken_ = consumes<FEDRawDataCollection>(params.getParameter<InputTag>("inputRawCollection"));
113 
114  if (produceDigis_) {
115  if (verbosity_ > 0)
116  cout << "[Matacq " << now()
117  << "] registering new "
118  "EcalMatacqDigiCollection product with instance name '"
119  << digiInstanceName_ << "'\n";
120  produces<EcalMatacqDigiCollection>(digiInstanceName_);
121  }
122 
123  if (produceRaw_) {
124  if (verbosity_ > 0)
125  cout << "[Matacq " << now()
126  << "] registering new FEDRawDataCollection "
127  "product with instance name '"
128  << rawInstanceName_ << "'\n";
129  produces<FEDRawDataCollection>(rawInstanceName_);
130  }
131 
132  startTime_.tv_sec = startTime_.tv_usec = 0;
133  if (!orbitOffsetFile_.empty()) {
134  doOrbitOffset_ = true;
135  loadOrbitOffset();
136  } else {
137  doOrbitOffset_ = false;
138  }
139  if (verbosity_ >= 4)
140  cout << "[Matacq " << now() << "] exiting MatacqProducer ctor" << endl;
141 }

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

◆ ~MatacqProducer()

MatacqProducer::~MatacqProducer ( )
override

Destructor

Definition at line 821 of file MatacqProducer.cc.

821  {
822  mclose();
823  timeval t;
824  gettimeofday(&t, nullptr);
825  if (logTiming_ && startTime_.tv_sec != 0) {
826  //not using logger, to allow timing with different logging options
827  cout << "[Matacq " << now()
828  << "] Time elapsed between first event and "
829  "destruction of MatacqProducer: "
830  << ((t.tv_sec - startTime_.tv_sec) * 1. + (t.tv_usec - startTime_.tv_usec) * 1.e-6) << "s\n";
831  }
832 }

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

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 174 of file MatacqProducer.cc.

174  {
176  event.getByToken(inputRawCollectionToken_, sourceColl);
177 
178  std::unique_ptr<FEDRawDataCollection> rawColl;
179  if (produceRaw_) {
180  if (mergeRaw_) {
181  rawColl = std::make_unique<FEDRawDataCollection>(*sourceColl);
182  } else {
183  rawColl = std::make_unique<FEDRawDataCollection>();
184  }
185  }
186 
187  auto digiColl = std::make_unique<EcalMatacqDigiCollection>();
188 
189  if (eventSkipCounter_ == 0) {
190  if (sourceColl->FEDData(matacqFedId_).size() > 4 && !produceRaw_) {
191  //input raw data collection already contains matacqData
193  } else {
194  bool isLaserEvent = (getCalibTriggerType(event) == laserType);
195 
196  // cout << "---> " << (ignoreTriggerType_?"yes":"no") << " " << getCalibTriggerType(event) << endl;
197 
198  if (isLaserEvent || ignoreTriggerType_) {
199  const uint32_t runNumber = getRunNumber(event);
200  const uint32_t orbitId = getOrbitId(event);
201 
202  LogInfo("Matacq") << "Run " << runNumber << "\t Orbit " << orbitId << "\n";
203 
204  bool fileChange;
205  if (doOrbitOffset_) {
206  map<uint32_t, uint32_t>::iterator it = orbitOffset_.find(runNumber);
207  if (it == orbitOffset_.end()) {
208  LogWarning("Matacq") << "Orbit offset not found for run " << runNumber
209  << ". No orbit correction will be applied.";
210  }
211  }
212 
213  if (getMatacqFile(runNumber, orbitId, &fileChange)) {
214  //matacq file retrieval succeeded
215  LogInfo("Matacq") << "Matacq data file found for "
216  << "run " << runNumber << " orbit " << orbitId;
217  if (getMatacqEvent(runNumber, orbitId, fileChange)) {
218  if (produceDigis_) {
220  }
221  if (produceRaw_) {
222  uint32_t dataLen64 = matacq_.getParsedLen();
223  if (dataLen64 > bufferSize * 8 || matacq_.getDccLen() != dataLen64) {
224  LogWarning("Matacq") << " Error in Matacq event fragment length! "
225  << "DCC len: " << matacq_.getDccLen()
226  << "*8 Bytes, Parsed len: " << matacq_.getParsedLen() << "*8 Bytes. "
227  << "Matacq data will not be included for this event.\n";
228  } else {
229  rawColl->FEDData(matacqFedId_).resize(dataLen64 * 8);
230  copy(data_.begin(), data_.begin() + dataLen64 * 8, rawColl->FEDData(matacqFedId_).data());
231  }
232  }
233  LogInfo("Matacq") << "Associating matacq data with orbit id " << matacq_.getOrbitId()
234  << " to dcc event with orbit id " << orbitId << std::endl;
235  if (isLaserEvent) {
237  } else {
239  }
240  } else {
241  if (isLaserEvent) {
242  LogWarning("Matacq") << "No matacq data found for laser event "
243  << "of run " << runNumber << " orbit " << orbitId;
244  }
245  }
246  } else {
247  LogWarning("Matacq") << "No matacq file found for event " << event.id();
248  }
249  }
250  }
251  if (eventSkipCounter_ > 0) { //error occured for this events
252  // and some events will be skipped following
253  // to this error.
254  LogInfo("Matacq") << " [" << now() << "] " << eventSkipCounter_
255  << " next events will be skipped, following to an "
256  << "error on the last processed event, "
257  << "which is expected to be persistant.";
258  }
259  } else {
261  }
262 
263  if (produceRaw_) {
264  if (verbosity_ > 1)
265  cout << "[Matacq " << now() << "] "
266  << "Adding FEDRawDataCollection collection "
267  << " to event.\n";
268  event.put(std::move(rawColl), rawInstanceName_);
269  }
270 
271  if (produceDigis_) {
272  if (verbosity_ > 1)
273  cout << "[Matacq " << now() << "] "
274  << "Adding EcalMatacqDigiCollection collection "
275  << " to event.\n";
276  event.put(std::move(digiColl), digiInstanceName_);
277  }
278 }

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().

◆ getCalibTriggerType()

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

Definition at line 692 of file MatacqProducer.cc.

692  {
694  ev.getByToken(inputRawCollectionToken_, rawdata);
695  if (!(rawdata.isValid())) {
696  throw cms::Exception("NotFound") << "No FED raw data collection found. ECAL raw data are "
697  "required to retrieve the trigger type";
698  }
699 
701  for (int id = 601; id <= 654; ++id) {
702  if (!FEDNumbering::inRange(id))
703  continue;
704  const FEDRawData& data = rawdata->FEDData(id);
705  const int detailedTrigger32 = 5;
706  if (data.size() >= 4 * (detailedTrigger32 + 1)) {
707  const unsigned char* pTType = data.data() + detailedTrigger32 * 4;
708  int tType = pTType[1] & 0x7;
709  stat.add(tType);
710  }
711  }
712  double p;
713  int tType = stat.result(&p);
714  if (p < 0) {
715  //throw cms::Exception("NotFound") << "No ECAL DCC data found\n";
716  LogWarning("NotFound") << "No ECAL DCC data found\n";
717  tType = -1;
718  }
719  if (p < .8) {
720  //throw cms::Exception("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
721  LogWarning("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
722  tType = -1;
723  }
724  return tType;
725 }

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

Referenced by addMatacqData().

◆ getMatacqEvent()

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

Definition at line 326 of file MatacqProducer.cc.

326  {
327  filepos_t startPos;
328  if (!mtell(startPos))
329  return false;
330 
331  int32_t startOrb = -1;
332  const size_t headerSize = 8 * 8;
333  if (mread((char*)&data_[0], headerSize, "Reading matacq header", true)) {
334  startOrb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
335  if (startOrb < 0)
336  startOrb = 0;
337  } else {
338  if (verbosity_ > 2) {
339  cout << "[Matacq " << now()
340  << "] Failed to read matacq header. Moved to start of "
341  " the file.\n";
342  }
343  mrewind();
344  if (mread((char*)&data_[0], headerSize, "Reading matacq header", true)) {
345  startPos = 0;
346  startOrb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
347  } else {
348  if (verbosity_ > 2)
349  cout << "[Matacq " << now() << "] Looks like matacq file is empty"
350  << "\n";
351  return false;
352  }
353  }
354 
355  if (verbosity_ > 2)
356  cout << "[Matacq " << now() << "] Last read orbit: " << lastOrb_ << " looking for orbit " << orbitId
357  << ". Current file position: " << startPos << " Orbit at current position: " << startOrb << "\n";
358 
359  // f.clear();
360  bool didCoarseMove = false;
361 
362  //FIXME: case where posEtim_.invalid() is false
363  if (!posEstim_.invalid() && (abs(lastOrb_ - orbitId) > fastRetrievalThresh_)) {
364  filepos_t pos = posEstim_.pos(orbitId);
365 
366  // struct stat st;
367  filepos_t fsize = -1;
368  // if(0==stat(inFileName_.c_str(), &st)){
369  if (msize(fsize)) {
370  // const int64_t fsize = st.st_size;
371  if (0 != posEstim_.eventLength() && pos > fsize) {
372  //estimated position is beyong end of file
373  //-> move to beginning of last event:
374  int64_t evtSize = posEstim_.eventLength() * sizeof(uint64_t);
375  pos = ((int64_t)fsize / evtSize - 1) * evtSize;
376  if (verbosity_ > 2) {
377  cout << "[Matacq " << now()
378  << "] Estimated position was beyond end of file. "
379  "Changed to "
380  << pos << "\n";
381  }
382  }
383  } else {
384  LogWarning("Matacq") << "Failed to access file " << inFileName_ << ".";
385  }
386  if (pos >= 0) {
387  if (verbosity_ > 2)
388  cout << "[Matacq " << now() << "] jumping to estimated position " << pos << "\n";
389  mseek(pos, SEEK_SET, "Jumping to estimated event position");
390  if (mread((char*)&data_[0], headerSize, "Reading matacq header", true)) {
391  didCoarseMove = true;
392  } else {
393  //estimated position might have been beyond the end of the file,
394  //try, with original position:
395  didCoarseMove = false;
396  if (!mread((char*)&data_[0], headerSize, "Reading event header", true)) {
397  return false;
398  }
399  }
400  } else {
401  if (verbosity_)
402  cout << "[Matacq " << now()
403  << "] Event orbit outside of orbit range "
404  "of matacq data file events\n";
405  return false;
406  }
407  }
408 
409  int32_t orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
410 
411  if (didCoarseMove) {
412  //autoadjustement of threshold for coarse move:
413  if (abs(orb - orbitId) > fastRetrievalThresh_) {
414  if (verbosity_ > 2)
415  cout << "[Matacq " << now() << "] Fast retrieval threshold increased from " << fastRetrievalThresh_;
416  fastRetrievalThresh_ = 2 * abs(orb - orbitId);
417  if (verbosity_ > 2)
418  cout << " to " << fastRetrievalThresh_ << "\n";
419  }
420 
421  //if coarse move did not improve situation, rolls back:
422  if (startOrb > 0 && (abs(orb - orbitId) > abs(startOrb - orbitId))) {
423  if (verbosity_ > 2)
424  cout << "[Matacq " << now() << "] Estimation (-> orbit " << orb
425  << ") "
426  "was worst than original position (-> orbit "
427  << startOrb << "). Restoring position (" << startPos << ").\n";
428  mseek(startPos, SEEK_SET);
429  mread((char*)&data_[0], headerSize, "Reading event header", true);
430  orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
431  }
432  }
433 
434  bool searchBackward = (orb > orbitId) ? true : false;
435  //BEWARE: len must be signed, because we are using latter in the code (-len)
436  //expression
437  int len = (int)MatacqRawEvent::getDccLen(&data_[0], headerSize);
438 
439  if (len == 0) {
440  cout << "[Matacq " << now() << "] read DCC length is null! Cancels matacq event search "
441  << " and move matacq file pointer to beginning of the file. "
442  << "(" << __FILE__ << ":" << __LINE__ << ")."
443  << "\n";
444  //rewind(f);
445  mrewind();
446  return false;
447  }
448 
449  enum state_t { searching, found, failed } state = searching;
450 
451  while (state == searching) {
452  orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
453  len = (int)MatacqRawEvent::getDccLen(&data_[0], headerSize);
454  uint32_t run = MatacqRawEvent::getRunNum(&data_[0], headerSize);
455  if (verbosity_ > 3) {
456  filepos_t pos = -1;
457  mtell(pos);
458  cout << "[Matacq " << now() << "] Header read at file position " << pos << ": orbit = " << orb
459  << " len = " << len << "x8 Byte"
460  << " run = " << run << "\n";
461  }
462  if ((abs(orb - orbitId) < orbitTolerance_) && (runNumber == 0 || runNumber == run)) {
463  state = found;
464  lastOrb_ = orb;
465  //reads the rest of the event:
466  if ((int)data_.size() < len * 8) {
467  throw cms::Exception("Matacq") << "Buffer overflow";
468  }
469  if (verbosity_ > 2)
470  cout << "[Matacq " << now()
471  << "] Event found. Reading "
472  " matacq event."
473  << "\n";
474  if (!mread((char*)&data_[0], len * 8, "Reading matacq event")) {
475  if (verbosity_ > 2)
476  cout << "[Matacq " << now() << "] Failed to read matacq event."
477  << "\n";
478  state = failed;
479  }
480  matacq_ = MatacqRawEvent((unsigned char*)&data_[0], len * 8);
481  } else {
482  if ((searchBackward && (orb < orbitId)) || (!searchBackward && (orb > orbitId))) { //search ended
483  lastOrb_ = orb;
484  state = failed;
485  if (verbosity_ > 2)
486  cout << "[Matacq " << now() << "] No matacq data found for run " << run << ", orbit ID " << orbitId << "."
487  << "\n";
488  } else {
489  off_t offset = (searchBackward ? -len : len) * 8;
490  lastOrb_ = orb;
491  if (verbosity_ > 3) {
492  cout << "[Matacq " << now() << "] In matacq file, moving " << abs(offset) << " byte "
493  << (offset > 0 ? "forward" : "backward") << ".\n";
494  }
495 
496  if (mseek(offset, SEEK_CUR, (searchBackward ? "Moving to previous event" : "Moving to next event")) &&
497  mread((char*)&data_[0], headerSize, "Reading event header", true)) {
498  } else {
499  if (!searchBackward)
500  mseek(-len * 8, SEEK_CUR, "Moving to start of last complete event");
501  state = failed;
502  }
503  }
504  }
505  }
506 
507  if (state == found) {
508  filepos_t pos = -1;
509  filepos_t fsize = -1;
510  mtell(pos);
511  msize(fsize);
512  if (pos == fsize - 1) { //last byte.
513  if (verbosity_ > 2) {
514  cout << "[Matacq " << now()
515  << "] Event found was at the end of the file. Moving "
516  "stream position to beginning of this event."
517  << "\n";
518  }
519  mseek(-(int)len * 8 - 1, SEEK_CUR, "Moving to beginning of last matacq event");
520  }
521  }
522  return (state == found);
523 }

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().

◆ 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 525 of file MatacqProducer.cc.

525  {
527  uint32_t firstOrb, lastOrb;
528  bool goodRange = getOrbitRange(firstOrb, lastOrb);
529  // if(orbitId < firstOrb || orbitId > lastOrb) continue;
530  if (goodRange && firstOrb <= orbitId && orbitId <= lastOrb) {
531  if (fileChange != nullptr)
532  *fileChange = false;
533  return misOpened();
534  }
535  }
536 
537  if (fileNames_.empty())
538  return false;
539 
540  const string runNumberFormat = "%08d{,_*}";
541  string sRunNumber = fmt::sprintf(runNumberFormat, runNumber);
542  //cout << "Run number string: " << sRunNumber << "\n";
543  bool found = false;
544  string fname;
545  uint32_t maxOrb = 0;
546  //we make two iterations to handle the case where the event is procesed
547  //before the matacq data are available. In such case we would have
548  //orbitId > maxOrb (maxOrb: orbit of last written matacq event)
549  // for(int itry = 0; itry < 2 && (orbitId > maxOrb); ++itry){
550  for (int itry = 0; itry < 1 && (orbitId > maxOrb); ++itry) {
551  if (itry > 0) {
552  int n_sec = 1;
553  std::cout << "[Matacq " << now() << "] Event orbit id (" << orbitId
554  << ") goes "
555  "beyound the range of available one. Waiting for "
556  << n_sec
557  << " seconds in case "
558  "it was not written yet to disk.";
559  sleep(n_sec);
560  }
561 
562  for (unsigned i = 0; i < fileNames_.size() && !found; ++i) {
563  fname = fileNames_[i];
564  boost::algorithm::replace_all(fname, "%run_subdir%", runSubDir(runNumber));
565  boost::algorithm::replace_all(fname, "%run_number%", sRunNumber);
566 
567  glob_t g;
568  int rc = glob(fname.c_str(), GLOB_BRACE, nullptr, &g);
569  if (rc) {
570  if (verbosity_ > 1) {
571  switch (rc) {
572  case GLOB_NOSPACE:
573  std::cout << "[Matacq " << now()
574  << "] Running out of memory while calling glob function to look for matacq file paths\n";
575  break;
576  case GLOB_ABORTED:
577  std::cout << "[Matacq " << now()
578  << "] Read error while calling glob function to look for matacq file paths\n";
579  break;
580  case GLOB_NOMATCH:
581  //ok. No message to report.
582  break;
583  }
584  continue;
585  }
586  } //rc
587  for (unsigned iglob = 0; iglob < g.gl_pathc; ++iglob) {
588  char* thePath = g.gl_pathv[iglob];
589  //FIXME: add sanity check on the path
590  static std::atomic<int> nOpenErrors{0};
591  const int maxOpenErrors = 50;
592  if (!mopen(thePath) && nOpenErrors < maxOpenErrors) {
593  std::cout << "[Matacq " << now() << "] Failed to open file " << thePath;
594  ++nOpenErrors;
595  if (nOpenErrors == maxOpenErrors) {
596  std::cout << nOpenErrors << "This is the " << maxOpenErrors
597  << "th occurence of this error. Report of this error is now disabled.\n";
598  } else {
599  std::cout << "\n";
600  }
601  }
602  uint32_t firstOrb;
603  uint32_t lastOrb;
604  bool goodRange = getOrbitRange(firstOrb, lastOrb);
605  std::cout << "Get orbit range " << (goodRange ? "succeeded" : "failed") << ". Range: " << firstOrb << "..."
606  << lastOrb << "\n";
607  if (goodRange && lastOrb > maxOrb)
608  maxOrb = lastOrb;
609  if (goodRange && firstOrb <= orbitId && orbitId <= lastOrb) {
610  found = true;
611  //continue;
612  fname = thePath;
613  if (verbosity_ > 1)
614  std::cout << "[Matacq " << now() << "] Switching to file " << fname << "\n";
615  break;
616  }
617  } //next iglob
618  globfree(&g);
619  } //next filenames
620  } //next itry
621 
622  if (found) {
623  LogInfo("Matacq") << "Uses matacq data file: '" << fname << "'\n";
624  } else {
625  if (verbosity_ >= 0)
626  cout << "[Matacq " << now()
627  << "] no matacq file found "
628  "for run "
629  << runNumber << ", orbit " << orbitId << "\n";
632  if (fileChange != nullptr)
633  *fileChange = false;
634  return false;
635  }
636 
637  if (found) {
639  lastOrb_ = 0;
640  posEstim_.init(this);
641  if (fileChange != nullptr)
642  *fileChange = true;
643  return true;
644  } else {
645  return false;
646  }
647 }

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().

◆ getOrbitId()

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

Definition at line 651 of file MatacqProducer.cc.

651  {
652  //on CVS HEAD (June 4, 08), class Event has a method orbitNumber()
653  //we could use here. The code would be shorten to:
654  //return ev.orbitNumber();
655  //we have to deal with what we have in current CMSSW releases:
657  ev.getByToken(inputRawCollectionToken_, rawdata);
658  if (!(rawdata.isValid())) {
659  throw cms::Exception("NotFound") << "No FED raw data collection found. ECAL raw data are "
660  "required to retrieve the orbit ID";
661  }
662 
663  int orbit = 0;
664  for (int id = 601; id <= 654; ++id) {
665  if (!FEDNumbering::inRange(id))
666  continue;
667  const FEDRawData& data = rawdata->FEDData(id);
668  const int orbitIdOffset64 = 3;
669  if (data.size() >= 8 * (orbitIdOffset64 + 1)) { //orbit id is in 4th 64-bit word
670  const unsigned char* pOrbit = data.data() + orbitIdOffset64 * 8;
671  int thisOrbit = pOrbit[0] | (pOrbit[1] << 8) | (pOrbit[2] << 16) | (pOrbit[3] << 24);
672  if (orbit != 0 && thisOrbit != 0 && abs(orbit - thisOrbit) > orbitTolerance_) {
673  //throw cms::Exception("EventCorruption")
674  // << "Orbit ID inconsitency in DCC headers";
675  LogWarning("EventCorruption") << "Orbit ID inconsitency in DCC headers";
676  orbit = 0;
677  break;
678  }
679  if (thisOrbit != 0)
680  orbit = thisOrbit;
681  }
682  }
683 
684  if (orbit == 0) {
685  // throw cms::Exception("NotFound")
686  // << "Failed to retrieve orbit ID of event "<< ev.id();
687  LogWarning("NotFound") << "Failed to retrieve orbit ID of event " << ev.id();
688  }
689  return orbit;
690 }

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

Referenced by addMatacqData().

◆ getOrbitRange()

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

Definition at line 1133 of file MatacqProducer.cc.

1133  {
1134  filepos_t pos = -1;
1135  filepos_t fsize = -1;
1136  mtell(pos);
1137  msize(fsize);
1138  const unsigned headerSize = 8 * 8;
1139  unsigned char header[headerSize];
1140  //FIXME: Don't we need here to rewind?
1141  mseek(0);
1142  if (!mread((char*)header, headerSize, nullptr, false))
1143  return false;
1144  firstOrb = MatacqRawEvent::getOrbitId(header, headerSize);
1145  int len = (int)MatacqRawEvent::getDccLen(header, headerSize);
1146  //number of complete events. If last event is partially written,
1147  //it won't be included in the count.
1148  unsigned nEvts = fsize / (len * 8);
1149  //Position of last complete event:
1150  filepos_t lastEvtPos = (filepos_t)(nEvts - 1) * len * 8;
1151  // std::cout << "Move to position : " << lastEvtPos
1152  // << "(" << (nEvts - 1) << "*" << len << "*" << 64 << ")"
1153  //<< "\n";
1154  mseek(lastEvtPos);
1155  filepos_t tmp;
1156  mtell(tmp);
1157  //std::cout << "New position, sizeof(tmp): " << tmp << "," << sizeof(tmp) << "\n";
1158  mread((char*)header, headerSize, nullptr, false);
1159  lastOrb = MatacqRawEvent::getOrbitId(header, headerSize);
1160 
1161  //restore file position:
1162  mseek(pos);
1163 
1164  return true;
1165 }

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

Referenced by getMatacqFile().

◆ getRunNumber()

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

Definition at line 649 of file MatacqProducer.cc.

649 { return ev.run(); }

References ev.

Referenced by addMatacqData(), and produce().

◆ loadOrbitOffset()

void MatacqProducer::loadOrbitOffset ( )
private

Loading orbit correction table from file.

See also
orbitOffsetFile_

Definition at line 834 of file MatacqProducer.cc.

834  {
835  std::ifstream f(orbitOffsetFile_.c_str());
836  if (f.bad()) {
837  throw cms::Exception("Matacq") << "Failed to open orbit ID correction file '" << orbitOffsetFile_ << "'\n";
838  }
839 
840  cout << "[Matacq " << now() << "] "
841  << "Offset to substract to Matacq events Orbit ID: \n"
842  << "#Run Number\t Offset\n";
843 
844  int iline = 0;
845  string s;
846  stringstream buf;
847  while (f.eof()) {
848  getline(f, s);
849  ++iline;
850  if (s[0] == '#') { //comment
851  //skip line:
852  f.ignore(numeric_limits<streamsize>::max(), '\n');
853  continue;
854  }
855  buf.str("");
856  buf << s;
857  int run;
858  int orbit;
859  buf >> run;
860  buf >> orbit;
861  if (buf.bad()) {
862  throw cms::Exception("Matacq") << "Syntax error in Orbit offset file '" << orbitOffsetFile_ << "'";
863  }
864  cout << run << "\t" << orbit << "\n";
865  orbitOffset_.insert(pair<int, int>(run, orbit));
866  }
867 }

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

Referenced by MatacqProducer().

◆ mcheck()

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

Definition at line 1070 of file MatacqProducer.cc.

1070  {
1071  struct stat dummy;
1072  return 0 == stat(name.c_str(), &dummy);
1073  // if(stat(name.c_str(), &dummy)==0){
1074  // return true;
1075  // } else{
1076  // cout << "[Matacq " << now() << "] Failed to stat file '"
1077  // << name.c_str() << "'. "
1078  // << "Error " << errno << ": " << strerror(errno) << "\n";
1079  // return false;
1080  // }
1081 }

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

◆ mclose()

void MatacqProducer::mclose ( )
private

Definition at line 1096 of file MatacqProducer.cc.

1096  {
1097  if (inFile_ != nullptr)
1098  fclose(inFile_);
1099  inFile_ = nullptr;
1100 }

References inFile_.

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

◆ meof()

bool MatacqProducer::meof ( )
private

Definition at line 1104 of file MatacqProducer.cc.

1104  {
1105  if (nullptr == inFile_)
1106  return true;
1107  return feof(inFile_) == 0;
1108 }

References inFile_.

◆ misOpened()

bool MatacqProducer::misOpened ( )
private

Definition at line 1102 of file MatacqProducer.cc.

1102 { return inFile_ != nullptr; }

References inFile_.

Referenced by getMatacqFile().

◆ mopen()

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

Definition at line 1083 of file MatacqProducer.cc.

1083  {
1084  if (inFile_ != nullptr)
1085  mclose();
1086  inFile_ = fopen(name.c_str(), "r");
1087  if (inFile_ != nullptr) {
1088  inFileName_ = name;
1089  return true;
1090  } else {
1091  inFileName_ = "";
1092  return false;
1093  }
1094 }

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

Referenced by getMatacqFile().

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

1019  {
1020  if (nullptr == inFile_)
1021  return false;
1022  off_t pos = ftello(inFile_);
1023  bool rc = (pos != -1) && (1 == fread(buf, n, 1, inFile_));
1024  if (!rc) {
1025  if (verbosity_) {
1026  cout << "[Matacq " << now() << "] ";
1027  if (mess)
1028  cout << mess << ". ";
1029  cout << "Read failure from input matacq file.\n";
1030  }
1031  clearerr(inFile_);
1032  }
1033  if (peek || !rc) { //need to restore file position
1034  if (0 != fseeko(inFile_, pos, SEEK_SET)) {
1035  if (verbosity_) {
1036  cout << "[Matacq " << now() << "] ";
1037  if (mess)
1038  cout << mess << ". ";
1039  cout << "Failed to restore file position of "
1040  "before read error. Rewind file.\n";
1041  }
1042  //rewind(inFile_.get());
1043  mrewind();
1044  lastOrb_ = 0;
1045  }
1046  }
1047  return rc;
1048 }

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

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

◆ mrewind()

bool MatacqProducer::mrewind ( )
private

Definition at line 1063 of file MatacqProducer.cc.

1063  {
1064  if (nullptr == inFile_)
1065  return false;
1066  clearerr(inFile_);
1067  return fseeko(inFile_, 0, SEEK_SET) != 0;
1068 }

References inFile_.

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

◆ 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 997 of file MatacqProducer.cc.

997  {
998  if (nullptr == inFile_)
999  return false;
1000  const int rc = fseeko(inFile_, offset, whence);
1001  if (rc != 0 && verbosity_) {
1002  cout << "[Matacq " << now() << "] ";
1003  if (mess)
1004  cout << mess << ". ";
1005  cout << "Random access error on input matacq file. "
1006  "Rewind file.\n";
1007  mrewind();
1008  }
1009  return rc == 0;
1010 }

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

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

◆ msize()

bool MatacqProducer::msize ( filepos_t s)
private

Definition at line 1050 of file MatacqProducer.cc.

1050  {
1051  if (nullptr == inFile_)
1052  return false;
1053  struct stat buf;
1054  if (0 != fstat(fileno(inFile_), &buf)) {
1055  s = 0;
1056  return false;
1057  } else {
1058  s = buf.st_size;
1059  return true;
1060  }
1061 }

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

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

◆ mtell()

bool MatacqProducer::mtell ( filepos_t pos)
private

Definition at line 1012 of file MatacqProducer.cc.

1012  {
1013  if (nullptr == inFile_)
1014  return false;
1015  pos = ftello(inFile_);
1016  return pos != -1;
1017 }

References inFile_.

Referenced by getMatacqEvent(), and getOrbitRange().

◆ newRun()

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

Definition at line 1119 of file MatacqProducer.cc.

1119  {
1120  runNumber_ = newRun;
1121  eventSkipCounter_ = 0;
1122  logFile_ << "[" << now() << "] Event count for run " << runNumber_ << ": "
1123  << "total: " << stats_.nEvents << ", "
1124  << "Laser event with Matacq data: " << stats_.nLaserEventsWithMatacq << ", "
1125  << "Non laser event (according to DCC header) with Matacq data: " << stats_.nNonLaserEventsWithMatacq << "\n"
1126  << flush;
1127 
1128  stats_.nEvents = 0;
1131 }

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

Referenced by produce().

◆ 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 143 of file MatacqProducer.cc.

143  {
144  if (verbosity_ >= 4)
145  cout << "[Matacq " << now() << "] in MatacqProducer::produce" << endl;
146  if (logTiming_) {
147  timeval t;
148  gettimeofday(&t, nullptr);
149 
150  timeLog_ << t.tv_sec << "." << setfill('0') << setw(3) << (t.tv_usec + 500) / 1000 << setfill(' ') << "\t"
151  << (t.tv_usec - timer_.tv_usec) * 1. + (t.tv_sec - timer_.tv_sec) * 1.e6 << "\t";
152  timer_ = t;
153  }
154 
155  if (startTime_.tv_sec == 0)
156  gettimeofday(&startTime_, nullptr);
157  ++stats_.nEvents;
158  if (disabled_)
159  return;
160  const uint32_t runNumber = getRunNumber(event);
161  if (runNumber != runNumber_) {
163  }
165 
166  if (logTiming_) {
167  timeval t;
168  gettimeofday(&t, nullptr);
169  timeLog_ << (t.tv_usec - timer_.tv_usec) * 1. + (t.tv_sec - timer_.tv_sec) * 1.e6 << "\n";
170  timer_ = t;
171  }
172 }

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_.

◆ runSubDir()

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

Definition at line 1112 of file MatacqProducer.cc.

1112  {
1113  int millions = runNumber / (1000 * 1000);
1114  int thousands = (runNumber - millions * 1000 * 1000) / 1000;
1115  int units = runNumber - millions * 1000 * 1000 - thousands * 1000;
1116  return fmt::sprintf("%03d/%03d/%03d", millions, thousands, units);
1117 }

References convertSQLiteXML::runNumber, and units().

Referenced by getMatacqFile().

Member Data Documentation

◆ bufferSize

const int MatacqProducer::bufferSize = 30000
staticprivate

Definition at line 243 of file MatacqProducer.h.

Referenced by addMatacqData().

◆ data_

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

Definition at line 245 of file MatacqProducer.h.

Referenced by addMatacqData(), and getMatacqEvent().

◆ digiInstanceName_

std::string MatacqProducer::digiInstanceName_
private

Instance name to use for the produced Matacq digi collection

Definition at line 192 of file MatacqProducer.h.

Referenced by addMatacqData(), and MatacqProducer().

◆ disabled_

bool MatacqProducer::disabled_
private

Parameter to disable matacq data production. For timing purpose.

Definition at line 204 of file MatacqProducer.h.

Referenced by produce().

◆ doOrbitOffset_

bool MatacqProducer::doOrbitOffset_
private

Switch for orbit ID correction.

See also
orbitOffsetFile_

Definition at line 268 of file MatacqProducer.h.

Referenced by addMatacqData(), and MatacqProducer().

◆ eventSkipCounter_

int MatacqProducer::eventSkipCounter_
private

counter for event skipping

Definition at line 293 of file MatacqProducer.h.

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

◆ fastRetrievalThresh_

int MatacqProducer::fastRetrievalThresh_
private

Definition at line 250 of file MatacqProducer.h.

Referenced by getMatacqEvent().

◆ fileNames_

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

Definition at line 188 of file MatacqProducer.h.

Referenced by getMatacqFile().

◆ formatter_

MatacqDataFormatter MatacqProducer::formatter_
private

Definition at line 246 of file MatacqProducer.h.

Referenced by addMatacqData().

◆ ignoreTriggerType_

bool MatacqProducer::ignoreTriggerType_
private

When true look for matacq data independently of trigger type.

Definition at line 235 of file MatacqProducer.h.

Referenced by addMatacqData().

◆ inFile_

FILE_t MatacqProducer::inFile_
private

Stream of currently opened matacq file

Definition at line 241 of file MatacqProducer.h.

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 272 of file MatacqProducer.h.

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 221 of file MatacqProducer.h.

◆ 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 226 of file MatacqProducer.h.

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

◆ lastOrb_

int32_t MatacqProducer::lastOrb_
private

Definition at line 249 of file MatacqProducer.h.

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

◆ logFile_

std::ofstream MatacqProducer::logFile_
private

Log file

Definition at line 289 of file MatacqProducer.h.

Referenced by MatacqProducer(), and newRun().

◆ logFileName_

std::string MatacqProducer::logFileName_
private

Log file name

Definition at line 285 of file MatacqProducer.h.

Referenced by MatacqProducer().

◆ logTiming_

bool MatacqProducer::logTiming_
private

Switch for code timing.

Definition at line 312 of file MatacqProducer.h.

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

◆ matacq_

MatacqRawEvent MatacqProducer::matacq_
private

Definition at line 237 of file MatacqProducer.h.

Referenced by addMatacqData(), and getMatacqEvent().

◆ matacqFedId_

const int MatacqProducer::matacqFedId_ = 655
staticprivate

Definition at line 274 of file MatacqProducer.h.

Referenced by addMatacqData().

◆ mergeRaw_

bool MatacqProducer::mergeRaw_
private

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

Definition at line 231 of file MatacqProducer.h.

Referenced by addMatacqData().

◆ onErrorDisablingEvtCnt_

int MatacqProducer::onErrorDisablingEvtCnt_
private

Number of events to skip in case of error

Definition at line 297 of file MatacqProducer.h.

Referenced by getMatacqFile().

◆ openedFileRunNumber_

uint32_t MatacqProducer::openedFileRunNumber_
private

Definition at line 248 of file MatacqProducer.h.

Referenced by getMatacqFile().

◆ orbitOffset_

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

Orbit offset table.

See also
orbitOffsetFile_

Definition at line 264 of file MatacqProducer.h.

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 260 of file MatacqProducer.h.

Referenced by loadOrbitOffset(), and MatacqProducer().

◆ orbitTolerance_

const int MatacqProducer::orbitTolerance_ = 80
staticprivate

Definition at line 247 of file MatacqProducer.h.

Referenced by getMatacqEvent(), and getOrbitId().

◆ posEstim_

PosEstimator MatacqProducer::posEstim_
private

Definition at line 252 of file MatacqProducer.h.

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

◆ produceDigis_

bool MatacqProducer::produceDigis_
private

Swictch for Matacq digi producion

Definition at line 212 of file MatacqProducer.h.

Referenced by addMatacqData(), and MatacqProducer().

◆ produceRaw_

bool MatacqProducer::produceRaw_
private

Switch for Matacq FED raw data production

Definition at line 216 of file MatacqProducer.h.

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 196 of file MatacqProducer.h.

Referenced by addMatacqData(), and MatacqProducer().

◆ runNumber_

uint32_t MatacqProducer::runNumber_
private

Number of the currently processed run

Definition at line 316 of file MatacqProducer.h.

Referenced by newRun(), and produce().

◆ startTime_

timeval MatacqProducer::startTime_
private

Definition at line 254 of file MatacqProducer.h.

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 282 of file MatacqProducer.h.

◆ timeLog_

std::ofstream MatacqProducer::timeLog_
private

Output stream to log code timing

Definition at line 308 of file MatacqProducer.h.

Referenced by MatacqProducer(), and produce().

◆ timeLogFile_

std::string MatacqProducer::timeLogFile_
private

Name of file to log timing

Definition at line 301 of file MatacqProducer.h.

Referenced by MatacqProducer().

◆ timer_

timeval MatacqProducer::timer_
private

Buffer for timing

Definition at line 304 of file MatacqProducer.h.

Referenced by MatacqProducer(), and produce().

◆ timing_

bool MatacqProducer::timing_
private

Parameter to switch module timing.

Definition at line 200 of file MatacqProducer.h.

◆ verbosity_

int MatacqProducer::verbosity_
private
MatacqDataFormatter::interpretRawData
void interpretRawData(const FEDRawData &data, EcalMatacqDigiCollection &matacqDigiCollection)
Definition: MatacqDataFormatter.cc:19
MatacqProducer::inFile_
FILE_t inFile_
Definition: MatacqProducer.h:241
MatacqRawEvent::getParsedLen
int getParsedLen()
Definition: MatacqRawEvent.h:286
DigiToRawDM_cff.digiColl
digiColl
Definition: DigiToRawDM_cff.py:32
MatacqProducer::inputRawCollectionToken_
edm::EDGetTokenT< FEDRawDataCollection > inputRawCollectionToken_
Definition: MatacqProducer.h:226
MatacqProducer::getOrbitId
uint32_t getOrbitId(edm::Event &ev) const
Definition: MatacqProducer.cc:651
mps_fire.i
i
Definition: mps_fire.py:428
MatacqProducer::verbosity_
int verbosity_
Definition: MatacqProducer.h:208
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
MatacqProducer::runNumber_
uint32_t runNumber_
Definition: MatacqProducer.h:316
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
MatacqProducer::stats_
struct MatacqProducer::stats_t stats_
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
MatacqProducer::inFileName_
std::string inFileName_
Definition: MatacqProducer.h:272
MatacqProducer::getMatacqEvent
bool getMatacqEvent(uint32_t runNumber, int32_t orbitId, bool fileChange)
Definition: MatacqProducer.cc:326
MatacqProducer::orbitOffset_
std::map< uint32_t, uint32_t > orbitOffset_
Definition: MatacqProducer.h:264
MatacqProducer::stats_init
const static stats_t stats_init
Definition: MatacqProducer.h:282
CalibrationSummaryClient_cfi.params
params
Definition: CalibrationSummaryClient_cfi.py:14
MatacqProducer::misOpened
bool misOpened()
Definition: MatacqProducer.cc:1102
MatacqProducer::filepos_t
off_t filepos_t
Definition: MatacqProducer.h:50
gather_cfg.cout
cout
Definition: gather_cfg.py:144
pos
Definition: PixelAliasList.h:18
MatacqProducer::timeLogFile_
std::string timeLogFile_
Definition: MatacqProducer.h:301
runEdmFileComparison.failed
failed
Definition: runEdmFileComparison.py:224
MatacqProducer::mread
bool mread(char *buf, size_t n, const char *mess=nullptr, bool peek=false)
Definition: MatacqProducer.cc:1019
MatacqProducer::rawInstanceName_
std::string rawInstanceName_
Definition: MatacqProducer.h:196
MatacqProducer::timing_
bool timing_
Definition: MatacqProducer.h:200
MatacqProducer::laserType
Definition: MatacqProducer.h:43
MatacqProducer::getMatacqFile
bool getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool *fileChange=nullptr)
Definition: MatacqProducer.cc:525
MatacqProducer::matacq_
MatacqRawEvent matacq_
Definition: MatacqProducer.h:237
MatacqProducer::PosEstimator::invalid
bool invalid() const
Definition: MatacqProducer.h:89
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
MatacqProducer::mtell
bool mtell(filepos_t &pos)
Definition: MatacqProducer.cc:1012
MatacqProducer::formatter_
MatacqDataFormatter formatter_
Definition: MatacqProducer.h:246
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
MatacqRawEvent::getOrbitId
static unsigned getOrbitId(unsigned char *data, size_t size)
Definition: MatacqRawEvent.h:216
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle< FEDRawDataCollection >
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
MatacqRawEvent::getRunNum
unsigned getRunNum() const
Definition: MatacqRawEvent.h:247
FEDRawData
Definition: FEDRawData.h:19
convertSQLiteXML.runNumber
runNumber
Definition: convertSQLiteXML.py:91
MatacqProducer::PosEstimator::init
void init(MatacqProducer *mp)
Definition: MatacqProducer.cc:727
units
TString units(TString variable, Char_t axis)
MatacqProducer::orbitTolerance_
const static int orbitTolerance_
Definition: MatacqProducer.h:247
MatacqProducer::logFile_
std::ofstream logFile_
Definition: MatacqProducer.h:289
alignCSCRings.s
s
Definition: alignCSCRings.py:92
MatacqProducer::openedFileRunNumber_
uint32_t openedFileRunNumber_
Definition: MatacqProducer.h:248
nEvts
const int nEvts
Definition: recycleTccEmu.cc:12
MatacqRawEvent::getDccLen
unsigned getDccLen() const
Definition: MatacqRawEvent.h:195
MatacqProducer::pedType
Definition: MatacqProducer.h:43
MatacqProducer::getOrbitRange
bool getOrbitRange(uint32_t &firstOrb, uint32_t &lastOrb)
Definition: MatacqProducer.cc:1133
MatacqProducer::posEstim_
PosEstimator posEstim_
Definition: MatacqProducer.h:252
MatacqProducer::logFileName_
std::string logFileName_
Definition: MatacqProducer.h:285
MatacqProducer::ignoreTriggerType_
bool ignoreTriggerType_
Definition: MatacqProducer.h:235
now
static std::string now()
Definition: MatacqProducer.cc:48
MatacqProducer::logTiming_
bool logTiming_
Definition: MatacqProducer.h:312
MatacqRawEvent
Definition: MatacqRawEvent.h:30
FEDRawDataCollection::FEDData
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
Definition: FEDRawDataCollection.cc:19
MatacqProducer::timer_
timeval timer_
Definition: MatacqProducer.h:304
MatacqProducer::tpType
Definition: MatacqProducer.h:43
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
MatacqProducer::stats_t::nEvents
double nEvents
Definition: MatacqProducer.h:277
MatacqProducer::produceRaw_
bool produceRaw_
Definition: MatacqProducer.h:216
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
MatacqProducer::lastOrb_
int32_t lastOrb_
Definition: MatacqProducer.h:249
MatacqProducer::fileNames_
std::vector< std::string > fileNames_
Definition: MatacqProducer.h:188
MatacqProducer::fastRetrievalThresh_
int fastRetrievalThresh_
Definition: MatacqProducer.h:250
MatacqProducer::produceDigis_
bool produceDigis_
Definition: MatacqProducer.h:212
MatacqProducer::disabled_
bool disabled_
Definition: MatacqProducer.h:204
MatacqProducer::orbitOffsetFile_
std::string orbitOffsetFile_
Definition: MatacqProducer.h:260
MatacqProducer::runSubDir
static std::string runSubDir(uint32_t runNumber)
Definition: MatacqProducer.cc:1112
createfilelist.int
int
Definition: createfilelist.py:10
MatacqProducer::onErrorDisablingEvtCnt_
int onErrorDisablingEvtCnt_
Definition: MatacqProducer.h:297
FEDNumbering::inRange
static bool inRange(int)
Definition: FEDNumbering.cc:106
ntuplemaker.iline
iline
Definition: ntuplemaker.py:186
MatacqProducer::PosEstimator::eventLength
int eventLength() const
Definition: MatacqProducer.h:91
MatacqProducer::eventSkipCounter_
int eventSkipCounter_
Definition: MatacqProducer.h:293
MatacqProducer::getRunNumber
uint32_t getRunNumber(edm::Event &ev) const
Definition: MatacqProducer.cc:649
MatacqProducer::PosEstimator::verbosity
void verbosity(int verb)
Definition: MatacqProducer.h:93
MatacqProducer::loadOrbitOffset
void loadOrbitOffset()
Definition: MatacqProducer.cc:834
MatacqProducer::data_
std::vector< unsigned char > data_
Definition: MatacqProducer.h:245
MatacqProducer::matacqFedId_
static const int matacqFedId_
Definition: MatacqProducer.h:274
MatacqProducer::mrewind
bool mrewind()
Definition: MatacqProducer.cc:1063
visDQMUpload.buf
buf
Definition: visDQMUpload.py:160
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FEDRawData::size
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
MatacqProducer::doOrbitOffset_
bool doOrbitOffset_
Definition: MatacqProducer.h:268
MatacqProducer::newRun
void newRun(int prevRun, int newRun)
Definition: MatacqProducer.cc:1119
MatacqProducer::ledType
Definition: MatacqProducer.h:43
MatacqProducer::mergeRaw_
bool mergeRaw_
Definition: MatacqProducer.h:231
MatacqProducer::stats_t::nNonLaserEventsWithMatacq
double nNonLaserEventsWithMatacq
Definition: MatacqProducer.h:279
MatacqProducer::addMatacqData
void addMatacqData(edm::Event &event)
Definition: MatacqProducer.cc:174
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
eostools.move
def move(src, dest)
Definition: eostools.py:511
writedatasetfile.run
run
Definition: writedatasetfile.py:27
RunInfoPI::state
state
Definition: RunInfoPayloadInspectoHelper.h:16
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
MatacqProducer::stats_t::nLaserEventsWithMatacq
double nLaserEventsWithMatacq
Definition: MatacqProducer.h:278
MatacqProducer::PosEstimator::pos
int64_t pos(int orb) const
Definition: MatacqProducer.cc:812
ev
bool ev
Definition: Hydjet2Hadronizer.cc:97
Exception
Definition: hltDiff.cc:245
MatacqRawEvent::getOrbitId
uint32_t getOrbitId() const
Definition: MatacqRawEvent.h:312
MatacqProducer::mseek
bool mseek(filepos_t offset, int whence=SEEK_SET, const char *mess=nullptr)
Definition: MatacqProducer.cc:997
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
MatacqProducer::timeLog_
std::ofstream timeLog_
Definition: MatacqProducer.h:308
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
RecoTauValidation_cfi.header
header
Definition: RecoTauValidation_cfi.py:291
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
MatacqProducer::inputRawCollection_
edm::InputTag inputRawCollection_
Definition: MatacqProducer.h:221
MatacqProducer::startTime_
timeval startTime_
Definition: MatacqProducer.h:254
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
dummy
Definition: DummySelector.h:38
MatacqProducer::mopen
bool mopen(const std::string &name)
Definition: MatacqProducer.cc:1083
MatacqProducer::mclose
void mclose()
Definition: MatacqProducer.cc:1096
edm_modernize_messagelogger.stat
stat
Definition: edm_modernize_messagelogger.py:27
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
event
Definition: event.py:1
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
MatacqProducer::msize
bool msize(filepos_t &s)
Definition: MatacqProducer.cc:1050
edm::InputTag
Definition: InputTag.h:15
Majority
Definition: Majority.h:12
g
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
MatacqProducer::bufferSize
static const int bufferSize
Definition: MatacqProducer.h:243
MatacqProducer::getCalibTriggerType
int getCalibTriggerType(edm::Event &ev) const
Definition: MatacqProducer.cc:692
MatacqProducer::digiInstanceName_
std::string digiInstanceName_
Definition: MatacqProducer.h:192