CMS 3D CMS Logo

TestSourceProcessor.cc
Go to the documentation of this file.
2 
11 
13 
16 
19 
25 
28 
30 
31 #include "oneTimeInitialization.h"
32 
33 namespace {
34  using namespace edm;
35 
37  switch (iType) {
39  return "Event";
41  return "File";
43  return "LuminosityBlock";
45  return "Repeat";
47  return "Stop";
49  return "Run";
51  return "Synchronize";
53  return "Invalid";
54  }
55  return "Invalid";
56  }
57  // ---------------------------------------------------------------
58  std::unique_ptr<InputSource> makeInput(unsigned int moduleIndex,
60  std::shared_ptr<ProductRegistry> preg,
61  std::shared_ptr<BranchIDListHelper> branchIDListHelper,
62  std::shared_ptr<ProcessBlockHelper> const& processBlockHelper,
63  std::shared_ptr<ThinnedAssociationsHelper> thinnedAssociationsHelper,
64  std::shared_ptr<ActivityRegistry> areg,
65  std::shared_ptr<ProcessConfiguration const> processConfiguration,
66  PreallocationConfiguration const& allocations) {
67  ParameterSet* main_input = params.getPSetForUpdate("@main_input");
68  if (main_input == nullptr) {
70  << "There must be exactly one source in the configuration.\n"
71  << "It is missing (or there are sufficient syntax errors such that it is not recognized as the source)\n";
72  }
73 
74  std::string modtype(main_input->getParameter<std::string>("@module_type"));
75 
76  std::unique_ptr<ParameterSetDescriptionFillerBase> filler(
78  ConfigurationDescriptions descriptions(filler->baseType(), modtype);
79  filler->fill(descriptions);
80 
81  descriptions.validate(*main_input, std::string("source"));
82 
83  main_input->registerIt();
84 
85  // Fill in "ModuleDescription", in case the input source produces
86  // any EDProducts, which would be registered in the ProductRegistry.
87  // Also fill in the process history item for this process.
88  // There is no module label for the unnamed input source, so
89  // just use "source".
90  // Only the tracked parameters belong in the process configuration.
91  ModuleDescription md(main_input->id(),
92  main_input->getParameter<std::string>("@module_type"),
93  "source",
94  processConfiguration.get(),
95  moduleIndex);
96 
98  md, preg, branchIDListHelper, processBlockHelper, thinnedAssociationsHelper, areg, -1, -1, 0, allocations);
99 
100  return std::unique_ptr<InputSource>(InputSourceFactory::get()->makeInputSource(*main_input, isdesc).release());
101  }
102 } // namespace
103 
104 namespace edm::test {
105 
107  : globalControl_(oneapi::tbb::global_control::max_allowed_parallelism, 1),
108  arena_(1),
109  historyAppender_(std::make_unique<HistoryAppender>()) {
110  //Setup various singletons
112 
113  ProcessDescImpl desc(iConfig, false);
114 
115  auto psetPtr = desc.parameterSet();
116 
117  validateTopLevelParameterSets(psetPtr.get());
118 
119  auto procDesc = desc.processDesc();
120  // Now do general initialization
122 
123  //initialize the services
124  auto& serviceSets = procDesc->getServicesPSets();
125  ServiceToken token = items.initServices(serviceSets, *psetPtr, iToken, serviceregistry::kOverlapIsError, true);
126  serviceToken_ = items.addCPRandTNS(*psetPtr, token);
127 
128  //make the services available
130 
131  // intialize miscellaneous items
132  items.initMisc(*psetPtr);
133 
134  auto nThreads = 1U;
135  auto nStreams = 1U;
136  auto nConcurrentLumis = 1U;
137  auto nConcurrentRuns = 1U;
138  preallocations_ = PreallocationConfiguration{nThreads, nStreams, nConcurrentLumis, nConcurrentRuns};
139 
140  processBlockHelper_ = std::make_shared<ProcessBlockHelper>();
141 
142  {
143  // initialize the input source
144  auto tempReg = std::make_shared<ProductRegistry>();
145  auto sourceID = ModuleDescription::getUniqueID();
146 
148  source_ = makeInput(sourceID,
149  *psetPtr,
150  /*items.preg(),*/ tempReg,
151  items.branchIDListHelper(),
153  items.thinnedAssociationsHelper(),
154  items.actReg_,
155  items.processConfiguration(),
157  items.preg()->addFromInput(*tempReg);
158  source_->switchTo(items.preg());
159  }
160 
161  actReg_ = items.actReg_;
162  branchIDListHelper_ = items.branchIDListHelper();
163  thinnedAssociationsHelper_ = items.thinnedAssociationsHelper();
164  processConfiguration_ = items.processConfiguration();
165 
167  preg_ = items.preg();
169 
170  preg_->setFrozen();
172 
173  for (unsigned int index = 0; index < preallocations_.numberOfStreams(); ++index) {
174  // Reusable event principal
175  auto ep = std::make_shared<EventPrincipal>(
178  }
179  for (unsigned int index = 0; index < preallocations_.numberOfRuns(); ++index) {
180  auto rp = std::make_unique<RunPrincipal>(
183  }
184  for (unsigned int index = 0; index < preallocations_.numberOfLuminosityBlocks(); ++index) {
185  auto lp =
186  std::make_unique<LuminosityBlockPrincipal>(preg_, *processConfiguration_, historyAppender_.get(), index);
188  }
189  {
190  auto pb = std::make_unique<ProcessBlockPrincipal>(preg_, *processConfiguration_);
192  }
193 
194  source_->doBeginJob();
195  }
196 
198  //make the services available
200  try {
201  source_.reset();
202  } catch (std::exception const& iExcept) {
203  std::cerr << " caught exception while destroying TestSourceProcessor\n" << iExcept.what();
204  }
205  }
206 
208  //make the services available
210 
211  lastTransition_ = source_->nextItemType();
212  return lastTransition_;
213  }
214 
215  std::shared_ptr<FileBlock> TestSourceProcessor::openFile() {
216  //make the services available
218 
219  size_t size = preg_->size();
220  fb_ = source_->readFile();
221  if (size < preg_->size()) {
223  }
225 
226  source_->fillProcessBlockHelper();
228  while (source_->nextProcessBlock(processBlockPrincipal)) {
229  source_->readProcessBlock(processBlockPrincipal);
230  processBlockPrincipal.clearPrincipal();
231  }
232  return fb_;
233  }
234  void TestSourceProcessor::closeFile(std::shared_ptr<FileBlock> iBlock) {
235  if (iBlock.get() != fb_.get()) {
236  throw cms::Exception("IncorrectFileBlock")
237  << "closeFile given a FileBlock that does not correspond to the one returned by openFile";
238  }
239  if (fb_) {
240  //make the services available
242 
243  source_->closeFile(fb_.get(), false);
244  }
245  }
246 
249  throw cms::Exception("NotARun") << "The last transition is " << name(lastTransition_.itemType()) << " not a Run";
250  }
251  //make the services available
253 
254  //NOTE: should probably handle merging as well
256  runPrincipal_->setAux(*source_->runAuxiliary());
258 
260  }
261 
264  throw cms::Exception("NotALuminosityBlock")
265  << "The last transition is " << name(lastTransition_.itemType()) << " not a LuminosityBlock";
266  }
267 
268  //make the services available
270 
273  lumiPrincipal_->setAux(*source_->luminosityBlockAuxiliary());
274  source_->readLuminosityBlock(*lumiPrincipal_, *historyAppender_);
275 
277  }
278 
281  throw cms::Exception("NotAnEvent") << "The last transition is " << name(lastTransition_.itemType())
282  << " not a Event";
283  }
284  //make the services available
286 
287  auto& event = principalCache_.eventPrincipal(0);
288  StreamContext streamContext(event.streamID(), &processContext_);
289 
290  source_->readEvent(event, streamContext);
291 
293  }
294 } // namespace edm::test
std::shared_ptr< ActivityRegistry > actReg_
void clearPrincipal()
Definition: Principal.cc:386
void setProcessesWithMergeableRunProducts(ProductRegistry const &productRegistry)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
static InputSourceFactory const * get()
edm::test::LuminosityBlockFromSource readLuminosityBlock()
std::shared_ptr< LuminosityBlockPrincipal > lumiPrincipal_
void setNumberOfConcurrentPrincipals(PreallocationConfiguration const &)
def create(alignables, pedeDump, additionalData, outputFile, config)
std::shared_ptr< ProcessConfiguration const > processConfiguration_
ProcessBlockPrincipal & inputProcessBlockPrincipal() const
std::shared_ptr< RunPrincipal > getAvailableRunPrincipalPtr()
void adjustEventsToNewProductRegistry(std::shared_ptr< ProductRegistry const >)
std::shared_ptr< ProductRegistry > preg_
void adjustIndexesAfterProductRegistryAddition()
assert(be >=bs)
static unsigned int getUniqueID()
Returns a unique id each time called. Intended to be passed to ModuleDescription&#39;s constructor&#39;s modI...
std::unique_ptr< InputSource > makeInputSource(ParameterSet const &, InputSourceDescription const &) const
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
void validateTopLevelParameterSets(ParameterSet *processParameterSet)
std::shared_ptr< FileBlock > fb_
InputSource::ItemTypeInfo findNextTransition()
ParameterSetID id() const
ParameterSet const & registerIt()
std::shared_ptr< BranchIDListHelper > branchIDListHelper_
std::shared_ptr< FileBlock > openFile()
std::unique_ptr< HistoryAppender > historyAppender_
MergeableRunProductProcesses mergeableRunProductProcesses_
std::shared_ptr< ProcessBlockHelper > processBlockHelper_
edm::test::EventFromSource readEvent()
void insert(std::unique_ptr< ProcessBlockPrincipal >)
void setProcessConfiguration(ProcessConfiguration const *processConfiguration)
std::unique_ptr< InputSource > makeInput(unsigned int moduleIndex, ParameterSet &params, CommonParams const &common, std::shared_ptr< ProductRegistry > preg, std::shared_ptr< BranchIDListHelper > branchIDListHelper, std::shared_ptr< ProcessBlockHelper > const &processBlockHelper, std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper, std::shared_ptr< ActivityRegistry > areg, std::shared_ptr< ProcessConfiguration const > processConfiguration, PreallocationConfiguration const &allocations)
std::shared_ptr< RunPrincipal > runPrincipal_
std::unique_ptr< edm::InputSource > source_
EventPrincipal & eventPrincipal(unsigned int iStreamIndex) const
edm::InputSource::ItemTypeInfo lastTransition_
HLT enums.
edm::test::RunFromSource readRun()
std::shared_ptr< LuminosityBlockPrincipal > getAvailableLumiPrincipalPtr()
TestSourceProcessor(std::string const &iConfig, ServiceToken iToken=ServiceToken())
#define get
void closeFile(std::shared_ptr< FileBlock >)
def move(src, dest)
Definition: eostools.py:511
std::shared_ptr< ThinnedAssociationsHelper > thinnedAssociationsHelper_
Definition: event.py:1
PreallocationConfiguration preallocations_