/[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.2 by kusanagi, Tue Jul 6 13:31:18 2004 UTC revision 2.4 by kusanagi, Fri Dec 3 22:08:00 2004 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Author: kusanagi $   * $Author: kusanagi $
3   * $Date: 2004/07/06 12:20:23 $   * $Date: 2004/10/17 12:28:38 $
4   * $Revision: 1.1.1.1 $   * $Revision: 2.3 $
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.
8   */   */
9    
10  #include <log4cpp/Category.hh>  #include <log4cxx/logger.h>
11  #include <fstream>  #include <fstream>
 #include "TechmodelAlgorithm.h"  
12  #include "EventReader.h"  #include "EventReader.h"
13  #include "ReaderAlgorithms.h"  #include "ReaderAlgorithms.h"
14  #include "Exception.h"  
15  #include "stdio.h"  
16  extern "C" {  extern "C" {
17  #include "CRC.h"      #include "CRC.h"
18  }  }
19    
 #define BYTE unsigned char  
   
20  using namespace pamela;  using namespace pamela;
21  using namespace pamela::techmodel;  using namespace pamela::techmodel;
22    
23  static log4cpp::Category& cat = log4cpp::Category::getInstance("pamela.techmodel.EventReader");  static log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(_T("pamela.techmodel.EventReader"));
24  static unsigned int prevPckCounter = 0;  
25  static unsigned int prevPckOBT     = 0;  unsigned int EventReader::maxPackets     = 0;
26    unsigned int EventReader::prevPckCounter = 0;
27    unsigned int EventReader::prevPckOBT     = 0;
28    
29    
30  /**  /**
31   * Constructor.   * Constructor.
32   */   */
33  EventReader::EventReader(void):  EventReader::EventReader(int packetsLimit = -1):
34    TechmodelAlgorithm(0, "TechmodelEventReader") {    TechmodelAlgorithm(0, "TechmodelEventReader"){
35    cat <<  log4cpp::Priority::DEBUG    EventReader::maxPackets = packetsLimit;
36        <<  "Constructor "    logger->debug(_T("Constructor"));
       <<  "\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::CalibTrk1, new CalibTrk1Reader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::EventTrk,        new EventTrkReader()));
58    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk2, new CalibTrk2Reader()));    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::TestTof,         new TestTofReader()));
60    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTof, new CalibTofReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Log,             new LogReader()));
61    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibS4,  new CalibS4Reader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::VarDump,         new VarDumpReader()));
62    /*    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ArrDump,         new ArrDumpReader()));
63    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::HA_Header_E5,    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TabDump,         new TabDumpReader()));
64                                                    new E5Reader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Tmtc,            new TmtcReader()));
65  */    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Mcmd,            new McmdReader()));
66      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ForcedFECmd,     new ForcedFECmdReader()));
67      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::AcInit,          new AcInitReader()));
68      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalInit,         new CalInitReader()));
69      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrkInit,         new TrkInitReader()));
70      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TofInit,         new TofInitReader()));
71      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgInit,         new TrgInitReader()));
72      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgInit,         new NdInitReader()));
73      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalAlarm,        new CalAlarmReader()));
74      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::AcAlarm,         new AcAlarmReader()));
75      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrkAlarm,        new TrkAlarmReader()));
76      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgAlarm,        new TrgAlarmReader()));
77      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TofAlarm,        new TofAlarmReader()));
78  }  }
79    
80  /**  /**
# Line 70  EventReader::EventReader(void): Line 82  EventReader::EventReader(void):
82   */   */
83  std::string EventReader::GetVersionInfo(void) const {  std::string EventReader::GetVersionInfo(void) const {
84    return    return
85      "$Header: /home/cvsmanager/yoda/techmodel/EventReader.cpp,v 1.1.1.1 2004/07/06 12:20:23 kusanagi Exp $\n";      "$Header: /home/cvsmanager/yoda/techmodel/EventReader.cpp,v 2.3 2004/10/17 12:28:38 kusanagi Exp $\n";
86  }  }
87    
88  /**  /**
# Line 86  void EventReader::Init(PamelaRun *run) { Line 98  void EventReader::Init(PamelaRun *run) {
98      //Create the xxx.root in it's specific directory      //Create the xxx.root in it's specific directory
99      for (AlgorithmMap::iterator i = TechmodelAlgorithmMap.begin();      for (AlgorithmMap::iterator i = TechmodelAlgorithmMap.begin();
100         i != TechmodelAlgorithmMap.end(); i++) {         i != TechmodelAlgorithmMap.end(); i++) {
101         cat  <<  log4cpp::Priority::DEBUG         oss.str("");
102              <<  " Initializing algo " << i->second->GetAlgorithmName()         oss << "Initializing algo " << i->second->GetAlgorithmName();
103              <<  "\n " << log4cpp::CategoryStream::ENDLINE;         logger->debug(oss.str().c_str());
104         i->second->Init(run);         i->second->Init(run);
105      }      }
106      Run = dynamic_cast<TechmodelPamelaRun*>(run);      Run = dynamic_cast<TechmodelPamelaRun*>(run);
# Line 103  static void SkipToNextHeader(ifstream *) Line 115  static void SkipToNextHeader(ifstream *)
115    
116  // 15 June 2004 ---note------------------  // 15 June 2004 ---note------------------
117  // A nice refacoring would require to not read again the packet data (which is  // A nice refacoring would require to not read again the packet data (which is
118  // read in the UnpackPscuHeader() and put directly in the  // read in the UnpackPscuHeader() and put directly in  the
119  // EventAlgorithm->RunEvent(....) directly the data inside the packet.... will see later....  // EventAlgorithm->RunEvent(....) directly the data inside the packet.... will see later....
120  // 15 June 2004 ---note------------------  // 15 June 2004 ---note------------------
121  void EventReader::RunEvent(int EventNumber) {  void EventReader::RunEvent(int EventNumber) {
     
   cat <<  log4cpp::Priority::ERROR <<  "Start Unpacking........"  
       <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
122    //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
123    //to insert a GetPacketStart()    //to insert a GetPacketStart()
124    while (!InputFile->eof()){    stringstream oss;
125      int step = 0;
126      while (!InputFile->eof() && ((step++ < maxPackets) || (maxPackets == 0))){
127      try {      try {
128        if (FindStart()) {        if (FindStart()) {
129          if(UnpackPscuHeader()){              UnpackPscuHeader();
130              const PacketType* type = Header->GetPscuHeader()->GetPacketType();              const PacketType* type = Header->GetPscuHeader()->GetPacketType();
131              AlgorithmMap::iterator i = TechmodelAlgorithmMap.find(type);              AlgorithmMap::iterator i = TechmodelAlgorithmMap.find(type);
132              if (i != TechmodelAlgorithmMap.end()) {              if (i != TechmodelAlgorithmMap.end()) {
# Line 123  void EventReader::RunEvent(int EventNumb Line 134  void EventReader::RunEvent(int EventNumb
134                  EventAlgorithm->RunEvent(EventNumber, Header->GetPscuHeader()->GetPacketLenght());                  EventAlgorithm->RunEvent(EventNumber, Header->GetPscuHeader()->GetPacketLenght());
135                  Run->FillTrees(type);                  Run->FillTrees(type);
136                  Header->GetCounter()->Increment(type);                  Header->GetCounter()->Increment(type);
137                    logger->info(Header->GetPscuHeader()->Print());
138              } else {              } else {
139              cat <<  log4cpp::Priority::ERROR                  throw NotExistingAlgorithmException(type->GetName().c_str()); //to exctract to an higher level and delete the logger!
140                  <<  "No way to read events of type" << type->GetName()              }
141                  <<  "\n " << log4cpp::CategoryStream::ENDLINE;        }
142              throw Exception("No way to read events of type " + type->GetName());      // In case of exception have to save the packet in a specific root file??
143          }      } catch (NotExistingAlgorithmException exc) {
144        } //else {        char *temp;
145          //**TO BE DONE**   <<WRONG CRC l --- LOST PACKET>>//        sprintf(temp, "%s %s \n", exc.print(), Header->GetPscuHeader()->Print());
146          //Have to be defined a "WrongCRC" packet::Type?        logger->warn(temp);
147          //}      } catch (WrongCRCHeaderException exc) {
148       }        char *temp;
149          sprintf(temp, "%s %s \n", exc.print(), Header->GetPscuHeader()->Print());
150          logger->warn(temp);
151        } catch (WrongCRCException exc) {
152          //char *temp;
153          //sprintf(temp, "%s %s \n", exc.print(), Header->GetPscuHeader()->Print());
154          //logger->warn(temp);
155            logger->warn(Header->GetPscuHeader()->Print());
156        } catch (UnidentifiedPacketException exc) {
157          char *temp;
158          sprintf(temp, "%s %s \n", exc.print(), Header->GetPscuHeader()->Print());
159          logger->warn(temp);
160        } catch (NotExistingCounterException exc) {
161          char *temp;
162          sprintf(temp, "%s %s \n", exc.print(), Header->GetPscuHeader()->Print());
163          logger->warn(temp);
164        } catch (LengthException exc) {
165          char *temp;
166          sprintf(temp, "%s %s \n", exc.print(), Header->GetPscuHeader()->Print());
167          logger->warn(temp);
168      } catch (...) {      } catch (...) {
169        //This have to be more detailed. More exceptions type are needed.        logger->error("Couldn't read the event. Skipping to the next header. \n");
       cat <<  log4cpp::Priority::ERROR <<  "Couldn't read the event. Skipping to the next header."  
           <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
170      }      }
171        if ((step%1000) == 0) std::cout << step/1000 << "K \n";
172    }    }
173    Header->GetCounter()->PrintCounters();      Header->GetCounter()->PrintCounters();
174  }  }
175    
176  static void SkipToNextHeader(ifstream* TechmodelFile) {  static void SkipToNextHeader(ifstream* TechmodelFile) {
# Line 152  static void SkipToNextHeader(ifstream* T Line 182  static void SkipToNextHeader(ifstream* T
182  /**  /**
183   * Unpack the PSCU header from a file into the structure.   * Unpack the PSCU header from a file into the structure.
184   */   */
185  int EventReader::UnpackPscuHeader(void) throw (std::exception) {  void EventReader::UnpackPscuHeader(void) throw (WrongCRCException, LengthException) {
186    int response;    stringstream oss;
187      int response = false;
188    char buff[16];    char buff[16];
189    InputFile->read(buff, sizeof(buff));    InputFile->read(buff, sizeof(buff));
190        
   prevPckCounter = 0;  
   prevPckOBT     = 0;  
191        
192    unsigned char PacketId1    = buff[3];    unsigned char PacketId1    = buff[3];
193    unsigned char PacketId2    = buff[4];    unsigned char PacketId2    = buff[4];
# Line 166  int EventReader::UnpackPscuHeader(void) Line 195  int EventReader::UnpackPscuHeader(void)
195    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);
196    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);
197    unsigned char CRC          = buff[15];    unsigned char CRC          = buff[15];
198      unsigned char FileOffset   = buff[15];
199    
200    if (Counter < prevPckCounter){    if (Counter < prevPckCounter){
201      cat <<  log4cpp::Priority::ERROR      oss.str("");
202          <<  " Packet counter is less than before of " << (prevPckCounter - Counter)      oss << "Packet counter is less than before of " << (prevPckCounter - Counter);
203          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->warn(oss.str().c_str());
204    }    }
205    
206    if (OrbitalTime < prevPckOBT){    if (OrbitalTime < prevPckOBT){
207        cat <<  log4cpp::Priority::WARN      oss.str("");
208            <<  " Orbital Time is less than before of " << (prevPckOBT - OrbitalTime)      oss << " Onboard Time is less than before of " << (prevPckOBT - OrbitalTime);
209            <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->warn(oss.str().c_str());
210    }    }
211    
212      if (((BYTE)CM_Compute_CRC16(0, (BYTE*)&buff, 15) == (BYTE)buff[15]) && (PacketId1 == PacketId2)){
213    if ((BYTE)CM_Compute_CRC16(0, (BYTE*)&buff, 15) == (BYTE)buff[15]){      prevPckCounter = Counter;
214        prevPckOBT     = OrbitalTime;
215      long int initPos = InputFile->tellg();      long int initPos = InputFile->tellg();
216      long int finalPos;      long int finalPos;
217      Header->GetPscuHeader()->SetPacketId(PacketId1, PacketId2);      Header->GetPscuHeader()->SetPacketId(PacketId1, PacketId2);
# Line 190  int EventReader::UnpackPscuHeader(void) Line 221  int EventReader::UnpackPscuHeader(void)
221      //plus the CRC legth (which varies for each type of packet)      //plus the CRC legth (which varies for each type of packet)
222      Header->GetPscuHeader()->SetPacketLenght(PacketLenght);      Header->GetPscuHeader()->SetPacketLenght(PacketLenght);
223      Header->GetPscuHeader()->SetCRC(CRC);      Header->GetPscuHeader()->SetCRC(CRC);
224        Header->GetPscuHeader()->SetFileOffset(((long int)(InputFile->tellg()) - 16));
225            
226      //commented out because of the above test code      //commented out because of the above test code
227      InputFile->seekg(Header->GetPscuHeader()->GetPacketLenght(), std::ios::cur);      InputFile->seekg(Header->GetPscuHeader()->GetPacketLenght(), std::ios::cur);
228      FindStart();      FindStart();
229      finalPos =  (long int)InputFile->tellg() - (1 + initPos + (long int)(Header->GetPscuHeader()->GetPacketLenght()));      finalPos =  (long int)InputFile->tellg() - (1 + initPos + (long int)(Header->GetPscuHeader()->GetPacketLenght()));
230          if(finalPos == 0){          if(finalPos == 0){
231              cat <<  log4cpp::Priority::INFO <<  " Correct packet length \n"              logger->debug(_T("Correct packet length"));
                 <<  "\n " << log4cpp::CategoryStream::ENDLINE;  
232              }              }
233          if (finalPos > 0 && finalPos < 64) {          if (finalPos > 0 && finalPos < 64) {
234              cat <<  log4cpp::Priority::WARN              oss.str("");
235                  <<  " Correct packet length: Padded of " << finalPos << " bytes \n"              oss << " Correct packet length: Padded of " << finalPos << " bytes";
236                  <<  "\n " << log4cpp::CategoryStream::ENDLINE;              logger->debug(oss.str().c_str());
237          }          }
238          if (finalPos > 64){          if (finalPos > 64){
239              cat <<  log4cpp::Priority::ERROR <<  " Wrong packet length? (because of wrong padding?) \n"              oss.str("");
240                  <<  "\n " << log4cpp::CategoryStream::ENDLINE;              oss << "The begin of the next packet is far more than 64 byte from the end of the previous."
241                    << Header->GetPscuHeader()->Print();
242                logger->warn(oss.str().c_str());
243                //throw LengthException("The begin of the next packet is far more than 64 byte from the end of the previous.");
244          }          }
245          InputFile->seekg(initPos, std::ios::beg);          InputFile->seekg(initPos, std::ios::beg);
         response =  true;  
246    } else {    } else {
247      cat <<  log4cpp::Priority::ERROR <<  " WRONG CRC FOR HEADER "      InputFile->seekg(-(13), std::ios::cur);
248          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      throw WrongCRCHeaderException();
     response =  false;  
249    }    }
250    
251      char tmpId1[4];  /*    char tmpId1[4];
252      char tmpId2[4];      char tmpId2[4];
253      char tmpLength[12];      char tmpLength[12];
254      char tmpStart[100];      char tmpStart[100];
255      char tmpCRC[4];      char tmpCRC[4];
256      sprintf(tmpId1, "%02X", PacketId1);      sprintf(tmpId1, "%02X", PacketId1);
257      sprintf(tmpId2, "%02X", PacketId2);      sprintf(tmpId2, "%02X", PacketId2);
258      sprintf(tmpLength, "%06X", PacketLenght);      sprintf(tmpLength, "%06X", Header->GetPscuHeader()->GetPacketLenght());
259      sprintf(tmpStart, "%X", ((long int)(InputFile->tellg()) - 16));      sprintf(tmpStart, "%X", Header->GetPscuHeader()->GetFileOffset());
260      sprintf(tmpCRC, "%02X", CRC);      sprintf(tmpCRC, "%02X", CRC);
261      cat <<  log4cpp::Priority::INFO        oss.flush();
262          <<  "\n Packet Counter (decimal) : "  <<  Counter      oss << "\n Packet Counter (decimal) : "  <<  Counter
263          <<  "\n Id1 - Id2                : "  <<  tmpId1 <<  " - " <<  tmpId2          <<  "\n Id1 - Id2                : "  <<  tmpId1 <<  " - " <<  tmpId2
264          <<  "\n Orbital Time (decimal)   : "  <<  OrbitalTime          <<  "\n Orbital Time (decimal)   : "  <<  OrbitalTime
265          <<  "\n Lenght                   : "  <<  tmpLength          <<  "\n Lenght                   : "  <<  tmpLength
266          <<  "\n CRC                      : "  <<  tmpCRC          <<  "\n CRC                      : "  <<  tmpCRC
267          <<  "\n Header Start Position    : "  <<  tmpStart          <<  "\n Header Start Position    : "  <<  tmpStart;
268          <<  "\n " << log4cpp::CategoryStream::ENDLINE;      logger->info(oss.str().c_str());
269    return response;  */
270  }  }
271    
272  /**  /**
# Line 255  int EventReader::FindStart(void) throw ( Line 287  int EventReader::FindStart(void) throw (
287  // return true if founds a match (else false)  // return true if founds a match (else false)
288  // subF point rigth after the match, if found. Else EOF.  // subF point rigth after the match, if found. Else EOF.
289  //Maurizio 15/11/2002-----------------------  //Maurizio 15/11/2002-----------------------
290    const unsigned char subSign[3]={0xFA, 0xFE, 0xDE};    const int subSignDim = 3;
291    int subSignDim = 3;    const unsigned char subSign[subSignDim]={0xFA, 0xFE, 0xDE};
292  //------------------------------------------  //------------------------------------------
293    int subIndex = 0;    int subIndex = 0;
294    char dataByte;    char dataByte;
295    /*InputFile->read(fileByte, 1);  
296      if ( *fileByte ==  *(subSign+subIndex)){    int  buffSize = 100;
297         if (subIndex++ == (subSignDim-1)) {    int  index = 0;
298          InputFile->seekg(-(subIndex), std::ios::cur);    int  loop = -1;
299          return 1;    char buffer[buffSize];
300        }  
       }*/  
301    while (!InputFile->eof()) {    while (!InputFile->eof()) {
302      InputFile->get(dataByte);      InputFile->read(buffer, sizeof(buffer));
303      if (dataByte == (char)(*(subSign+subIndex))){      index = 0;
304        if (subIndex++ == (subSignDim-1)) {      loop++;
305           InputFile->seekg(-(subIndex), std::ios::cur);      while (index < buffSize){
306          return 1;          dataByte = buffer[index++];
307         }          if (dataByte == (char)(*(subSign+subIndex))){
308      } else {              if (subIndex++ == (subSignDim-1)) {
309        if (InputFile->eof()) {                  InputFile->seekg( (index - (subIndex + buffSize)), std::ios::cur);
310          throw Exception("Extra bytes over the last packets");                  return 1;
311        } else {              }
312          return 0;          } else {
313        }              index = index - (subIndex);
314        //InputFile->seekg(-(subIndex+1), std::ios::cur);              subIndex = 0;
315        //subIndex = 0;          }
316      }      }
317    }      //Needs to guarantee the overap of the buffer(s) in several loop
318        InputFile->seekg( (-1)*(subSignDim + 1) , std::ios::cur);
319      }
320    return 0;    return 0;
321  }  }
322    

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

  ViewVC Help
Powered by ViewVC 1.1.23