/[PAMELA software]/yoda/techmodel/EventReader.cpp
ViewVC logotype

Diff of /yoda/techmodel/EventReader.cpp

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

revision 1.1.1.1 by kusanagi, Tue Jul 6 12:20:23 2004 UTC revision 1.9 by kusanagi, Wed Aug 25 10:14:26 2004 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Author: nagni $   * $Author: kusanagi $
3   * $Date: 2004/06/09 23:18:20 $   * $Date: 2004/08/24 13:19:59 $
4   * $Revision: 1.12 $   * $Revision: 1.8 $
5   *   *
6   * Implementation of the functions of a sample Algorithm class.   * Implementation of the functions of a sample Algorithm class.
7   * This file can be used as a templace to develop your own algorithm.   * This file can be used as a templace to develop your own algorithm.
# Line 24  using namespace pamela; Line 24  using namespace pamela;
24  using namespace pamela::techmodel;  using namespace pamela::techmodel;
25    
26  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.EventReader");  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.EventReader");
27  static unsigned int prevPckCounter = 0;  unsigned int EventReader::prevPckCounter = 0;
28  static unsigned int prevPckOBT     = 0;  unsigned int EventReader::prevPckOBT     = 0;
29  /**  /**
30   * Constructor.   * Constructor.
31   */   */
# Line 35  EventReader::EventReader(void): Line 35  EventReader::EventReader(void):
35        <<  "Constructor "        <<  "Constructor "
36        <<  "\n " << log4cpp::CategoryStream::ENDLINE;        <<  "\n " << log4cpp::CategoryStream::ENDLINE;
37    Header = new EventHeader();    Header = new EventHeader();
38    /*  
39        TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::PhysEndRun,      new PhysEndRunReader()));
40        TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPulse1,  new CalibCalPulse1Reader()));
41    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Alarm,    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPulse2,  new CalibCalPulse2Reader()));
42                                                    new AlarmReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Physics,         new PhysicsReader()));
43    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Khb,    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrkBoth,    new CalibTrkBothReader()));
44                                                    new KhbReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk1,       new CalibTrk1Reader()));
45   */    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk2,       new CalibTrk2Reader()));
46    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Physics,    new PhysicsReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrd,        new CalibTrdReader()));
47    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ForcedPkt,  new ForcedPktReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTof,        new CalibTofReader()));
48    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunHeader,  new RunHeaderReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibS4,         new CalibS4Reader()));
49    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunTrailer, new RunTrailerReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPed,     new CalibCalPedReader()));
50    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Log,      new LogReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibAc,         new CalibAcReader()));
51    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::VarDump,  new VarDumpReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunHeader,       new RunHeaderReader()));
52    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ArrDump,  new ArrDumpReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunTrailer,      new RunTrailerReader()));
53    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TabDump,  new TabDumpReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibHeader,     new CalibHeaderReader()));
54    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Tmtc,     new TmtcReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrailer,    new CalibTrailerReader()));
55    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Mcmd,     new McmdReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::InitHeader,      new InitHeaderReader()));
56    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCal, new CalibCalReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::InitTrailer,     new InitTrailerReader()));
57    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk, new CalibTrkReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::EventTrk,        new EventTrkReader()));
58    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrg, new CalibTrgReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TestTrk,         new TestTrkReader()));
59    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrd, new CalibTrdReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Log,             new LogReader()));
60    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTof, new CalibTofReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::VarDump,         new VarDumpReader()));
61    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibS4,  new CalibS4Reader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ArrDump,         new ArrDumpReader()));
62    /*    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TabDump,         new TabDumpReader()));
63    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::HA_Header_E5,    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Tmtc,            new TmtcReader()));
64                                                    new E5Reader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Mcmd,            new McmdReader()));
65  */    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ForcedFECmd,     new ForcedFECmdReader()));
66      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::AcInit,          new AcInitReader()));
67      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalInit,         new CalInitReader()));
68      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrkInit,         new TrkInitReader()));
69      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TofInit,         new TofInitReader()));
70      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgInit,         new TrgInitReader()));
71  }  }
72    
73  /**  /**
# Line 70  EventReader::EventReader(void): Line 75  EventReader::EventReader(void):
75   */   */
76  std::string EventReader::GetVersionInfo(void) const {  std::string EventReader::GetVersionInfo(void) const {
77    return    return
78      "$Header: /home/cvspamela/yoda/techmodel/EventReader.cpp,v 1.12 2004/06/09 23:18:20 nagni Exp $\n";      "$Header: /home/cvsmanager/yoda/techmodel/EventReader.cpp,v 1.8 2004/08/24 13:19:59 kusanagi Exp $\n";
79  }  }
80    
81  /**  /**
# Line 108  static void SkipToNextHeader(ifstream *) Line 113  static void SkipToNextHeader(ifstream *)
113  // 15 June 2004 ---note------------------  // 15 June 2004 ---note------------------
114  void EventReader::RunEvent(int EventNumber) {  void EventReader::RunEvent(int EventNumber) {
115        
116    cat <<  log4cpp::Priority::ERROR <<  "Start Unpacking........"    cat <<  log4cpp::Priority::INFO <<  "Start Unpacking........"
117        <<  "\n " << log4cpp::CategoryStream::ENDLINE;        <<  "\n " << log4cpp::CategoryStream::ENDLINE;
118    //for now i'll suppose that the raw file starts immediately with the right bytes    //for now i'll suppose that the raw file starts immediately with the right bytes
119    //to insert a GetPacketStart()    //to insert a GetPacketStart()
# Line 133  void EventReader::RunEvent(int EventNumb Line 138  void EventReader::RunEvent(int EventNumb
138          //**TO BE DONE**   <<WRONG CRC l --- LOST PACKET>>//          //**TO BE DONE**   <<WRONG CRC l --- LOST PACKET>>//
139          //Have to be defined a "WrongCRC" packet::Type?          //Have to be defined a "WrongCRC" packet::Type?
140          //}          //}
141       }       }
142      } catch (...) {      } catch (...) {
143        //This have to be more detailed. More exceptions type are needed.        //This have to be more detailed. More exceptions type are needed.
144        cat <<  log4cpp::Priority::ERROR <<  "Couldn't read the event. Skipping to the next header."        cat <<  log4cpp::Priority::ERROR <<  "Couldn't read the event. Skipping to the next header."
# Line 157  int EventReader::UnpackPscuHeader(void) Line 162  int EventReader::UnpackPscuHeader(void)
162    char buff[16];    char buff[16];
163    InputFile->read(buff, sizeof(buff));    InputFile->read(buff, sizeof(buff));
164        
   prevPckCounter = 0;  
   prevPckOBT     = 0;  
165        
166    unsigned char PacketId1    = buff[3];    unsigned char PacketId1    = buff[3];
167    unsigned char PacketId2    = buff[4];    unsigned char PacketId2    = buff[4];
# Line 166  int EventReader::UnpackPscuHeader(void) Line 169  int EventReader::UnpackPscuHeader(void)
169    unsigned int  OrbitalTime  = (((UINT32)buff[8]<<24)&0xFF000000) + (((UINT32)buff[9]<<16)&0x00FF0000) +  (((UINT32)buff[10]<<8)&0x0000FF00) + (((UINT32)buff[11])&0x000000FF);    unsigned int  OrbitalTime  = (((UINT32)buff[8]<<24)&0xFF000000) + (((UINT32)buff[9]<<16)&0x00FF0000) +  (((UINT32)buff[10]<<8)&0x0000FF00) + (((UINT32)buff[11])&0x000000FF);
170    unsigned int  PacketLenght = (((UINT32)buff[12]<<16)&0x00FF0000) +  (((UINT32)buff[13]<<8)&0x0000FF00) + (((UINT32)buff[14])&0x000000FF);    unsigned int  PacketLenght = (((UINT32)buff[12]<<16)&0x00FF0000) +  (((UINT32)buff[13]<<8)&0x0000FF00) + (((UINT32)buff[14])&0x000000FF);
171    unsigned char CRC          = buff[15];    unsigned char CRC          = buff[15];
172      unsigned char FileOffset   = buff[15];
173    
174    if (Counter < prevPckCounter){    if (Counter < prevPckCounter){
175      cat <<  log4cpp::Priority::ERROR      cat <<  log4cpp::Priority::WARN
176          <<  " Packet counter is less than before of " << (prevPckCounter - Counter)          <<  " Packet counter is less than before of " << (prevPckCounter - Counter)
177          <<  "\n " << log4cpp::CategoryStream::ENDLINE;          <<  " " << log4cpp::CategoryStream::ENDLINE;
178    }    }
179    
180    if (OrbitalTime < prevPckOBT){    if (OrbitalTime < prevPckOBT){
181        cat <<  log4cpp::Priority::WARN        cat <<  log4cpp::Priority::WARN
182            <<  " Orbital Time is less than before of " << (prevPckOBT - OrbitalTime)            <<  " Orbital Time is less than before of " << (prevPckOBT - OrbitalTime)
183            <<  "\n " << log4cpp::CategoryStream::ENDLINE;            <<  " " << log4cpp::CategoryStream::ENDLINE;
184    }    }
185    
186    
187    if ((BYTE)CM_Compute_CRC16(0, (BYTE*)&buff, 15) == (BYTE)buff[15]){    if (((BYTE)CM_Compute_CRC16(0, (BYTE*)&buff, 15) == (BYTE)buff[15]) && (PacketId1 == PacketId2)){
188        prevPckCounter = Counter;
189        prevPckOBT     = OrbitalTime;
190      long int initPos = InputFile->tellg();      long int initPos = InputFile->tellg();
191      long int finalPos;      long int finalPos;
192      Header->GetPscuHeader()->SetPacketId(PacketId1, PacketId2);      Header->GetPscuHeader()->SetPacketId(PacketId1, PacketId2);
# Line 190  int EventReader::UnpackPscuHeader(void) Line 196  int EventReader::UnpackPscuHeader(void)
196      //plus the CRC legth (which varies for each type of packet)      //plus the CRC legth (which varies for each type of packet)
197      Header->GetPscuHeader()->SetPacketLenght(PacketLenght);      Header->GetPscuHeader()->SetPacketLenght(PacketLenght);
198      Header->GetPscuHeader()->SetCRC(CRC);      Header->GetPscuHeader()->SetCRC(CRC);
199        Header->GetPscuHeader()->SetFileOffset(((long int)(InputFile->tellg()) - 16));
200            
201      //commented out because of the above test code      //commented out because of the above test code
202      InputFile->seekg(Header->GetPscuHeader()->GetPacketLenght(), std::ios::cur);      InputFile->seekg(Header->GetPscuHeader()->GetPacketLenght(), std::ios::cur);
203      FindStart();      FindStart();
204      finalPos =  (long int)InputFile->tellg() - (1 + initPos + (long int)(Header->GetPscuHeader()->GetPacketLenght()));      finalPos =  (long int)InputFile->tellg() - (1 + initPos + (long int)(Header->GetPscuHeader()->GetPacketLenght()));
205          if(finalPos == 0){          if(finalPos == 0){
206              cat <<  log4cpp::Priority::INFO <<  " Correct packet length \n"              cat <<  log4cpp::Priority::DEBUG <<  " Correct packet length"
207                  <<  "\n " << log4cpp::CategoryStream::ENDLINE;                  <<  " " << log4cpp::CategoryStream::ENDLINE;
208              }              }
209          if (finalPos > 0 && finalPos < 64) {          if (finalPos > 0 && finalPos < 64) {
210              cat <<  log4cpp::Priority::WARN              cat <<  log4cpp::Priority::WARN
211                  <<  " Correct packet length: Padded of " << finalPos << " bytes \n"                  <<  " Correct packet length: Padded of " << finalPos << " bytes"
212                  <<  "\n " << log4cpp::CategoryStream::ENDLINE;                  <<  " " << log4cpp::CategoryStream::ENDLINE;
213          }          }
214          if (finalPos > 64){          if (finalPos > 64){
215              cat <<  log4cpp::Priority::ERROR <<  " Wrong packet length? (because of wrong padding?) \n"              cat <<  log4cpp::Priority::ERROR <<  " Wrong packet length? (because of wrong padding?) "
216                  <<  "\n " << log4cpp::CategoryStream::ENDLINE;                  <<  " " << log4cpp::CategoryStream::ENDLINE;
217          }          }
218          InputFile->seekg(initPos, std::ios::beg);          InputFile->seekg(initPos, std::ios::beg);
219          response =  true;          response =  true;
220    } else {    } else {
221      cat <<  log4cpp::Priority::ERROR <<  " WRONG CRC FOR HEADER "      cat <<  log4cpp::Priority::ERROR <<  " WRONG CRC FOR HEADER "
222          <<  "\n " << log4cpp::CategoryStream::ENDLINE;          <<  " " << log4cpp::CategoryStream::ENDLINE;
223        InputFile->seekg(-(13), std::ios::cur);
224      response =  false;      response =  false;
225    }    }
   
226      char tmpId1[4];      char tmpId1[4];
227      char tmpId2[4];      char tmpId2[4];
228      char tmpLength[12];      char tmpLength[12];
# Line 223  int EventReader::UnpackPscuHeader(void) Line 230  int EventReader::UnpackPscuHeader(void)
230      char tmpCRC[4];      char tmpCRC[4];
231      sprintf(tmpId1, "%02X", PacketId1);      sprintf(tmpId1, "%02X", PacketId1);
232      sprintf(tmpId2, "%02X", PacketId2);      sprintf(tmpId2, "%02X", PacketId2);
233      sprintf(tmpLength, "%06X", PacketLenght);      sprintf(tmpLength, "%06X", Header->GetPscuHeader()->GetPacketLenght());
234      sprintf(tmpStart, "%X", ((long int)(InputFile->tellg()) - 16));      sprintf(tmpStart, "%X", Header->GetPscuHeader()->GetFileOffset());
235      sprintf(tmpCRC, "%02X", CRC);      sprintf(tmpCRC, "%02X", CRC);
236      cat <<  log4cpp::Priority::INFO        cat <<  log4cpp::Priority::INFO  
237          <<  "\n Packet Counter (decimal) : "  <<  Counter          <<  "\n Packet Counter (decimal) : "  <<  Counter
# Line 278  int EventReader::FindStart(void) throw ( Line 285  int EventReader::FindStart(void) throw (
285        if (InputFile->eof()) {        if (InputFile->eof()) {
286          throw Exception("Extra bytes over the last packets");          throw Exception("Extra bytes over the last packets");
287        } else {        } else {
288          return 0;          subIndex = 0;
289            //return 0;
290        }        }
291        //InputFile->seekg(-(subIndex+1), std::ios::cur);        //InputFile->seekg(-(subIndex+1), std::ios::cur);
292        //subIndex = 0;        //subIndex = 0;

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.9

  ViewVC Help
Powered by ViewVC 1.1.23