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()),
51 currentLumiSection_(0),
52 currentInputJson_(
""),
53 currentInputEventCount_(0),
55 dataBuffer_(new unsigned
char[1024 * 1024 * eventChunkSize_]),
56 bufferCursor_(dataBuffer_),
60 gethostname(thishost, 255);
63 <<
" on host " << thishost;
81 if (eventAvailable < 0) {
87 else if(eventAvailable == 0) {
115 const string fuEoLS =
118 bool found = (stat(fuEoLS.c_str(), &buf) == 0);
120 int eol_fd = open(fuEoLS.c_str(), O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
130 gettimeofday(&tv, 0);
131 const edm::Timestamp lsopentime( (
unsigned long long) tv.tv_sec * 1000000 + (
unsigned long long) tv.tv_usec );
136 lumiSection, lsopentime,
141 edm::LogInfo(
"FedRawDataInputSource") <<
"New lumi section " << lumiSection <<
" opened";
151 if ( check ==-1)
return 0;
152 if ( check ==-100)
return -1;
157 const uint32_t msgSize =
event_->size();
164 "Premature end of input file while reading event data";
171 uint32_t adler = adler32(0
L,Z_NULL,0);
172 adler = adler32(adler,(Bytef*)
event_->payload(),
event_->eventSize());
174 if ( adler !=
event_->adler32() ) {
176 "Found a wrong Adler32 checksum: expected 0x" << std::hex <<
event_->adler32() <<
177 " but calculated 0x" << adler;
193 int fileStatus = 100;
198 if(fileStatus==0)
return -100;
208 bufferLeft_ += fread((
void*) (
dataBuffer_ + bufferLeft_),
256 edm::LogInfo(
"FedRawDataInputSource") <<
"No file for me... sleep and try again..." << std::endl;
285 uint32_t eventSize =
event_->eventSize();
286 char*
event = (
char*)
event_->payload();
288 while (eventSize > 0) {
289 eventSize -=
sizeof(
fedt_t);
292 eventSize -= (fedSize -
sizeof(
fedh_t));
299 tstamp =
edm::Timestamp(static_cast<edm::TimeValue_t> ((gpsh << 32) + gpsl));
301 FEDRawData& fedData = rawData->FEDData(fedId);
303 memcpy(fedData.
data(),
event + eventSize, fedSize);
305 assert(eventSize == 0);
314 throw cms::Exception(
"RuntimeError") <<
"Went to search for next file but according to BU more events in "
321 edm::LogInfo(
"FedRawDataInputSource") <<
"Asking for next file... to the DaqDirector";
326 if (fileIsOKToGrab) {
328 edm::LogInfo(
"FedRawDataInputSource") <<
"The director says to grab: " << nextFile;
333 jsonFile.replace_extension(
".jsn");
338 edm::LogInfo(
"FedRawDataInputSource") <<
"The DAQ Director has nothing for me! ";
355 std::ostringstream fileNameWithPID;
356 fileNameWithPID << jsonSourcePath.stem().string() <<
"_pid"
357 << std::setfill(
'0') << std::setw(5) << getpid() <<
".jsn";
359 jsonDestPath /= fileNameWithPID.str();
361 edm::LogInfo(
"FedRawDataInputSource") <<
" JSON rename " << jsonSourcePath <<
" to "
373 boost::filesystem::ifstream ij(jsonDestPath);
377 throw std::runtime_error(
"Cannot deserialize input JSON file");
388 catch (
const boost::filesystem::filesystem_error& ex)
391 edm::LogError(
"FedRawDataInputSource") <<
" - grabNextFile BOOST FILESYSTEM ERROR CAUGHT: " << ex.what()
392 <<
" - Maybe the BU run dir disappeared? Ending process with code 0...";
395 catch (std::runtime_error
e)
398 edm::LogError(
"FedRawDataInputSource") <<
" - grabNextFile runtime Exception: " << e.what() << std::endl;
403 edm::LogError(
"FedRawDataInputSource") <<
" - grabNextFileSOME OTHER EXCEPTION OCCURED!!!! ->" << e.what()
411 const int fileDescriptor = open(nextFile.c_str(), O_RDONLY);
412 if (fileDescriptor != -1) {
415 edm::LogInfo(
"FedRawDataInputSource") <<
" opened file " << nextFile;
420 " failed to open file " << nextFile <<
" fd:" << fileDescriptor;
430 <<
" to: " << destination.string();
431 boost::filesystem::rename(source,destination);
432 boost::filesystem::rename(source.replace_extension(
".jsn"),destination.replace_extension(
".jsn"));
440 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
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)