CMS 3D CMS Logo

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