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 Member Functions | Private Attributes | Static Private Attributes
RawEventFileWriterForBU Class Reference

#include <RawEventFileWriterForBU.h>

Public Member Functions

uint32 adler32 () const
 
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)
 
void makeRunPrefix (std::string const &destinationDir)
 
 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 Member Functions

bool closefd ()
 
void finishFileWrite (int ls)
 
void writeJsds ()
 

Private Attributes

uint32 adlera_
 
uint32 adlerb_
 
std::string destinationDir_
 
DataPointDefinition eolJsonDef_
 
DataPointDefinition eorJsonDef_
 
FastMonitorfileMon_ = nullptr
 
std::string fileName_
 
FastMonitorlumiMon_ = nullptr
 
int microSleep_
 
std::auto_ptr< std::ofstream > ost_
 
int outfd_ = -1
 
IntJ perFileEventCount_
 
IntJ perLumiEventCount_
 
IntJ perLumiFileCount_
 
IntJ perLumiTotalEventCount_
 
IntJ perRunEventCount_
 
IntJ perRunFileCount_
 
IntJ perRunLumiCount_
 
DataPointDefinition rawJsonDef_
 
int run_ = -1
 
FastMonitorrunMon_ = nullptr
 
std::string runPrefix_
 
bool writtenJSDs_ =false
 

Static Private Attributes

static RawEventFileWriterForBUinstance = 0
 

Detailed Description

Definition at line 21 of file RawEventFileWriterForBU.h.

Constructor & Destructor Documentation

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

Definition at line 26 of file RawEventFileWriterForBU.cc.

References jsoncollector::DataPointDefinition::addLegendItem(), jsoncollector::FastMonitor::commit(), eolJsonDef_, eorJsonDef_, fileMon_, instance, lumiMon_, NULL, perFileEventCount_, perLumiEventCount_, perLumiFileCount_, perLumiTotalEventCount_, perRunEventCount_, perRunFileCount_, perRunLumiCount_, rawJsonDef_, jsoncollector::FastMonitor::registerGlobalMonitorable(), runMon_, jsoncollector::DataPointDefinition::setDefaultGroup(), jsoncollector::JsonMonitorable::setName(), staticHandler(), and SUM.

26  :
27  // default to .5ms sleep per event
28  microSleep_(ps.getUntrackedParameter<int>("microSleep", 0))
29  //debug_(ps.getUntrackedParameter<bool>("debug", False))
30 {
31 
32  //per-file JSD and FastMonitor
33  rawJsonDef_.setDefaultGroup("legend");
35 
36  perFileEventCount_.setName("NEvents");
37 
38  fileMon_ = new FastMonitor(&rawJsonDef_,false);
40  fileMon_->commit(nullptr);
41 
42  //per-lumi JSD and FastMonitor
43  eolJsonDef_.setDefaultGroup("legend");
46  eolJsonDef_.addLegendItem("TotalEvents","integer",DataPointDefinition::SUM);
47 
48  perLumiEventCount_.setName("NEvents");
49  perLumiFileCount_.setName("NFiles");
50  perLumiTotalEventCount_.setName("TotalEvents");
51 
52  lumiMon_ = new FastMonitor(&eolJsonDef_,false);
56  lumiMon_->commit(nullptr);
57 
58 
59  //per-run JSD and FastMonitor
60  eorJsonDef_.setDefaultGroup("legend");
64 
65  perRunEventCount_.setName("NEvents");
66  perRunFileCount_.setName("NFiles");
67  perRunLumiCount_.setName("NLumis");
68 
69  runMon_ = new FastMonitor(&eorJsonDef_,false);
73  runMon_->commit(nullptr);
74 
75  instance = this;
76 
77  // SIGINT Handler
78  struct sigaction sigIntHandler;
79  sigIntHandler.sa_handler = RawEventFileWriterForBU::staticHandler;
80  sigemptyset(&sigIntHandler.sa_mask);
81  sigIntHandler.sa_flags = 0;
82  sigaction(SIGINT, &sigIntHandler, NULL);
83 
84 }
void addLegendItem(std::string const &name, std::string const &type, std::string const &operation)
DataPointDefinition rawJsonDef_
#define NULL
Definition: scimark2.h:8
void registerGlobalMonitorable(JsonMonitorable *newMonitorable, bool NAifZeroUpdates, unsigned int *nBins=nullptr)
Definition: FastMonitor.cc:62
DataPointDefinition eorJsonDef_
virtual void setName(std::string name)
static void staticHandler(int s)
void commit(std::vector< unsigned int > *streamLumisPtr)
Definition: FastMonitor.cc:109
#define SUM(A, B)
static RawEventFileWriterForBU * instance
void setDefaultGroup(std::string const &group)
DataPointDefinition eolJsonDef_
RawEventFileWriterForBU::RawEventFileWriterForBU ( std::string const &  fileName)
explicit

