/[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 2.6 by kusanagi, Thu Dec 16 17:32:57 2004 UTC revision 5.0 by kusanagi, Mon Aug 29 09:46:13 2005 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Author: kusanagi $   * $Author: kusanagi $
3   * $Date: 2004/12/09 08:48:41 $   * $Date: 2005/08/29 09:26:54 $
4   * $Revision: 2.5 $   * $Revision: 4.5 $
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 40  EventReader::EventReader(int packetsLimi Line 40  EventReader::EventReader(int packetsLimi
40    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPulse1,  new CalibCalPulse1Reader));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPulse1,  new CalibCalPulse1Reader));
41    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPulse2,  new CalibCalPulse2Reader));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPulse2,  new CalibCalPulse2Reader));
42    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Physics,         new PhysicsReader));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Physics,         new PhysicsReader));
   TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrkBoth,    new CalibTrkBothReader));  
43    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk1,       new CalibTrk1Reader));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk1,       new CalibTrk1Reader));
44    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk2,       new CalibTrk2Reader));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk2,       new CalibTrk2Reader));
   TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrd,        new CalibTrdReader));  
45    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTof,        new CalibTofReader));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTof,        new CalibTofReader));
46    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibS4,         new CalibS4Reader));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibS4,         new CalibS4Reader));
47    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPed,     new CalibCalPedReader));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPed,     new CalibCalPedReader));
# Line 81  EventReader::EventReader(int packetsLimi Line 79  EventReader::EventReader(int packetsLimi
79    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgAlarm,        new TrgAlarmReader));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgAlarm,        new TrgAlarmReader));
80    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TofAlarm,        new TofAlarmReader));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TofAlarm,        new TofAlarmReader));
81    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::S4Alarm,         new S4AlarmReader));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::S4Alarm,         new S4AlarmReader));
82      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TsbT,            new TsbTReader));
83      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TsbB,            new TsbBReader));
84  }  }
85    
86  /**  /**
# Line 88  EventReader::EventReader(int packetsLimi Line 88  EventReader::EventReader(int packetsLimi
88   */   */
89  std::string EventReader::GetVersionInfo(void) const {  std::string EventReader::GetVersionInfo(void) const {
90    return    return
91      "$Header: /home/cvsmanager/yoda/techmodel/EventReader.cpp,v 2.5 2004/12/09 08:48:41 kusanagi Exp $\n";      "$Header: /home/cvsmanager/yoda/techmodel/EventReader.cpp,v 4.5 2005/08/29 09:26:54 kusanagi Exp $\n";
92  }  }
93    
94  /**  /**
# Line 143  void EventReader::RunEvent(int EventNumb Line 143  void EventReader::RunEvent(int EventNumb
143                  Header->GetCounter()->Increment(type);                  Header->GetCounter()->Increment(type);
144                  logger->info(Header->GetPscuHeader()->Print());                  logger->info(Header->GetPscuHeader()->Print());
145              } else {              } else {
146                  throw NotExistingAlgorithmException(type->GetName().c_str()); //to exctract to an higher level and delete the logger!                  oss.str("");
147                    oss << "\n No way to read events of type  " << type->GetName().c_str() << Header->GetPscuHeader()->Print();
148                    throw NotExistingAlgorithmException(oss.str().c_str()); //to exctract to an higher level and delete the logger!
149              }              }
150        }        }
151      // In case of exception have to save the packet in a specific root file??      // In case of exception have to save the packet in a specific root file??
# Line 153  void EventReader::RunEvent(int EventNumb Line 155  void EventReader::RunEvent(int EventNumb
155        logger->error(oss.str().c_str());        logger->error(oss.str().c_str());
156      } catch (WrongCRCHeaderException exc) {      } catch (WrongCRCHeaderException exc) {
157        oss.str("");        oss.str("");
158        oss << exc.print() << " " << Header->GetPscuHeader()->Print();        oss << exc.print();
159        logger->error(oss.str().c_str());        logger->error(oss.str().c_str());
160      } catch (WrongCRCException exc) {      } catch (WrongCRCException exc) {
161        oss.str("");        oss.str("");
162        oss << exc.print() << " " << Header->GetPscuHeader()->Print();        oss << exc.print() << " " << Header->GetPscuHeader()->Print();
163        logger->error(oss.str().c_str());        logger->error(oss.str().c_str());
164          InputFile->seekg( (-1)*(Header->GetPscuHeader()->GetPacketLenght() + 15) , std::ios::cur);
165      } catch (UnidentifiedPacketException exc) {      } catch (UnidentifiedPacketException exc) {
166        oss.str("");        oss.str("");
167        oss << exc.print() << " " << Header->GetPscuHeader()->Print();        oss << exc.print() << " " << Header->GetPscuHeader()->Print();
# Line 171  void EventReader::RunEvent(int EventNumb Line 174  void EventReader::RunEvent(int EventNumb
174        oss.str("");        oss.str("");
175        oss << exc.print() << " " << Header->GetPscuHeader()->Print();        oss << exc.print() << " " << Header->GetPscuHeader()->Print();
176        logger->error(oss.str().c_str());        logger->error(oss.str().c_str());
177        } catch (BackwardCounterException exc) {
178          oss.str("");
179          oss << exc.print() << " " << Header->GetPscuHeader()->Print();
180          logger->error(oss.str().c_str());
181      } catch (...) {      } catch (...) {
182        logger->error("Couldn't read the event. Skipping to the next header. \n");        logger->error("Couldn't read the event. Skipping to the next header. \n");
183      }      }
184      if ((step%1000) == 0) std::cout << step/1000 << "K \n";      if ((step%1000) == 0) std::cout << step/1000 << "K \n";
185        oss.str("");
186        oss << "----endPck " << Header->GetPscuHeader()->GetCounter() << "\n";
187        logger->info(oss.str().c_str());
188    }    }
189      Header->GetCounter()->PrintCounters();      Header->GetCounter()->PrintCounters();
190  }  }
# Line 188  static void SkipToNextHeader(ifstream* T Line 198  static void SkipToNextHeader(ifstream* T
198  /**  /**
199   * Unpack the PSCU header from a file into the structure.   * Unpack the PSCU header from a file into the structure.
200   */   */
201  void EventReader::UnpackPscuHeader(void) throw (WrongCRCException, LengthException) {  void EventReader::UnpackPscuHeader(void) throw (WrongCRCHeaderException, LengthException, BackwardCounterException) {
202    stringstream oss;    stringstream oss;
203    int response = false;    int response = 0;
204    char buff[16];    char buff[16];
205    InputFile->read(buff, sizeof(buff));    InputFile->read(buff, sizeof(buff));
206        
# Line 203  void EventReader::UnpackPscuHeader(void) Line 213  void EventReader::UnpackPscuHeader(void)
213    unsigned char CRC          = buff[15];    unsigned char CRC          = buff[15];
214    unsigned char FileOffset   = buff[15];    unsigned char FileOffset   = buff[15];
215    
216    
217    if (Counter < prevPckCounter){    if (Counter < prevPckCounter){
218        response = prevPckCounter - Counter;
219        //oss.str("");
220        //oss << "Packet counter is less than before of " << (prevPckCounter - Counter);
221        //throw BackwardCounterException(oss.str().c_str());
222        //logger->error(oss.str().c_str());
223      }
224    
225      if (Counter > prevPckCounter + 1){
226      oss.str("");      oss.str("");
227      oss << "Packet counter is less than before of " << (prevPckCounter - Counter);      oss << "Packet counter is greater than before of " << (Counter - prevPckCounter);
228      logger->warn(oss.str().c_str());      logger->error(oss.str().c_str());
229      }
230      
231      if ((OrbitalTime == prevPckOBT) & (PacketId1 == 0x10)){
232        oss.str("");
233        oss << "Onboard Time of this packet is equal to the previous packet OBT";
234        logger->error(oss.str().c_str());
235        logger->error(Header->GetPscuHeader()->Print());
236    }    }
237    
238    if (OrbitalTime < prevPckOBT){    if (OrbitalTime < prevPckOBT){
239      oss.str("");      oss.str("");
240      oss << " Onboard Time is less than before of " << (prevPckOBT - OrbitalTime);      oss << " Onboard Time is less than before of " << (prevPckOBT - OrbitalTime);
241      logger->warn(oss.str().c_str());      logger->error(oss.str().c_str());
242    }    }
243    
244    if (((BYTE)CM_Compute_CRC16(0, (BYTE*)&buff, 15) == (BYTE)buff[15]) && (PacketId1 == PacketId2)){    if (((BYTE)CM_Compute_CRC16(0, (BYTE*)&buff, 15) == (BYTE)buff[15]) && (PacketId1 == PacketId2)){
# Line 230  void EventReader::UnpackPscuHeader(void) Line 256  void EventReader::UnpackPscuHeader(void)
256      Header->GetPscuHeader()->SetFileOffset(((long int)(InputFile->tellg()) - 16));      Header->GetPscuHeader()->SetFileOffset(((long int)(InputFile->tellg()) - 16));
257            
258      //commented out because of the above test code      //commented out because of the above test code
259      InputFile->seekg(Header->GetPscuHeader()->GetPacketLenght(), std::ios::cur);      /*InputFile->seekg(Header->GetPscuHeader()->GetPacketLenght(), std::ios::cur);
260      FindStart();      if (FindStart()) {
261      finalPos =  (long int)InputFile->tellg() - (1 + initPos + (long int)(Header->GetPscuHeader()->GetPacketLenght()));          finalPos =  (long int)InputFile->tellg() - (initPos + (long int)(Header->GetPscuHeader()->GetPacketLenght()));
262          if(finalPos == 0){          if(finalPos == 0){
263              logger->debug(_T("Correct packet length"));              logger->debug(_T(" Correct packet length"));
264              }              }
265          if (finalPos > 0 && finalPos < 64) {          if (finalPos > 0 && finalPos < 64) {
266              oss.str("");              oss.str("");
267              oss << " Correct packet length: Padded of " << finalPos << " bytes";              oss << "Correct packet length: Padded of " << finalPos << " bytes";
268              logger->debug(oss.str().c_str());              logger->debug(oss.str().c_str());
269          }          }
270          if (finalPos > 64){          if (finalPos > 64){
271              oss.str("");              oss.str("");
272              oss << "The begin of the next packet is far more than 64 byte from the end of the previous."              oss << "\n The begin of the next packet is far more than 64 byte from the end of the previous."
273                  << Header->GetPscuHeader()->Print();                  << "\n Below the is the now unpacking packet";
274              logger->error(oss.str().c_str());              logger->error(oss.str().c_str());
275                logger->error(Header->GetPscuHeader()->Print());
276              //throw LengthException("The begin of the next packet is far more than 64 byte from the end of the previous.");              //throw LengthException("The begin of the next packet is far more than 64 byte from the end of the previous.");
277          }          }
278          InputFile->seekg(initPos, std::ios::beg);      }
279        else {
280            logger->debug(_T(" END OF FILE"));        
281        }*/
282            
283    } else {    } else {
284         /*Here i should extract the block of Data for later analysis */
285      InputFile->seekg(-(13), std::ios::cur);      InputFile->seekg(-(13), std::ios::cur);
286      throw WrongCRCHeaderException();      oss.str("");
287        oss << "CRC Header Error on packet:" << PscuHeader::Print(buff);
288        throw WrongCRCHeaderException(oss.str().c_str());
289      }
290    
291      if (response > 0){
292        oss.str("");
293        oss << "Packet counter is less than before of " << response;
294        throw BackwardCounterException(oss.str().c_str());
295    }    }
296    
297  /*    char tmpId1[4];  /*    char tmpId1[4];
# Line 285  void EventReader::UnpackPscuTrailer(void Line 325  void EventReader::UnpackPscuTrailer(void
325  /**  /**
326   * Find the next starting poin for the PSCU event looking for a {0xFA, 0xFE, 0xDE} sequence   * Find the next starting poin for the PSCU event looking for a {0xFA, 0xFE, 0xDE} sequence
327   */   */
328  int EventReader::FindStart(void) throw (std::exception) {  bool EventReader::FindStart(void) throw (std::exception) {
329  //search an hexadecimal sequence in a file  //search an hexadecimal sequence in a file
330  //subSign    ------> pointer to the sequence buffer  //subSign    ------> pointer to the sequence buffer
331  //subSignDim ------> dimension of the buffer  //subSignDim ------> dimension of the buffer
# Line 298  int EventReader::FindStart(void) throw ( Line 338  int EventReader::FindStart(void) throw (
338  //------------------------------------------  //------------------------------------------
339    int subIndex = 0;    int subIndex = 0;
340    char dataByte;    char dataByte;
341    
342    int  buffSize = 100;    int  buffSize = 64;
343    int  index = 0;    int  index = 0;
344    int  loop = -1;    int  loop = -1;
345    char buffer[buffSize];    char buffer[buffSize];
346      bool flagOverPad = false;
347    
348    while (!InputFile->eof()) {    while (!InputFile->eof()) {
349      InputFile->read(buffer, sizeof(buffer));      InputFile->read(buffer, sizeof(buffer));
# Line 313  int EventReader::FindStart(void) throw ( Line 354  int EventReader::FindStart(void) throw (
354          if (dataByte == (char)(*(subSign+subIndex))){          if (dataByte == (char)(*(subSign+subIndex))){
355              if (subIndex++ == (subSignDim-1)) {              if (subIndex++ == (subSignDim-1)) {
356                  InputFile->seekg( (index - (subIndex + buffSize)), std::ios::cur);                  InputFile->seekg( (index - (subIndex + buffSize)), std::ios::cur);
357                  return 1;                  if (flagOverPad){
358                        oss.str("");
359                        oss << "\n This packet beginning is farther than 64 byte from the end of the previous."
360                            << "\n Below the is the last already unpacked packet";
361                        logger->error(oss.str().c_str());
362                        logger->error(Header->GetPscuHeader()->Print());
363                    }
364                    return true;
365              }              }
366          } else {          } else {
367              index = index - (subIndex);              index = index - (subIndex);
# Line 321  int EventReader::FindStart(void) throw ( Line 369  int EventReader::FindStart(void) throw (
369          }          }
370      }      }
371      //Needs to guarantee the overap of the buffer(s) in several loop      //Needs to guarantee the overap of the buffer(s) in several loop
372        flagOverPad = true;
373      InputFile->seekg( (-1)*(subSignDim + 1) , std::ios::cur);      InputFile->seekg( (-1)*(subSignDim + 1) , std::ios::cur);
374    }    }
375    return 0;    return false;
376  }  }
377    
378  ClassImp(EventReader)  ClassImp(EventReader)

Legend:
Removed from v.2.6  
changed lines
  Added in v.5.0

  ViewVC Help
Powered by ViewVC 1.1.23