CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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::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
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 

Public Member Functions

 MatacqProducer (const edm::ParameterSet &params)
 
virtual void produce (edm::Event &event, const edm::EventSetup &eventSetup)
 
 ~MatacqProducer ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Types

typedef std::auto_ptr< StorageFILE_t
 
typedef IOOffset 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
 
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)
 

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 fastRetrievalThresh_
 
std::vector< std::string > fileNames_
 
MatacqDataFormatter formatter_
 
bool ignoreTriggerType_
 
FILE_t inFile_
 
std::string inFileName_
 
edm::InputTag inputRawCollection_
 
int32_t lastOrb_
 
std::ofstream logFile_
 
std::string logFileName_
 
MatacqRawEvent matacq_
 
bool mergeRaw_
 
uint32_t openedFileRunNumber_
 
std::map< uint32_t, uint32_t > orbitOffset_
 
std::string orbitOffsetFile_
 
PosEstimator posEstim_
 
bool produceDigis_
 
bool produceRaw_
 
std::string rawInstanceName_
 
timeval startTime_
 
struct MatacqProducer::stats_t stats_
 
bool timing_
 
int verbosity_
 

Static Private Attributes

static const int bufferSize = 30000
 
static const int matacqFedId_ = 655
 
static int orbitTolerance_ = 80
 
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)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

EDM producer module providing MATACQ data. The MATACQ is a board sampling the ECAL laser pulse. Data are recording in dedicated files. This module permits to read these files add to each laser type EDM the corresponding MATACQ data: as digis (#see MatacqDigiCollection) or the raw data FED block (#see FEDRawDataCollection). Run and orbit numbers are used to match the MATACQ data with the ECAL DCC data.

Module parameters are listed and documented in EventFilter/EcalRawToDigi/ecalMatacq_cfi.py.

Definition at line 51 of file MatacqProducer.h.

Member Typedef Documentation

typedef std::auto_ptr<Storage> MatacqProducer::FILE_t
private

Definition at line 63 of file MatacqProducer.h.

Definition at line 62 of file MatacqProducer.h.

Member Enumeration Documentation

Enumerator
laserType 
ledType 
tpType 
pedType 

Definition at line 54 of file MatacqProducer.h.

Constructor & Destructor Documentation

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

Constructor

Parameters
paramsseletive readout parameters

Definition at line 49 of file MatacqProducer.cc.

References gather_cfg::cout, digiInstanceName_, doOrbitOffset_, edm::hlt::Exception, loadOrbitOffset(), logFile_, logFileName_, orbitOffsetFile_, dbtoconf::out, posEstim_, produceDigis_, produceRaw_, rawInstanceName_, startTime_, MatacqProducer::PosEstimator::verbosity(), and verbosity_.

49  :
50  fileNames_(params.getParameter<std::vector<std::string> >("fileNames")),
51  digiInstanceName_(params.getParameter<string>("digiInstanceName")),
52  rawInstanceName_(params.getParameter<string>("rawInstanceName")),
53  timing_(params.getUntrackedParameter<bool>("timing", false)),
54  disabled_(params.getParameter<bool>("disabled")),
55  verbosity_(params.getUntrackedParameter<int>("verbosity", 0)),
56  produceDigis_(params.getParameter<bool>("produceDigis")),
57  produceRaw_(params.getParameter<bool>("produceRaw")),
58  inputRawCollection_(params.getParameter<InputTag>("inputRawCollection")),
59  mergeRaw_(params.getParameter<bool>("mergeRaw")),
60  ignoreTriggerType_(params.getParameter<bool>("ignoreTriggerType")),
61  matacq_(0, 0),
62  inFile_(0),
65  lastOrb_(0),
67  orbitOffsetFile_(params.getUntrackedParameter<std::string>("orbitOffsetFile",
68  "")),
69  inFileName_(""),
71  logFileName_(params.getUntrackedParameter<std::string>("logFileName",
72  "matacqProducer.log")){
73  if(verbosity_>=4) cout << "[Matacq] in MatacqProducer ctor" << endl;
74 
76 
77  logFile_.open(logFileName_.c_str(), ios::app | ios::out);
78 
79  if(logFile_.bad()){
80  throw cms::Exception("FileOpen") << "Failed to open file "
81  << logFileName_ << " for logging.\n";
82  }
83 
84  if(produceDigis_){
85  if(verbosity_>0) cout << "[Matacq] registering new "
86  "EcalMatacqDigiCollection product with instance name '"
87  << digiInstanceName_ << "'\n";
88  produces<EcalMatacqDigiCollection>(digiInstanceName_);
89  }
90 
91  if(produceRaw_){
92  if(verbosity_>0) cout << "[Matacq] registering new FEDRawDataCollection "
93  "product with instance name '"
94  << rawInstanceName_ << "'\n";
95  produces<FEDRawDataCollection>(rawInstanceName_);
96  }
97 
98  startTime_.tv_sec = startTime_.tv_usec = 0;
99  if(orbitOffsetFile_.size()>0){
100  doOrbitOffset_ = true;
101  loadOrbitOffset();
102  } else{
103  doOrbitOffset_ = false;
104  }
105  if(verbosity_>=4) cout << "[Matacq] exiting MatacqProducer ctor" << endl;
106 }
std::string inFileName_
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
std::ofstream logFile_
std::vector< std::string > fileNames_
std::string digiInstanceName_
static stats_t stats_init
struct MatacqProducer::stats_t stats_
edm::InputTag inputRawCollection_
std::string orbitOffsetFile_
tuple out
Definition: dbtoconf.py:99
uint32_t openedFileRunNumber_
PosEstimator posEstim_
static const int bufferSize
MatacqRawEvent matacq_
std::string rawInstanceName_
tuple cout
Definition: gather_cfg.py:41
std::string logFileName_
std::vector< unsigned char > data_
MatacqProducer::~MatacqProducer ( )

Destructor

Definition at line 682 of file MatacqProducer.cc.

References gather_cfg::cout, logFile_, mclose(), MatacqProducer::stats_t::nEvents, MatacqProducer::stats_t::nLaserEventsWithMatacq, MatacqProducer::stats_t::nNonLaserEventsWithMatacq, startTime_, stats_, matplotRender::t, and timing_.

682  {
683  mclose();
684  timeval t;
685  gettimeofday(&t, 0);
686  if(timing_ && startTime_.tv_sec!=0){
687  //not using logger, to allow timing with different logging options
688  cout << "[Matacq] Time elapsed between first event and "
689  "destruction of MatacqProducer: "
690  << ((t.tv_sec-startTime_.tv_sec)*1.
691  + (t.tv_usec-startTime_.tv_usec)*1.e-6) << "s\n";
692  }
693  logFile_ << "Event count: "
694  << "total: " << stats_.nEvents << ", "
695  << "Laser event with Matacq data: "
696  << stats_.nLaserEventsWithMatacq << ", "
697  << "Non laser event (according to DCC header) with Matacq data: "
699 }
std::ofstream logFile_
struct MatacqProducer::stats_t stats_
tuple cout
Definition: gather_cfg.py:41

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

References bufferSize, filterCSVwithJSON::copy, gather_cfg::cout, data_, digiInstanceName_, doOrbitOffset_, formatter_, getCalibTriggerType(), MatacqRawEvent::getDccLen(), getMatacqEvent(), getMatacqFile(), getOrbitId(), MatacqRawEvent::getOrbitId(), MatacqRawEvent::getParsedLen(), getRunNumber(), ignoreTriggerType_, inputRawCollection_, edm::InputTag::instance(), MatacqDataFormatter::interpretRawData(), edm::InputTag::label(), laserType, matacq_, matacqFedId_, mergeRaw_, MatacqProducer::stats_t::nLaserEventsWithMatacq, MatacqProducer::stats_t::nNonLaserEventsWithMatacq, evf::evtn::offset(), orbitOffset_, produceDigis_, produceRaw_, rawInstanceName_, inputsource_file_cfi::runNumber, stats_, and verbosity_.

Referenced by produce().

119  {
121  if(inputRawCollection_.label().size() == 0
122  && inputRawCollection_.instance().size() == 0){
123  event.getByType(sourceColl);
124  } else{
125  event.getByLabel(inputRawCollection_, sourceColl);
126  }
127 
128  std::auto_ptr<FEDRawDataCollection> rawColl;
129  if(produceRaw_){
130  if(mergeRaw_){
131  rawColl = auto_ptr<FEDRawDataCollection>(new FEDRawDataCollection(*sourceColl));
132  } else{
133  rawColl = auto_ptr<FEDRawDataCollection>(new FEDRawDataCollection());
134  }
135  }
136 
137  std::auto_ptr<EcalMatacqDigiCollection>
138  digiColl(new EcalMatacqDigiCollection());
139 
140  if(sourceColl->FEDData(matacqFedId_).size()>4 && !produceRaw_){
141  //input raw data collection already contains matacqData
142  formatter_.interpretRawData(sourceColl->FEDData(matacqFedId_),
143  *digiColl);
144  } else{
145  bool isLaserEvent = (getCalibTriggerType(event) == laserType);
146  if(isLaserEvent || ignoreTriggerType_){
147 
148  const uint32_t runNumber = getRunNumber(event);
149  const uint32_t orbitId = getOrbitId(event);
150 
151  LogInfo("Matacq") << "Run " << runNumber << "\t Orbit " << orbitId << "\n";
152 
153  bool fileChange;
154  uint32_t offset = 0;
155  if(doOrbitOffset_){
156  map<uint32_t,uint32_t>::iterator it = orbitOffset_.find(runNumber);
157  if(it == orbitOffset_.end()){
158  LogWarning("IncorrectLaserEvent") << "Orbit offset not found for run "
159  << runNumber
160  << ". No orbit correction will be applied.";
161  } else{
162  offset = it->second;
163  }
164  }
165 
166  if(getMatacqFile(runNumber, orbitId, &fileChange)){
167  //matacq file retrieval succeeded
168  LogInfo("Matacq") << "Matacq data file found for "
169  << "run " << runNumber << " orbit " << orbitId;
170  if(getMatacqEvent(runNumber, orbitId, fileChange)){
171  if(produceDigis_){
172  formatter_.interpretRawData(matacq_, *digiColl);
173  }
174  if(produceRaw_){
175  uint32_t dataLen64 = matacq_.getParsedLen();
176  if(dataLen64 > bufferSize*8 || matacq_.getDccLen()!= dataLen64){
177  LogWarning("IncorrectLaserEvent") << " Error in Matacq event fragment length! "
178  << "DCC len: " << matacq_.getDccLen()
179  << "*8 Bytes, Parsed len: "
180  << matacq_.getParsedLen() << "*8 Bytes. "
181  << "Matacq data will not be included for this event.\n";
182  } else{
183  rawColl->FEDData(matacqFedId_).resize(dataLen64*8);
184  copy(data_.begin(), data_.begin() + dataLen64*8,
185  rawColl->FEDData(matacqFedId_).data());
186  }
187  }
188  LogInfo("Matacq") << "Associating matacq data with orbit id "
189  << matacq_.getOrbitId()
190  << " to dcc event with orbit id "
191  << orbitId << std::endl;
192  if(isLaserEvent){
194  } else{
196  }
197  } else{
198  LogWarning("IncorrectLaserEvent") << "No matacq data found for "
199  << "run " << runNumber << " orbit " << orbitId;
200  }
201  } else{
202  LogWarning("IncorrectLaserEvent") << "No matacq file found for event "
203  << event.id();
204  }
205  }
206  }
207 
208  if(produceRaw_){
209  if(verbosity_>1) cout << "[Matacq] "
210  << "Adding FEDRawDataCollection collection "
211  << " to event.\n";
212  event.put(rawColl, rawInstanceName_);
213  }
214 
215  if(produceDigis_){
216  if(verbosity_>1) cout << "[Matacq] "
217  << "Adding EcalMatacqDigiCollection collection "
218  << " to event.\n";
219  event.put(digiColl, digiInstanceName_);
220  }
221 }
std::map< uint32_t, uint32_t > orbitOffset_
static const int matacqFedId_
edm::SortedCollection< EcalMatacqDigi > EcalMatacqDigiCollection
static unsigned getOrbitId(unsigned char *data, size_t size)
std::string digiInstanceName_
uint32_t getRunNumber(edm::Event &ev) const
unsigned getDccLen() const
uint32_t getOrbitId(edm::Event &ev) const
struct MatacqProducer::stats_t stats_
edm::InputTag inputRawCollection_
unsigned int offset(bool)
int getCalibTriggerType(edm::Event &ev) const
MatacqDataFormatter formatter_
std::string const & label() const
Definition: InputTag.h:25
static const int bufferSize
MatacqRawEvent matacq_
std::string rawInstanceName_
void interpretRawData(const FEDRawData &data, EcalMatacqDigiCollection &matacqDigiCollection)
tuple cout
Definition: gather_cfg.py:41
std::vector< unsigned char > data_
bool getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool *fileChange=0)
std::string const & instance() const
Definition: InputTag.h:26
bool getMatacqEvent(uint32_t runNumber, int32_t orbitId, bool fileChange)
int MatacqProducer::getCalibTriggerType ( edm::Event ev) const
private

Definition at line 564 of file MatacqProducer.cc.

References Majority< T >::add(), FEDRawData::data(), runTheMatrix::data, edm::hlt::Exception, edm::Event::getByType(), FEDNumbering::inRange(), edm::HandleBase::isValid(), L1TEmulatorMonitor_cff::p, Majority< T >::result(), and FEDRawData::size().

Referenced by addMatacqData().

564  {
566  if(!(ev.getByType(rawdata) && rawdata.isValid())){
567  throw cms::Exception("NotFound")
568  << "No FED raw data collection found. ECAL raw data are "
569  "required to retrieve the trigger type";
570  }
571 
572  Majority<int> stat;
573  for(int id=601; id<=654; ++id){
574  if(!FEDNumbering::inRange(id)) continue;
575  const FEDRawData& data = rawdata->FEDData(id);
576  const int detailedTrigger32 = 5;
577  if(data.size()>=4*(detailedTrigger32+1)){
578  const unsigned char* pTType = data.data() + detailedTrigger32*4;
579  int tType = pTType[1] & 0x7;
580  stat.add(tType);
581  }
582  }
583  double p;
584  int tType = stat.result(&p);
585  if(p<0){
586  //throw cms::Exception("NotFound") << "No ECAL DCC data found\n";
587  LogWarning("IncorrectEvent") << "No ECAL DCC data found\n";
588  tType = -1;
589  }
590  if(p<.8){
591  //throw cms::Exception("EventCorruption") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
592  LogWarning("IncorrectEvent") << "Inconsitency in detailed trigger type indicated in ECAL DCC data headers\n";
593  tType = -1;
594  }
595  return tType;
596 }
bool getByType(Handle< PROD > &result) const
Definition: Event.h:397
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void add(const T &value)
Definition: Majority.h:25
bool isValid() const
Definition: HandleBase.h:76
static bool inRange(int)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
T result(double *proba) const
Definition: Majority.h:30
bool MatacqProducer::getMatacqEvent ( uint32_t  runNumber,
int32_t  orbitId,
bool  fileChange 
)
private

