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
 
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)
 
 ~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
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Types

typedef 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=0)
 
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=0, bool peek=false)
 
bool mrewind ()
 
bool mseek (filepos_t offset, int whence=SEEK_SET, const char *mess=0)
 
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 wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::ProducerBase
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Definition at line 41 of file MatacqProducer.h.

Member Typedef Documentation

typedef FILE* MatacqProducer::FILE_t
private

Definition at line 51 of file MatacqProducer.h.

typedef off_t MatacqProducer::filepos_t
private

Definition at line 50 of file MatacqProducer.h.

Member Enumeration Documentation

Enumerator
laserType 
ledType 
tpType 
pedType 

Definition at line 43 of file MatacqProducer.h.

Constructor & Destructor Documentation

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

Constructor

Parameters
paramsseletive readout parameters

Definition at line 64 of file MatacqProducer.cc.

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

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

Destructor

Definition at line 815 of file MatacqProducer.cc.

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

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

Member Function Documentation

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

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

Definition at line 691 of file MatacqProducer.cc.

References Majority< T >::add(), FEDRawData::data(), data, Exception, FEDRawDataCollection::FEDData(), edm::Event::getByToken(), triggerObjects_cff::id, inputRawCollectionToken_, FEDNumbering::inRange(), edm::HandleBase::isValid(), AlCaHLTBitMon_ParallelJobs::p, Majority< T >::result(), FEDRawData::size(), and hgcalPlots::stat.

Referenced by addMatacqData().

