CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 #ifndef PRODUCER_H
00002 #define PRODUCER_H
00003 
00004 #include "FWCore/Framework/interface/EDProducer.h"
00005 #include "FWCore/Utilities/interface/InputTag.h"
00006 #include "EventFilter/EcalRawToDigi/interface/MatacqRawEvent.h"
00007 #include "EventFilter/EcalRawToDigi/src/MatacqDataFormatter.h"
00008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00009 
00010 #include <string>
00011 #include <inttypes.h>
00012 #include <fstream>
00013 #include <memory>
00014 
00015 #include <sys/time.h>
00016 
00017 #define USE_STORAGE_MANAGER
00018 
00019 #ifdef USE_STORAGE_MANAGER
00020 #  include "Utilities/StorageFactory/interface/Storage.h"
00021 #  include "Utilities/StorageFactory/interface/StorageFactory.h"
00022 #else //USE_STORAGE_MANAGER not defined
00023 #  ifndef _LARGEFILE64_SOURCE
00024 #    define _LARGEFILE64_SOURCE
00025 #  endif //_LARGEFILE64_SOURCE not defined
00026 #  include <stdio.h>
00027 #endif //USE_STORAGE_MANAGER defined
00028 
00029 struct NullOut{
00030   NullOut&
00031   operator<<(std::ostream& (*pf)(std::ostream&)){
00032     return *this;
00033   }
00034   template<typename T>
00035   inline NullOut& operator<<(const T& a){
00036     return *this;
00037   }
00038 };
00039 
00051 class MatacqProducer : public edm::EDProducer
00052 {
00053 public:
00054   enum calibTrigType_t{
00055     laserType = 4,
00056     ledType   = 5,
00057     tpType    = 6,
00058     pedType   = 7
00059   };
00060 private:
00061 #ifdef USE_STORAGE_MANAGER
00062   typedef IOOffset filepos_t;
00063   typedef std::auto_ptr<Storage> FILE_t;
00064 #else
00065   typedef off_t filepos_t;
00066   typedef FILE* FILE_t;
00067 #endif
00068   struct MatacqEventId{
00069     MatacqEventId(): run(0), orbit(0){}
00070     MatacqEventId(uint32_t r, uint32_t o): run(r), orbit(o){}
00071                                           
00074     uint32_t run;
00075     
00078     uint32_t orbit;
00079     
00080     bool
00081     operator<(const MatacqEventId& a){
00082       return (this->run < a.run)
00083         || ((this->run == a.run) && (this->orbit < a.orbit));
00084     }
00085     
00086     bool
00087     operator>(const MatacqEventId& a){
00088       return (this->run > a.run)
00089         || ((this->run == a.run) && (this->orbit > a.orbit));
00090     }
00091     
00092     bool
00093     operator==(const MatacqEventId& a){
00094       return !((*this) < a || (*this) > a);
00095     }
00096   };
00097 
00098 
00105   class PosEstimator{
00106     //Note: a better estimate could be obtained by using segment of linear
00107     //functions. In such implementation, the estimator must be updated
00108     //each time a point with wrong estimate has been found.
00109   public:
00110     PosEstimator():eventLength_(0), orbitStepMean_(0), firstOrbit_(0),
00111                    invalid_(true), verbosity_(0) { }
00112     void init(MatacqProducer* mp);
00113     bool invalid() const { return invalid_; }
00114     int64_t pos(int orb) const;
00115     int eventLength() const { return eventLength_; }
00116     int firstOrbit() const { return firstOrbit_; }
00117     void verbosity(int verb) { verbosity_ = verb; }
00118   private:
00119     int eventLength_;
00120     int orbitStepMean_;
00121     int firstOrbit_;
00122     bool invalid_;
00123     int verbosity_;
00124   };
00125 
00126 public:
00130   explicit
00131   MatacqProducer(const edm::ParameterSet& params);
00132 
00135   ~MatacqProducer();
00136 
00141   virtual void
00142   produce(edm::Event& event, const edm::EventSetup& eventSetup);
00143 
00144 private:
00149   void
00150   addMatacqData(edm::Event& event);
00151 
00159   bool
00160   getMatacqFile(uint32_t runNumber, uint32_t orbitId, bool* fileChange =0);
00161 
00162   bool
00163   getMatacqEvent(uint32_t runNumber, int32_t orbitId,
00164                  bool fileChange);
00165   /*,bool doWrap = false, std::streamoff maxPos = -1);*/
00166 
00167   uint32_t getRunNumber(edm::Event& ev) const;
00168   uint32_t getOrbitId(edm::Event& ev) const;
00169   int getCalibTriggerType(edm::Event& ev) const;
00170 
00173   void loadOrbitOffset();
00174 
00181   bool mseek(filepos_t offset, int whence = SEEK_SET, const char* mess = 0);
00182 
00183   bool mtell(filepos_t& pos);
00184   
00193   bool mread(char* buf, size_t n, const char* mess = 0, bool peek = false);
00194 
00195   bool mcheck(const std::string& name);
00196 
00197   bool mopen(const std::string& name);
00198 
00199   void mclose();
00200 
00201   bool misOpened();
00202 
00203   bool meof();
00204   
00205   bool mrewind();
00206 
00207   bool msize(filepos_t& s);
00208 
00209   static std::string runSubDir(uint32_t runNumber);
00210   
00211 private:
00212   std::vector<std::string> fileNames_;
00213 
00216   std::string digiInstanceName_;
00217 
00220   std::string rawInstanceName_;
00221   
00224   bool timing_;
00225 
00228   bool disabled_;
00229 
00232   int verbosity_;
00233 
00236   bool produceDigis_;
00237 
00240   bool produceRaw_;
00241 
00245   edm::InputTag inputRawCollection_;
00246 
00250   bool mergeRaw_;
00251 
00254   bool ignoreTriggerType_;
00255   
00256   MatacqRawEvent matacq_;
00257   
00260   FILE_t inFile_;
00261 
00262   static const int bufferSize =  30000; //must greater or equal to maximum
00263   //                                      matacq event size.
00264   std::vector<unsigned char> data_;
00265   MatacqDataFormatter formatter_;
00266   static int orbitTolerance_;
00267   uint32_t openedFileRunNumber_;
00268   int32_t lastOrb_;
00269   int fastRetrievalThresh_;
00270   
00271   PosEstimator posEstim_;
00272   
00273   timeval startTime_;
00274 
00279   std::string orbitOffsetFile_;
00280 
00283   std::map<uint32_t,uint32_t> orbitOffset_;
00284   
00287   bool doOrbitOffset_;
00288 
00291   std::string inFileName_;
00292 
00293   static const int matacqFedId_ = 655;
00294 
00295   struct stats_t {
00296     double nEvents;
00297     double nLaserEventsWithMatacq;
00298     double nNonLaserEventsWithMatacq;
00299   } stats_;
00300 
00301   static stats_t stats_init;
00304   std::string logFileName_;
00305 
00308   std::ofstream logFile_;
00309 };
00310 
00311 #endif