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

Diff of /yodaUtility/YodaProfiler/PamelaDBOperations.cpp

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

revision 1.1 by kusanagi, Tue Jun 6 07:39:45 2006 UTC revision 1.2 by kusanagi, Sat Jun 10 18:07:03 2006 UTC
# Line 11  Line 11 
11  #include <TSQLRow.h>  #include <TSQLRow.h>
12  #include <TTree.h>  #include <TTree.h>
13  #include <TGraph.h>  #include <TGraph.h>
14    #include <TDatime.h>
15  #include <TF1.h>  #include <TF1.h>
16    
17  #include <cOrbit.h>  #include <cOrbit.h>
# Line 33  Line 34 
34    
35  extern "C" {  extern "C" {
36  #include <dirent.h>  #include <dirent.h>
37            //INITIZE(YEAR,DIMO)
38            extern void initize_();
39            //FELDCOF(YEAR,DIMO)
40            extern void feldcof_(float*, float*);
41            //FELDG(LATI,LONGI,HEIGHT,BNORTH,BEAST,BDOWN,BABS)
42            extern void feldg_(float*, float*, float*, float*, float*, float*, float*);
43            //SHELLG(LATI,LONGI,HEIGHT,DIMO,XL,ICODE,BAB1)
44            extern void shellg_(float*, float*, float*, float*, float*, float*, float*);
45            //FINDB0(STPS,BDEL,VALUE,BEQU,RR0)
46            extern void findb0_(float*, float*, bool*, float*, float*);
47  }  }
48    
49  using namespace log4cxx;  using namespace log4cxx;
# Line 300  int PamelaDBOperations::insertPamelaTM_H Line 311  int PamelaDBOperations::insertPamelaTM_H
311      getPacketsNames(packetsNames);      getPacketsNames(packetsNames);
312      for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){      for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){
313          tr      = (TTree*)file->Get(*Iter);          tr      = (TTree*)file->Get(*Iter);
314            if (tr == NULL || tr->IsZombie()) {
315                    cout << "Missing Tree: " << *Iter << "\n";
316                    continue;
317            }
318          nevents = tr->GetEntries();          nevents = tr->GetEntries();
319          tr->SetBranchAddress("Header", &eh);          tr->SetBranchAddress("Header", &eh);
320          for (UInt_t i = 0; i < nevents; i++){          for (UInt_t i = 0; i < nevents; i++){
# Line 752  int PamelaDBOperations::assignPamelaTIME Line 767  int PamelaDBOperations::assignPamelaTIME
767            if (secRow == NULL) throw YSQLQueryException("No Timesync!");            if (secRow == NULL) throw YSQLQueryException("No Timesync!");
768            id_Raw = (ULong64_t)atof(secRow->GetField(0));            id_Raw = (ULong64_t)atof(secRow->GetField(0));
769          }          }
           
770        }        }
         
771      }      }
772    
773      //Collect the TM_HEADER to assign them the correct TIMESYNC      //Collect the TM_HEADER to assign them the correct TIMESYNC
# Line 773  int PamelaDBOperations::assignPamelaTIME Line 786  int PamelaDBOperations::assignPamelaTIME
786      while (true) {        while (true) {  
787        row = result->Next();        row = result->Next();
788        if (row == 0) break;        if (row == 0) break;
       //diff = 1;  
       //if (syncOBT < (unsigned long)atol(row->GetField(0))) diff = -1;  
       //absTime   = (syncTIME + konstant)*1000 + diff*((unsigned long)atol(row->GetField(0)) - syncOBT);  
789        absTime   =  (ULong64_t)atof(row->GetField(0)) + syncTIME;        absTime   =  (ULong64_t)atof(row->GetField(0)) + syncTIME;
790        oss.str("");        oss.str("");
791        oss << " UPDATE TM_HEADER "        oss << " UPDATE TM_HEADER "
# Line 830  int PamelaDBOperations::createPamelaRegi Line 840  int PamelaDBOperations::createPamelaRegi
840                        throw (YSQLNotConnectedException, YSQLQueryException, YNotExistingFileException, YExistingFileException) {                        throw (YSQLNotConnectedException, YSQLQueryException, YNotExistingFileException, YExistingFileException) {
841      if (conn == 0) throw YSQLNotConnectedException("Connection missing");      if (conn == 0) throw YSQLNotConnectedException("Connection missing");
842    
843        stringstream   oss;
844        TSQLResult      *result, *secResult;
845        TSQLRow         *row,    *secRow;
846        ULong64_t        offset_date;
847    
848        /*Took all the root file related to a specific raw file*/
849        oss.str("");
850        oss << "SELECT OFFSET_DATE FROM GL_RAW WHERE ID = '" << idRaw << "'";
851        result = conn->Query(oss.str().c_str());
852        row = result->Next();
853        if (row != NULL && row != 0 && row->GetField(0) != NULL && row->GetField(0) != ""){
854            offset_date = TDatime(row->GetField(0)).Convert();
855        } else {
856            return NOK;
857        }
858    
859      ///TBD: Put the check "IF THE REGISTRY ALREDY EXISTS" before this try.      ///TBD: Put the check "IF THE REGISTRY ALREDY EXISTS" before this try.
860      try {      try {
861        if (insertPamelaTM_HEADER(conn, idRaw)){        if (insertPamelaTM_HEADER(conn, idRaw)){
# Line 844  int PamelaDBOperations::createPamelaRegi Line 870  int PamelaDBOperations::createPamelaRegi
870        return NOK;        return NOK;
871      }      }
872    
     stringstream   oss;  
     TSQLResult      *result, *secResult;  
     TSQLRow         *row,    *secRow;  
       
873      const char      *idRoot;      const char      *idRoot;
874      string          registryName;      string          registryName;
875      RegistryEvent   *registry   = new RegistryEvent();      RegistryEvent   *registry   = new RegistryEvent();
# Line 860  int PamelaDBOperations::createPamelaRegi Line 882  int PamelaDBOperations::createPamelaRegi
882      oss.str("");      oss.str("");
883      oss << "SELECT ID, PATH, NAME FROM GL_ROOT WHERE ID_RAW = '" << idRaw << "'";      oss << "SELECT ID, PATH, NAME FROM GL_ROOT WHERE ID_RAW = '" << idRaw << "'";
884      result = conn->Query(oss.str().c_str());      result = conn->Query(oss.str().c_str());
     //cout << oss.str().c_str() << "\n";  
     //if (result->GetRowCount() == 0) throw YSQLQueryException(oss.str().c_str());  
885      row = result->Next();      row = result->Next();
886      if (row == 0) return NOK;      if (row == 0) return NOK;
887    
888      idRoot      = row->GetField(0);      idRoot      = row->GetField(0);
889      oss.str("");      oss.str("");
890      oss << row->GetField(1) << "/" << row->GetField(2);      oss << row->GetField(1) << "/" << row->GetField(2);
891        
892      file    = YFile::Open(oss.str().c_str(), "UPDATE");      file    = YFile::Open(oss.str().c_str(), "UPDATE");
893      pcksList packetsNames;      pcksList packetsNames;
894      pcksList::iterator Iter;      pcksList::iterator Iter;
# Line 876  int PamelaDBOperations::createPamelaRegi Line 897  int PamelaDBOperations::createPamelaRegi
897      for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){      for(Iter = packetsNames.begin(); Iter != packetsNames.end(); Iter++){
898          //cout << "Tree Name: " << *Iter << "\n";          //cout << "Tree Name: " << *Iter << "\n";
899          tr      = (TTree*)file->Get(*Iter);          tr      = (TTree*)file->Get(*Iter);
900                            if (tr == NULL || tr->IsZombie()) {
901                            cout << "Missing Tree: " << *Iter << "\n";
902                            continue;
903                    }
904          //Branch Registry exist?          //Branch Registry exist?
905          if (!tr->GetBranchStatus("Registry")){          if (!tr->GetBranchStatus("Registry")){
906                  branch  = tr->Branch("Registry", "pamela::RegistryEvent", &registry);                  branch  = tr->Branch("Registry", "pamela::RegistryEvent", &registry);
# Line 887  int PamelaDBOperations::createPamelaRegi Line 911  int PamelaDBOperations::createPamelaRegi
911                  branch->Reset();                  branch->Reset();
912          }          }
913                    
         //This select s temporary. Better selection on time should be done,  
914          oss.str("");          oss.str("");
915          oss << "SELECT TLE1, TLE2, TLE3"          oss << "SELECT TLE1, TLE2, TLE3"
916                  << " FROM GL_TLE "                  << " FROM GL_TLE "
917                  << " WHERE VALID_FROM_TIME = 0 ";                  << " WHERE FROM_TIME >= 0 ";
918          //cout << oss.str().c_str() << "\n";          //cout << oss.str().c_str() << "\n";
919          result = conn->Query(oss.str().c_str());          result = conn->Query(oss.str().c_str());
920          row = result->Next();          row = result->Next();
921          if (!(row == 0)){          if (!(row == NULL)){
922          string tle1 = row->GetField(0);                  string tle1 = row->GetField(0);
923          string tle2 = row->GetField(1);                  string tle2 = row->GetField(1);
924          string tle3 = row->GetField(2);                  string tle3 = row->GetField(2);
925                  cTle tle(tle1, tle2, tle3);                  cTle tle(tle1, tle2, tle3);
926                  orbit = new cOrbit(tle);                  orbit = new cOrbit(tle);
927            } else {
928                    cout << "TLE table empty." << "\n";
929                    return NOK;
930          }          }
931                    
932            
933          /*Took all the TM_HEADER rows related to a specific root file and TREE_NAME*/          /*Took all the TM_HEADER rows related to a specific root file and TREE_NAME*/
934          oss.str("");          oss.str("");
935          oss << "SELECT EVENT, TIME FROM TM_HEADER WHERE ID_ROOT = '" << idRoot << "' "          oss << "SELECT EVENT, TIME FROM TM_HEADER WHERE ID_ROOT = '" << idRoot << "' "
# Line 912  int PamelaDBOperations::createPamelaRegi Line 939  int PamelaDBOperations::createPamelaRegi
939    
940          //Fill the 'Registry' TBranch          //Fill the 'Registry' TBranch
941          secRow = secResult->Next();          secRow = secResult->Next();
942          while (!(secRow == 0)){          initize_();
943            while (secRow != NULL){
944                  registry->event   = (unsigned int)atoi(secRow->GetField(0));                  registry->event   = (unsigned int)atoi(secRow->GetField(0));
945                  registry->absTime = (ULong64_t)atof(secRow->GetField(1));                  registry->absTime = (ULong64_t)atof(secRow->GetField(1)) + (offset_date*1000);
946                                    setGeo(orbit, registry);
947                  branch->Fill();                  branch->Fill();
948                  secRow = secResult->Next();                  secRow = secResult->Next();
949                  /*                  /*
# Line 2466  const char* PamelaDBOperations::getID_RA Line 2494  const char* PamelaDBOperations::getID_RA
2494    return row->GetField(0);    return row->GetField(0);
2495  }  }
2496    
2497  const char* PamelaDBOperations::setGeo(cOrbit *orbit, RegistryEvent &reg)  const char* PamelaDBOperations::setGeo(cOrbit *orbit, RegistryEvent* &reg)
2498                        throw (YSQLNotConnectedException, YSQLQueryException){                        throw (YSQLNotConnectedException, YSQLQueryException){
2499                  cEci         eci;                  cEci         eci;
2500                  cCoordGeo    coo;                  cCoordGeo    coo;
2501                  orbit->getPosition(reg.absTime, &eci);                  TDatime time = TDatime((reg->absTime/1000));
2502                    orbit->getPosition( (time.GetYear() + time.GetMonth()/12.), &eci);
2503                  coo = eci.toGeo();                  coo = eci.toGeo();
2504                  reg.m_Lat = rad2deg(coo.m_Lat);                  reg->m_Lat = rad2deg(coo.m_Lat);
2505                  reg.m_Lon = rad2deg(coo.m_Lon);                  reg->m_Lon = rad2deg(coo.m_Lon);
2506                  reg.m_Alt = coo.m_Alt;                  reg->m_Alt = coo.m_Alt;
2507                  //rate->Fill(rad2deg(coo.m_Lon), rad2deg(coo.m_Lat));                  cout << "coo.m_Lat " << dec << coo.m_Lat << "\n";
2508                    cout << "rad2deg(coo.m_Lat) " << dec << rad2deg(coo.m_Lat) << "\n";
2509                    float dimo = 0.0;
2510                    float year = time.GetYear();
2511                    float bnorth, beast, bdown, babs;
2512                    float xl, icode, bab1;
2513                    float stps = 0.05;
2514                    float bdel = 0.001;
2515                    bool value = 0;
2516                    year = 2004;
2517                    float bequ, rr0;
2518                    feldcof_(&year, &dimo);
2519                    feldg_(&reg->m_Lat, &reg->m_Lon, &reg->m_Alt, &bnorth, &beast, &bdown, &babs);
2520                    shellg_(&reg->m_Lat, &reg->m_Lon, &reg->m_Alt, &dimo, &xl, &icode, &bab1);
2521                    findb0_(&stps, &bdel, &value, &bequ, &rr0);
2522                    reg->magnGeo = YMagnGeo();
2523                    reg->magnGeo.setBNorth(bnorth);
2524                    reg->magnGeo.setBEast(beast);
2525                    reg->magnGeo.setBDown(bdown);
2526                    reg->magnGeo.setBAbs(babs);
2527                    reg->magnGeo.setL(xl);
2528                    reg->magnGeo.setBvsB0(babs/bequ);
2529  }  }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.23