File indexing completed on 2025-02-26 04:25:15
0001 #include "EventFilter//Utilities/interface/DAQSourceModelsScoutingRun3.h"
0002
0003 using namespace edm::streamer;
0004
0005 void DataModeScoutingRun3::makeDirectoryEntries(std::vector<std::string> const& baseDirs,
0006 std::vector<int> const& numSources,
0007 std::vector<int> const& sourceIDs,
0008 std::string const& sourceIdentifier,
0009 std::string const& runDir) {
0010 std::filesystem::path runDirP(runDir);
0011 for (auto& baseDir : baseDirs) {
0012 std::filesystem::path baseDirP(baseDir);
0013 buPaths_.emplace_back(baseDirP / runDirP);
0014 }
0015
0016
0017 buNumSources_ = numSources;
0018 }
0019
0020 std::pair<bool, std::vector<std::string>> DataModeScoutingRun3::defineAdditionalFiles(std::string const& primaryName,
0021 bool fileListMode) const {
0022 std::vector<std::string> additionalFiles;
0023
0024 if (fileListMode) {
0025
0026 for (int j = 1; j < buNumSources_[0]; j++) {
0027 additionalFiles.push_back(primaryName + "_" + std::to_string(j));
0028 }
0029 return std::make_pair(true, additionalFiles);
0030 }
0031
0032 auto fullpath = std::filesystem::path(primaryName);
0033 auto fullname = fullpath.filename();
0034
0035 for (size_t i = 0; i < buPaths_.size(); i++) {
0036 std::filesystem::path newPath = buPaths_[i] / fullname;
0037
0038 if (i != 0) {
0039
0040 additionalFiles.push_back(newPath.generic_string());
0041 }
0042
0043
0044 for (int j = 1; j < buNumSources_[i]; j++) {
0045 additionalFiles.push_back(newPath.generic_string() + "_" + std::to_string(j));
0046 }
0047 }
0048 return std::make_pair(true, additionalFiles);
0049 }
0050
0051 void DataModeScoutingRun3::readEvent(edm::EventPrincipal& eventPrincipal) {
0052 assert(!events_.empty());
0053
0054 edm::TimeValue_t time;
0055 timeval stv;
0056 gettimeofday(&stv, nullptr);
0057 time = stv.tv_sec;
0058 time = (time << 32) + stv.tv_usec;
0059 edm::Timestamp tstamp(time);
0060
0061
0062 uint32_t hdrEventID = currOrbit_;
0063 edm::EventID eventID = edm::EventID(daqSource_->eventRunNumber(), daqSource_->currentLumiSection(), hdrEventID);
0064 edm::EventAuxiliary aux(
0065 eventID, daqSource_->processGUID(), tstamp, events_[0]->isRealData(), edm::EventAuxiliary::PhysicsTrigger);
0066
0067 aux.setProcessHistoryID(daqSource_->processHistoryID());
0068 daqSource_->makeEventWrapper(eventPrincipal, aux);
0069
0070
0071 std::unique_ptr<SDSRawDataCollection> rawData(new SDSRawDataCollection);
0072
0073
0074 for (const auto& pair : sourceValidOrbitPair_) {
0075 fillSDSRawDataCollection(*rawData, (char*)events_[pair.second]->payload(), events_[pair.second]->eventSize());
0076 }
0077
0078 std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<SDSRawDataCollection>(std::move(rawData)));
0079 eventPrincipal.put(
0080 daqProvenanceHelpers_[0]->productDescription(), std::move(edp), daqProvenanceHelpers_[0]->dummyProvenance());
0081
0082 eventCached_ = false;
0083 }
0084
0085 void DataModeScoutingRun3::fillSDSRawDataCollection(SDSRawDataCollection& rawData, char* buff, size_t len) {
0086 size_t pos = 0;
0087
0088
0089 int sourceId = *((uint32_t*)(buff + pos));
0090 pos += 4;
0091
0092
0093 size_t orbitSize = len - pos;
0094
0095
0096
0097
0098 FEDRawData& fedData = rawData.FEDData(sourceId);
0099 fedData.resize(orbitSize, 4);
0100
0101 memcpy(fedData.data(), buff + pos, orbitSize);
0102
0103 return;
0104 }
0105
0106 std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& DataModeScoutingRun3::makeDaqProvenanceHelpers() {
0107
0108 daqProvenanceHelpers_.clear();
0109 daqProvenanceHelpers_.emplace_back(std::make_shared<const edm::DaqProvenanceHelper>(
0110 edm::TypeID(typeid(SDSRawDataCollection)), "SDSRawDataCollection", "SDSRawDataCollection", "DAQSource"));
0111 return daqProvenanceHelpers_;
0112 }
0113
0114 bool DataModeScoutingRun3::nextEventView(RawInputFile*) {
0115 blockCompleted_ = false;
0116 if (eventCached_)
0117 return true;
0118
0119
0120
0121 for (const auto& pair : sourceValidOrbitPair_) {
0122 dataBlockAddrs_[pair.first] += events_[pair.second]->size();
0123 }
0124
0125 return makeEvents();
0126 }
0127
0128 bool DataModeScoutingRun3::makeEvents() {
0129
0130 events_.clear();
0131 sourceValidOrbitPair_.clear();
0132 currOrbit_ = 0xFFFFFFFF;
0133 assert(!blockCompleted_);
0134
0135
0136
0137 for (int i = 0; i < numFiles_; i++) {
0138 if (dataBlockAddrs_[i] >= dataBlockMaxAddrs_[i]) {
0139 completedBlocks_[i] = true;
0140 continue;
0141 }
0142
0143
0144 events_.emplace_back(std::make_unique<FRDEventMsgView>(dataBlockAddrs_[i]));
0145 if (dataBlockAddrs_[i] + events_.back()->size() > dataBlockMaxAddrs_[i])
0146 throw cms::Exception("DAQSource::getNextEvent")
0147 << " event id:" << events_.back()->event() << " lumi:" << events_.back()->lumi()
0148 << " run:" << events_.back()->run() << " of size:" << events_.back()->size()
0149 << " bytes does not fit into the buffer or has corrupted header";
0150
0151
0152 if ((events_.back()->event() < currOrbit_) && (!completedBlocks_[i])) {
0153 currOrbit_ = events_.back()->event();
0154 }
0155 }
0156
0157
0158
0159 bool allBlocksCompleted = true;
0160 int evt_idx = 0;
0161 for (int i = 0; i < numFiles_; i++) {
0162 if (completedBlocks_[i]) {
0163 continue;
0164 }
0165
0166 if (events_[evt_idx]->event() != currOrbit_) {
0167
0168
0169 } else {
0170
0171
0172
0173 sourceValidOrbitPair_.emplace_back(std::make_pair(i, evt_idx));
0174 allBlocksCompleted = false;
0175 }
0176
0177 evt_idx++;
0178 }
0179
0180 if (allBlocksCompleted) {
0181 blockCompleted_ = true;
0182 }
0183 return !allBlocksCompleted;
0184 }
0185
0186 bool DataModeScoutingRun3::checksumValid() { return true; }
0187
0188 std::string DataModeScoutingRun3::getChecksumError() const { return std::string(); }