12 #include <boost/algorithm/string.hpp>
13 #include <boost/filesystem/fstream.hpp>
40 edm::RawInputSource(pset, desc),
41 eventChunkSize_(pset.getUntrackedParameter<unsigned int> (
"eventChunkSize",16)),
42 getLSFromFilename_(pset.getUntrackedParameter<bool> (
"getLSFromFilename",
true)),
43 verifyAdler32_(pset.getUntrackedParameter<bool> (
"verifyAdler32",
true)),
44 testModeNoBuilderUnit_(edm::Service<evf::EvFDaqDirector>()->getTestModeNoBuilderUnit()),
45 runNumber_(edm::Service<evf::EvFDaqDirector>()->getRunNumber()),
46 buInputDir_(edm::Service<evf::EvFDaqDirector>()->buBaseDir()),
47 fuOutputDir_(edm::Service<evf::EvFDaqDirector>()->fuBaseDir()),
52 currentLumiSection_(0),
53 currentInputJson_(
""),
54 currentInputEventCount_(0),
56 dataBuffer_(new unsigned
char[1024 * 1024 * eventChunkSize_]),
57 bufferCursor_(dataBuffer_),
61 gethostname(thishost, 255);
64 <<
" on host " << thishost;
83 if (eventAvailable < 0) {
89 else if(eventAvailable == 0) {
117 const string fuEoLS =
120 bool found = (stat(fuEoLS.c_str(), &buf) == 0);
122 int eol_fd = open(fuEoLS.c_str(), O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
132 gettimeofday(&tv, 0);
133 const edm::Timestamp lsopentime( (
unsigned long long) tv.tv_sec * 1000000 + (
unsigned long long) tv.tv_usec );
138 lumiSection, lsopentime,
144 edm::LogInfo(
"FedRawDataInputSource") <<
"New lumi section " << lumiSection <<
" opened";
154 if ( check ==-1)
return 0;
155 if ( check ==-100)
return -1;
160 const uint32_t msgSize =
event_->size();
167 "Premature end of input file while reading event data";
174 uint32_t adler = adler32(0
L,Z_NULL,0);
175 adler = adler32(adler,(Bytef*)
event_->payload(),
event_->eventSize());
177 if ( adler !=
event_->adler32() ) {
179 "Found a wrong Adler32 checksum: expected 0x" << std::hex <<
event_->adler32() <<
180 " but calculated 0x" << adler;
196 int fileStatus = 100;
201 if(fileStatus==0)
return -100;
211 bufferLeft_ += fread((
void*) (
dataBuffer_ + bufferLeft_),
259 edm::LogInfo(
"FedRawDataInputSource") <<
"No file for me... sleep and try again..." << std::endl;
289 uint32_t eventSize =
event_->eventSize();
290 char*
event = (
char*)
event_->payload();
292 while (eventSize > 0) {
293 eventSize -=
sizeof(
fedt_t);
296 eventSize -= (fedSize -
sizeof(
fedh_t));
303 tstamp =
edm::Timestamp(static_cast<edm::TimeValue_t> ((gpsh << 32) + gpsl));
305 FEDRawData& fedData = rawData->FEDData(fedId);
307 memcpy(fedData.
data(),
event + eventSize, fedSize);
309 assert(eventSize == 0);
318 throw cms::Exception(
"RuntimeError") <<
"Went to search for next file but according to BU more events in "
325 edm::LogInfo(
"FedRawDataInputSource") <<
"Asking for next file... to the DaqDirector";
330 if (fileIsOKToGrab) {
332 edm::LogInfo(
"FedRawDataInputSource") <<
"The director says to grab: " << nextFile;
337 jsonFile.replace_extension(
".jsn");
342 edm::LogInfo(
"FedRawDataInputSource") <<
"The DAQ Director has nothing for me! ";
359 std::ostringstream fileNameWithPID;
360 fileNameWithPID << jsonSourcePath.stem().string() <<
"_pid"
361 << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
363 jsonDestPath /= fileNameWithPID.str();
365 edm::LogInfo(
"FedRawDataInputSource") <<
" JSON rename " << jsonSourcePath <<
" to "
377 boost::filesystem::ifstream ij(jsonDestPath);
381 throw std::runtime_error(
"Cannot deserialize input JSON file");
392 catch (
const boost::filesystem::filesystem_error& ex)
395 edm::LogError(
"FedRawDataInputSource") <<
" - grabNextFile BOOST FILESYSTEM ERROR CAUGHT: " << ex.what()
396 <<
" - Maybe the BU run dir disappeared? Ending process with code 0...";
399 catch (std::runtime_error
e)
402 edm::LogError(
"FedRawDataInputSource") <<
" - grabNextFile runtime Exception: " << e.what() << std::endl;
407 edm::LogError(
"FedRawDataInputSource") <<
" - grabNextFileSOME OTHER EXCEPTION OCCURED!!!! ->" << e.what()
415 const int fileDescriptor = open(nextFile.c_str(), O_RDONLY);
416 if (fileDescriptor != -1) {
419 edm::LogInfo(
"FedRawDataInputSource") <<
" opened file " << nextFile;
424 " failed to open file " << nextFile <<
" fd:" << fileDescriptor;
434 <<
" to: " << destination.string();
435 boost::filesystem::rename(source,destination);
436 boost::filesystem::rename(source.replace_extension(
".jsn"),destination.replace_extension(
".jsn"));
444 InputSource::rewind();
static const char runNumber_[]
unsigned int getgpshigh(const unsigned char *)
void startedLookingForFile()
ProductProvenance dummyProvenance_
static Timestamp invalidTimestamp()
bool parse(const std::string &document, Value &root, bool collectComments=true)
Read a Value from a JSON document.
static Timestamp beginOfTime()
void evm_board_setformat(size_t size)
void resize(size_t newsize)
bool check(const DataFrame &df, bool capcheck, bool dvercheck)
#define FED_EVSZ_EXTRACT(a)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
virtual void deserialize(Json::Value &root)
ProcessHistoryID daqInit(ProductRegistry &productRegistry, ProcessHistoryRegistry &processHistoryRegistry) const
std::vector< std::string > getData() const
unsigned long long uint64_t
void setProcessHistoryID(ProcessHistoryID const &phid)
char data[epos_bytes_allocation]
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
BranchDescription const constBranchDescription_
volatile std::atomic< bool > shutdown_flag false
void stoppedLookingForFile()
static std::string const source
unsigned int getgpslow(const unsigned char *)
void put(BranchDescription const &bd, WrapperOwningHolder const &edp, ProductProvenance const &productProvenance)