Definition at line 86 of file RawEventFileWriterForBU.cc.

87 {
88 
89 }
RawEventFileWriterForBU::~RawEventFileWriterForBU ( )

Definition at line 91 of file RawEventFileWriterForBU.cc.

References fileMon_, lumiMon_, and runMon_.

92 {
93  delete fileMon_;
94  delete lumiMon_;
95  delete runMon_;
96 }

Member Function Documentation

uint32 RawEventFileWriterForBU::adler32 ( ) const
inline

Definition at line 34 of file RawEventFileWriterForBU.h.

bool RawEventFileWriterForBU::closefd ( )
inlineprivate

Definition at line 48 of file RawEventFileWriterForBU.h.

Referenced by endOfLS(), and initialize().

48 {if(outfd_>=0){close(outfd_); outfd_=-1; return true;} else return false;}
void RawEventFileWriterForBU::doOutputEvent ( FRDEventMsgView const &  msg)

Definition at line 98 of file RawEventFileWriterForBU.cc.

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

99 {
100  ssize_t retval = write(outfd_,(void*)msg.startAddress(), msg.size());
101 
102  if((unsigned)retval!= msg.size()){
103  throw cms::Exception("RawEventFileWriterForBU", "doOutputEvent")
104  << "Error writing FED Raw Data event data to "
105  << fileName_ << ". Possibly the output disk "
106  << "is full?" << std::endl;
107  }
108 
109  // throttle event output
110  usleep(microSleep_);
111 
115 
116  // cms::Adler32((const char*) msg.startAddress(), msg.size(), adlera_, adlerb_);
117 }
void RawEventFileWriterForBU::doOutputEvent ( boost::shared_array< unsigned char > &  msg)
inline

Definition at line 30 of file RawEventFileWriterForBU.h.

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

Definition at line 119 of file RawEventFileWriterForBU.cc.

References edm::hlt::Exception.

120 {
121 
122  throw cms::Exception("RawEventFileWriterForBU", "doOutputEventFragment")
123  << "Unsupported output mode ";
124 
125  //cms::Adler32((const char*) dataPtr, dataSize, adlera_, adlerb_);
126 }
void RawEventFileWriterForBU::endOfLS ( int  ls)

Definition at line 249 of file RawEventFileWriterForBU.cc.

References closefd(), destinationDir_, jsoncollector::FastMonitor::discardCollected(), finishFileWrite(), lumiMon_, makeRunPrefix(), jsoncollector::FastMonitor::outputFullJSON(), cmsHarvester::path, perLumiEventCount_, perLumiFileCount_, perLumiTotalEventCount_, perRunEventCount_, perRunFileCount_, perRunLumiCount_, run_, runPrefix_, jsoncollector::FastMonitor::snap(), AlCaHLTBitMon_QueryRunRegistry::string, and jsoncollector::IntJ::value().

