| 1175 | rh->GetEntry(i); | rh->GetEntry(i); | 
| 1176 | // | // | 
| 1177 | TSYNC = runh->LAST_TIME_SYNC_INFO; | TSYNC = runh->LAST_TIME_SYNC_INFO; | 
| 1178 | OBT = runh->OBT_TIME_SYNC; | OBT = runh->OBT_TIME_SYNC * 1000; | 
| 1179 | // | // | 
| 1180 | TYPE = 20; | TYPE = 20; | 
| 1181 | // | // | 
| 1198 | rt->GetEntry(i); | rt->GetEntry(i); | 
| 1199 | // | // | 
| 1200 | TSYNC = runt->LAST_TYME_SYNC_INFO; | TSYNC = runt->LAST_TYME_SYNC_INFO; | 
| 1201 | OBT = runt->OBT_TYME_SYNC; | OBT = runt->OBT_TYME_SYNC * 1000; | 
| 1202 | // | // | 
| 1203 | TYPE = 21; | TYPE = 21; | 
| 1204 | // | // | 
| 1717 | //                                  ( runhead_time <= _our_runhead_time &&  runtrail_time >= _our_runtrail_time) && | //                                  ( runhead_time <= _our_runhead_time &&  runtrail_time >= _our_runtrail_time) && | 
| 1718 | //                                  ( runhead_obt <= _our_runheadobt || runhead_pkt <= _our_runheadpkt ) && | //                                  ( runhead_obt <= _our_runheadobt || runhead_pkt <= _our_runheadpkt ) && | 
| 1719 | //                                  ( runtrail_obt <= _our_runtrailobt || runtrail_pkt <= _our_runtrailpkt ) ) | //                                  ( runtrail_obt <= _our_runtrailobt || runtrail_pkt <= _our_runtrailpkt ) ) | 
| 1720 |  | //                                  || | 
| 1721 |  | //                                  ( runhead_time = _our_runhead_time &&  runtrail_time = _our_runtrail_time && nevents > 100 ) | 
| 1722 |  | //                                  ) | 
| 1723 |  | //                                  || | 
| 1724 |  | //                                  ( runhead_time = _our_runhead_time &&  runtrail_time > _our_runtrail_time && nevents > 100 ) | 
| 1725 |  | //                                  ) | 
| 1726 |  | //                                  || | 
| 1727 |  | //                                  ( runhead_time < _our_runhead_time &&  runtrail_time = _our_runtrail_time && nevents > 100 ) | 
| 1728 | //                                  ) | //                                  ) | 
| 1729 | // | // | 
| 1730 | oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE " | oss << " SELECT ID,NEVENTS,TRK_CALIB_USED,PKT_COUNTER FROM GL_RUN WHERE " | 
| 1740 | << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " | << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR " | 
| 1741 | << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" | << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND (" | 
| 1742 | << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " | << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR " | 
| 1743 | << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));"; | << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") OR " | 
| 1744 |  | << " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "                //  these two lines in a certain way disable the patch below... | 
| 1745 |  | << " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100) OR"    // | 
| 1746 |  | << " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "                // | 
| 1747 |  | << " RUNTRAILER_TIME>" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100) OR"    // | 
| 1748 |  | << " (RUNHEADER_TIME<" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "                // | 
| 1749 |  | << " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100)"    // | 
| 1750 |  | << " ));"; | 
| 1751 | // | // | 
| 1752 | if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); | if ( IsDebug() ) printf(" check if run has been inserted: query is \n %s \n",oss.str().c_str()); | 
| 1753 | result = conn->Query(oss.str().c_str()); | result = conn->Query(oss.str().c_str()); | 
| 1769 | // | // | 
| 1770 | // the run has already been inserted | // the run has already been inserted | 
| 1771 | // | // | 
| 1772 | //    return(true);  //<<<<<<<<<<<<<<<<<<<<<<<< patch follows, uncomment here | if ( signal && IsDebug() ) printf(" The run has already been inserted \n"); | 
| 1773 |  | return(true);  //<<<<<<<<<<<<<<<<<<<<<<<< patch follows, uncomment here | 
| 1774 | // | // | 
| 1775 | // PATCH! | // PATCH! | 
| 1776 | // we keep the processing run if (in order of growing importance) 1) we have the runtrailer while the old run doesn't have it 2) we have the runheader | // we keep the processing run if (in order of growing importance) 1) we have the runtrailer while the old run doesn't have it 2) we have the runheader | 
| 4694 | TSQLRow    *row    = 0; | TSQLRow    *row    = 0; | 
| 4695 | TSQLResult *result2 = 0; | TSQLResult *result2 = 0; | 
| 4696 | TSQLRow    *row2    = 0; | TSQLRow    *row2    = 0; | 
| 4697 |  | TSQLResult *result3 = 0; | 
| 4698 |  | TSQLRow    *row3    = 0; | 
| 4699 | oss.str(""); | oss.str(""); | 
| 4700 | oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN order by RUNHEADER_TIME asc;"; | oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME,NEVENTS FROM GL_RUN order by RUNHEADER_TIME asc;"; | 
| 4701 | //  oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;"; | //  oss << "SELECT ID,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN where ID>10170 and ID<10190 order by RUNHEADER_TIME asc;"; | 
| 4702 | result = conn->Query(oss.str().c_str()); | result = conn->Query(oss.str().c_str()); | 
| 4703 | // | // | 
| 4711 | thisrht = (UInt_t)atoll(row->GetField(2)); | thisrht = (UInt_t)atoll(row->GetField(2)); | 
| 4712 | thisrtt = (UInt_t)atoll(row->GetField(3)); | thisrtt = (UInt_t)atoll(row->GetField(3)); | 
| 4713 | // | // | 
| 4714 |  | if ( (UInt_t)atoll(row->GetField(4)) > 1 ){ | 
| 4715 |  | // | 
| 4716 |  | // | 
| 4717 |  | // | 
| 4718 |  | oss.str(""); | 
| 4719 |  | oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" | 
| 4720 |  | << thisid << " AND RUNHEADER_TIME=" | 
| 4721 |  | << thisrht << " AND RUNTRAILER_TIME!=" | 
| 4722 |  | << thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; | 
| 4723 |  | result3 = conn->Query(oss.str().c_str()); | 
| 4724 |  | if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); | 
| 4725 |  | if ( result3 ){ | 
| 4726 |  | row3 = result3->Next(); | 
| 4727 |  | // | 
| 4728 |  | while ( row3 ){ | 
| 4729 |  | // | 
| 4730 |  | // 2 runs with same runheader | 
| 4731 |  | // | 
| 4732 |  | printf(" CHECK n.4 RUNs %u and %u HAVE SAME RUNHEADER \n",thisid,(UInt_t)atoll(row3->GetField(0))); | 
| 4733 |  | row3 = result3->Next(); | 
| 4734 |  | }; | 
| 4735 |  | }; | 
| 4736 |  | // | 
| 4737 |  | oss.str(""); | 
| 4738 |  | oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" | 
| 4739 |  | << thisid << " AND RUNHEADER_TIME!=" | 
| 4740 |  | << thisrht << " AND RUNTRAILER_TIME=" | 
| 4741 |  | << thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; | 
| 4742 |  | result3 = conn->Query(oss.str().c_str()); | 
| 4743 |  | if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); | 
| 4744 |  | if ( result3 ){ | 
| 4745 |  | row3 = result3->Next(); | 
| 4746 |  | // | 
| 4747 |  | while ( row3 ){ | 
| 4748 |  | // | 
| 4749 |  | // 2 runs with same runtrailer | 
| 4750 |  | // | 
| 4751 |  | printf(" CHECK n.5 RUNs %u and %u HAVE SAME RUNTRAILER \n",thisid,(UInt_t)atoll(row3->GetField(0))); | 
| 4752 |  | row3 = result3->Next(); | 
| 4753 |  | }; | 
| 4754 |  | }; | 
| 4755 |  | // | 
| 4756 |  | oss.str(""); | 
| 4757 |  | oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" | 
| 4758 |  | << thisid << " AND RUNHEADER_TIME>" | 
| 4759 |  | << thisrht << " AND RUNTRAILER_TIME<" | 
| 4760 |  | << thisrtt << " order by RUNHEADER_TIME asc;"; | 
| 4761 |  | result3 = conn->Query(oss.str().c_str()); | 
| 4762 |  | if ( result3 ){ | 
| 4763 |  | row3 = result3->Next(); | 
| 4764 |  | // | 
| 4765 |  | while ( row3 ){ | 
| 4766 |  | // | 
| 4767 |  | // run contained in the checked one | 
| 4768 |  | // | 
| 4769 |  | printf(" CHECK n.6 RUN %u CONTAINS RUN %u  \n",thisid,(UInt_t)atoll(row3->GetField(0))); | 
| 4770 |  | row3 = result3->Next(); | 
| 4771 |  | }; | 
| 4772 |  | }; | 
| 4773 |  | // | 
| 4774 |  | oss.str(""); | 
| 4775 |  | oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" | 
| 4776 |  | << thisid << " AND RUNHEADER_TIME=" | 
| 4777 |  | << thisrht << " AND RUNTRAILER_TIME=" | 
| 4778 |  | << thisrtt << " AND ID_RUN_FRAG!=" | 
| 4779 |  | << thisid << " order by RUNHEADER_TIME asc;"; | 
| 4780 |  | result3 = conn->Query(oss.str().c_str()); | 
| 4781 |  | if ( result3 ){ | 
| 4782 |  | row3 = result3->Next(); | 
| 4783 |  | // | 
| 4784 |  | while ( row3 ){ | 
| 4785 |  | // | 
| 4786 |  | // duplicated run | 
| 4787 |  | // | 
| 4788 |  | printf(" CHECK n.7 RUNs %u and %u HAVE SAME RUNTRAILER AND RUNHEADER (ARE THE SAME?) \n",thisid,(UInt_t)atoll(row3->GetField(0))); | 
| 4789 |  | row3 = result3->Next(); | 
| 4790 |  | }; | 
| 4791 |  | }; | 
| 4792 |  | }; | 
| 4793 |  | // | 
| 4794 | //    if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ | //    if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ | 
| 4795 | //    if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){ | //    if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){ | 
| 4796 | if ( (thisrht < prevrtt) && (thisrht != prevrht) ){ | if ( (thisrht < prevrtt) && (thisrht != prevrht) ){ | 
| 4822 | oss.str(""); | oss.str(""); | 
| 4823 | oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; | oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; | 
| 4824 | result2 = conn->Query(oss.str().c_str()); | result2 = conn->Query(oss.str().c_str()); | 
| 4825 | if ( !result2 ) throw -4;; | if ( !result2 ) throw -4; | 
| 4826 | row2 = result2->Next(); | row2 = result2->Next(); | 
| 4827 | prevf = (TString)row2->GetField(0); | prevf = (TString)row2->GetField(0); | 
| 4828 | oss.str(""); | oss.str(""); |