CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FUShmOutputModule.cc
Go to the documentation of this file.
1 /*
2  Description:
3  EDM output module that will write data to shared memory for
4  the resource broker to send to the Storage Manager.
5  See the CMS EvF Storage Manager wiki page for further notes.
6 
7  $Id: FUShmOutputModule.cc,v 1.12 2011/01/19 13:19:02 meschi Exp $
8 */
9 
15 
21 
22 #include "xdaq/Application.h"
23 #include "xdaq/ApplicationContext.h"
24 #include "xdaq/ApplicationGroup.h"
25 #include "zlib.h"
26 
27 #include <string>
28 #include <fstream>
29 #include <iostream>
30 
31 using namespace edm;
32 using namespace std;
33 
35 
36 namespace edm
37 {
38 
44 
46  shmBuffer_(0)
47  , name_(ps.getParameter<std::string>( "@module_label" ))
48  , count_(0)
49  {
50  FDEBUG(9) << "FUShmOutputModule: constructor" << endl;
52  edm::Service<evf::ShmOutputModuleRegistry>()->registerModule(name_, this);
53  if (! fuIdsInitialized_) {
54  fuIdsInitialized_ = true;
55 
56  edm::Guid guidObj(true);
57  std::string guidString = guidObj.toString();
58 
59  uLong crc = crc32(0L, Z_NULL, 0);
60  Bytef* buf = (Bytef*)guidString.data();
61  crc = crc32(crc, buf, guidString.length());
62  fuGuidValue_ = crc;
63  }
64  }
65 
67  {
68  FDEBUG(9) << "FUShmOutputModule: FUShmOutputModule destructor" << endl;
70  //shmdt(shmBuffer_);
71  }
72 
74  {
75  count_ = 0;
77  if(!shmBuffer_) edm::LogError("FUShmOutputModule")
78  << " Error getting shared memory buffer for INIT. "
79  << " Make sure you configure the ResourceBroker before the FUEventProcessor! "
80  << " No INIT is sent - this is probably fatal!";
81  if(shmBuffer_)
82  {
83  unsigned char* buffer = (unsigned char*) initMessage.startAddress();
84  unsigned int size = initMessage.size();
85  FDEBUG(10) << "writing out INIT message with size = " << size << std::endl;
86  // no method in InitMsgBuilder to get the output module id, recast
87  InitMsgView dummymsg(buffer);
88  uint32 dmoduleId = dummymsg.outputModuleId();
89 
90  //bool ret = shmBuffer_->writeRecoInitMsg(dmoduleId, buffer, size);
91  bool ret = sm_sharedmemory.getShmBuffer()->writeRecoInitMsg(dmoduleId, getpid(), fuGuidValue_, buffer, size);
92  if(!ret) edm::LogError("FUShmOutputModule") << " Error writing preamble to ShmBuffer";
93  }
94  }
95 
97  {
98  if(!shmBuffer_) edm::LogError("FUShmOutputModule")
99  << " Invalid shared memory buffer at first event"
100  << " Make sure you configure the ResourceBroker before the FUEventProcessor! "
101  << " No event is sent - this is fatal! Should throw here";
102  else
103  {
104  count_++;
105  unsigned char* buffer = (unsigned char*) eventMessage.startAddress();
106  unsigned int size = eventMessage.size();
107  EventMsgView eventView(eventMessage.startAddress());
108  unsigned int runid = eventView.run();
109  unsigned int eventid = eventView.event();
110  unsigned int outModId = eventView.outModId();
111  FDEBUG(10) << "FUShmOutputModule: event size = " << size << std::endl;
112  //bool ret = shmBuffer_->writeRecoEventData(runid, eventid, outModId, buffer, size);
113  bool ret = sm_sharedmemory.getShmBuffer()->writeRecoEventData(runid, eventid, outModId, getpid(), fuGuidValue_, buffer, size);
114  if(!ret) edm::LogError("FUShmOutputModule") << " Error with writing data to ShmBuffer";
115  }
116  }
117 
119  {
120  //shmBuffer_ = evf::FUShmBuffer::getShmBuffer();
122  if(0==shmBuffer_)
123  edm::LogError("FUShmOutputModule")<<"Failed to attach to shared memory";
124  }
125 
127  {
128  FDEBUG(9) << "FUShmOutputModule: sending terminate run" << std::endl;
129  if(0!=shmBuffer_){
131  //shmdt(shmBuffer_);
132  shmBuffer_ = 0;
133  }
134  }
135 
136 }
FUShmOutputModule(edm::ParameterSet const &ps)
bool writeRecoEventData(unsigned int runNumber, unsigned int evtNumber, unsigned int outModId, unsigned int fuProcessId, unsigned int fuGuid, unsigned char *data, unsigned int dataSize)
Definition: FUShmBuffer.cc:670
bool writeRecoInitMsg(unsigned int outModId, unsigned int fuProcessId, unsigned int fuGuid, unsigned char *data, unsigned int dataSize)
Definition: FUShmBuffer.cc:647
uint8 * startAddress() const
#define FDEBUG(lev)
Definition: DebugMacros.h:18
uint32 run() const
Definition: EventMessage.cc:73
void doOutputHeader(InitMsgBuilder const &initMessage)
std::string const toString() const
Automatic conversion from string reprentation.
Definition: Guid.cc:44
Definition: Guid.h:23
uint32 size() const
evf::FUShmBuffer * getShmBuffer()
unsigned int uint32
Definition: MsgTools.h:13
static SM_SharedMemoryHandle sm_sharedmemory
uint32 outputModuleId() const
Definition: InitMessage.h:75
void doOutputEvent(EventMsgBuilder const &eventMessage)
uint8 * startAddress() const
tuple size
Write out results.
evf::FUShmBuffer * shmBuffer_
uint32 size() const