1516 |
rt->SetBranchAddress("RunTrailer", &runt); |
rt->SetBranchAddress("RunTrailer", &runt); |
1517 |
rt->SetBranchAddress("Header", &eht); |
rt->SetBranchAddress("Header", &eht); |
1518 |
// |
// |
1519 |
|
TTree *T = (TTree*)file->Get("Physics"); |
1520 |
|
if ( !T || T->IsZombie() ) throw -16; |
1521 |
|
EventHeader *eh = 0; |
1522 |
|
T->SetBranchAddress("Header", &eh); |
1523 |
|
// |
1524 |
|
if ( !(rh->GetEntries()) && !(rt->GetEntries()) && !(T->GetEntries()) ) return(16); |
1525 |
|
// |
1526 |
UInt_t obtt = 0; |
UInt_t obtt = 0; |
1527 |
UInt_t obth = 0; |
UInt_t obth = 0; |
1528 |
UInt_t pktt = 0; |
UInt_t pktt = 0; |
1597 |
// |
// |
1598 |
if ( PKT(pkth)>PKT(pktfirst) && OBT(obth)>OBT(obtfirst) && !ptt ){ |
if ( PKT(pkth)>PKT(pktfirst) && OBT(obth)>OBT(obtfirst) && !ptt ){ |
1599 |
// |
// |
1600 |
if ( IsDebug() ) printf(" Piece of run at the beginning of the file WITH NO RUNTRAILER \n"); |
if ( IsDebug() ) printf(" Piece of run at the beginning of the file WITH NO RUNTRAILER evbefh = %u \n",evbefh); |
1601 |
// |
// |
1602 |
if ( evbefh == 1 ){ |
if ( evbefh == 0 ) { |
1603 |
// |
// |
1604 |
signal = 8; |
signal = 8; |
1605 |
if ( IsDebug() ) printf(" Not supported yet: run with no events, no runtrailer, no runheader \n"); |
if ( IsDebug() ) printf(" Not supported yet: run with no events, no runtrailer, no runheader \n"); |
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 |
// |
// |
4704 |
if ( !result ) throw -4;; |
if ( !result ) throw -4;; |
4705 |
// |
// |
4706 |
row = result->Next(); |
row = result->Next(); |
4707 |
|
UInt_t nid = 0; |
4708 |
// |
// |
4709 |
while ( row ){ |
while ( row ){ |
4710 |
|
nid++; |
4711 |
|
if ( !(nid%1000) && nid ) printf(" %iK run scanned \n",nid/1000); |
4712 |
thisid = (UInt_t)atoll(row->GetField(0)); |
thisid = (UInt_t)atoll(row->GetField(0)); |
4713 |
thisl0id = (UInt_t)atoll(row->GetField(1)); |
thisl0id = (UInt_t)atoll(row->GetField(1)); |
4714 |
thisrht = (UInt_t)atoll(row->GetField(2)); |
thisrht = (UInt_t)atoll(row->GetField(2)); |
4715 |
thisrtt = (UInt_t)atoll(row->GetField(3)); |
thisrtt = (UInt_t)atoll(row->GetField(3)); |
4716 |
// |
// |
4717 |
|
if ( (UInt_t)atoll(row->GetField(4)) > 1 ){ |
4718 |
|
// |
4719 |
|
// |
4720 |
|
// |
4721 |
|
oss.str(""); |
4722 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
4723 |
|
<< thisid << " AND ( RUNHEADER_TIME=" |
4724 |
|
<< thisrht << " OR RUNTRAILER_TIME=" |
4725 |
|
<< thisrtt << " ) AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; |
4726 |
|
result3 = conn->Query(oss.str().c_str()); |
4727 |
|
if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); |
4728 |
|
if ( result3 ){ |
4729 |
|
// |
4730 |
|
oss.str(""); |
4731 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
4732 |
|
<< thisid << " AND RUNHEADER_TIME=" |
4733 |
|
<< thisrht << " AND RUNTRAILER_TIME!=" |
4734 |
|
<< thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; |
4735 |
|
result3 = conn->Query(oss.str().c_str()); |
4736 |
|
if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); |
4737 |
|
if ( result3 ){ |
4738 |
|
row3 = result3->Next(); |
4739 |
|
// |
4740 |
|
while ( row3 ){ |
4741 |
|
// |
4742 |
|
// 2 runs with same runheader |
4743 |
|
// |
4744 |
|
printf(" CHECK n.4 RUNs %u and %u HAVE SAME RUNHEADER \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
4745 |
|
row3 = result3->Next(); |
4746 |
|
}; |
4747 |
|
}; |
4748 |
|
// |
4749 |
|
oss.str(""); |
4750 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
4751 |
|
<< thisid << " AND RUNHEADER_TIME!=" |
4752 |
|
<< thisrht << " AND RUNTRAILER_TIME=" |
4753 |
|
<< thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;"; |
4754 |
|
result3 = conn->Query(oss.str().c_str()); |
4755 |
|
if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str()); |
4756 |
|
if ( result3 ){ |
4757 |
|
row3 = result3->Next(); |
4758 |
|
// |
4759 |
|
while ( row3 ){ |
4760 |
|
// |
4761 |
|
// 2 runs with same runtrailer |
4762 |
|
// |
4763 |
|
printf(" CHECK n.5 RUNs %u and %u HAVE SAME RUNTRAILER \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
4764 |
|
row3 = result3->Next(); |
4765 |
|
}; |
4766 |
|
}; |
4767 |
|
// |
4768 |
|
oss.str(""); |
4769 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
4770 |
|
<< thisid << " AND RUNHEADER_TIME=" |
4771 |
|
<< thisrht << " AND RUNTRAILER_TIME=" |
4772 |
|
<< thisrtt << " AND ID_RUN_FRAG!=" |
4773 |
|
<< thisid << " order by RUNHEADER_TIME asc;"; |
4774 |
|
result3 = conn->Query(oss.str().c_str()); |
4775 |
|
if ( result3 ){ |
4776 |
|
row3 = result3->Next(); |
4777 |
|
// |
4778 |
|
while ( row3 ){ |
4779 |
|
// |
4780 |
|
// duplicated run |
4781 |
|
// |
4782 |
|
printf(" CHECK n.7 RUNs %u and %u HAVE SAME RUNTRAILER AND RUNHEADER (ARE THE SAME?) \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
4783 |
|
row3 = result3->Next(); |
4784 |
|
}; |
4785 |
|
}; |
4786 |
|
}; |
4787 |
|
// |
4788 |
|
oss.str(""); |
4789 |
|
oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!=" |
4790 |
|
<< thisid << " AND RUNHEADER_TIME>" |
4791 |
|
<< thisrht << " AND RUNTRAILER_TIME<" |
4792 |
|
<< thisrtt << " order by RUNHEADER_TIME asc;"; |
4793 |
|
result3 = conn->Query(oss.str().c_str()); |
4794 |
|
if ( result3 ){ |
4795 |
|
row3 = result3->Next(); |
4796 |
|
// |
4797 |
|
while ( row3 ){ |
4798 |
|
// |
4799 |
|
// run contained in the checked one |
4800 |
|
// |
4801 |
|
printf(" CHECK n.6 RUN %u CONTAINS RUN %u \n",thisid,(UInt_t)atoll(row3->GetField(0))); |
4802 |
|
row3 = result3->Next(); |
4803 |
|
}; |
4804 |
|
}; |
4805 |
|
// |
4806 |
|
}; |
4807 |
|
// |
4808 |
// if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ |
// if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){ |
4809 |
// if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){ |
// if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){ |
4810 |
if ( (thisrht < prevrtt) && (thisrht != prevrht) ){ |
if ( (thisrht < prevrtt) && (thisrht != prevrht) ){ |
4811 |
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4812 |
printf(" CHECK n.1 TIME SCREW of %u s AROUND RUNs %u and %u \n",(thisrht-prevrtt),previd,thisid); |
printf(" CHECK n.1 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-prevrtt),previd,thisid); |
4813 |
TString prevf = ""; |
TString prevf = ""; |
4814 |
TString thisf = ""; |
TString thisf = ""; |
4815 |
oss.str(""); |
oss.str(""); |
4830 |
// |
// |
4831 |
if ( (thisrtt < prevrht) && (thisrht != prevrht) ){ |
if ( (thisrtt < prevrht) && (thisrht != prevrht) ){ |
4832 |
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4833 |
printf(" CHECK n.2 TIME SCREW of %u s AROUND RUNs %u and %u \n",(thisrtt-prevrht),previd,thisid); |
printf(" CHECK n.2 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrtt-prevrht),previd,thisid); |
4834 |
TString prevf = ""; |
TString prevf = ""; |
4835 |
TString thisf = ""; |
TString thisf = ""; |
4836 |
oss.str(""); |
oss.str(""); |
4837 |
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";"; |
4838 |
result2 = conn->Query(oss.str().c_str()); |
result2 = conn->Query(oss.str().c_str()); |
4839 |
if ( !result2 ) throw -4;; |
if ( !result2 ) throw -4; |
4840 |
row2 = result2->Next(); |
row2 = result2->Next(); |
4841 |
prevf = (TString)row2->GetField(0); |
prevf = (TString)row2->GetField(0); |
4842 |
oss.str(""); |
oss.str(""); |
4851 |
// |
// |
4852 |
if ( (thisrht > thisrtt) && (thisrht != prevrht) ){ |
if ( (thisrht > thisrtt) && (thisrht != prevrht) ){ |
4853 |
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
if ( IsDebug() ) printf(" IDprev %u ID %u prevrht %u prevrtt %u thisrht %u thisrtt %u \n",previd,thisid,prevrht,prevrtt,thisrht,thisrtt); |
4854 |
printf(" CHECK n.3 TIME SCREW of %u s AROUND RUNs %u and %u \n",(thisrht-thisrtt),previd,thisid); |
printf(" CHECK n.3 TIME SCREW of %i s AROUND RUNs %u and %u \n",(thisrht-thisrtt),previd,thisid); |
4855 |
TString prevf = ""; |
TString prevf = ""; |
4856 |
TString thisf = ""; |
TString thisf = ""; |
4857 |
oss.str(""); |
oss.str(""); |