CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes
RawEventFileWriterForBU Class Reference

#include <RawEventFileWriterForBU.h>

Public Member Functions

uint32 adler32 () const
 
void doFlushFile ()
 
void doOutputEvent (FRDEventMsgView const &msg)
 
void doOutputEvent (boost::shared_array< unsigned char > &msg)
 
void doOutputEventFragment (unsigned char *dataPtr, unsigned long dataSize)
 
void endOfLS (int ls)
 
void handler (int s)
 
void initialize (std::string const &destinationDir, std::string const &name, int ls)
 
 RawEventFileWriterForBU (edm::ParameterSet const &ps)
 
 RawEventFileWriterForBU (std::string const &fileName)
 
bool sharedMode () const
 
void start ()
 
void stop ()
 
 ~RawEventFileWriterForBU ()
 

Static Public Member Functions

static void staticHandler (int s)
 

Private Attributes

uint32 adlera_
 
uint32 adlerb_
 
std::string destinationDir_
 
std::string fileName_
 
string jsonDefLocation_
 
DataPointMonitorlumiMon_
 
int microSleep_
 
std::auto_ptr< std::ofstream > ost_
 
int outfd_
 
IntJ perFileEventCount_
 
DataPointMonitorperFileMon_
 
IntJ perLumiEventCount_
 

Static Private Attributes

static RawEventFileWriterForBUinstance = 0
 

Detailed Description

Definition at line 23 of file RawEventFileWriterForBU.h.

Constructor & Destructor Documentation

RawEventFileWriterForBU::RawEventFileWriterForBU ( edm::ParameterSet const &  ps)
explicit

Definition at line 36 of file RawEventFileWriterForBU.cc.

References instance, jsonDefLocation_, lumiMon_, NULL, perFileEventCount_, perFileMon_, perLumiEventCount_, jsoncollector::JsonMonitorable::setName(), staticHandler(), and jsoncollector::IntJ::value().

36  : lumiMon_(0), outfd_(0),
37  jsonDefLocation_(ps.getUntrackedParameter<string>("jsonDefLocation","")),
38  // default to .5ms sleep per event
39  microSleep_(ps.getUntrackedParameter<int>("microSleep", 0))
40 {
41  // initialize(ps.getUntrackedParameter<std::string>("fileName", "testFRDfile.dat"));
43  // set names of the variables to be matched with JSON Definition
44  perLumiEventCount_.setName("NEvents");
45 
46  // create a vector of all monitorable parameters to be passed to the monitor
47  vector<JsonMonitorable*> lumiMonParams;
48  lumiMonParams.push_back(&perLumiEventCount_);
49 
50  // create a DataPointMonitor using vector of monitorable parameters and a path to a JSON Definition file
51  lumiMon_ = new DataPointMonitor(lumiMonParams, jsonDefLocation_);
52 
53 
55  perFileEventCount_.setName("NEvents");
56 
57  // create a vector of all monitorable parameters to be passed to the monitor
58  vector<JsonMonitorable*> fileMonParams;
59  fileMonParams.push_back(&perFileEventCount_);
60 
61  perFileMon_ = new DataPointMonitor(fileMonParams, jsonDefLocation_);
62  instance = this;
63 
64  // SIGINT Handler
65  struct sigaction sigIntHandler;
66  sigIntHandler.sa_handler = RawEventFileWriterForBU::staticHandler;
67  sigemptyset(&sigIntHandler.sa_mask);
68  sigIntHandler.sa_flags = 0;
69  sigaction(SIGINT, &sigIntHandler, NULL);
70 
71 }
#define NULL
Definition: scimark2.h:8
static void staticHandler(int s)
static RawEventFileWriterForBU * instance
RawEventFileWriterForBU::RawEventFileWriterForBU ( std::string const &  fileName)
explicit

Definition at line 73 of file RawEventFileWriterForBU.cc.

74 {
75  // initialize(fileName);
76 
77 }
RawEventFileWriterForBU::~RawEventFileWriterForBU ( )

Definition at line 79 of file RawEventFileWriterForBU.cc.

References lumiMon_, and perFileMon_.

80 {
81  // ost_->close();
82  if (lumiMon_ != 0)
83  delete lumiMon_;
84  if (perFileMon_ != 0)
85  delete perFileMon_;
86 }

Member Function Documentation

uint32 RawEventFileWriterForBU::adler32 ( ) const
inline

Definition at line 36 of file RawEventFileWriterForBU.h.

void RawEventFileWriterForBU::doFlushFile ( )

Definition at line 117 of file RawEventFileWriterForBU.cc.

References edm::hlt::Exception, fileName_, and ost_.

118 {
119  ost_->flush();
120  if (ost_->fail()) {
121  throw cms::Exception("RawEventFileWriterForBU", "doOutputEvent")
122  << "Error writing FED Raw Data event data to "
123  << fileName_ << ". Possibly the output disk "
124  << "is full?" << std::endl;
125  }
126 }
std::auto_ptr< std::ofstream > ost_
void RawEventFileWriterForBU::doOutputEvent ( FRDEventMsgView const &  msg)

Definition at line 88 of file RawEventFileWriterForBU.cc.

References edm::hlt::Exception, fileName_, microSleep_, outfd_, perFileEventCount_, perLumiEventCount_, FRDEventMsgView::size(), FRDEventMsgView::startAddress(), jsoncollector::IntJ::value(), and TablePrint::write.

89 {
90  // ost_->write((const char*) msg.startAddress(), msg.size());
91  // if (ost_->fail()) {
92  ssize_t retval = write(outfd_,(void*)msg.startAddress(), msg.size());
93  if((unsigned)retval!= msg.size()){
94  throw cms::Exception("RawEventFileWriterForBU", "doOutputEvent")
95  << "Error writing FED Raw Data event data to "
96  << fileName_ << ". Possibly the output disk "
97  << "is full?" << std::endl;
98  }
99 
100  // throttle event output
101  usleep(microSleep_);
102 
105 
106  // ost_->flush();
107  // if (ost_->fail()) {
108  // throw cms::Exception("RawEventFileWriterForBU", "doOutputEvent")
109  // << "Error writing FED Raw Data event data to "
110  // << fileName_ << ". Possibly the output disk "
111  // << "is full?" << std::endl;
112  // }
113 
114  // cms::Adler32((const char*) msg.startAddress(), msg.size(), adlera_, adlerb_);
115 }
void RawEventFileWriterForBU::doOutputEvent ( boost::shared_array< unsigned char > &  msg)
inline

Definition at line 32 of file RawEventFileWriterForBU.h.

32 {};
void RawEventFileWriterForBU::doOutputEventFragment ( unsigned char *  dataPtr,
unsigned long  dataSize 
)

Definition at line 128 of file RawEventFileWriterForBU.cc.

References cms::Adler32(), adlera_, adlerb_, edm::hlt::Exception, fileName_, and ost_.

130 {
131  ost_->write((const char*) dataPtr, dataSize);
132  if (ost_->fail()) {
133  throw cms::Exception("RawEventFileWriterForBU", "doOutputEventFragment")
134  << "Error writing FED Raw Data event data to "
135  << fileName_ << ". Possibly the output disk "
136  << "is full?" << std::endl;
137  }
138 
139  ost_->flush();
140  if (ost_->fail()) {
141  throw cms::Exception("RawEventFileWriterForBU", "doOutputEventFragment")
142  << "Error writing FED Raw Data event data to "
143  << fileName_ << ". Possibly the output disk "
144  << "is full?" << std::endl;
145  }
146 
147  cms::Adler32((const char*) dataPtr, dataSize, adlera_, adlerb_);
148 }
std::auto_ptr< std::ofstream > ost_
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
void RawEventFileWriterForBU::endOfLS ( int  ls)

Definition at line 202 of file RawEventFileWriterForBU.cc.

References destinationDir_, reco::dp, lumiMon_, outfd_, convertSQLitetoXML_cfg::output, getHLTPrescaleColumns::path, perLumiEventCount_, cond::serialize(), and jsoncollector::DataPointMonitor::snap().