Definition at line 270 of file MatacqProducer.cc.

References abs, gather_cfg::cout, data_, MatacqProducer::PosEstimator::eventLength(), edm::hlt::Exception, fastRetrievalThresh_, newFWLiteAna::found, MatacqRawEvent::getDccLen(), MatacqRawEvent::getOrbitId(), MatacqRawEvent::getRunNum(), inFileName_, MatacqProducer::PosEstimator::invalid(), lastOrb_, matacq_, mread(), mrewind(), mseek(), msize(), mtell(), evf::evtn::offset(), orbitTolerance_, pos, MatacqProducer::PosEstimator::pos(), posEstim_, DTTTrigCorrFirst::run, evf::utils::state, and verbosity_.

Referenced by addMatacqData().

272  {
273  filepos_t startPos;
274  if(!mtell(startPos)) return false;
275 
276  int32_t startOrb = -1;
277  const size_t headerSize = 8*8;
278  if(mread((char*)&data_[0], headerSize, "Reading matacq header", true)){
279  startOrb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
280  if(startOrb<0) startOrb = 0;
281  } else{
282  if(verbosity_>2){
283  cout << "[Matacq] Failed to read matacq header. Moved to start of "
284  " the file.\n";
285  }
286  mrewind();
287  if(mread((char*)&data_[0], headerSize, "Reading matacq header", true)){
288  startPos = 0;
289  startOrb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
290  } else{
291  if(verbosity_>2) cout << "[Matacq] Looks like matacq file is empty"
292  << "\n";
293  return false;
294  }
295  }
296 
297  if(verbosity_>2) cout << "[Matacq] Last read orbit: " << lastOrb_
298  << " looking for orbit " << orbitId
299  << ". Current file position: " << startPos
300  << " Orbit at current position: " << startOrb << "\n";
301 
302  // f.clear();
303  bool didCoarseMove = false;
304  if(!posEstim_.invalid()
305  && (abs(lastOrb_-orbitId) > fastRetrievalThresh_)){
306  filepos_t pos = posEstim_.pos(orbitId);
307 
308  // struct stat st;
309  filepos_t fsize;
310  // if(0==stat(inFileName_.c_str(), &st)){
311  if(msize(fsize)){
312  // const int64_t fsize = st.st_size;
313  if(0!=posEstim_.eventLength() && pos > fsize){
314  //estimated position is beyong end of file
315  //-> move to beginning of last event:
316  int64_t evtSize = posEstim_.eventLength()*sizeof(uint64_t);
317  pos = ((int64_t)fsize/evtSize-1)*evtSize;
318  if(verbosity_>2){
319  cout << "[Matacq] Estimated position was beyond end of file. "
320  "Changed to " << pos << "\n";
321  }
322  }
323  } else{
324  LogWarning("IncorrectConfiguration") << "Failed to access file " << inFileName_ << ".";
325  }
326  if(pos>=0){
327  if(verbosity_>2) cout << "[Matacq] jumping to estimated position "
328  << pos << "\n";
329  mseek(pos, SEEK_SET, "Jumping to estimated event position");
330  if(mread((char*)&data_[0], headerSize, "Reading matacq header", true)){
331  didCoarseMove = true;
332  } else{
333  //estimated position might have been beyond the end of the file,
334  //try, with original position:
335  didCoarseMove = false;
336  if(!mread((char*)&data_[0], headerSize, "Reading event header", true)){
337  return false;
338  }
339  }
340  } else{
341  if(verbosity_) cout << "[Matacq] Event orbit outside of orbit range "
342  "of matacq data file events\n";
343  return false;
344  }
345  }
346 
347  int32_t orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
348 
349  if(didCoarseMove){
350  //autoadjustement of threshold for coarse move:
351  if(abs(orb-orbitId) > fastRetrievalThresh_){
352  if(verbosity_>2) cout << "[Matacq] Fast retrieval threshold increased from "
354  fastRetrievalThresh_ = 2*abs(orb-orbitId);
355  if(verbosity_>2) cout << " to " << fastRetrievalThresh_ << "\n";
356  }
357 
358  //if coarse move did not improve situation, rolls back:
359  if(startOrb > 0
360  && (abs(orb-orbitId) > abs(startOrb-orbitId))){
361  if(verbosity_>2) cout << "[Matacq] Estimation (-> orbit " << orb << ") "
362  "was worst than original position (-> orbit "
363  << startOrb
364  << "). Restoring position (" << startPos << ").\n";
365  mseek(startPos, SEEK_SET);
366  mread((char*)&data_[0], headerSize, "Reading event header", true);
367  orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
368  }
369  }
370 
371  bool searchBackward = (orb>orbitId)?true:false;
372  //BEWARE: len must be signed, because we are using latter in the code (-len)
373  //expression
374  int len = (int)MatacqRawEvent::getDccLen(&data_[0], headerSize);
375 
376  if(len==0){
377  cout << "[Matacq] read DCC length is null! Cancels matacq event search "
378  << " and move matacq file pointer to beginning of the file. "
379  << "(" << __FILE__ << ":" << __LINE__ << ")."
380  << "\n";
381  //rewind(f);
382  mrewind();
383  return false;
384  }
385 
386  enum state_t { searching, found, failed } state = searching;
387 
388  while(state == searching){
389  orb = MatacqRawEvent::getOrbitId(&data_[0], headerSize);
390  len = (int)MatacqRawEvent::getDccLen(&data_[0], headerSize);
391  uint32_t run = MatacqRawEvent::getRunNum(&data_[0], headerSize);
392  if(verbosity_>3){
393  filepos_t pos;
394  mtell(pos);
395  cout << "[Matacq] Header read at file position "
396  << pos
397  << ": orbit = " << orb
398  << " len = " << len << "x8 Byte"
399  << " run = " << run << "\n";
400  }
401  if((abs(orb-orbitId) < orbitTolerance_)
402  && (runNumber==0 || runNumber==run)){
403  state = found;
404  lastOrb_ = orb;
405  //reads the rest of the event:
406  if((int)data_.size() < len*8){
407  throw cms::Exception("Matacq") << "Buffer overflow";
408  }
409  if(verbosity_>2) cout << "[Matacq] Event found. Reading "
410  " matacq event." << "\n";
411  if(!mread((char*)&data_[0], len*8, "Reading matacq event")){
412  if(verbosity_>2) cout << "[Matacq] Failed to read matacq event."
413  << "\n";
414  state = failed;
415  }
416  matacq_ = MatacqRawEvent((unsigned char*)&data_[0], len*8);
417  } else {
418  if((searchBackward && (orb < orbitId))
419  || (!searchBackward && orb > orbitId)){ //search ended
420  lastOrb_ = orb;
421  state = failed;
422  if(verbosity_) cout << "[Matacq] Event search failed." << "\n";
423  } else{
424  off_t offset = (searchBackward?-len:len)*8;
425  lastOrb_ = orb;
426  if(verbosity_>3){
427  cout << "[Matacq] In matacq file, moving "
428  << abs(offset) << " byte " << (offset>0?"forward":"backward")
429  << ".\n";
430  }
431 
432  if(mseek(offset, SEEK_CUR,
433  (searchBackward?"Moving to previous event":
434  "Moving to next event"))
435  && mread((char*)&data_[0], headerSize, "Reading event header",
436  true)){
437  } else{
438  if(!searchBackward) mseek(-len*8, SEEK_CUR,
439  "Moving to start of last complete event");
440  state = failed;
441  }
442  }
443  }
444  }
445 
446  if(state==found){
447  filepos_t pos;
448  filepos_t fsize;
449  mtell(pos);
450  msize(fsize);
451  if(pos==fsize-1){ //last byte.
452  if(verbosity_>2){
453  cout << "[Matacq] Event found was at the end of the file. Moving "
454  "stream position to beginning of this event."
455  << "\n";
456  }
457  mseek(-(int)len*8-1, SEEK_CUR,
458  "Moving to beginning of last matacq event");
459  }
460  }
461  return (state==found);
462 }
std::string inFileName_
static int orbitTolerance_
unsigned getRunNum() const
#define abs(x)
Definition: mlp_lapack.h:159
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)
unsigned int offset(bool)
unsigned long long uint64_t
Definition: Time.h:15
PosEstimator posEstim_
bool mtell(filepos_t &pos)
char state
Definition: procUtils.cc:75
bool mseek(filepos_t offset, int whence=SEEK_SET, const char *mess=0)
MatacqRawEvent matacq_
IOOffset filepos_t
tuple cout
Definition: gather_cfg.py:41
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 466 of file MatacqProducer.cc.

