CMS 3D CMS Logo

DAQSourceModelsScoutingRun3.cc
Go to the documentation of this file.
2 
3 using namespace edm::streamer;
4 
5 void DataModeScoutingRun3::makeDirectoryEntries(std::vector<std::string> const& baseDirs,
6  std::vector<int> const& numSources,
7  std::string const& runDir) {
8  std::filesystem::path runDirP(runDir);
9  for (auto& baseDir : baseDirs) {
11  buPaths_.emplace_back(baseDirP / runDirP);
12  }
13 
14  // store the number of sources in each BU
15  buNumSources_ = numSources;
16 }
17 
18 std::pair<bool, std::vector<std::string>> DataModeScoutingRun3::defineAdditionalFiles(std::string const& primaryName,
19  bool fileListMode) const {
20  std::vector<std::string> additionalFiles;
21 
22  if (fileListMode) {
23  // Expected file naming when working in file list mode
24  for (int j = 1; j < buNumSources_[0]; j++) {
25  additionalFiles.push_back(primaryName + "_" + std::to_string(j));
26  }
27  return std::make_pair(true, additionalFiles);
28  }
29 
30  auto fullpath = std::filesystem::path(primaryName);
31  auto fullname = fullpath.filename();
32 
33  for (size_t i = 0; i < buPaths_.size(); i++) {
34  std::filesystem::path newPath = buPaths_[i] / fullname;
35 
36  if (i != 0) {
37  // secondary files from other ramdisks
38  additionalFiles.push_back(newPath.generic_string());
39  }
40 
41  // add extra sources from the same ramdisk
42  for (int j = 1; j < buNumSources_[i]; j++) {
43  additionalFiles.push_back(newPath.generic_string() + "_" + std::to_string(j));
44  }
45  }
46  return std::make_pair(true, additionalFiles);
47 }
48 
50  assert(!events_.empty());
51 
53  timeval stv;
54  gettimeofday(&stv, nullptr);
55  time = stv.tv_sec;
56  time = (time << 32) + stv.tv_usec;
57  edm::Timestamp tstamp(time);
58 
59  // set provenance helpers
60  uint32_t hdrEventID = currOrbit_;
61  edm::EventID eventID = edm::EventID(daqSource_->eventRunNumber(), daqSource_->currentLumiSection(), hdrEventID);
63  eventID, daqSource_->processGUID(), tstamp, events_[0]->isRealData(), edm::EventAuxiliary::PhysicsTrigger);
64 
65  aux.setProcessHistoryID(daqSource_->processHistoryID());
66  daqSource_->makeEventWrapper(eventPrincipal, aux);
67 
68  // create scouting raw data collection
69  std::unique_ptr<SDSRawDataCollection> rawData(new SDSRawDataCollection);
70 
71  // Fill the ScoutingRawDataCollection with valid orbit data from the multiple sources
72  for (const auto& pair : sourceValidOrbitPair_) {
73  fillSDSRawDataCollection(*rawData, (char*)events_[pair.second]->payload(), events_[pair.second]->eventSize());
74  }
75 
76  std::unique_ptr<edm::WrapperBase> edp(new edm::Wrapper<SDSRawDataCollection>(std::move(rawData)));
77  eventPrincipal.put(
78  daqProvenanceHelpers_[0]->branchDescription(), std::move(edp), daqProvenanceHelpers_[0]->dummyProvenance());
79 
80  eventCached_ = false;
81 }
82 
84  size_t pos = 0;
85 
86  // get the source ID
87  int sourceId = *((uint32_t*)(buff + pos));
88  pos += 4;
89 
90  // size of the orbit paylod
91  size_t orbitSize = len - pos;
92 
93  // set the size (=orbit size) in the SRDColletion of the current source.
94  // FRD size is expecting 8 bytes words, while scouting is using 4 bytes
95  // words. This could be different for some future sources.
96  FEDRawData& fedData = rawData.FEDData(sourceId);
97  fedData.resize(orbitSize, 4);
98 
99  memcpy(fedData.data(), buff + pos, orbitSize);
100 
101  return;
102 }
103 
104 std::vector<std::shared_ptr<const edm::DaqProvenanceHelper>>& DataModeScoutingRun3::makeDaqProvenanceHelpers() {
105  //set SRD data collection
106  daqProvenanceHelpers_.clear();
107  daqProvenanceHelpers_.emplace_back(std::make_shared<const edm::DaqProvenanceHelper>(
108  edm::TypeID(typeid(SDSRawDataCollection)), "SDSRawDataCollection", "SDSRawDataCollection", "DAQSource"));
109  return daqProvenanceHelpers_;
110 }
111 
113  blockCompleted_ = false;
114  if (eventCached_)
115  return true;
116 
117  // move the data block address only for the sources processed
118  // un the previous event by adding the last event size
119  for (const auto& pair : sourceValidOrbitPair_) {
120  dataBlockAddrs_[pair.first] += events_[pair.second]->size();
121  }
122 
123  return makeEvents();
124 }
125 
127  // clear events and reset current orbit
128  events_.clear();
129  sourceValidOrbitPair_.clear();
130  currOrbit_ = 0xFFFFFFFF; // max uint
131  assert(!blockCompleted_);
132 
133  // create current "events" (= orbits) list from each data source,
134  // check if one dataBlock terminated earlier than others.
135  for (int i = 0; i < numFiles_; i++) {
136  if (dataBlockAddrs_[i] >= dataBlockMaxAddrs_[i]) {
137  completedBlocks_[i] = true;
138  continue;
139  }
140 
141  // event contains data, add it to the events list
142  events_.emplace_back(std::make_unique<FRDEventMsgView>(dataBlockAddrs_[i]));
143  if (dataBlockAddrs_[i] + events_.back()->size() > dataBlockMaxAddrs_[i])
144  throw cms::Exception("DAQSource::getNextEvent")
145  << " event id:" << events_.back()->event() << " lumi:" << events_.back()->lumi()
146  << " run:" << events_.back()->run() << " of size:" << events_.back()->size()
147  << " bytes does not fit into the buffer or has corrupted header";
148 
149  // find the minimum orbit for the current event between all files
150  if ((events_.back()->event() < currOrbit_) && (!completedBlocks_[i])) {
151  currOrbit_ = events_.back()->event();
152  }
153  }
154 
155  // mark valid orbits from each data source
156  // e.g. find when orbit is missing from one source
157  bool allBlocksCompleted = true;
158  int evt_idx = 0;
159  for (int i = 0; i < numFiles_; i++) {
160  if (completedBlocks_[i]) {
161  continue;
162  }
163 
164  if (events_[evt_idx]->event() != currOrbit_) {
165  // current source (=i-th source) doesn't contain the expected orbit.
166  // skip it, and move to the next orbit
167  } else {
168  // add a pair <current surce index, event index>
169  // evt_idx can be different from variable i, as some data blocks can be
170  // completed before others
171  sourceValidOrbitPair_.emplace_back(std::make_pair(i, evt_idx));
172  allBlocksCompleted = false;
173  }
174 
175  evt_idx++;
176  }
177 
178  if (allBlocksCompleted) {
179  blockCompleted_ = true;
180  }
181  return !allBlocksCompleted;
182 }
183 
184 bool DataModeScoutingRun3::checksumValid() { return true; }
185 
void makeDirectoryEntries(std::vector< std::string > const &baseDirs, std::vector< int > const &numSources, std::string const &runDir) override
void fillSDSRawDataCollection(SDSRawDataCollection &rawData, char *buff, size_t len)
std::vector< std::shared_ptr< const edm::DaqProvenanceHelper > > & makeDaqProvenanceHelpers() override
assert(be >=bs)
static std::string to_string(const XMLCh *ch)
void put(BranchDescription const &bd, std::unique_ptr< WrapperBase > edp, ProductProvenance const &productProvenance) const
std::string getChecksumError() const override
unsigned long long TimeValue_t
Definition: Timestamp.h:21
std::pair< bool, std::vector< std::string > > defineAdditionalFiles(std::string const &primaryName, bool fileListMode) const override
void resize(size_t newsize, size_t wordsize=8)
Definition: FEDRawData.cc:28
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:24
def move(src, dest)
Definition: eostools.py:511
void readEvent(edm::EventPrincipal &eventPrincipal) override
buff
***.cc ################