691  {
694  if (!(rawdata.isValid())) {
695  throw cms::Exception("NotFound") << "No FED raw data collection found. ECAL raw data are "
696  "required to retrieve the trigger type";
697  }
698 
700  for (int id = 601; id <= 654; ++id) {
701  if (!FEDNumbering::inRange(id))
702  continue;
703  const FEDRawData& data = rawdata->FEDData(id);
704  const int detailedTrigger32 = 5;
705  if (data.size() >= 4 * (detailedTrigger32 + 1)) {
706  const unsigned char* pTType = data.data() + detailedTrigger32 * 4;
707  int tType = pTType[1] & 0x7;
708  stat.add(tType);
709  }
710  }
711  double p;
712  int tType = stat.result(&p);
713  if (p < 0) {
714  //throw cms::Exception("NotFound") << "No ECAL DCC data found\n";
715  LogWarning("NotFound") << "No ECAL DCC data found\n";
716  tType = -1;
717  }
718  if (p < .8) {
719  //throw cms::Exception("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
720  LogWarning("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
721  tType = -1;
722  }
723  return tType;
724 }
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
void add(const T &value)
Definition: Majority.h:23
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
edm::EDGetTokenT< FEDRawDataCollection > inputRawCollectionToken_
bool isValid() const
Definition: HandleBase.h:70
static bool inRange(int)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
T result(double *proba) const
Definition: Majority.h:28
bool MatacqProducer::getMatacqEvent ( uint32_t  runNumber,
int32_t  orbitId,
bool  fileChange 
)
private

Definition at line 328 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, and verbosity_.

Referenced by addMatacqData().

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

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

Referenced by addMatacqData().

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

Definition at line 650 of file MatacqProducer.cc.

References funct::abs(), FEDRawData::data(), data, Exception, FEDRawDataCollection::FEDData(), edm::Event::getByToken(), triggerObjects_cff::id, edm::EventBase::id(), inputRawCollectionToken_, FEDNumbering::inRange(), edm::HandleBase::isValid(), orbitTolerance_, and FEDRawData::size().

Referenced by addMatacqData().

650  {
651  //on CVS HEAD (June 4, 08), class Event has a method orbitNumber()
652  //we could use here. The code would be shorten to:
653  //return ev.orbitNumber();
654  //we have to deal with what we have in current CMSSW releases:
657  if (!(rawdata.isValid())) {
658  throw cms::Exception("NotFound") << "No FED raw data collection found. ECAL raw data are "
659  "required to retrieve the orbit ID";
660  }
661 
662  int orbit = 0;
663  for (int id = 601; id <= 654; ++id) {
664  if (!FEDNumbering::inRange(id))
665  continue;
666  const FEDRawData& data = rawdata->FEDData(id);
667  const int orbitIdOffset64 = 3;
668  if (data.size() >= 8 * (orbitIdOffset64 + 1)) { //orbit id is in 4th 64-bit word
669  const unsigned char* pOrbit = data.data() + orbitIdOffset64 * 8;
670  int thisOrbit = pOrbit[0] | (pOrbit[1] << 8) | (pOrbit[2] << 16) | (pOrbit[3] << 24);
671  if (orbit != 0 && thisOrbit != 0 && abs(orbit - thisOrbit) > orbitTolerance_) {
672  //throw cms::Exception("EventCorruption")
673  // << "Orbit ID inconsitency in DCC headers";
674  LogWarning("EventCorruption") << "Orbit ID inconsitency in DCC headers";
675  orbit = 0;
676  break;
677  }
678  if (thisOrbit != 0)
679  orbit = thisOrbit;
680  }
681  }
682 
683  if (orbit == 0) {
684  // throw cms::Exception("NotFound")
685  // << "Failed to retrieve orbit ID of event "<< ev.id();
686  LogWarning("NotFound") << "Failed to retrieve orbit ID of event " << ev.id();
687  }
688  return orbit;
689 }
static const int orbitTolerance_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:45
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
edm::EDGetTokenT< FEDRawDataCollection > inputRawCollectionToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool isValid() const
Definition: HandleBase.h:70
static bool inRange(int)
edm::EventID id() const
Definition: EventBase.h:59
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
bool MatacqProducer::getOrbitRange ( uint32_t &  firstOrb,
uint32_t &  lastOrb 
)
private

Definition at line 1127 of file MatacqProducer.cc.

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

Referenced by getMatacqFile().

1127  {
1128  filepos_t pos = -1;
1129  filepos_t fsize = -1;
1130  mtell(pos);
1131  msize(fsize);
1132  const unsigned headerSize = 8 * 8;
1133  unsigned char header[headerSize];
1134  //FIXME: Don't we need here to rewind?
1135  mseek(0);
1136  if (!mread((char*)header, headerSize, nullptr, false))
1137  return false;
1138  firstOrb = MatacqRawEvent::getOrbitId(header, headerSize);
1139  int len = (int)MatacqRawEvent::getDccLen(header, headerSize);
1140  //number of complete events. If last event is partially written,
1141  //it won't be included in the count.
1142  unsigned nEvts = fsize / (len * 64);
1143  //Position of last complete event:
1144  filepos_t lastEvtPos = (nEvts - 1) * len * 64;
1145  mseek(lastEvtPos);
1146  mread((char*)header, headerSize, nullptr, false);
1147  lastOrb = MatacqRawEvent::getOrbitId(header, headerSize);
1148 
1149  //restore file position:
1150  mseek(pos);
1151 
1152  return true;
1153 }
uint32_t getOrbitId() const
unsigned getDccLen() const
bool mread(char *buf, size_t n, const char *mess=0, bool peek=false)
const int nEvts
bool mtell(filepos_t &pos)
bool mseek(filepos_t offset, int whence=SEEK_SET, const char *mess=0)
bool msize(filepos_t &s)
uint32_t MatacqProducer::getRunNumber ( edm::Event ev) const
private

Definition at line 648 of file MatacqProducer.cc.

References edm::Event::run().

Referenced by addMatacqData(), and produce().

648 { return ev.run(); }
RunNumber_t run() const
Definition: Event.h:107
void MatacqProducer::loadOrbitOffset ( )
private

Loading orbit correction table from file.

See also
orbitOffsetFile_

Definition at line 828 of file MatacqProducer.cc.

References StorageFactory::check(), gather_cfg::cout, Storage::CURRENT, MillePedeFileConverter_cfg::e, Storage::END, Exception, f, FrontierConditions_GlobalTag_cff::file, StorageFactory::get(), ntuplemaker::iline, inFile_, inFileName_, SiStripPI::max, mcheck(), mclose(), meof(), misOpened(), mopen(), mread(), mrewind(), mseek(), msize(), mtell(), dqmiodumpmetadata::n, Skims_PA_cff::name, now(), hltrates_dqm_sourceclient-live_cfg::offset, StorageFactory::open(), IOFlags::OpenRead, orbitOffset_, orbitOffsetFile_, Storage::rewind(), writedatasetfile::run, alignCSCRings::s, Storage::SET, AlCaHLTBitMon_QueryRunRegistry::string, verbosity_, and cms::Exception::what().

Referenced by MatacqProducer().

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

Definition at line 1064 of file MatacqProducer.cc.

References hgcalPlots::stat.

Referenced by loadOrbitOffset().

1064  {
1065  struct stat dummy;
1066  return 0 == stat(name.c_str(), &dummy);
1067  // if(stat(name.c_str(), &dummy)==0){
1068  // return true;
1069  // } else{
1070  // cout << "[Matacq " << now() << "] Failed to stat file '"
1071  // << name.c_str() << "'. "
1072  // << "Error " << errno << ": " << strerror(errno) << "\n";
1073  // return false;
1074  // }
1075 }
void MatacqProducer::mclose ( )
private

Definition at line 1090 of file MatacqProducer.cc.

References inFile_.

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

1090  {
1091  if (inFile_ != nullptr)
1092  fclose(inFile_);
1093  inFile_ = nullptr;
1094 }
bool MatacqProducer::meof ( )
private

Definition at line 1098 of file MatacqProducer.cc.

References inFile_.

Referenced by loadOrbitOffset().

1098  {
1099  if (nullptr == inFile_)
1100  return true;
1101  return feof(inFile_) == 0;
1102 }
bool MatacqProducer::misOpened ( )
private

Definition at line 1096 of file MatacqProducer.cc.

References inFile_.

Referenced by getMatacqFile(), and loadOrbitOffset().

1096 { return inFile_ != nullptr; }
bool MatacqProducer::mopen ( const std::string &  name)
private

Definition at line 1077 of file MatacqProducer.cc.

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

Referenced by getMatacqFile(), and loadOrbitOffset().

1077  {
1078  if (inFile_ != nullptr)
1079  mclose();
1080  inFile_ = fopen(name.c_str(), "r");
1081  if (inFile_ != nullptr) {
1082  inFileName_ = name;
1083  return true;
1084  } else {
1085  inFileName_ = "";
1086  return false;
1087  }
1088 }
std::string inFileName_
bool MatacqProducer::mread ( char *  buf,
size_t  n,
const char *  mess = 0,
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 1013 of file MatacqProducer.cc.

References gather_cfg::cout, inFile_, lastOrb_, mrewind(), now(), and verbosity_.

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

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

Definition at line 1057 of file MatacqProducer.cc.

References inFile_.

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

1057  {
1058  if (nullptr == inFile_)
1059  return false;
1060  clearerr(inFile_);
1061  return fseeko(inFile_, 0, SEEK_SET) != 0;
1062 }
bool MatacqProducer::mseek ( filepos_t  offset,
int  whence = SEEK_SET,
const char *  mess = 0 
)
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 991 of file MatacqProducer.cc.

References gather_cfg::cout, inFile_, mrewind(), now(), and verbosity_.

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

991  {
992  if (nullptr == inFile_)
993  return false;
994  const int rc = fseeko(inFile_, offset, whence);
995  if (rc != 0 && verbosity_) {
996  cout << "[Matacq " << now() << "] ";
997  if (mess)
998  cout << mess << ". ";
999  cout << "Random access error on input matacq file. "
1000  "Rewind file.\n";
1001  mrewind();
1002  }
1003  return rc == 0;
1004 }
static std::string now()
bool MatacqProducer::msize ( filepos_t s)
private

Definition at line 1044 of file MatacqProducer.cc.

References inFile_.

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

1044  {
1045  if (nullptr == inFile_)
1046  return false;
1047  struct stat buf;
1048  if (0 != fstat(fileno(inFile_), &buf)) {
1049  s = 0;
1050  return false;
1051  } else {
1052  s = buf.st_size;
1053  return true;
1054  }
1055 }
bool MatacqProducer::mtell ( filepos_t pos)
private

Definition at line 1006 of file MatacqProducer.cc.

References inFile_.

Referenced by getMatacqEvent(), getOrbitRange(), and loadOrbitOffset().

1006  {
1007  if (nullptr == inFile_)
1008  return false;
1009  pos = ftello(inFile_);
1010  return pos != -1;
1011 }
void MatacqProducer::newRun ( int  prevRun,
int  newRun 
)
private

Definition at line 1113 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().

1113  {
1114  runNumber_ = newRun;
1115  eventSkipCounter_ = 0;
1116  logFile_ << "[" << now() << "] Event count for run " << runNumber_ << ": "
1117  << "total: " << stats_.nEvents << ", "
1118  << "Laser event with Matacq data: " << stats_.nLaserEventsWithMatacq << ", "
1119  << "Non laser event (according to DCC header) with Matacq data: " << stats_.nNonLaserEventsWithMatacq << "\n"
1120  << flush;
1121 
1122  stats_.nEvents = 0;
1125 }
uint32_t runNumber_
std::ofstream logFile_
struct MatacqProducer::stats_t stats_
static std::string now()
void newRun(int prevRun, int newRun)
void MatacqProducer::produce ( edm::Event event,
const edm::EventSetup eventSetup 
)
override

Produces the EDM products

Parameters
CMSevent
eventSetupevent conditions

Definition at line 145 of file MatacqProducer.cc.

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

Referenced by JSONExport.JsonExport::export(), HTMLExport.HTMLExport::export(), and HTMLExport.HTMLExportStatic::export().

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

Definition at line 1106 of file MatacqProducer.cc.

References dqm-mbProfile::format, str, and units().

Referenced by getMatacqFile().

1106  {
1107  int millions = runNumber / (1000 * 1000);
1108  int thousands = (runNumber - millions * 1000 * 1000) / 1000;
1109  int units = runNumber - millions * 1000 * 1000 - thousands * 1000;
1110  return str(boost::format("%03d/%03d/%03d") % millions % thousands % units);
1111 }
TString units(TString variable, Char_t axis)
#define str(s)

Member Data Documentation

const int MatacqProducer::bufferSize = 30000
staticprivate

Definition at line 243 of file MatacqProducer.h.

Referenced by addMatacqData().

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

Definition at line 245 of file MatacqProducer.h.

Referenced by addMatacqData(), and getMatacqEvent().

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

bool MatacqProducer::disabled_
private

Parameter to disable matacq data production. For timing purpose.

Definition at line 204 of file MatacqProducer.h.

Referenced by produce().

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

int MatacqProducer::eventSkipCounter_
private

counter for event skipping

Definition at line 293 of file MatacqProducer.h.

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

int MatacqProducer::fastRetrievalThresh_
private

Definition at line 250 of file MatacqProducer.h.

Referenced by getMatacqEvent().

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

Definition at line 188 of file MatacqProducer.h.

Referenced by getMatacqFile().

MatacqDataFormatter MatacqProducer::formatter_
private

Definition at line 246 of file MatacqProducer.h.

Referenced by addMatacqData().

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

FILE_t MatacqProducer::inFile_
private

Stream of currently opened matacq file

Definition at line 241 of file MatacqProducer.h.

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

std::string MatacqProducer::inFileName_
private

Name of currently opened matacq file

Definition at line 272 of file MatacqProducer.h.

Referenced by getMatacqEvent(), loadOrbitOffset(), and mopen().

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.

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

int32_t MatacqProducer::lastOrb_
private

Definition at line 249 of file MatacqProducer.h.

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

std::ofstream MatacqProducer::logFile_
private

Log file

Definition at line 289 of file MatacqProducer.h.

Referenced by MatacqProducer(), and newRun().

std::string MatacqProducer::logFileName_
private

Log file name

Definition at line 285 of file MatacqProducer.h.

Referenced by MatacqProducer().

bool MatacqProducer::logTiming_
private

Switch for code timing.

Definition at line 312 of file MatacqProducer.h.

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

MatacqRawEvent MatacqProducer::matacq_
private

Definition at line 237 of file MatacqProducer.h.

Referenced by addMatacqData(), and getMatacqEvent().

const int MatacqProducer::matacqFedId_ = 655
staticprivate

Definition at line 274 of file MatacqProducer.h.

Referenced by addMatacqData().

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

int MatacqProducer::onErrorDisablingEvtCnt_
private

Number of events to skip in case of error

Definition at line 297 of file MatacqProducer.h.

Referenced by getMatacqFile().

uint32_t MatacqProducer::openedFileRunNumber_
private

Definition at line 248 of file MatacqProducer.h.

Referenced by getMatacqFile().

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

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

const int MatacqProducer::orbitTolerance_ = 80
staticprivate

Definition at line 247 of file MatacqProducer.h.

Referenced by getMatacqEvent(), and getOrbitId().

PosEstimator MatacqProducer::posEstim_
private

Definition at line 252 of file MatacqProducer.h.

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

bool MatacqProducer::produceDigis_
private

Swictch for Matacq digi producion

Definition at line 212 of file MatacqProducer.h.

Referenced by addMatacqData(), and MatacqProducer().

bool MatacqProducer::produceRaw_
private

Switch for Matacq FED raw data production

Definition at line 216 of file MatacqProducer.h.

Referenced by addMatacqData(), and MatacqProducer().

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

uint32_t MatacqProducer::runNumber_
private

Number of the currently processed run

Definition at line 316 of file MatacqProducer.h.

Referenced by newRun(), and produce().

timeval MatacqProducer::startTime_
private

Definition at line 254 of file MatacqProducer.h.

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

struct MatacqProducer::stats_t MatacqProducer::stats_
private

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

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

Definition at line 282 of file MatacqProducer.h.

std::ofstream MatacqProducer::timeLog_
private

Output stream to log code timing

Definition at line 308 of file MatacqProducer.h.

Referenced by MatacqProducer(), and produce().

std::string MatacqProducer::timeLogFile_
private

Name of file to log timing

Definition at line 301 of file MatacqProducer.h.

Referenced by MatacqProducer().

timeval MatacqProducer::timer_
private

Buffer for timing

Definition at line 304 of file MatacqProducer.h.

Referenced by MatacqProducer(), and produce().

bool MatacqProducer::timing_
private

Parameter to switch module timing.

Definition at line 200 of file MatacqProducer.h.

int MatacqProducer::verbosity_
private