References gather_cfg::cout, fileNames_, alignmentValidation::fname, diffTreeTool::format(), newFWLiteAna::found, i, MatacqProducer::PosEstimator::init(), lastOrb_, mcheck(), misOpened(), mopen(), openedFileRunNumber_, posEstim_, inputsource_file_cfi::runNumber, runSubDir(), and verbosity_.

Referenced by addMatacqData().

467  {
470  if(fileChange!=0) *fileChange = false;
471  return misOpened();
472  }
473 
474  if(fileNames_.size()==0) return 0;
475 
476  const string runNumberFormat = "%08d";
477  string sRunNumber = str(boost::format(runNumberFormat) % runNumber);
478  //cout << "Run number string: " << sRunNumber << "\n";
479  bool found = false;
480  string fname;
481  for(unsigned i=0; i < fileNames_.size() && !found; ++i){
482  fname = fileNames_[i];
483  boost::algorithm::replace_all(fname, "%run_subdir%",
485  boost::algorithm::replace_all(fname, "%run_number%", sRunNumber);
486 
487  if(verbosity_) cout << "[Matacq] Looking for a file with path "
488  << fname << "\n";
489 
490  if(mcheck(fname)){
491  LogInfo("Matacq") << "Uses matacq data file: '" << fname << "'\n";
492  found = true;
493  }
494  }
495  if(!found){
497  if(fileChange!=0) *fileChange = false;
498  return 0;
499  }
500 
501  if(!mopen(fname)){
502  LogWarning("IncorrectConfiguration") << "Failed to open file " << fname << "\n";
504  if(fileChange!=0) *fileChange = false;
505  return false;
506  } else{
508  lastOrb_ = 0;
509  posEstim_.init(this);
510  if(fileChange!=0) *fileChange = true;
511  return true;
512  }
513 }
int i
Definition: DBlmapReader.cc:9
std::vector< std::string > fileNames_
bool mcheck(const std::string &name)
static std::string runSubDir(uint32_t runNumber)
uint32_t openedFileRunNumber_
PosEstimator posEstim_
void init(MatacqProducer *mp)
string fname
main script
tuple cout
Definition: gather_cfg.py:41
bool mopen(const std::string &name)
uint32_t MatacqProducer::getOrbitId ( edm::Event ev) const
private