203 {
204  //writing empty EoLS file (will be filled with information)
205  // create a DataPoint object and take a snapshot of the monitored data into it
206  DataPoint dp;
207  lumiMon_->snap(dp);
208 
209  std::ostringstream ostr;
210  ostr << destinationDir_ << "/EoLS_" << std::setfill('0') << std::setw(4) << ls << ".jsn";
211  int outfd_ = open(ostr.str().c_str(), O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
212  if(outfd_!=0){close(outfd_); outfd_=0;}
213 
214  // serialize the DataPoint and output it
215  string output;
216  JSONSerializer::serialize(&dp, output);
217 
218  string path = ostr.str();
219  FileIO::writeStringToFile(path, output);
220 
221  perLumiEventCount_ = 0;
222 }
auto dp
Definition: deltaR.h:24
Binary serialize(const T &payload, bool packingOnly=false)
Definition: Serialization.h:88
void snap(DataPoint &outputDataPoint)
void RawEventFileWriterForBU::handler ( int  s)

Definition at line 19 of file RawEventFileWriterForBU.cc.

References destinationDir_, convertSQLitetoXML_cfg::output, getHLTPrescaleColumns::path, DTTTrigCorrFirst::run, and AlCaHLTBitMon_QueryRunRegistry::string.

19  {
20  printf("Caught signal %d. Writing EOR file!\n",s);
21  if (destinationDir_.size() > 0)
22  {
23  // CREATE EOR file
24  string path = destinationDir_ + "/" + "EoR.jsd";
25  string output = "EOR";
26  FileIO::writeStringToFile(path, output);
27  //dirty hack: extract run number from destination directory
28  std::string::size_type pos = destinationDir_.find("run");
29  std::string run = destinationDir_.substr(pos+3);
30  path=destinationDir_ + "/" + "EoR_" + run + ".jsn";
31  FileIO::writeStringToFile(path, output);
32  }
33  _exit(0);
34 }
uint16_t size_type
void RawEventFileWriterForBU::initialize ( std::string const &  destinationDir,
std::string const &  name,
int  ls 
)

Definition at line 150 of file RawEventFileWriterForBU.cc.

References adlera_, adlerb_, destinationDir_, reco::dp, edm::hlt::Exception, fileName_, mergeVDriftHistosByStation::name, ost_, dbtoconf::out, outfd_, convertSQLitetoXML_cfg::output, getHLTPrescaleColumns::path, perFileEventCount_, perFileMon_, cond::serialize(), jsoncollector::DataPointMonitor::snap(), AlCaHLTBitMon_QueryRunRegistry::string, and jsoncollector::IntJ::value().

151 {
152  std::string oldFileName = fileName_;
153  fileName_ = name;
154  destinationDir_ = destinationDir;
155  if(outfd_!=0){
156  close(outfd_);
157  outfd_=0;
158  }
159  outfd_ = open(fileName_.c_str(), O_WRONLY | O_CREAT, S_IRWXU);
160  if(outfd_ <= 0) { //attention here... it may happen that outfd_ is *not* set (e.g. missing initialize call...)
161  throw cms::Exception("RawEventFileWriterForBU","initialize")
162  << "Error opening FED Raw Data event output file: " << name
163  << ": " << strerror(errno) << "\n";
164  }
165  ost_.reset(new std::ofstream(name.c_str(), std::ios_base::binary | std::ios_base::out));
166 
167  //move old file to done directory
168  if (!oldFileName.empty()) {
169  //rename(oldFileName.c_str(),destinationDir_.c_str());
170 
171  DataPoint dp;
172  perFileMon_->snap(dp);
173  string output;
174  JSONSerializer::serialize(&dp, output);
175  std::stringstream ss;
176  ss << destinationDir_ << "/" << oldFileName.substr(oldFileName.rfind("/") + 1, oldFileName.size() - oldFileName.rfind("/") - 5) << ".jsn";
177  string path = ss.str();
178  FileIO::writeStringToFile(path, output);
179  //now that the json file is there, move the raw file
180  int fretval = rename(oldFileName.c_str(),(destinationDir_+oldFileName.substr(oldFileName.rfind("/"))).c_str());
181  // if (debug_)
182  edm::LogInfo("RawEventFileWriterForBU") << " tried move " << oldFileName << " to " << destinationDir_
183  << " status " << fretval << " errno " << strerror(errno);
184 
185  edm::LogInfo("RawEventFileWriterForBU") << "Wrote JSON input file: " << path
186  << " with perFileEventCount = " << perFileEventCount_.value();
187 
189 
190  }
191 
192 
193  if (!ost_->is_open()) {
194  throw cms::Exception("RawEventFileWriterForBU","initialize")
195  << "Error opening FED Raw Data event output file: " << name << "\n";
196  }
197 
198  adlera_ = 1;
199  adlerb_ = 0;
200 }
std::auto_ptr< std::ofstream > ost_
tuple out
Definition: dbtoconf.py:99
auto dp
Definition: deltaR.h:24
Binary serialize(const T &payload, bool packingOnly=false)
Definition: Serialization.h:88
void snap(DataPoint &outputDataPoint)
bool RawEventFileWriterForBU::sharedMode ( ) const
inline

Definition at line 42 of file RawEventFileWriterForBU.h.

42 {return false;}
void RawEventFileWriterForBU::start ( void  )
inline
static void RawEventFileWriterForBU::staticHandler ( int  s)
inlinestatic

Definition at line 45 of file RawEventFileWriterForBU.h.

References instance.

Referenced by RawEventFileWriterForBU().

45 { instance->handler(s); }
static RawEventFileWriterForBU * instance
void RawEventFileWriterForBU::stop ( )
inline

Definition at line 39 of file RawEventFileWriterForBU.h.

39 {}

Member Data Documentation

uint32 RawEventFileWriterForBU::adlera_
private

Definition at line 62 of file RawEventFileWriterForBU.h.

Referenced by doOutputEventFragment(), and initialize().

uint32 RawEventFileWriterForBU::adlerb_
private

Definition at line 63 of file RawEventFileWriterForBU.h.

Referenced by doOutputEventFragment(), and initialize().

std::string RawEventFileWriterForBU::destinationDir_
private

Definition at line 57 of file RawEventFileWriterForBU.h.

Referenced by endOfLS(), handler(), and initialize().

std::string RawEventFileWriterForBU::fileName_
private
RawEventFileWriterForBU * RawEventFileWriterForBU::instance = 0
staticprivate

Definition at line 65 of file RawEventFileWriterForBU.h.

Referenced by RawEventFileWriterForBU().

string RawEventFileWriterForBU::jsonDefLocation_
private

Definition at line 59 of file RawEventFileWriterForBU.h.

Referenced by RawEventFileWriterForBU().

DataPointMonitor* RawEventFileWriterForBU::lumiMon_
private
int RawEventFileWriterForBU::microSleep_
private

Definition at line 60 of file RawEventFileWriterForBU.h.

Referenced by doOutputEvent().

std::auto_ptr<std::ofstream> RawEventFileWriterForBU::ost_
private

Definition at line 54 of file RawEventFileWriterForBU.h.

Referenced by doFlushFile(), doOutputEventFragment(), and initialize().

int RawEventFileWriterForBU::outfd_
private

Definition at line 55 of file RawEventFileWriterForBU.h.

Referenced by doOutputEvent(), endOfLS(), and initialize().

IntJ RawEventFileWriterForBU::perFileEventCount_
private

Definition at line 51 of file RawEventFileWriterForBU.h.

Referenced by doOutputEvent(), initialize(), and RawEventFileWriterForBU().

DataPointMonitor* RawEventFileWriterForBU::perFileMon_
private
IntJ RawEventFileWriterForBU::perLumiEventCount_
private

Definition at line 49 of file RawEventFileWriterForBU.h.

Referenced by doOutputEvent(), endOfLS(), and RawEventFileWriterForBU().