Report problems to ATLAS LXR Team (with time and IP address indicated)

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: linux ]
Version: head ] [ nightly ] [ GaudiDev ]
  Links to LXR source navigation pages for stable releases [ 12.*.* ]   [ 13.*.* ]   [ 14.*.* ] 

001 package triggertool.HLTRecords;
002 
003 import java.awt.Color;
004 import java.awt.Graphics2D;
005 import java.awt.Point;
006 import java.awt.event.ActionEvent;
007 import java.awt.event.ActionListener;
008 import java.sql.PreparedStatement;
009 import java.sql.ResultSet;
010 import java.sql.SQLException;
011 import java.util.Iterator;
012 import java.util.TreeMap;
013 import java.util.Vector;
014 import java.util.logging.Logger;
015 import javax.swing.JMenuItem;
016 import javax.swing.JPopupMenu;
017 import javax.swing.JTextField;
018 import javax.swing.tree.DefaultMutableTreeNode;
019 import triggertool.Components.AbstractTable;
020 import triggertool.Components.ConnectionManager;
021 import triggertool.Components.NewJPanel;
022 import triggertool.Components.SearchDialog;
023 import triggertool.Components.TriggerInfo;
024 
025 ///HLT Trigger Element.
026 /**
027  * HLT Trigger Element object.
028  *
029  * @author Paul Bell
030  * @author Simon Head
031  */
032 public class HLTTriggerElement extends AbstractTable {
033 
034     ///Message Log.
035     protected static Logger logger = Logger.getLogger(HLTTriggerElement.class.getName());
036     ///Vector of input trigger elements.
037     private Vector<HLTTE_TE> tete = null;
038     ///Vector of components that belong to a trigger element.
039     private Vector<HLTComponent> algorithms = null;
040     ///So the tree knows what to display.
041     private boolean needtoadd_tete = true;
042     ///Useful for the tree.
043     private Vector<DefaultMutableTreeNode> tree_data = new Vector<DefaultMutableTreeNode>();
044     ///Held in a link table.
045     private Integer element_counter = -1;
046     ///Panel that we draw components to.
047     private NewJPanel pan = null;
048     ///So the name of the trigger element can be changed.
049     private TriggerInfo nameBtn = null;
050     ///Probably shouldn't be here.
051     private JTextField textName = new JTextField();
052 
053     ///Default constructor.
054     public HLTTriggerElement(int input_id) {
055         super(input_id);
056 
057         tableName = "HLT_TRIGGER_ELEMENT";
058         tablePrefix = "HTE_";
059 
060         if (input_id > 0) {
061             forceLoad();
062         }
063 
064         nameBtn = new TriggerInfo("NAME", keyValue, textName);
065     }
066 
067     ///Trick the class into thinking that the children have been loaded.
068     public void confuseLoader() {
069         tete = new Vector<HLTTE_TE>();
070         algorithms = new Vector<HLTComponent>();
071     }
072 
073     ///After an edit we need to force the record to read from the database.
074     @Override
075     public void forceLoad() {
076         needtoadd_tete = true;
077         algorithms = null;
078         tete = null;
079         ConnectionManager.getInstance().forceLoad(this);
080     }
081 
082     ///Left click if something was pressed, otherwise do nothing.
083     public boolean leftClickIfPossible(Point p, boolean expand_only) {
084     
085         boolean maybeedited = false;
086         boolean clicked = false;
087         
088         checkClickArrow(p);
089         
090         if(!expand_only) {
091             
092             boolean clickedcross = checkClickCross(p);    
093             if(clickedcross&&maybeedited==false) maybeedited=true;
094             
095             clicked = nameBtn.leftClickIfPossible(p);  
096             if(clicked&&maybeedited==false) maybeedited=true;
097             
098         }
099         
100         if(!clicked){
101             for (HLTComponent algorithm : getAlgorithms()) {
102                 algorithm.leftClickIfPossible(p, expand_only);
103             }
104             for (HLTTE_TE inputele : getInputElements()) {
105                 inputele.leftClickIfPossible(p, expand_only);
106             }
107         }
108         
109         if(maybeedited){
110             //System.out.println("Setting ele id negative for " + get_name());
111             set_id(-1);
112         }
113         return maybeedited;
114     }
115      
116 
117     ///Probably not a good idea, fiddles with numbers in links?
118     public void renumberAlgorithms() {
119         if (algorithms != null) {
120             int i = 0;
121             for (HLTComponent component : getAlgorithms()) {
122                 component.set_algorithm_counter(i);
123                 ++i;
124             }
125         }
126     }
127 
128     ///Add components to the tree view.
129     @Override
130     public void addToTree(DefaultMutableTreeNode treeNode, int counter) {
131         --counter;
132         if (counter >= 0) {
133 
134             //inputs
135             Vector<HLTTE_TE> inputs = getInputElements();
136             Iterator<HLTTE_TE> inputs_it = inputs.iterator();
137 
138             if (needtoadd_tete) {
139                 while (inputs_it.hasNext()) {
140                     HLTTE_TE test = (HLTTE_TE) inputs_it.next();
141                     DefaultMutableTreeNode anotherLayer = new DefaultMutableTreeNode(test);
142                     treeNode.add(anotherLayer);
143                 }
144                 needtoadd_tete = false;
145             }
146 
147             if (tree_data.size() == 0) {
148                 for (HLTComponent comp : getAlgorithms()) {
149                     DefaultMutableTreeNode anotherLayer = new DefaultMutableTreeNode(comp);
150                     treeNode.add(anotherLayer);
151                     tree_data.add(anotherLayer);
152                 }
153             } else {
154                 int i = 0;
155                 for (HLTComponent comp : getAlgorithms()) {
156                     comp.addToTree(tree_data.get(i), counter);
157                     ++i;
158                 }
159             }
160         }
161     }
162 
163     ///Make a deep copy of a trigger element.
164     /**
165      * When the user clicks the copy button we copy the class. This contains the
166      * code to set all the variables in the new class to the correct values
167      * 
168      * Don't increment the version this will be done automagically
169      */
170     public Object clone() {
171         HLTTriggerElement copy = new HLTTriggerElement(-1);
172         copy.set_name(get_name());
173         copy.set_version(get_version());
174         //copy.add_gui(pan);
175         //copy.setX(getX());
176         //copy.setY(getY());
177         for (HLTTE_TE tetelink : getInputElements()) {
178             HLTTE_TE newtete = (HLTTE_TE) tetelink.clone();
179             copy.getInputElements().add(newtete);
180         }
181         for (HLTComponent comp : getAlgorithms()) {
182             HLTComponent newcomp = (HLTComponent) comp.clone();
183             copy.getAlgorithms().add(newcomp);
184         }
185         return copy;
186     }
187 
188     ///Save the trigger element, check input TE and components.
189     /**
190      * Contains the code that saves the record to the database Again, see LVL1
191      * for an implementation.
192      * 
193      * @throws SQLException Stop on SQL problems.
194      */
195     public int save() throws SQLException {
196 
197         logger.fine("In HLT TE Save for TE: " + get_name());
198         //logger.info("Num of input TEs = " + getInputElements().size());
199         //logger.info("Num of algorithms: " + getAlgorithms().size());
200 
201         //Map of comp IDs with their counters - for comparison late
202         TreeMap<Integer, Integer> comp_ids = new TreeMap<Integer, Integer>();
203         for (HLTComponent comp : getAlgorithms()) {
204             comp_ids.put(comp.get_id(), comp.get_algorithm_counter());
205         }
206         //NB treemaps are sorted by key, so should be able to compare them!
207         
208         //PJB 25/4/08 want a better way to do this - if the name matches, start comparing inputs, 
209         //then if the input matches start comparing algorithms
210         //also need to do this in types and groups etc!
211         int matchingID = -1;
212         //FIRST STEP - find list of candidated by matching the name and used
213 
214         Vector<Integer> hteName_ids = ConnectionManager.getInstance().get_IDs(tableName, tablePrefix, keyValue, null, "ID");
215         logger.fine("Number of candidate TEs (with matching name) : " + hteName_ids.size());
216         //
217         //Now loop over the candidates
218         //
219         HLTTriggerElement matchTETE = null;
220         for (Integer iTE : hteName_ids) {
221           
222             //FIRST STEP - match the components
223             String query = "SELECT HTE2CP_COMPONENT_ID, HTE2CP_ALGORITHM_COUNTER FROM HLT_TE_TO_CP WHERE HTE2CP_TRIGGER_ELEMENT_ID=?";
224             TreeMap<Integer, Integer> compresults = ConnectionManager.getInstance().getConstrainedItemList(query, iTE);
225             if (!compresults.equals(comp_ids)) {
226                 logger.fine("PJB different components so going to next candidate");
227                 continue;
228             }
229             
230             //SECOND STEP - match the input TEs
231             //get one of the candidate TEs with matching name
232             matchTETE = new HLTTriggerElement(iTE);
233             logger.fine("PJB potential match has this many input TEs: " + matchTETE.getInputElements().size());
234             //if the size is different we can stop here
235             if (matchTETE.getInputElements().size() != getInputElements().size()) {
236                 logger.fine("PJB different number of inputs so going to next candidate");
237                 continue;
238             }
239             matchTETE = null;
240             logger.fine("PJB potential match " + iTE + " has same number of inputs (" + getInputElements().size() + ")");
241             //if same number of inputs, are they the same ones? loop over inputs and see if the match has them
242             //
243             Vector<String> Inputs_Found = new Vector<String>();
244             for (HLTTE_TE Input : getInputElements()) {
245 
246                 TreeMap<String, Object> fields_values2 = new TreeMap<String, Object>();
247                 fields_values2.put("TE_ID", iTE);
248                 fields_values2.put("TE_INP_ID", Input.get_element_inp_id());
249                 fields_values2.put("TE_INP_TYPE", Input.get_element_inp_type());
250                 fields_values2.put("TE_COUNTER", Input.get_element_counter());
251                 fields_values2.put("USED", Input.get_used());
252                 //ids of TETEs belonging to candidate which match what we are trying to save
253                 //logger.info("PJB this TE has input " + )
254                 Vector<Integer> te2teIDs = ConnectionManager.getInstance().get_IDs("HLT_TE_TO_TE", "HTE2TE_", fields_values2, null, "ID");
255                 if (te2teIDs.size() > 0) {
256                     Inputs_Found.add(Input.get_element_inp_id());
257                 }
258             }
259             //now, TEInputs_Found will have same size as getInputElements if the match is the same!
260             if (Inputs_Found.size() != getInputElements().size()) {
261                 logger.fine("PJB same number of inputs but not identical so going to next candidate");
262                 continue;
263             }
264             Inputs_Found.clear();
265             
266             logger.fine("PJB TE candidate matches exactly: " + iTE);
267             //  
268             //if we got to here, we have a match so stop
269             matchingID = iTE;
270             break;
271         }
272 
273         if (matchingID < 0) {
274             logger.fine("Saving new TE");
275 
276             int version = 1 + ConnectionManager.getInstance().getMaxVersion(tableName, tablePrefix, get_name());
277             keyValue.put("VERSION", version);
278             set_id(ConnectionManager.getInstance().save(tableName, tablePrefix, get_id(), keyValue));
279 
280             for (HLTComponent comp : getAlgorithms()) {
281                 TreeMap<String, Object> link = new TreeMap<String, Object>();
282                 link.put("TRIGGER_ELEMENT_ID", get_id());
283                 link.put("COMPONENT_ID", comp.get_id());
284                 link.put("ALGORITHM_COUNTER", comp.get_algorithm_counter());
285                 link.put("USED", false);
286                 ConnectionManager.getInstance().save("HLT_TE_TO_CP", "HTE2CP_", -1, link);
287             }
288             
289             for (HLTTE_TE link : getInputElements()) {
290                 link.set_id(-1);
291                 link.set_trigger_element_id(get_id());
292                 logger.fine("PJB going to save TETE with id " + link.get_id() + " for TE id " + link.get_element_inp_id());
293                 link.save();
294             }
295 
296             logger.fine("[SAVE TE :: new id = " + get_id() + " ] " + get_name());
297         } else {
298             ////id = hteNameInputAlg_ids.get(0);
299             set_id(matchingID);
300             logger.fine("[SAVE TE :: returned id = " + get_id() + " ] " + get_name());
301         }
302 
303         logger.fine("TE id as selected by save: " + get_id());
304 
305         return get_id();
306     }
307 
308     ///Set the element counter in the link table.
309     public void set_element_counter(int iTE) {
310         element_counter = iTE;
311     }
312 
313     ///Get the element counter from the link table.
314     public Integer get_element_counter() {
315         return element_counter;
316     }
317 
318     ///String representation of the object.
319     @Override
320     public String toString() {
321         if (get_id() == -1) {
322             return "HLT Trigger Element";
323         }
324         return "HLT TRIGGER ELEMENT: ID=" + get_id() +
325                 ", Name=" + get_name() +
326                 ", Input TE(s)=" + get_input_trigger_element_names();
327     }
328 
329     ///Minimum names for search results.
330     @Override
331     public Vector<String> get_min_names() {
332         Vector<String> info = new Vector<String>();
333         info.add("ID");
334         info.add("Name");
335         info.add("Input TE Name(Type)");
336         return info;
337     }
338 
339     ///Minimum info for search result.
340     @Override
341     public Vector<Object> get_min_info() {
342         Vector<Object> info = new Vector<Object>();
343         info.add(get_id());
344         info.add(get_name());
345         info.add(get_input_trigger_element_names_and_counters());
346         return info;
347     }
348 
349     ///Returns a string of names of all the input trigger elements.
350     public String get_input_trigger_element_names() {
351         String inp_te_names = "";
352         getInputElements();
353         Iterator<HLTTE_TE> myIterator = tete.iterator();
354         while (myIterator.hasNext()) {
355             HLTTE_TE link_TETE = (HLTTE_TE) myIterator.next();
356             if (inp_te_names.length() == 0) {
357                 inp_te_names = link_TETE.get_element_inp_id() + "(" + link_TETE.get_element_inp_type() + ")";
358             } else {
359                 inp_te_names = inp_te_names + ", " + link_TETE.get_element_inp_id() + "(" + link_TETE.get_element_inp_type() + ")";
360             }
361         }
362         return inp_te_names;
363     }
364 
365     ///Returns a string of names of all the input trigger elements also with counter information.
366     public String get_input_trigger_element_names_and_counters() {
367         String inp_te_names = "";
368         getInputElements();
369         Iterator<HLTTE_TE> myIterator = tete.iterator();
370         while (myIterator.hasNext()) {
371             HLTTE_TE link_TETE = (HLTTE_TE) myIterator.next();
372             if (inp_te_names.length() == 0) {
373                 inp_te_names = link_TETE.get_element_counter() + ": " + link_TETE.get_element_inp_id() + "(" + link_TETE.get_element_inp_type() + ")";
374             } else {
375                 inp_te_names = inp_te_names + ", " + link_TETE.get_element_counter() + ": " + link_TETE.get_element_inp_id() + "(" + link_TETE.get_element_inp_type() + ")";
376             }
377         }
378         return inp_te_names;
379     }
380 
381     ///Returns a string of types of all the input trigger elements.
382     public String get_input_trigger_element_types() {
383         String inp_te_types = "";
384         Vector<HLTTE_TE> links = getInputElements();
385         Iterator<HLTTE_TE> It_TETE = links.iterator();
386         while (It_TETE.hasNext()) {
387             HLTTE_TE link_TETE = (HLTTE_TE) It_TETE.next();
388             if (inp_te_types.length() == 0) {
389                 inp_te_types = link_TETE.get_element_inp_type();
390             } else {
391                 inp_te_types = inp_te_types + ", " + link_TETE.get_element_inp_type();
392             }
393         }
394         return inp_te_types;
395     }
396 
397     
398     
399     //get the components (ie the algorithms (and with them their tools) from the TE-CP link)
400     public Vector<HLTComponent> getAlgorithms() {
401         
402         if (algorithms == null) {
403             algorithms = new Vector<HLTComponent>();
404 
405             if (get_id() > 0) {
406                 
407                 HLTComponent tmp = new HLTComponent(-1);
408 
409                 String query = tmp.getQueryString();
410 
411                 query = query.replace("FROM ", "FROM HLT_TRIGGER_ELEMENT, HLT_TE_TO_CP, ");
412 
413                 String and = " WHERE " +
414                         "HTE_ID=? " +
415                         "AND " +
416                         "HTE2CP_TRIGGER_ELEMENT_ID=HTE_ID " +
417                         "AND " +
418                         "HTE2CP_COMPONENT_ID=HCP_ID ";
419 
420                 query = ConnectionManager.getInstance().fix_schema_name(query + and);
421 
422                 //System.out.println(query);
423 
424                 try {
425                     PreparedStatement ps = ConnectionManager.getInstance().getConnection().prepareStatement(query);
426                     ps.setInt(1, get_id());
427                     ResultSet rset = ps.executeQuery();
428 
429                     while (rset.next()) {
430                         HLTComponent comp = new HLTComponent(-1);
431                         comp.loadFromRset(rset);
432                         algorithms.add(comp);
433                     }
434 
435                     rset.close();
436                     ps.close();
437                 } catch (Exception e) {
438                     e.printStackTrace();
439                 }
440             }
441 
442         }
443         return algorithms;
444     }
445                 
446     
447     ///Load all the input trigger elements.
448     public Vector<HLTTE_TE> getInputElements() {
449         if (tete == null) {
450             tete = new Vector<HLTTE_TE>();
451 
452             if (get_id() > 0) {
453                 String query = "SELECT HTE2TE_ID " +
454                         "FROM HLT_TE_TO_TE " +
455                         "WHERE HTE2TE_TE_ID=? " +
456                         "ORDER BY HTE2TE_TE_COUNTER";
457 
458                 query = ConnectionManager.getInstance().fix_schema_name(query);
459                 Vector<Integer> ids = new Vector<Integer>();
460 
461                 try {
462                     PreparedStatement ps = ConnectionManager.getInstance().getConnection().prepareStatement(query);
463                     ps.setInt(1, get_id());
464                     ResultSet rset = ps.executeQuery();
465 
466                     while (rset.next()) {
467                         int idn = rset.getInt(1);
468                         ids.addElement(idn);
469                     }
470                     rset.close();
471                     ps.close();
472                 } catch (SQLException e) {
473                     e.printStackTrace();
474                 }
475 
476                 Iterator<Integer> it = ids.iterator();
477 
478                 while (it.hasNext()) {
479                     tete.addElement(new HLTTE_TE((Integer) it.next()));
480                 }
481             }
482         }
483         return tete;
484     }
485 
486 
487     ///Add components to the panel.
488     public void add_gui(NewJPanel o) {
489         nameBtn.addGui(o);
490         pan = o;
491     }
492 
493     ///User performed a right click.
494     public JPopupMenu rightClickIfPossible(Point p, 
495                                            HLTTriggerSignature parentsig, 
496                                            HLTTriggerChain parentchain,
497                                            HLTTriggerMenu parentmenu) {
498         
499         if(contains(p)){
500             //logger.info("Right clicked element " + get_name());
501             //logger.info("Parent signature is " + parentsig.get_name());
502             //logger.info("Parent chain is     " + parentchain.get_name());
503             
504             JPopupMenu jPopupMenu1 = new JPopupMenu();
505             JMenuItem menuAddAlgo = new JMenuItem("Add algorithm");
506 
507             menuAddAlgo.addActionListener(new ActionListener() {
508 
509                 public void actionPerformed(ActionEvent e) {
510                     SearchDialog dialog = new SearchDialog(new HLTComponent(-1));
511                     HLTComponent newalgo = (HLTComponent) dialog.getchild();
512                     newalgo.add_gui(pan);
513                     
514                     newalgo.set_id(-1);
515                     //System.out.println("Adding new algo to element " + get_name() + 
516                     //                   " and setting id of element, parent sig and parent chain to -1");
517                     set_id(-1);
518                     getAlgorithms().add(newalgo);
519                     
520                     pan.repaint();
521                 }
522             });
523             if(get_id()==-1){
524                 parentsig.set_id(-1);
525                 parentchain.set_id(-1);
526                 parentmenu.set_id(-1);
527             }
528             
529             jPopupMenu1.add(menuAddAlgo);
530         
531             return jPopupMenu1;
532         
533         }else{
534             return null;
535         }
536     }
537 
538     ///Calculate the height of this thing on the screen.
539     @Override
540     protected void calculateHeight() {
541         if (expanded) {
542             int h = 45;
543             h += 5;
544             for (HLTComponent comp : getAlgorithms()) {
545                 comp.calculateHeight();
546                 h += comp.getHeight() + 5;
547             }
548             h += 5;
549             for (HLTTE_TE inputte: getInputElements()) {
550                 inputte.calculateHeight();
551                 h += inputte.getHeight() + 5;
552             }
553             setSize(250, h);
554         } else {
555             setSize(250, 20);
556         }
557     }
558 
559     ///Draw this to the screen.
560     @Override
561     public void paintSquare(Graphics2D g2) {
562         calculateHeight();
563 
564         int iX = (int) getX();
565         int iY = (int) getY();
566         int iW = (int) getWidth();
567 
568         setArrow(getLocation()); //< put the arrow in the top left
569 
570         drawBackground(g2);      //< draw the background and border
571 
572         drawArrow(g2);           //< draw the expand / retract arrow
573 
574         nameBtn.draw(g2, iX + 20, iY - 3, iW - 50, 20);
575 
576         drawCross(g2);           //< draw the cross to remove
577 
578         showDBInfo(g2);          //< show the db info
579 
580         drawHighlight(g2);       //< highlight if we did a search
581 
582         
583         if (expanded) {
584             g2.setColor(border);
585             g2.drawLine(iX, iY + 20, iX + iW, iY + 20);
586 
587             //draw input elements
588             int h = iY + 25;
589             for (HLTTE_TE input : getInputElements()) {
590                  input.setLocation(iX + 5, h);
591                  input.paintSquare(g2);
592                  //h += input.getHeight();
593                  h += 75;
594             }
595 
596             //draw a string here
597             Color keep = g2.getColor();
598             g2.setColor(Color.BLACK);
599             g2.drawString("ALGORITHMS:", iX+5, h+11);
600             g2.setColor(keep);
601             
602             //draw algorithms
603             h += 15;
604             for (HLTComponent algorithm : getAlgorithms()) {
605                 algorithm.setLocation(iX + 5, h);
606                 algorithm.paintSquare(g2);
607                 // h += algorithm.getHeight();
608                 h += 25;
609             }
610 
611         } else {
612             //nothing to do?
613         }
614 
615     }
616 
617     ///Set this as expanded, short cut from other things.
618     public void setExpanded(boolean ex) {
619         expanded = ex;
620     }
621 }

source navigation ] diff markup ] identifier search ] general search ]

Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems
This page was automatically generated by the LXR engine. Valid HTML 4.01!