ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/grimes/L1Menu/src/TriggerMenu.cpp
(Generate patch)

Comparing UserCode/grimes/L1Menu/src/TriggerMenu.cpp (file contents):
Revision 1.3 by grimes, Tue May 28 23:14:03 2013 UTC vs.
Revision 1.9 by grimes, Fri Jun 28 14:30:08 2013 UTC

# Line 5 | Line 5
5   #include <sstream>
6   #include <iostream>
7   #include "l1menu/ITrigger.h"
8 + #include "l1menu/tools/tools.h"
9  
10   namespace // Use the unnamed namespace for things only used in this file
11   {
# Line 114 | Line 115 | l1menu::TriggerMenu& l1menu::TriggerMenu
115          return *this;
116   }
117  
118 < bool l1menu::TriggerMenu::addTrigger( const std::string& triggerName )
118 > l1menu::ITrigger& l1menu::TriggerMenu::addTrigger( const std::string& triggerName )
119   {
120          std::unique_ptr<l1menu::ITrigger> pNewTrigger=triggerTable_.getTrigger( triggerName );
121 <        if( pNewTrigger.get()==NULL ) return false;
121 >        if( pNewTrigger.get()==NULL ) throw std::range_error( "Trigger requested that does not exist" );
122  
123          triggers_.push_back( std::move(pNewTrigger) );
124  
125          // Make sure triggerResults_ is always the same size as triggers_
126          triggerResults_.resize( triggers_.size() );
127 <        return true;
127 >        return *triggers_.back();
128   }
129  
130 < bool l1menu::TriggerMenu::addTrigger( const std::string& triggerName, unsigned int version )
130 > l1menu::ITrigger& l1menu::TriggerMenu::addTrigger( const std::string& triggerName, unsigned int version )
131   {
132          std::unique_ptr<l1menu::ITrigger> pNewTrigger=triggerTable_.getTrigger( triggerName, version );
133 <        if( pNewTrigger.get()==NULL ) return false;
133 >        if( pNewTrigger.get()==NULL ) throw std::range_error( "Trigger requested that does not exist" );
134  
135          triggers_.push_back( std::move(pNewTrigger) );
136  
137          // Make sure triggerResults_ is always the same size as triggers_
138          triggerResults_.resize( triggers_.size() );
139 <        return true;
139 >        return *triggers_.back();
140 > }
141 >
142 > l1menu::ITrigger& l1menu::TriggerMenu::addTrigger( const l1menu::ITrigger& triggerToCopy )
143 > {
144 >        std::unique_ptr<l1menu::ITrigger> pNewTrigger=triggerTable_.copyTrigger( triggerToCopy );
145 >        if( pNewTrigger.get()==NULL ) throw std::range_error( "Trigger requested that does not exist" );
146 >
147 >        triggers_.push_back( std::move(pNewTrigger) );
148 >
149 >        // Make sure triggerResults_ is always the same size as triggers_
150 >        triggerResults_.resize( triggers_.size() );
151 >        return *triggers_.back();
152   }
153  
154   size_t l1menu::TriggerMenu::numberOfTriggers() const
# Line 164 | Line 177 | std::unique_ptr<l1menu::ITrigger> l1menu
177          return triggerTable_.copyTrigger(*triggers_[position]);
178   }
179  
180 < bool l1menu::TriggerMenu::apply( const l1menu::IEvent& event ) const
180 > bool l1menu::TriggerMenu::apply( const l1menu::L1TriggerDPGEvent& event ) const
181   {
182          bool atLeastOneTriggerHasFired=false;
183  
# Line 207 | Line 220 | void l1menu::TriggerMenu::loadMenuInOldF
220                          float prescale=::convertStringToFloat( tableColumns[2] );
221                          if( prescale!=0 )
222                          {
223 <                                if( addTrigger( tableColumns[0] ) ) // Try and create a trigger with the name supplied
211 <                                {
212 <                                        std::cout << "Added trigger \"" << tableColumns[0] << "\"" << std::endl;
213 <
214 <                                        l1menu::ITrigger& newTrigger=*(triggers_.back());
223 >                                std::string triggerName=tableColumns[0];
224  
225 <                                        // Try and set all of the relevant parameters. I know not all triggers have these parameters
226 <                                        // so wrap in individual try/catch blocks.
227 <                                        try{ newTrigger.parameter("threshold1")=::convertStringToFloat( tableColumns[3] ); }
228 <                                        catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
220 <
221 <                                        try{ newTrigger.parameter("threshold2")=::convertStringToFloat( tableColumns[4] ); }
222 <                                        catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
223 <
224 <                                        try{ newTrigger.parameter("threshold3")=::convertStringToFloat( tableColumns[5] ); }
225 <                                        catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
225 >                                try
226 >                                {
227 >                                        //std::cout << "Added trigger \"" << tableColumns[0] << "\"" << std::endl;
228 >                                        l1menu::ITrigger& newTrigger=addTrigger( triggerName ); // Try and create a trigger with the name supplied
229  
230 <                                        try{ newTrigger.parameter("threshold4")=::convertStringToFloat( tableColumns[6] ); }
230 >                                        // Different triggers will have different numbers of thresholds, and even different names. E.g. Single triggers
231 >                                        // will have "threshold1" whereas a cross trigger will have "leg1threshold1", "leg2threshold1" etcetera. This
232 >                                        // utility function will get the threshold names in the correct order.
233 >                                        const auto& thresholdNames=l1menu::tools::getThresholdNames(newTrigger);
234 >                                        if( thresholdNames.size()>1 ) newTrigger.parameter(thresholdNames[0])=::convertStringToFloat( tableColumns[3] );
235 >                                        if( thresholdNames.size()>2 ) newTrigger.parameter(thresholdNames[1])=::convertStringToFloat( tableColumns[4] );
236 >                                        if( thresholdNames.size()>3 ) newTrigger.parameter(thresholdNames[2])=::convertStringToFloat( tableColumns[5] );
237 >                                        if( thresholdNames.size()>4 ) newTrigger.parameter(thresholdNames[3])=::convertStringToFloat( tableColumns[6] );
238 >
239 >                                        float etaOrRegionCut=::convertStringToFloat( tableColumns[7] );
240 >                                        // For most triggers, I can just try and set both the etaCut and regionCut parameters
241 >                                        // with this value. If it doesn't have either of the parameters just catch the exception
242 >                                        // and nothing will happen. Some cross triggers however have both, and need to set them
243 >                                        // both from this value which requires a conversion. Most cross triggers expect this
244 >                                        // value to be the regionCut, except for L1_SingleMu_CJet which expects it as the etaCut.
245 >                                        if( triggerName=="L1_SingleMu_CJet" )
246 >                                        {
247 >                                                newTrigger.parameter("leg1etaCut")=etaOrRegionCut;
248 >                                                newTrigger.parameter("leg2regionCut")=l1menu::tools::convertEtaCutToRegionCut( etaOrRegionCut );
249 >                                        }
250 >                                        else if( triggerName=="L1_isoMu_EG" )
251 >                                        {
252 >                                                newTrigger.parameter("leg1etaCut")=l1menu::tools::convertRegionCutToEtaCut( etaOrRegionCut );
253 >                                                newTrigger.parameter("leg2regionCut")=etaOrRegionCut;
254 >                                        }
255 >                                        else if( triggerName=="L1_isoEG_Mu" )
256 >                                        {
257 >                                                newTrigger.parameter("leg1regionCut")=etaOrRegionCut;
258 >                                                newTrigger.parameter("leg2etaCut")=l1menu::tools::convertRegionCutToEtaCut( etaOrRegionCut );
259 >                                        }
260 >                                        else if( triggerName=="L1_isoMu_Tau" )
261 >                                        {
262 >                                                newTrigger.parameter("leg1etaCut")=l1menu::tools::convertRegionCutToEtaCut( etaOrRegionCut );
263 >                                                newTrigger.parameter("leg2regionCut")=etaOrRegionCut;
264 >                                        }
265 >                                        else
266 >                                        {
267 >                                                // Any remaining triggers should only have one of these parameters and won't
268 >                                                // need conversion. I'll just try and set them both, not a problem if one fails.
269 >                                                // The cross triggers will have e.g. "leg1" prefixed to the parameter name so I'll
270 >                                                // also try for those.
271 >                                                try{ newTrigger.parameter("etaCut")=etaOrRegionCut; }
272 >                                                catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
273 >
274 >                                                try{ newTrigger.parameter("regionCut")=etaOrRegionCut; }
275 >                                                catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
276 >
277 >                                                try{ newTrigger.parameter("leg1etaCut")=etaOrRegionCut; }
278 >                                                catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
279 >
280 >                                                try{ newTrigger.parameter("leg1regionCut")=etaOrRegionCut; }
281 >                                                catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
282 >
283 >                                                try{ newTrigger.parameter("leg2etaCut")=etaOrRegionCut; }
284 >                                                catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
285 >
286 >                                                try{ newTrigger.parameter("leg2regionCut")=etaOrRegionCut; }
287 >                                                catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
288 >                                        }
289 >
290 >                                        // The trigger may or may not have a muon quality cut. I also don't know if its name
291 >                                        // is prefixed with e.g. "leg1". I'll try setting all combinations, but wrap individually
292 >                                        // in a try block so that it doesn't matter if it fails.
293 >                                        try{ newTrigger.parameter("muonQuality")=::convertStringToFloat( tableColumns[8] ); }
294                                          catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
295  
296 <                                        try{ newTrigger.parameter("etaCut")=::convertStringToFloat( tableColumns[7] ); }
296 >                                        try{ newTrigger.parameter("leg1muonQuality")=::convertStringToFloat( tableColumns[8] ); }
297                                          catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
298  
299 <                                        try{ newTrigger.parameter("muonQuality")=::convertStringToFloat( tableColumns[8] ); }
299 >                                        try{ newTrigger.parameter("leg2muonQuality")=::convertStringToFloat( tableColumns[8] ); }
300                                          catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
301  
302 <                                } // end of "if able to add trigger"
303 <                                else std::cout << "The trigger \"" << tableColumns[0] << "\" is not registered in the trigger table" << std::endl;
302 >                                } // end of try block
303 >                                catch( std::exception& error )
304 >                                {
305 >                                        std::cerr << "Unable to add trigger \"" << tableColumns[0] << "\" because: " << error.what() << std::endl;
306 >                                }
307                          } // end of "if( prescale!=0 )"
308                  } // end of try block
309                  catch( std::runtime_error& exception )

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines