CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MTRawEventFileWriterForBU.h
Go to the documentation of this file.
1 #ifndef EVFMTRAWEVENTFILEWRITERFORBU
2 #define EVFMTRAWEVENTFILEWRITERFORBU
3 
4 // $Id: MTRawEventFileWriterForBU.h,v 1.1.2.6 2013/01/16 11:33:54 aspataru Exp $
5 
8 
9 #include "../interface/JsonMonitorable.h"
10 #include "../interface/DataPointMonitor.h"
11 #include "../interface/JSONSerializer.h"
12 
13 
14 #ifdef linux
15 #include <atomic>
16 #include <mutex>
17 #include <thread>
18 #endif
19 
20 #include <fstream>
21 #include <deque>
22 #include <string.h>
23 #include <stdio.h>
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 #include <fcntl.h>
27 
28 #include "boost/shared_array.hpp"
29 
30 using namespace jsoncollector;
31 
32 namespace fwriter {
33  class EventContainer;
34 }
35 
37 {
38  public:
39 
40  explicit MTRawEventFileWriterForBU(edm::ParameterSet const& ps);
42 
43  void doOutputEvent(FRDEventMsgView const& msg);
44  void doOutputEvent(boost::shared_array<unsigned char> & msg);
45  void doOutputEventFragment(unsigned char* dataPtr,
46  unsigned long dataSize);
47  void doFlushFile();
48  uint32 adler32(uint32 adlera, uint32 adlerb) const { return 0;/*return (adlerb_ << 16) | adlera_;*/ }
49 
50  void start() {}
51  void stop() {
52  finishThreads();
53  }
54  void initialize(std::string const& destinationDir, std::string const& name, int ls);
55  void endOfLS(int ls);
56  bool sharedMode() const {return sharedMode_;}
57  private:
58 
62 
63  inline void queueEvent(const char* buffer,unsigned long size);
64  inline void queueEvent(boost::shared_array<unsigned char> & msg);
65  void dispatchThreads(std::string fileBase, unsigned int instances, std::string suffix);
66 
68  {
69 #ifdef linux
70  close_flag_=true;
71  for (auto w: writers) w->join();
72  writers.clear();
73 #endif
74  }
75  //opens file and waits for events
76  void threadRunner(std::string fileName, unsigned int instance);
77 
78  //std::string name_;
79  //unsigned int count_;
82 
83  unsigned int numWriters_;
84  unsigned int eventBufferSize_;
87  bool debug_;
89 #ifdef linux
90  std::atomic<bool> close_flag_;
91  std::mutex queue_lock;
92 #endif
93 
94  //event buffer
95  std::deque<unsigned int> freeIds;
96  std::deque<unsigned int> queuedIds;
97  std::vector<fwriter::EventContainer*> EventPool;
98  //thread pool
99 #ifdef linux
100  std::vector<std::auto_ptr<std::thread>> writers;
101 #endif
102  std::vector<uint32> v_adlera_;
103  std::vector<uint32> v_adlerb_;
104 
105  unsigned char * fileHeader_;
106 
107  std::vector<IntJ*> perFileCounters_;
108  std::vector<DataPointMonitor*> perFileMonitors_;
109 };
110 #endif
static boost::mutex mutex
Definition: LHEProxy.cc:11
static PFTauRenderPlugin instance
std::vector< fwriter::EventContainer * > EventPool
unsigned int uint32
Definition: MsgTools.h:13
uint32 adler32(uint32 adlera, uint32 adlerb) const
std::deque< unsigned int > queuedIds
T w() const
std::deque< unsigned int > freeIds
std::vector< DataPointMonitor * > perFileMonitors_
tuple size
Write out results.
std::vector< IntJ * > perFileCounters_