Definition at line 520 of file MatacqProducer.cc.

References abs, FEDRawData::data(), runTheMatrix::data, edm::hlt::Exception, edm::Event::getByType(), edm::EventBase::id(), FEDNumbering::inRange(), edm::HandleBase::isValid(), orbitTolerance_, and FEDRawData::size().

Referenced by addMatacqData().

520  {
521  //on CVS HEAD (June 4, 08), class Event has a method orbitNumber()
522  //we could use here. The code would be shorten to:
523  //return ev.orbitNumber();
524  //we have to deal with what we have in current CMSSW releases:
526  if(!(ev.getByType(rawdata) && rawdata.isValid())){
527  throw cms::Exception("NotFound")
528  << "No FED raw data collection found. ECAL raw data are "
529  "required to retrieve the orbit ID";
530  }
531 
532  int orbit = 0;
533  for(int id=601; id<=654; ++id){
534  if(!FEDNumbering::inRange(id)) continue;
535  const FEDRawData& data = rawdata->FEDData(id);
536  const int orbitIdOffset64 = 3;
537  if(data.size()>=8*(orbitIdOffset64+1)){//orbit id is in 4th 64-bit word
538  const unsigned char* pOrbit = data.data() + orbitIdOffset64*8;
539  int thisOrbit = pOrbit[0]
540  | (pOrbit[1] <<8)
541  | (pOrbit[2] <<16)
542  | (pOrbit[3] <<24);
543  if(orbit!=0 && thisOrbit!=0 && abs(orbit-thisOrbit)>orbitTolerance_){
544  //throw cms::Exception("EventCorruption")
545  // << "Orbit ID inconsitency in DCC headers";
546  LogWarning("IncorrectEvent")
547  << "Orbit ID inconsitency in DCC headers";
548  orbit = 0;
549  break;
550  }
551  if(thisOrbit!=0) orbit = thisOrbit;
552  }
553  }
554 
555  if(orbit==0){
556  // throw cms::Exception("NotFound")
557  // << "Failed to retrieve orbit ID of event "<< ev.id();
558  LogWarning("IncorrectEvent") << "Failed to retrieve orbit ID of event "
559  << ev.id();
560  }
561  return orbit;
562 }
static int orbitTolerance_
#define abs(x)
Definition: mlp_lapack.h:159
bool getByType(Handle< PROD > &result) const
Definition: Event.h:397
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
bool isValid() const
Definition: HandleBase.h:76
static bool inRange(int)
edm::EventID id() const
Definition: EventBase.h:56
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
uint32_t MatacqProducer::getRunNumber ( edm::Event ev) const
private

Definition at line 516 of file MatacqProducer.cc.

References edm::Event::run().

Referenced by addMatacqData().

516  {
517  return ev.run();
518 }
RunNumber_t run() const
Definition: Event.h:66
void MatacqProducer::loadOrbitOffset ( )
private

Loading orbit correction table from file.

See Also
orbitOffsetFile_

Definition at line 701 of file MatacqProducer.cc.

References gather_cfg::cout, edm::hlt::Exception, f, ntuplemaker::iline, max(), orbitOffset_, orbitOffsetFile_, DTTTrigCorrFirst::run, and asciidump::s.

Referenced by MatacqProducer().

