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.7 by grimes, Mon Jun 24 14:47:38 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   size_t l1menu::TriggerMenu::numberOfTriggers() const
# Line 207 | Line 208 | void l1menu::TriggerMenu::loadMenuInOldF
208                          float prescale=::convertStringToFloat( tableColumns[2] );
209                          if( prescale!=0 )
210                          {
211 <                                if( addTrigger( tableColumns[0] ) ) // Try and create a trigger with the name supplied
211 <                                {
212 <                                        std::cout << "Added trigger \"" << tableColumns[0] << "\"" << std::endl;
211 >                                std::string triggerName=tableColumns[0];
212  
213 <                                        l1menu::ITrigger& newTrigger=*(triggers_.back());
213 >                                try
214 >                                {
215 >                                        //std::cout << "Added trigger \"" << tableColumns[0] << "\"" << std::endl;
216 >                                        l1menu::ITrigger& newTrigger=addTrigger( triggerName ); // Try and create a trigger with the name supplied
217  
218                                          // Try and set all of the relevant parameters. I know not all triggers have these parameters
219                                          // so wrap in individual try/catch blocks.
# Line 227 | Line 229 | void l1menu::TriggerMenu::loadMenuInOldF
229                                          try{ newTrigger.parameter("threshold4")=::convertStringToFloat( tableColumns[6] ); }
230                                          catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
231  
232 <                                        try{ newTrigger.parameter("etaCut")=::convertStringToFloat( tableColumns[7] ); }
233 <                                        catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
232 >                                        float etaOrRegionCut=::convertStringToFloat( tableColumns[7] );
233 >                                        // For most triggers, I can just try and set both the etaCut and regionCut parameters
234 >                                        // with this value. If it doesn't have either of the parameters just catch the exception
235 >                                        // and nothing will happen. Some cross triggers however have both, and need to set them
236 >                                        // both from this value which requires a conversion. Most cross triggers expect this
237 >                                        // value to be the regionCut, except for L1_SingleMu_CJet which expects it as the etaCut.
238 >                                        if( triggerName=="L1_SingleMu_CJet" )
239 >                                        {
240 >                                                newTrigger.parameter("leg1etaCut")=etaOrRegionCut;
241 >                                                newTrigger.parameter("leg2regionCut")=l1menu::tools::convertEtaCutToRegionCut( etaOrRegionCut );
242 >                                        }
243 >                                        else if( triggerName=="L1_SingleIsoEG_CJet" )
244 >                                        {
245 >                                                newTrigger.parameter("leg1regionCut")=etaOrRegionCut;
246 >                                                newTrigger.parameter("leg2regionCut")=etaOrRegionCut;
247 >                                        }
248 >                                        else
249 >                                        {
250 >                                                // Any remaining triggers should only have one of these parameters and won't
251 >                                                // need conversion. I'll just try and set them both, not a problem if one fails.
252 >                                                try{ newTrigger.parameter("etaCut")=etaOrRegionCut; }
253 >                                                catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
254 >
255 >                                                try{ newTrigger.parameter("regionCut")=etaOrRegionCut; }
256 >                                                catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
257 >                                        }
258  
259                                          try{ newTrigger.parameter("muonQuality")=::convertStringToFloat( tableColumns[8] ); }
260                                          catch( std::exception& error ) { } // Do nothing, just try and convert the other parameters
261  
262                                  } // end of "if able to add trigger"
263 <                                else std::cout << "The trigger \"" << tableColumns[0] << "\" is not registered in the trigger table" << std::endl;
263 >                                catch( std::exception& error )
264 >                                {
265 >                                        std::cerr << "Unable to add trigger \"" << tableColumns[0] << "\" because: " << error.what() << std::endl;
266 >                                }
267                          } // end of "if( prescale!=0 )"
268                  } // end of try block
269                  catch( std::runtime_error& exception )

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines