/[PAMELA software]/YodaProfiler/src/PamelaDBOperations.cpp
ViewVC logotype

Diff of /YodaProfiler/src/PamelaDBOperations.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.44 by mocchiut, Sun Jun 3 16:44:36 2007 UTC revision 1.50 by mocchiut, Wed Sep 5 15:34:49 2007 UTC
# Line 56  string getTleDatetime(cTle*); Line 56  string getTleDatetime(cTle*);
56   * @param debug        debug flag.   * @param debug        debug flag.
57   * @param tlefilename  ascii file with TLE 3 line elements.   * @param tlefilename  ascii file with TLE 3 line elements.
58   */   */
59  PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename, UInt_t dwinput, Bool_t staticp){  PamelaDBOperations::PamelaDBOperations(TString host, TString user, TString password, TString filerawname, TString filerootname, UInt_t boot, UInt_t tsync, UInt_t obt0, Bool_t debug, TString tlefilename, UInt_t dwinput, Bool_t staticp, Bool_t gpamela){
60    //    //
61    STATIC=false;    STATIC=false;
62    if ( staticp ) STATIC=true;    if ( staticp ) STATIC=true;
# Line 68  PamelaDBOperations::PamelaDBOperations(T Line 68  PamelaDBOperations::PamelaDBOperations(T
68    glrun = new GL_RUN();    glrun = new GL_RUN();
69    //    //
70    if ( !boot ) SetNOBOOT(false);    if ( !boot ) SetNOBOOT(false);
71    SetBOOTnumber(boot);    SetTsync(tsync,gpamela);
72    SetTsync(tsync);    SetBOOTnumber(boot,gpamela);
73    SetObt0(obt0);    SetObt0(obt0);
74    //    //
75    SetTLEPath(tlefilename);    SetTLEPath(tlefilename);
# Line 179  void PamelaDBOperations::SetNoFrag(Bool_ Line 179  void PamelaDBOperations::SetNoFrag(Bool_
179   * @param boot    BOOT number of the RAW file   * @param boot    BOOT number of the RAW file
180   */   */
181  void PamelaDBOperations::SetBOOTnumber(UInt_t boot){  void PamelaDBOperations::SetBOOTnumber(UInt_t boot){
182      this->SetBOOTnumber(boot,false);
183    };
184    
185    /**
186     * Store the BOOT number of the RAW file.
187     * @param boot    BOOT number of the RAW file
188     */
189    void PamelaDBOperations::SetBOOTnumber(UInt_t boot, Bool_t gpamela){
190    BOOTNO=boot;    BOOTNO=boot;
191      if ( gpamela ){
192        stringstream oss;
193        TSQLResult *result = 0;
194        TSQLRow    *row    = 0;    
195        if ( !boot ){
196          //
197          BOOTNO = 1;
198          //
199          // look in the DB for the last timesync and the last run
200          //
201          oss.str("");
202          oss << "SELECT BOOT_NUMBER FROM GL_RUN order by RUNHEADER_TIME desc limit 1;";
203          result = conn->Query(oss.str().c_str());
204          if ( result ){
205            row = result->Next();
206            if ( row ){
207              BOOTNO = (UInt_t)atoll(row->GetField(0)) + 1;
208            };
209          };
210        };
211      };
212  };  };
213    
214  /**  /**
# Line 187  void PamelaDBOperations::SetBOOTnumber(U Line 216  void PamelaDBOperations::SetBOOTnumber(U
216   * @param boot    time sync   * @param boot    time sync
217   */   */
218  void PamelaDBOperations::SetTsync(UInt_t ts){  void PamelaDBOperations::SetTsync(UInt_t ts){
219      this->SetTsync(ts,false);
220    };
221    
222    /**
223     * Store the time sync of the RAW file.
224     * @param boot    time sync
225     */
226    void PamelaDBOperations::SetTsync(UInt_t ts, Bool_t gpamela){
227      //
228      // if not gpamela or given tsync file set ts
229      //
230    tsync=ts;    tsync=ts;
231      if ( gpamela ){
232        stringstream oss;
233        TSQLResult *result = 0;
234        TSQLRow    *row    = 0;    
235        TSQLResult *result2 = 0;
236        TSQLRow    *row2    = 0;    
237        if ( !ts ){
238          //
239          tsync = 1;
240          //
241          // look in the DB for the last timesync and the last run
242          //
243          oss.str("");
244          oss << "SELECT TIMESYNC FROM GL_TIMESYNC order by TIMESYNC desc limit 1;";
245          result = conn->Query(oss.str().c_str());
246          if ( result ){
247            row = result->Next();
248            if ( row ){
249              tsync = (UInt_t)atoll(row->GetField(0)) + 1;
250              oss.str("");
251              oss << "SELECT (RUNTRAILER_TIME-RUNHEADER_TIME) FROM GL_RUN order by RUNHEADER_TIME desc limit 1;";
252              result2 = conn->Query(oss.str().c_str());
253              if ( result2 ){
254                row2 = result2->Next();
255                if ( row2 ){
256                  tsync += (UInt_t)atoll(row2->GetField(0));
257                };
258              }
259            };
260          };
261        };
262      };
263  };  };
264    
265  /**  /**
# Line 1175  Int_t PamelaDBOperations::insertPamelaGL Line 1247  Int_t PamelaDBOperations::insertPamelaGL
1247          rh->GetEntry(i);          rh->GetEntry(i);
1248          //          //
1249          TSYNC = runh->LAST_TIME_SYNC_INFO;          TSYNC = runh->LAST_TIME_SYNC_INFO;
1250          OBT = runh->OBT_TIME_SYNC;          OBT = runh->OBT_TIME_SYNC * 1000;
1251          //          //
1252          TYPE = 20;          TYPE = 20;
1253          //          //
# Line 1198  Int_t PamelaDBOperations::insertPamelaGL Line 1270  Int_t PamelaDBOperations::insertPamelaGL
1270          rt->GetEntry(i);          rt->GetEntry(i);
1271          //          //
1272          TSYNC = runt->LAST_TYME_SYNC_INFO;          TSYNC = runt->LAST_TYME_SYNC_INFO;
1273          OBT = runt->OBT_TYME_SYNC;          OBT = runt->OBT_TYME_SYNC * 1000;
1274          //          //
1275          TYPE = 21;          TYPE = 21;
1276          //          //
# Line 1717  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1789  Bool_t PamelaDBOperations::IsRunAlreadyI
1789    //                                  ( runhead_time <= _our_runhead_time &&  runtrail_time >= _our_runtrail_time) &&    //                                  ( runhead_time <= _our_runhead_time &&  runtrail_time >= _our_runtrail_time) &&
1790    //                                  ( runhead_obt <= _our_runheadobt || runhead_pkt <= _our_runheadpkt ) &&    //                                  ( runhead_obt <= _our_runheadobt || runhead_pkt <= _our_runheadpkt ) &&
1791    //                                  ( runtrail_obt <= _our_runtrailobt || runtrail_pkt <= _our_runtrailpkt ) )    //                                  ( runtrail_obt <= _our_runtrailobt || runtrail_pkt <= _our_runtrailpkt ) )
1792      //                                  ||
1793      //                                  ( runhead_time = _our_runhead_time &&  runtrail_time = _our_runtrail_time && nevents > 100 )
1794      //                                  )
1795      //                                  ||
1796      //                                  ( runhead_time = _our_runhead_time &&  runtrail_time > _our_runtrail_time && nevents > 100 )
1797      //                                  )
1798      //                                  ||
1799      //                                  ( runhead_time < _our_runhead_time &&  runtrail_time = _our_runtrail_time && nevents > 100 )
1800    //                                  )    //                                  )
1801    //    //
1802    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 "
# Line 1732  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1812  Bool_t PamelaDBOperations::IsRunAlreadyI
1812        << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR "        << " RUNHEADER_OBT<=" << glrun->GetRUNHEADER_OBT() << " OR "
1813        << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND ("        << " RUNHEADER_PKT<=" << glrun->GetRUNHEADER_PKT() << ") AND ("
1814        << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR "        << " RUNTRAILER_OBT>=" << glrun->GetRUNTRAILER_OBT() << " OR "
1815        << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") ));";        << " RUNTRAILER_PKT>=" << glrun->GetRUNTRAILER_PKT() << ") OR "
1816          << " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "                //  these two lines in a certain way disable the patch below...
1817          << " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100) OR"    //
1818          << " (RUNHEADER_TIME=" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "                //
1819          << " RUNTRAILER_TIME>" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100) OR"    //
1820          << " (RUNHEADER_TIME<" << (UInt_t)glrun->GetRUNHEADER_TIME() << " AND "                //
1821          << " RUNTRAILER_TIME=" << (UInt_t)glrun->GetRUNTRAILER_TIME() <<" AND NEVENTS>100)"    //
1822          << " ));";
1823    //    //
1824    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());
1825    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
# Line 1754  Bool_t PamelaDBOperations::IsRunAlreadyI Line 1841  Bool_t PamelaDBOperations::IsRunAlreadyI
1841      //      //
1842      // the run has already been inserted      // the run has already been inserted
1843      //      //
1844      //    return(true);  //<<<<<<<<<<<<<<<<<<<<<<<< patch follows, uncomment here      if ( signal && IsDebug() ) printf(" The run has already been inserted \n");    
1845        return(true);  //<<<<<<<<<<<<<<<<<<<<<<<< patch follows, uncomment here
1846      //      //
1847      // PATCH!      // PATCH!
1848      // 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
# Line 4678  UInt_t PamelaDBOperations::Check(){ Line 4766  UInt_t PamelaDBOperations::Check(){
4766    TSQLRow    *row    = 0;    TSQLRow    *row    = 0;
4767    TSQLResult *result2 = 0;    TSQLResult *result2 = 0;
4768    TSQLRow    *row2    = 0;    TSQLRow    *row2    = 0;
4769      TSQLResult *result3 = 0;
4770      TSQLRow    *row3    = 0;
4771    oss.str("");    oss.str("");
4772    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;";
4773    //  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;";
4774    result = conn->Query(oss.str().c_str());    result = conn->Query(oss.str().c_str());
4775    //    //
4776    if ( !result ) throw -4;;    if ( !result ) throw -4;;
4777    //    //
4778    row = result->Next();    row = result->Next();
4779      UInt_t nid = 0;
4780    //    //
4781    while ( row ){    while ( row ){
4782        nid++;
4783        if ( !(nid%1000) && nid ) printf(" %iK run scanned \n",nid/1000);
4784      thisid = (UInt_t)atoll(row->GetField(0));      thisid = (UInt_t)atoll(row->GetField(0));
4785      thisl0id = (UInt_t)atoll(row->GetField(1));      thisl0id = (UInt_t)atoll(row->GetField(1));
4786      thisrht = (UInt_t)atoll(row->GetField(2));      thisrht = (UInt_t)atoll(row->GetField(2));
4787      thisrtt = (UInt_t)atoll(row->GetField(3));      thisrtt = (UInt_t)atoll(row->GetField(3));
4788      //      //
4789        if ( (UInt_t)atoll(row->GetField(4)) > 1 ){
4790          //
4791          //
4792          //
4793          oss.str("");
4794          oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!="
4795              << thisid << " AND ( RUNHEADER_TIME="
4796              << thisrht << " OR RUNTRAILER_TIME="
4797              << thisrtt << " ) AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;";
4798          result3 = conn->Query(oss.str().c_str());
4799          if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str());
4800          if ( result3 ){
4801            //
4802            oss.str("");
4803            oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!="
4804                << thisid << " AND RUNHEADER_TIME="
4805                << thisrht << " AND RUNTRAILER_TIME!="
4806                << thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;";
4807            result3 = conn->Query(oss.str().c_str());
4808            if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str());
4809            if ( result3 ){
4810              row3 = result3->Next();
4811              //
4812              while ( row3 ){
4813                //
4814                // 2 runs with same runheader
4815                //
4816                printf(" CHECK n.4 RUNs %u and %u HAVE SAME RUNHEADER \n",thisid,(UInt_t)atoll(row3->GetField(0)));  
4817                row3 = result3->Next();
4818              };
4819            };
4820            //
4821            oss.str("");
4822            oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!="
4823                << thisid << " AND RUNHEADER_TIME!="
4824                << thisrht << " AND RUNTRAILER_TIME="
4825                << thisrtt << " AND NEVENTS!=0 AND NEVENTS!=1 order by RUNHEADER_TIME asc;";
4826            result3 = conn->Query(oss.str().c_str());
4827            if ( IsDebug() ) printf(" query is %s \n",oss.str().c_str());
4828            if ( result3 ){
4829              row3 = result3->Next();
4830              //
4831              while ( row3 ){
4832                //
4833                // 2 runs with same runtrailer
4834                //
4835                printf(" CHECK n.5 RUNs %u and %u HAVE SAME RUNTRAILER \n",thisid,(UInt_t)atoll(row3->GetField(0)));
4836                row3 = result3->Next();
4837              };
4838            };
4839            //
4840            oss.str("");
4841            oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!="
4842                << thisid << " AND RUNHEADER_TIME="
4843                << thisrht << " AND RUNTRAILER_TIME="
4844                << thisrtt << " AND ID_RUN_FRAG!="
4845                << thisid << " order by RUNHEADER_TIME asc;";
4846            result3 = conn->Query(oss.str().c_str());
4847            if ( result3 ){
4848              row3 = result3->Next();
4849              //
4850              while ( row3 ){
4851                //
4852                // duplicated run
4853                //
4854                printf(" CHECK n.7 RUNs %u and %u HAVE SAME RUNTRAILER AND RUNHEADER (ARE THE SAME?) \n",thisid,(UInt_t)atoll(row3->GetField(0)));
4855                row3 = result3->Next();
4856              };
4857            };
4858          };
4859          //
4860          oss.str("");
4861          oss << "SELECT ID,ID_ROOT_L0,RUNHEADER_TIME,RUNTRAILER_TIME FROM GL_RUN WHERE ID!="
4862              << thisid << " AND RUNHEADER_TIME>"
4863              << thisrht << " AND RUNTRAILER_TIME<"
4864              << thisrtt << " order by RUNHEADER_TIME asc;";
4865          result3 = conn->Query(oss.str().c_str());
4866          if ( result3 ){
4867            row3 = result3->Next();
4868            //
4869            while ( row3 ){
4870              //
4871              // run contained in the checked one
4872              //
4873              printf(" CHECK n.6 RUN %u CONTAINS RUN %u  \n",thisid,(UInt_t)atoll(row3->GetField(0)));
4874              row3 = result3->Next();
4875            };
4876          };
4877          //
4878        };
4879        //
4880      //    if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){      //    if ( thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt && !(!prevrht && !prevrtt &&!previd) ){
4881      //    if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){      //    if ( (thisrht < prevrtt || thisrtt < prevrht || thisrht > thisrtt) && (thisrht != prevrht) ){
4882      if ( (thisrht < prevrtt) && (thisrht != prevrht) ){      if ( (thisrht < prevrtt) && (thisrht != prevrht) ){
# Line 4724  UInt_t PamelaDBOperations::Check(){ Line 4908  UInt_t PamelaDBOperations::Check(){
4908        oss.str("");        oss.str("");
4909        oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";";        oss << "SELECT NAME FROM GL_ROOT where ID=" << (UInt_t)prevl0id <<";";
4910        result2 = conn->Query(oss.str().c_str());        result2 = conn->Query(oss.str().c_str());
4911        if ( !result2 ) throw -4;;        if ( !result2 ) throw -4;
4912        row2 = result2->Next();        row2 = result2->Next();
4913        prevf = (TString)row2->GetField(0);        prevf = (TString)row2->GetField(0);
4914        oss.str("");        oss.str("");

Legend:
Removed from v.1.44  
changed lines
  Added in v.1.50

  ViewVC Help
Powered by ViewVC 1.1.23