@@ -64,51 +64,82 @@ void OMTFReconstruction::beginRun(edm::Run const& run,
6464 const MuonGeometryTokens& muonGeometryTokens,
6565 const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord>& magneticFieldEsToken,
6666 const edm::ESGetToken<Propagator, TrackingComponentsRecord>& propagatorEsToken) {
67- const L1TMuonOverlapParams* omtfParams = nullptr ;
68-
6967 std::string processorType = " OMTFProcessor" ; // GoldenPatternWithStat GoldenPattern
7068 if (edmParameterSet.exists (" processorType" )) {
7169 processorType = edmParameterSet.getParameter <std::string>(" processorType" );
7270 }
7371
7472 bool buildPatternsFromXml = (edmParameterSet.exists (" patternsXMLFile" ) || edmParameterSet.exists (" patternsXMLFiles" ));
7573
74+ bool readConfigFromXml = edmParameterSet.exists (" configXMLFile" );
75+
76+ if (buildPatternsFromXml != readConfigFromXml)
77+ throw cms::Exception (
78+ " OMTFReconstruction::beginRun: buildPatternsFromXml != readConfigFromXml - both patternsXMLFiles and "
79+ " configXMLFile should be defined (or not) for the simOmtDigis or simOmtfPhase2Digis" );
80+
7681 edm::LogVerbatim (" OMTFReconstruction" ) << " OMTFReconstruction::beginRun " << run.id ()
7782 << " buildPatternsFromXml: " << buildPatternsFromXml << std::endl;
7883
7984 // if the buildPatternsFromXml == false - we are making the omtfConfig and omtfProc for every run,
8085 // as the configuration my change between the runs,
81- // if buildPatternsFromXml == true - we assume the the entire configuration comes from phyton,
82- // so we do it only for the first run
83- if (omtfProc == nullptr || buildPatternsFromXml == false ) {
86+ if (buildPatternsFromXml == false ) {
8487 if (omtfParamsRecordWatcher.check (eventSetup)) {
8588 edm::LogVerbatim (" OMTFReconstruction" ) << " retrieving omtfParams from EventSetup" << std::endl;
8689
87- omtfParams = &(eventSetup.getData (omtfParamsEsToken));
88- if (!omtfParams) {
89- edm::LogError (" OMTFReconstruction" ) << " Could not retrieve parameters from Event Setup" << std::endl;
90+ const L1TMuonOverlapParams* omtfParamsFromES = &(eventSetup.getData (omtfParamsEsToken));
91+ if (!omtfParamsFromES) {
92+ edm::LogError (" OMTFReconstruction" ) << " Could not retrieve omtfParams from Event Setup" << std::endl;
93+ throw cms::Exception (" OMTFReconstruction::beginRun: Could not retrieve omtfParams from Event Setup" );
9094 }
91- omtfConfig->configure (omtfParams);
95+
96+ omtfConfig->configure (omtfParamsFromES);
9297
9398 // the parameters can be overwritten from the python config
9499 omtfConfig->configureFromEdmParameterSet (edmParameterSet);
95100
96101 inputMaker->initialize (edmParameterSet, eventSetup, muonGeometryTokens);
97102
98103 // patterns from the edm::EventSetup are reloaded every beginRun
99- if (buildPatternsFromXml == false ) {
100- edm::LogVerbatim (" OMTFReconstruction" ) << " getting patterns from EventSetup" << std::endl;
101- if (processorType == " OMTFProcessor" ) {
102- omtfProc = std::make_unique<OMTFProcessor<GoldenPattern> >(
103- omtfConfig.get (), edmParameterSet, eventSetup, omtfParams);
104- omtfProc->printInfo ();
105- }
104+ // therefore OMTFProcessor is re-created here
105+ edm::LogVerbatim (" OMTFReconstruction" ) << " getting patterns from EventSetup" << std::endl;
106+ if (processorType == " OMTFProcessor" ) {
107+ omtfProc = std::make_unique<OMTFProcessor<GoldenPattern> >(
108+ omtfConfig.get (), edmParameterSet, eventSetup, omtfParamsFromES);
109+ omtfProc->printInfo ();
106110 }
107111 }
108112 }
109113
110- // if we read the patterns directly from the xml, we do it only once, at the beginning of the first run, not every run
114+ // if buildPatternsFromXml == true - the entire configuration (patterns and hwToLogicLayer) comes from phyton,
115+ // so we read it only once, at the beginning of the first run, not every run
111116 if (omtfProc == nullptr && buildPatternsFromXml) {
117+ std::string fName = edmParameterSet.getParameter <edm::FileInPath>(" configXMLFile" ).fullPath ();
118+
119+ edm::LogVerbatim (" OMTFReconstruction" )
120+ << " OMTFReconstruction::beginRun - reading config from file: " << fName << std::endl;
121+
122+ XMLConfigReader xmlConfigReader;
123+ xmlConfigReader.setConfigFile (fName );
124+
125+ omtfParams.reset (new L1TMuonOverlapParams ());
126+ xmlConfigReader.readConfig (omtfParams.get ());
127+
128+ // getPatternsVersion() parses the entire patterns xml - si it is very inefficient
129+ // moreover, PatternsVersion is not used anywhere
130+ // Therefore we we dont use xmlPatternReader.getPatternsVersion(); but set patternsVersion to 0
131+ unsigned int patternsVersion = 0 ;
132+ unsigned int fwVersion = omtfParams->fwVersion ();
133+ omtfParams->setFwVersion ((fwVersion << 16 ) + patternsVersion);
134+
135+ omtfConfig->configure (omtfParams.get ());
136+
137+ // the parameters can be overwritten from the python config
138+ omtfConfig->configureFromEdmParameterSet (edmParameterSet);
139+
140+ inputMaker->initialize (edmParameterSet, eventSetup, muonGeometryTokens);
141+
142+ // reading patterns from the xml----------------------------------------------------------
112143 std::vector<std::string> patternsXMLFiles;
113144
114145 if (edmParameterSet.exists (" patternsXMLFile" )) {
@@ -122,8 +153,6 @@ void OMTFReconstruction::beginRun(edm::Run const& run,
122153 for (auto & patternsXMLFile : patternsXMLFiles)
123154 edm::LogVerbatim (" OMTFReconstruction" ) << " reading patterns from " << patternsXMLFile << std::endl;
124155
125- XMLConfigReader xmlReader;
126-
127156 std::string patternType = " GoldenPattern" ; // GoldenPatternWithStat GoldenPattern
128157 if (edmParameterSet.exists (" patternType" )) {
129158 patternType = edmParameterSet.getParameter <std::string>(" patternType" );
@@ -136,15 +165,14 @@ void OMTFReconstruction::beginRun(edm::Run const& run,
136165 omtfConfig.get (),
137166 edmParameterSet,
138167 eventSetup,
139- xmlReader .readPatterns <GoldenPattern>(*omtfParams, patternsXMLFiles, false ));
168+ xmlConfigReader .readPatterns <GoldenPattern>(*omtfParams, patternsXMLFiles, false ));
140169 } else { // in principle should not happen
141170 throw cms::Exception (" OMTFReconstruction::beginRun: omtfParams is nullptr" );
142171 }
143172 }
144173
145- edm::LogVerbatim (" OMTFReconstruction" )
146- << " OMTFProcessor constructed. processorType " << processorType << " . GoldenPattern type: " << patternType
147- << " nProcessors " << omtfConfig->nProcessors () << std::endl;
174+ edm::LogVerbatim (" OMTFReconstruction" ) << " OMTFProcessor constructed. processorType " << processorType
175+ << " . GoldenPattern type: " << patternType << std::endl;
148176 } else if (patternType == " GoldenPatternWithStat" ) {
149177 // pattern generation is only possible if the processor is constructed only once per job
150178 // PatternGenerator modifies the patterns!!!
@@ -154,7 +182,7 @@ void OMTFReconstruction::beginRun(edm::Run const& run,
154182 omtfConfig.get (),
155183 edmParameterSet,
156184 eventSetup,
157- xmlReader .readPatterns <GoldenPatternWithStat>(*omtfParams, patternsXMLFiles, false ));
185+ xmlConfigReader .readPatterns <GoldenPatternWithStat>(*omtfParams, patternsXMLFiles, false ));
158186 } else { // in principle should not happen
159187 throw cms::Exception (" OMTFReconstruction::beginRun: omtfParams is nullptr" );
160188 }
@@ -205,7 +233,7 @@ void OMTFReconstruction::addObservers(
205233 if (edmParameterSet.getParameter <bool >(" eventCaptureDebug" )) {
206234 observers.emplace_back (std::make_unique<EventCapture>(
207235 edmParameterSet, omtfConfig.get (), candidateSimMuonMatcher, muonGeometryTokens
208- // , &(omtfProcGoldenPat->getPatterns() )
236+ // &(omtfProcGoldenPat->getPatterns() ),
209237 // watch out, will crash if the proc is re-constructed from the DB after L1TMuonOverlapParamsRcd change
210238 ));
211239 }
@@ -228,7 +256,7 @@ void OMTFReconstruction::addObservers(
228256 if (edmParameterSet.getParameter <bool >(" eventCaptureDebug" )) {
229257 observers.emplace_back (std::make_unique<EventCapture>(
230258 edmParameterSet, omtfConfig.get (), candidateSimMuonMatcher, muonGeometryTokens
231- // &(omtfProcGoldenPat->getPatterns() )
259+ // &(omtfProcGoldenPat->getPatterns() ),
232260 // watch out, will crash if the proc is re-constructed from the DB after L1TMuonOverlapParamsRcd change
233261 ));
234262 }
0 commit comments