CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/EventFilter/EcalRawToDigi/interface/MatacqProducer.h

Go to the documentation of this file.
00001 #ifndef PRODUCER_H
00002 #define PRODUCER_H
00003 
00004 //#define USE_STORAGE_MANAGER
00005 
00006 #ifdef USE_STORAGE_MANAGER
00007 #  include "Utilities/StorageFactory/interface/Storage.h"
00008 #  include "Utilities/StorageFactory/interface/StorageFactory.h"
00009 #else //USE_STORAGE_MANAGER not defined
00010 #  ifndef _LARGEFILE64_SOURCE
00011 #    define _LARGEFILE64_SOURCE
00012 #  endif //_LARGEFILE64_SOURCE not defined
00013 #  define  _FILE_OFFSET_BITS 64 
00014 #  include <stdio.h>
00015 #endif //USE_STORAGE_MANAGER defined
00016 
00017 
00018 #include "FWCore/Framework/interface/EDProducer.h"
00019 #include "FWCore/Utilities/interface/InputTag.h"
00020 #include "EventFilter/EcalRawToDigi/interface/MatacqRawEvent.h"
00021 #include "EventFilter/EcalRawToDigi/src/MatacqDataFormatter.h"
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 #include "FWCore/Utilities/interface/InputTag.h"
00024 
00025 #include <string>
00026 #include <inttypes.h>
00027 #include <fstream>
00028 #include <memory>
00029 
00030 #include <sys/time.h>
00031 
00032 struct NullOut{
00033   NullOut&
00034   operator<<(std::ostream& (*pf)(std::ostream&)){
00035     return *this;
00036   }
00037   template<typename T>
00038   inline NullOut& operator<<(const T& a){
00039     return *this;
00040   }
00041 };
00042 
00043 class MatacqProducer : public edm::EDProducer
00044 {
00045 public:
00046   enum calibTrigType_t{
00047     laserType = 4,
00048     ledType   = 5,
00049     tpType    = 6,
00050     pedType   = 7
00051   };
00052 private:
00053 #ifdef USE_STORAGE_MANAGER
00054   typedef IOOffset filepos_t;
00055   typedef std::auto_ptr<Storage> FILE_t;
00056 #else
00057   typedef off_t filepos_t;
00058   typedef FILE* FILE_t;
00059 #endif
00060   struct MatacqEventId{
00061     MatacqEventId(): run(0), orbit(0){}
00062     MatacqEventId(uint32_t r, uint32_t o): run(r), orbit(o){}
00063                                           
00066     uint32_t run;
00067     
00070     uint32_t orbit;
00071     
00072     bool
00073     operator<(const MatacqEventId& a){
00074       return (this->run < a.run)
00075         || ((this->run == a.run) && (this->orbit < a.orbit));
00076     }
00077     
00078     bool
00079     operator>(const MatacqEventId& a){
00080       return (this->run > a.run)
00081         || ((this->run == a.run) && (this->orbit > a.orbit));
00082     }
00083     
00084     bool
00085     operator==(const MatacqEventId& a){
00086       return !((*this) < a || (*this) > a);
00087     }
00088   };
00089 
00090 
00097   class PosEstimator{
00098     //Note: a better estimate could be obtained by using segment of linear
00099     //functions. In such implementation, the estimator must be updated
00100     //each time a point with wrong estimate has been found.
00101   public:
00102     PosEstimator():eventLength_(0), orbitStepMean_(0), firstOrbit_(0),
00103                    invalid_(true), verbosity_(0) { }
00104     void init(MatacqProducer* mp);
00105     bool invalid() const { return invalid_; }
00106     int64_t pos(int orb) const;
00107     int eventLength() const { return eventLength_; }
00108     int firstOrbit() const { return firstOrbit_; }
00109     void verbosity(int verb) { verbosity_ = verb; }
00110   private:
00111     int eventLength_;
00112     int orbitStepMean_;
00113     int firstOrbit_;
00114     bool invalid_;
00115     int verbosity_;
00116   };
00117 
00118 public:
00122   explicit
00123   MatacqProducer(const edm::ParameterSet& params);
00124 
00127   ~MatacqProducer();
00128 
00133   virtual void
00134   produce(edm::Event& event, const edm::EventSetup& eventSetup);
00135 
00136 private:
00141   void
00142   addMatacqData(edm::Event& event);
00143 
00151   bool
00152   getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool* fileChange =0);
00153 
00154   bool
00155   getMatacqEvent(uint32_t runNumber, int32_t orbitId,
00156                  bool fileChange);
00157   /*,bool doWrap = false, std::streamoff maxPos = -1);*/
00158 
00159   uint32_t getRunNumber(edm::Event& ev) const;
00160   uint32_t getOrbitId(edm::Event& ev) const;
00161   int getCalibTriggerType(edm::Event& ev) const;
00162 
00165   void loadOrbitOffset();
00166 
00173   bool mseek(filepos_t offset, int whence = SEEK_SET, const char* mess = 0);
00174 
00175   bool mtell(filepos_t& pos);
00176   
00185   bool mread(char* buf, size_t n, const char* mess = 0, bool peek = false);
00186 
00187   bool mcheck(const std::string& name);
00188 
00189   bool mopen(const std::string& name);
00190 
00191   void mclose();
00192 
00193   bool misOpened();
00194 
00195   bool meof();
00196   
00197   bool mrewind();
00198 
00199   bool msize(filepos_t& s);
00200 
00201   void newRun(int prevRun, int newRun);
00202   
00203   static std::string runSubDir(uint32_t runNumber);
00204   
00205 private:
00206   std::vector<std::string> fileNames_;
00207 
00210   std::string digiInstanceName_;
00211 
00214   std::string rawInstanceName_;
00215   
00218   bool timing_;
00219 
00222   bool disabled_;
00223 
00226   int verbosity_;
00227 
00230   bool produceDigis_;
00231 
00234   bool produceRaw_;
00235 
00239   edm::InputTag inputRawCollection_;
00240 
00244   bool mergeRaw_;
00245 
00248   bool ignoreTriggerType_;
00249   
00250   MatacqRawEvent matacq_;
00251   
00254   FILE_t inFile_;
00255 
00256   static const int bufferSize =  30000; //must greater or equal to maximum
00257   //                                      matacq event size.
00258   std::vector<unsigned char> data_;
00259   MatacqDataFormatter formatter_;
00260   static int orbitTolerance_;
00261   uint32_t openedFileRunNumber_;
00262   int32_t lastOrb_;
00263   int fastRetrievalThresh_;
00264   
00265   PosEstimator posEstim_;
00266   
00267   timeval startTime_;
00268 
00273   std::string orbitOffsetFile_;
00274 
00277   std::map<uint32_t,uint32_t> orbitOffset_;
00278   
00281   bool doOrbitOffset_;
00282 
00285   std::string inFileName_;
00286 
00287   static const int matacqFedId_ = 655;
00288 
00289   struct stats_t {
00290     double nEvents;
00291     double nLaserEventsWithMatacq;
00292     double nNonLaserEventsWithMatacq;
00293   } stats_;
00294 
00295   static stats_t stats_init;
00298   std::string logFileName_;
00299 
00302   std::ofstream logFile_;
00303 
00304 
00307   int eventSkipCounter_;
00308 
00311   int onErrorDisablingEvtCnt_;
00312 
00315   std::string timeLogFile_;
00318   timeval timer_;
00319 
00322   std::ofstream timeLog_;
00323 
00326   bool logTiming_;
00327 
00330   uint32_t runNumber_;
00331 };
00332 
00333 #endif