701  {
702  ifstream f(orbitOffsetFile_.c_str());
703  if(f.bad()){
704  throw cms::Exception("Matacq")
705  << "Failed to open orbit ID correction file '"
706  << orbitOffsetFile_ << "'\n";
707  }
708 
709  cout << "[Matacq] "
710  << "Offset to substract to Matacq events Orbit ID: \n"
711  << "#Run Number\t Offset\n";
712 
713  int iline = 0;
714  string s;
715  stringstream buf;
716  while(f.eof()){
717  getline(f, s);
718  ++iline;
719  if(s[0]=='#'){//comment
720  //skip line:
721  f.ignore(numeric_limits<streamsize>::max(), '\n');
722  continue;
723  }
724  buf.str("");
725  buf << s;
726  int run;
727  int orbit;
728  buf >> run;
729  buf >> orbit;
730  if(buf.bad()){
731  throw cms::Exception("Matacq")
732  << "Syntax error in Orbit offset file '"
733  << orbitOffsetFile_ << "'";
734  }
735  cout << run << "\t" << orbit << "\n";
736  orbitOffset_.insert(pair<int, int>(run, orbit));
737  }
738 }
std::map< uint32_t, uint32_t > orbitOffset_
const T & max(const T &a, const T &b)
double f[11][100]
std::string orbitOffsetFile_
tuple cout
Definition: gather_cfg.py:41
string s
Definition: asciidump.py:422
bool MatacqProducer::mcheck ( const std::string &  name)
private

Definition at line 923 of file MatacqProducer.cc.

Referenced by getMatacqFile().

923  {
924  struct stat dummy;
925  return 0==stat(name.c_str(), &dummy);
926 }
void MatacqProducer::mclose ( )
private

Definition at line 940 of file MatacqProducer.cc.

References inFile_.

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

940  {
941  if(inFile_!=0) fclose(inFile_);
942  inFile_ = 0;
943 }
bool MatacqProducer::meof ( )
private

Definition at line 949 of file MatacqProducer.cc.

References inFile_.

949  {
950  if(0==inFile_) return true;
951  return feof(inFile_)==0;
952 }
bool MatacqProducer::misOpened ( )
private

Definition at line 945 of file MatacqProducer.cc.

References inFile_.

Referenced by getMatacqFile().

945  {
946  return inFile_!=0;
947 }
bool MatacqProducer::mopen ( const std::string &  name)
private

Definition at line 928 of file MatacqProducer.cc.

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

Referenced by getMatacqFile().

928  {
929  if(inFile_!=0) mclose();
930  inFile_ = fopen(name.c_str(), "r");
931  if(inFile_!=0){
932  inFileName_ = name;
933  return true;
934  } else{
935  inFileName_ = "";
936  return false;
937  }
938 }
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 877 of file MatacqProducer.cc.

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

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

877  {
878  if(0==inFile_) return false;
879  off_t pos = ftello(inFile_);
880  bool rc = (pos!=-1) && (1==fread(buf, n, 1, inFile_));
881  if(!rc){
882  if(verbosity_){
883  cout << "[Matacq] ";
884  if(mess) cout << mess << ". ";
885  cout << "Read failure from input matacq file.\n";
886  }
887  clearerr(inFile_);
888  }
889  if(peek || !rc){//need to restore file position
890  if(0!=fseeko(inFile_, pos, SEEK_SET)){
891  if(verbosity_){
892  cout << "[Matacq] ";
893  if(mess) cout << mess << ". ";
894  cout << "Failed to restore file position of "
895  "before read error. Rewind file.\n";
896  }
897  //rewind(inFile_.get());
898  mrewind();
899  lastOrb_ = 0;
900  }
901  }
902  return rc;
903 }
tuple cout
Definition: gather_cfg.py:41
bool MatacqProducer::mrewind ( )
private

Definition at line 917 of file MatacqProducer.cc.

References inFile_.

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

917  {
918  if(0==inFile_) return false;
919  clearerr(inFile_);
920  return fseeko(inFile_, 0, SEEK_SET)!=0;
921 }
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 857 of file MatacqProducer.cc.

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

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

857  {
858  if(0==inFile_) return false;
859  const int rc = fseeko(inFile_, offset, whence);
860  if(rc!=0 && verbosity_){
861  cout << "[Matacq] ";
862  if(mess) cout << mess << ". ";
863  cout << "Random access error on input matacq file. "
864  "Rewind file.\n";
865  mrewind();
866  }
867  return rc==0;
868 }
unsigned int offset(bool)
tuple cout
Definition: gather_cfg.py:41
bool MatacqProducer::msize ( filepos_t s)
private

Definition at line 905 of file MatacqProducer.cc.

References inFile_.

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

905  {
906  if(0==inFile_) return false;
907  struct stat buf;
908  if(0!=fstat(fileno(inFile_), &buf)){
909  s = 0;
910  return false;
911  } else{
912  s = buf.st_size;
913  return true;
914  }
915 }
string s
Definition: asciidump.py:422
bool MatacqProducer::mtell ( filepos_t pos)
private

Definition at line 870 of file MatacqProducer.cc.

References inFile_.

Referenced by getMatacqEvent().

870  {
871  if(0==inFile_) return false;
872  pos = ftello(inFile_);
873  return pos != -1;
874 
875 }
void MatacqProducer::produce ( edm::Event event,
const edm::EventSetup eventSetup 
)
virtual