250 {
251  if (closefd()) finishFileWrite(ls);
252  lumiMon_->snap(ls);
253 
254  std::ostringstream ostr;
255 
257 
258  ostr << destinationDir_ << "/"<< runPrefix_ << "_ls" << std::setfill('0') << std::setw(4) << ls << "_EoLS" << ".jsn";
259  //outfd_ = open(ostr.str().c_str(), O_WRONLY | O_CREAT, S_IWUSR | S_IRUSR | S_IWGRP | S_IRGRP | S_IWOTH | S_IROTH);
260  //closefd();
261 
262  std::string path = ostr.str();
263  lumiMon_->outputFullJSON(path, ls);
265 
268  perRunLumiCount_.value() += 1;
269 
270  perLumiEventCount_ = 0;
271  perLumiFileCount_ = 0;
273 }
bool outputFullJSON(std::string const &path, unsigned int lumi, bool log=true)
Definition: FastMonitor.cc:249
tuple path
else: Piece not in the list, fine.
void snap(unsigned int ls)
Definition: FastMonitor.cc:190
void makeRunPrefix(std::string const &destinationDir)
void discardCollected(unsigned int forLumi)
Definition: FastMonitor.cc:268
void RawEventFileWriterForBU::finishFileWrite ( int  ls)
private

Definition at line 224 of file RawEventFileWriterForBU.cc.

References destinationDir_, jsoncollector::FastMonitor::discardCollected(), fileMon_, fileName_, jsoncollector::FastMonitor::outputFullJSON(), cmsHarvester::path, perFileEventCount_, jsoncollector::FastMonitor::snap(), source, contentValuesCheck::ss, AlCaHLTBitMon_QueryRunRegistry::string, and jsoncollector::IntJ::value().

Referenced by endOfLS(), and initialize().

225 {
226 
227  //move raw file from open to run directory
228  rename(fileName_.c_str(),(destinationDir_+fileName_.substr(fileName_.rfind("/"))).c_str());
229 
230  //create equivalent JSON file
231  std::stringstream ss;
232  //TODO:fix this to use DaqDirector convention and better extension replace
234  std::string path = source.replace_extension(".jsn").string();
235 
236  fileMon_->snap(ls);
237  fileMon_->outputFullJSON(path, ls, false);
239 
240  //move the json file from open
241  rename(path.c_str(),(destinationDir_+path.substr(path.rfind("/"))).c_str());
242 
243  edm::LogInfo("RawEventFileWriterForBU") << "Wrote JSON input file: " << path
244  << " with perFileEventCount = " << perFileEventCount_.value();
245 
246 }
bool outputFullJSON(std::string const &path, unsigned int lumi, bool log=true)
Definition: FastMonitor.cc:249
tuple path
else: Piece not in the list, fine.
void snap(unsigned int ls)
Definition: FastMonitor.cc:190
static std::string const source
Definition: EdmProvDump.cc:43
void discardCollected(unsigned int forLumi)
Definition: FastMonitor.cc:268
void RawEventFileWriterForBU::handler ( int  s)

Definition at line 276 of file RawEventFileWriterForBU.cc.

References destinationDir_, makeRunPrefix(), jsoncollector::FastMonitor::outputFullJSON(), cmsHarvester::path, run_, runMon_, runPrefix_, jsoncollector::FastMonitor::snap(), and AlCaHLTBitMon_QueryRunRegistry::string.

276  {
277  printf("Caught signal %d. Writing EOR file!\n",s);
278  if (destinationDir_.size() > 0)
279  {
280  // CREATE EOR file
282  std::string path = destinationDir_ + "/" + runPrefix_ + "_ls0000_EoR.jsn";
283  runMon_->snap(0);
284  runMon_->outputFullJSON(path, 0);
285  }
286  _exit(0);
287 }
bool outputFullJSON(std::string const &path, unsigned int lumi, bool log=true)
Definition: FastMonitor.cc:249
tuple path
else: Piece not in the list, fine.
void snap(unsigned int ls)
Definition: FastMonitor.cc:190
void makeRunPrefix(std::string const &destinationDir)
void RawEventFileWriterForBU::initialize ( std::string const &  destinationDir,
std::string const &  name,
int  ls 
)

Definition at line 128 of file RawEventFileWriterForBU.cc.

References adlera_, adlerb_, closefd(), destinationDir_, edm::hlt::Exception, fileName_, finishFileWrite(), mergeVDriftHistosByStation::name, outfd_, perFileEventCount_, perLumiFileCount_, jsoncollector::IntJ::value(), writeJsds(), and writtenJSDs_.