Produces the EDM products

Parameters
CMSevent
eventSetupevent conditions

Implements edm::EDProducer.

Definition at line 110 of file MatacqProducer.cc.

References addMatacqData(), gather_cfg::cout, disabled_, MatacqProducer::stats_t::nEvents, startTime_, stats_, and verbosity_.

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

110  {
111  if(verbosity_>=4) cout << "[Matacq] in MatacqProducer::produce" << endl;
112  if(startTime_.tv_sec==0) gettimeofday(&startTime_, 0);
113  ++stats_.nEvents;
114  if(disabled_) return;
115  addMatacqData(event);
116 }
struct MatacqProducer::stats_t stats_
void addMatacqData(edm::Event &event)
tuple cout
Definition: gather_cfg.py:41
std::string MatacqProducer::runSubDir ( uint32_t  runNumber)
staticprivate

Definition at line 956 of file MatacqProducer.cc.

References diffTreeTool::format().

Referenced by getMatacqFile().

956  {
957  int millions = runNumber / (1000*1000);
958  int thousands = (runNumber-millions*1000*1000) / 1000;
959  int units = runNumber-millions*1000*1000 - thousands*1000;
960  return str(boost::format("%03d/%03d/%03d") % millions % thousands % units);
961 }

Member Data Documentation

const int MatacqProducer::bufferSize = 30000
staticprivate

Definition at line 262 of file MatacqProducer.h.

Referenced by addMatacqData().

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

Definition at line 264 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 216 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 228 of file MatacqProducer.h.

Referenced by produce().

bool MatacqProducer::doOrbitOffset_
private

Switch for orbit ID correction.

See Also
orbitOffsetFile_

Definition at line 287 of file MatacqProducer.h.

Referenced by addMatacqData(), and MatacqProducer().

int MatacqProducer::fastRetrievalThresh_
private

Definition at line 269 of file MatacqProducer.h.

Referenced by getMatacqEvent().

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

Definition at line 212 of file MatacqProducer.h.

Referenced by getMatacqFile().

MatacqDataFormatter MatacqProducer::formatter_
private

Definition at line 265 of file MatacqProducer.h.

Referenced by addMatacqData().

bool MatacqProducer::ignoreTriggerType_
private

When true look for matacq data independently of trigger type.

Definition at line 254 of file MatacqProducer.h.

Referenced by addMatacqData().

FILE_t MatacqProducer::inFile_
private

Stream of currently opened matacq file

Definition at line 260 of file MatacqProducer.h.

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

std::string MatacqProducer::inFileName_
private

Name of currently opened matacq file

Definition at line 291 of file MatacqProducer.h.

Referenced by getMatacqEvent(), and mopen().

edm::InputTag MatacqProducer::inputRawCollection_
private

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

Definition at line 245 of file MatacqProducer.h.

Referenced by addMatacqData().

int32_t MatacqProducer::lastOrb_
private

Definition at line 268 of file MatacqProducer.h.

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

std::ofstream MatacqProducer::logFile_
private

Log file

Definition at line 308 of file MatacqProducer.h.

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

std::string MatacqProducer::logFileName_
private

Log file name

Definition at line 304 of file MatacqProducer.h.

Referenced by MatacqProducer().

MatacqRawEvent MatacqProducer::matacq_
private

Definition at line 256 of file MatacqProducer.h.

Referenced by addMatacqData(), and getMatacqEvent().

const int MatacqProducer::matacqFedId_ = 655
staticprivate

Definition at line 293 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 250 of file MatacqProducer.h.

Referenced by addMatacqData().

uint32_t MatacqProducer::openedFileRunNumber_
private

Definition at line 267 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 283 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 279 of file MatacqProducer.h.

Referenced by loadOrbitOffset(), and MatacqProducer().

int MatacqProducer::orbitTolerance_ = 80
staticprivate

Definition at line 266 of file MatacqProducer.h.

Referenced by getMatacqEvent(), and getOrbitId().

PosEstimator MatacqProducer::posEstim_
private

Definition at line 271 of file MatacqProducer.h.

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

bool MatacqProducer::produceDigis_
private

Swictch for Matacq digi producion

Definition at line 236 of file MatacqProducer.h.

Referenced by addMatacqData(), and MatacqProducer().

bool MatacqProducer::produceRaw_
private

Switch for Matacq FED raw data production

Definition at line 240 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 220 of file MatacqProducer.h.

Referenced by addMatacqData(), and MatacqProducer().

timeval MatacqProducer::startTime_
private

Definition at line 273 of file MatacqProducer.h.

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

struct MatacqProducer::stats_t MatacqProducer::stats_
private
MatacqProducer::stats_t MatacqProducer::stats_init = {0,0,0}
staticprivate

Definition at line 301 of file MatacqProducer.h.

bool MatacqProducer::timing_
private

Parameter to switch module timing.

Definition at line 224 of file MatacqProducer.h.

Referenced by ~MatacqProducer().

int MatacqProducer::verbosity_
private