129 {
130  destinationDir_ = destinationDir;
131 
132  if (closefd()) finishFileWrite(ls);
133 
134  fileName_ = name;
135 
136  if (!writtenJSDs_) {
137  writeJsds();
138 /* std::stringstream ss;
139  ss << destinationDir_ << "/jsd";
140  mkdir(ss.str().c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
141 
142  std::string rawJSDName = ss.str()+"/rawData.jsd";
143  std::string eolJSDName = ss.str()+"/EoLS.jsd";
144  std::string eorJSDName = ss.str()+"/EoR.jsd";
145 
146  fileMon_->setDefPath(rawJSDName);
147  lumiMon_->setDefPath(eolJSDName);
148  runMon_->setDefPath(eorJSDName);
149 
150  struct stat fstat;
151  if (stat (rawJSDName.c_str(), &fstat) != 0) {
152  std::string content;
153  JSONSerializer::serialize(&rawJsonDef_,content);
154  FileIO::writeStringToFile(rawJSDName, content);
155  }
156 
157  if (stat (eolJSDName.c_str(), &fstat) != 0) {
158  std::string content;
159  JSONSerializer::serialize(&eolJsonDef_,content);
160  FileIO::writeStringToFile(eolJSDName, content);
161  }
162 
163  if (stat (eorJSDName.c_str(), &fstat) != 0) {
164  std::string content;
165  JSONSerializer::serialize(&eorJsonDef_,content);
166  FileIO::writeStringToFile(eorJSDName, content);
167  }
168 */
169  writtenJSDs_=true;
170 
171  }
172 
173  outfd_ = open(fileName_.c_str(), O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
174  edm::LogInfo("RawEventFileWriterForBU") << " opened " << fileName_;
175  if(outfd_ < 0) { //attention here... it may happen that outfd_ is *not* set (e.g. missing initialize call...)
176  throw cms::Exception("RawEventFileWriterForBU","initialize")
177  << "Error opening FED Raw Data event output file: " << name
178  << ": " << strerror(errno) << "\n";
179  }
180 
183 
184 
185  adlera_ = 1;
186  adlerb_ = 0;
187 }
void RawEventFileWriterForBU::makeRunPrefix ( std::string const &  destinationDir)

Definition at line 290 of file RawEventFileWriterForBU.cc.

References DTTTrigCorrFirst::run, run_, runPrefix_, contentValuesCheck::ss, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by endOfLS(), and handler().

291 {
292  //dirty hack: extract run number from destination directory
293  std::string::size_type pos = destinationDir.find("run");
294  std::string run = destinationDir.substr(pos+3);
295  run_=atoi(run.c_str());
296  std::stringstream ss;
297  ss << "run" << std::setfill('0') << std::setw(6) << run_;
298  runPrefix_ = ss.str();
299 }
uint16_t size_type
bool RawEventFileWriterForBU::sharedMode ( ) const
inline

Definition at line 40 of file RawEventFileWriterForBU.h.

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

Definition at line 44 of file RawEventFileWriterForBU.h.

References instance.

Referenced by RawEventFileWriterForBU().

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

Definition at line 37 of file RawEventFileWriterForBU.h.

37 {}
void RawEventFileWriterForBU::writeJsds ( )
private

Definition at line 189 of file RawEventFileWriterForBU.cc.

References ws_sso_content_reader::content, destinationDir_, eolJsonDef_, eorJsonDef_, fileMon_, lumiMon_, rawJsonDef_, runMon_, cond::serialize(), jsoncollector::FastMonitor::setDefPath(), contentValuesCheck::ss, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by initialize().

190 {
191 
192  std::stringstream ss;
193  ss << destinationDir_ << "/jsd";
194  mkdir(ss.str().c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
195 
196  std::string rawJSDName = ss.str()+"/rawData.jsd";
197  std::string eolJSDName = ss.str()+"/EoLS.jsd";
198  std::string eorJSDName = ss.str()+"/EoR.jsd";
199 
200  fileMon_->setDefPath(rawJSDName);
201  lumiMon_->setDefPath(eolJSDName);
202  runMon_->setDefPath(eorJSDName);
203 
204  struct stat fstat;
205  if (stat (rawJSDName.c_str(), &fstat) != 0) {
208  FileIO::writeStringToFile(rawJSDName, content);
209  }
210 
211  if (stat (eolJSDName.c_str(), &fstat) != 0) {
214  FileIO::writeStringToFile(eolJSDName, content);
215  }
216 
217  if (stat (eorJSDName.c_str(), &fstat) != 0) {
220  FileIO::writeStringToFile(eorJSDName, content);
221  }
222 }
void setDefPath(std::string const &dpath)
Definition: FastMonitor.h:30
DataPointDefinition rawJsonDef_
DataPointDefinition eorJsonDef_
std::pair< Binary, Binary > serialize(const T &payload, bool packingOnly=false)
Definition: Serialization.h:92
DataPointDefinition eolJsonDef_

Member Data Documentation

uint32 RawEventFileWriterForBU::adlera_
private

Definition at line 81 of file RawEventFileWriterForBU.h.

Referenced by initialize().

uint32 RawEventFileWriterForBU::adlerb_
private

Definition at line 82 of file RawEventFileWriterForBU.h.

Referenced by initialize().

std::string RawEventFileWriterForBU::destinationDir_
private

Definition at line 77 of file RawEventFileWriterForBU.h.

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

DataPointDefinition RawEventFileWriterForBU::eolJsonDef_
private

Definition at line 71 of file RawEventFileWriterForBU.h.

Referenced by RawEventFileWriterForBU(), and writeJsds().

DataPointDefinition RawEventFileWriterForBU::eorJsonDef_
private

Definition at line 72 of file RawEventFileWriterForBU.h.

Referenced by RawEventFileWriterForBU(), and writeJsds().

FastMonitor* RawEventFileWriterForBU::fileMon_ = nullptr
private
std::string RawEventFileWriterForBU::fileName_
private

Definition at line 76 of file RawEventFileWriterForBU.h.

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

RawEventFileWriterForBU * RawEventFileWriterForBU::instance = 0
staticprivate

Definition at line 84 of file RawEventFileWriterForBU.h.

Referenced by RawEventFileWriterForBU().

FastMonitor* RawEventFileWriterForBU::lumiMon_ = nullptr
private
int RawEventFileWriterForBU::microSleep_
private

Definition at line 79 of file RawEventFileWriterForBU.h.

Referenced by doOutputEvent().

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

Definition at line 75 of file RawEventFileWriterForBU.h.

int RawEventFileWriterForBU::outfd_ = -1
private

Definition at line 51 of file RawEventFileWriterForBU.h.

Referenced by doOutputEvent(), and initialize().

IntJ RawEventFileWriterForBU::perFileEventCount_
private
IntJ RawEventFileWriterForBU::perLumiEventCount_
private

Definition at line 60 of file RawEventFileWriterForBU.h.

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

IntJ RawEventFileWriterForBU::perLumiFileCount_
private

Definition at line 61 of file RawEventFileWriterForBU.h.

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

IntJ RawEventFileWriterForBU::perLumiTotalEventCount_
private

Definition at line 62 of file RawEventFileWriterForBU.h.

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

IntJ RawEventFileWriterForBU::perRunEventCount_
private

Definition at line 56 of file RawEventFileWriterForBU.h.

Referenced by endOfLS(), and RawEventFileWriterForBU().

IntJ RawEventFileWriterForBU::perRunFileCount_
private

Definition at line 57 of file RawEventFileWriterForBU.h.

Referenced by endOfLS(), and RawEventFileWriterForBU().

IntJ RawEventFileWriterForBU::perRunLumiCount_
private

Definition at line 58 of file RawEventFileWriterForBU.h.

Referenced by endOfLS(), and RawEventFileWriterForBU().

DataPointDefinition RawEventFileWriterForBU::rawJsonDef_
private

Definition at line 70 of file RawEventFileWriterForBU.h.

Referenced by RawEventFileWriterForBU(), and writeJsds().

int RawEventFileWriterForBU::run_ = -1
private

Definition at line 53 of file RawEventFileWriterForBU.h.

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

FastMonitor* RawEventFileWriterForBU::runMon_ = nullptr
private
std::string RawEventFileWriterForBU::runPrefix_
private

Definition at line 54 of file RawEventFileWriterForBU.h.

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

bool RawEventFileWriterForBU::writtenJSDs_ =false
private

Definition at line 73 of file RawEventFileWriterForBU.h.

Referenced by initialize().