/[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.3 by kusanagi, Sun Oct 17 12:28:38 2004 UTC revision 2.7 by kusanagi, Wed Dec 22 11:38:35 2004 UTC
# Line 1  Line 1 
1  /** @file  /** @file
2   * $Author: kusanagi $   * $Author: kusanagi $
3   * $Date: 2004/09/24 11:57:49 $   * $Date: 2004/12/16 17:32:57 $
4   * $Revision: 2.2 $   * $Revision: 2.6 $
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 9  Line 9 
9    
10  #include <log4cxx/logger.h>  #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    
# Line 35  unsigned int EventReader::prevPckOBT     Line 32  unsigned int EventReader::prevPckOBT    
32   */   */
33  EventReader::EventReader(int packetsLimit = -1):  EventReader::EventReader(int packetsLimit = -1):
34    TechmodelAlgorithm(0, "TechmodelEventReader"){    TechmodelAlgorithm(0, "TechmodelEventReader"){
 //EventReader::EventReader(void):  
 //  TechmodelAlgorithm(0, "TechmodelEventReader") {  
35    EventReader::maxPackets = packetsLimit;    EventReader::maxPackets = packetsLimit;
36    logger->debug(_T("Constructor"));    logger->debug(_T("Constructor"));
37    Header = new EventHeader();    Header = new EventHeader();
38    
39    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::PhysEndRun,      new PhysEndRunReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::PhysEndRun,      new PhysEndRunReader));
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));
43    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrkBoth,    new CalibTrkBothReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrkBoth,    new CalibTrkBothReader));
44    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk1,       new CalibTrk1Reader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk1,       new CalibTrk1Reader));
45    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk2,       new CalibTrk2Reader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk2,       new CalibTrk2Reader));
46    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrd,        new CalibTrdReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrd,        new CalibTrdReader));
47    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTof,        new CalibTofReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTof,        new CalibTofReader));
48    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibS4,         new CalibS4Reader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibS4,         new CalibS4Reader));
49    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPed,     new CalibCalPedReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPed,     new CalibCalPedReader));
50    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibAc,         new CalibAcReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Calib1_Ac1,      new Calib1_Ac1Reader));
51    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunHeader,       new RunHeaderReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Calib2_Ac1,      new Calib2_Ac1Reader));
52    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunTrailer,      new RunTrailerReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Calib1_Ac2,      new Calib1_Ac2Reader));
53    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibHeader,     new CalibHeaderReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Calib2_Ac2,      new Calib2_Ac2Reader));
54    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrailer,    new CalibTrailerReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunHeader,       new RunHeaderReader));
55    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::InitHeader,      new InitHeaderReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunTrailer,      new RunTrailerReader));
56    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::InitTrailer,     new InitTrailerReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibHeader,     new CalibHeaderReader));
57    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::EventTrk,        new EventTrkReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrailer,    new CalibTrailerReader));
58    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TestTrk,         new TestTrkReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::InitHeader,      new InitHeaderReader));
59    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TestTof,         new TestTofReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::InitTrailer,     new InitTrailerReader));
60    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Log,             new LogReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::EventTrk,        new EventTrkReader));
61    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::VarDump,         new VarDumpReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TestTrk,         new TestTrkReader));
62    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ArrDump,         new ArrDumpReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TestTof,         new TestTofReader));
63    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TabDump,         new TabDumpReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Log,             new LogReader));
64    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Tmtc,            new TmtcReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::VarDump,         new VarDumpReader));
65    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Mcmd,            new McmdReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ArrDump,         new ArrDumpReader));
66    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ForcedFECmd,     new ForcedFECmdReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TabDump,         new TabDumpReader));
67    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::AcInit,          new AcInitReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Tmtc,            new TmtcReader));
68    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalInit,         new CalInitReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Mcmd,            new McmdReader));
69    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrkInit,         new TrkInitReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ForcedFECmd,     new ForcedFECmdReader));
70    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TofInit,         new TofInitReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Ac1Init,         new Ac1InitReader));
71    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgInit,         new TrgInitReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalInit,         new CalInitReader));
72    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgInit,         new NdInitReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrkInit,         new TrkInitReader));
73    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalAlarm,        new CalAlarmReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TofInit,         new TofInitReader));
74    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::AcAlarm,         new AcAlarmReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgInit,         new TrgInitReader));
75    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrkAlarm,        new TrkAlarmReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::NdInit,          new NdInitReader));
76    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgAlarm,        new TrgAlarmReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::S4Init,          new S4InitReader));
77    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TofAlarm,        new TofAlarmReader()));    TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Ac2Init,         new Ac2InitReader));
78      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalAlarm,        new CalAlarmReader));
79      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::AcAlarm,         new AcAlarmReader));
80      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrkAlarm,        new TrkAlarmReader));
81      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgAlarm,        new TrgAlarmReader));
82      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TofAlarm,        new TofAlarmReader));
83      TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::S4Alarm,         new S4AlarmReader));
84  }  }
85    
86  /**  /**
# Line 87  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.2 2004/09/24 11:57:49 kusanagi Exp $\n";      "$Header: /home/cvsmanager/yoda/techmodel/EventReader.cpp,v 2.6 2004/12/16 17:32:57 kusanagi Exp $\n";
92  }  }
93    
94  /**  /**
# Line 95  std::string EventReader::GetVersionInfo( Line 96  std::string EventReader::GetVersionInfo(
96   * event reader routines for all packet types.   * event reader routines for all packet types.
97   */   */
98  void EventReader::Init(PamelaRun *run) {  void EventReader::Init(PamelaRun *run) {
     std::stringstream oss;  
     logger->debug(_T("Initialize"));  
99      SetInputStream(run);      SetInputStream(run);
100            
101      //Create the structure of directories and create xxx.Header.root files      //Create the structure of directories and create xxx.Header.root files
# Line 105  void EventReader::Init(PamelaRun *run) { Line 104  void EventReader::Init(PamelaRun *run) {
104      //Create the xxx.root in it's specific directory      //Create the xxx.root in it's specific directory
105      for (AlgorithmMap::iterator i = TechmodelAlgorithmMap.begin();      for (AlgorithmMap::iterator i = TechmodelAlgorithmMap.begin();
106         i != TechmodelAlgorithmMap.end(); i++) {         i != TechmodelAlgorithmMap.end(); i++) {
107         oss.flush();         oss.str("");
108         oss << "Initializing algo " << i->second->GetAlgorithmName();         oss << "Initializing algo " << i->second->GetAlgorithmName();
        //cout << "Initializing algo " << i->second->GetAlgorithmName();  
109         logger->debug(oss.str().c_str());         logger->debug(oss.str().c_str());
110         i->second->Init(run);         i->second->Init(run);
111      }      }
# Line 123  static void SkipToNextHeader(ifstream *) Line 121  static void SkipToNextHeader(ifstream *)
121    
122  // 15 June 2004 ---note------------------  // 15 June 2004 ---note------------------
123  // 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
124  // read in the UnpackPscuHeader() and put directly in the  // read in the UnpackPscuHeader() and put directly in  the
125  // EventAlgorithm->RunEvent(....) directly the data inside the packet.... will see later....  // EventAlgorithm->RunEvent(....) directly the data inside the packet.... will see later....
126  // 15 June 2004 ---note------------------  // 15 June 2004 ---note------------------
127  void EventReader::RunEvent(int EventNumber) {  void EventReader::RunEvent(int EventNumber) {
# Line 131  void EventReader::RunEvent(int EventNumb Line 129  void EventReader::RunEvent(int EventNumb
129    //to insert a GetPacketStart()    //to insert a GetPacketStart()
130    stringstream oss;    stringstream oss;
131    int step = 0;    int step = 0;
132      const PacketType* type;
133    while (!InputFile->eof() && ((step++ < maxPackets) || (maxPackets == 0))){    while (!InputFile->eof() && ((step++ < maxPackets) || (maxPackets == 0))){
134      try {      try {
135        if (FindStart()) {        if (FindStart()) {
136          if(UnpackPscuHeader()){              UnpackPscuHeader();
137              const PacketType* type = Header->GetPscuHeader()->GetPacketType();              type = Header->GetPscuHeader()->GetPacketType();
             //if (filter->CheckPacket(type))  
138              AlgorithmMap::iterator i = TechmodelAlgorithmMap.find(type);              AlgorithmMap::iterator i = TechmodelAlgorithmMap.find(type);
139              if (i != TechmodelAlgorithmMap.end()) {              if (i != TechmodelAlgorithmMap.end()) {
140                  TechmodelAlgorithm *EventAlgorithm = i->second;                  TechmodelAlgorithm *EventAlgorithm(i->second);
141                  EventAlgorithm->RunEvent(EventNumber, Header->GetPscuHeader()->GetPacketLenght());                  EventAlgorithm->RunEvent(EventNumber, Header->GetPscuHeader()->GetPacketLenght());
142                  Run->FillTrees(type);                  Run->FillTrees(type);
143                  Header->GetCounter()->Increment(type);                  Header->GetCounter()->Increment(type);
144                    logger->info(Header->GetPscuHeader()->Print());
145              } else {              } else {
146                  oss.flush();                  throw NotExistingAlgorithmException(type->GetName().c_str()); //to exctract to an higher level and delete the logger!
                 oss << "No way to read events of type" << type->GetName();  
                 logger->info(oss.str().c_str());  
                 throw Exception("No way to read events of type " + type->GetName());  
147              }              }
         } //else {  
             //**TO BE DONE**   <<WRONG CRC l --- LOST PACKET>>//  
             //Have to be defined a "WrongCRC" packet::Type?  
             //}  
148        }        }
149        // In case of exception have to save the packet in a specific root file??
150        } catch (NotExistingAlgorithmException exc) {
151          oss.str("");
152          oss << exc.print() << " " << Header->GetPscuHeader()->Print();
153          logger->error(oss.str().c_str());
154        } catch (WrongCRCHeaderException exc) {
155          oss.str("");
156          oss << exc.print() << " " << Header->GetPscuHeader()->Print();
157          logger->error(oss.str().c_str());
158        } catch (WrongCRCException exc) {
159          oss.str("");
160          oss << exc.print() << " " << Header->GetPscuHeader()->Print();
161          logger->error(oss.str().c_str());
162        } catch (UnidentifiedPacketException exc) {
163          oss.str("");
164          oss << exc.print() << " " << Header->GetPscuHeader()->Print();
165          logger->error(oss.str().c_str());
166        } catch (NotExistingCounterException exc) {
167          oss.str("");
168          oss << exc.print() << " " << Header->GetPscuHeader()->Print();
169          logger->error(oss.str().c_str());
170        } catch (LengthException exc) {
171          oss.str("");
172          oss << exc.print() << " " << Header->GetPscuHeader()->Print();
173          logger->error(oss.str().c_str());
174      } catch (...) {      } catch (...) {
175        //This have to be more detailed. More exceptions type are needed.        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.");  
176      }      }
177      if ((step%1000) == 0) std::cout << step/1000 << "K \n";      if ((step%1000) == 0) std::cout << step/1000 << "K \n";
178    }    }
# Line 172  static void SkipToNextHeader(ifstream* T Line 188  static void SkipToNextHeader(ifstream* T
188  /**  /**
189   * Unpack the PSCU header from a file into the structure.   * Unpack the PSCU header from a file into the structure.
190   */   */
191  int EventReader::UnpackPscuHeader(void) throw (std::exception) {  void EventReader::UnpackPscuHeader(void) throw (WrongCRCException, LengthException) {
192    stringstream oss;    stringstream oss;
193    int response;    int response = false;
194    char buff[16];    char buff[16];
195    InputFile->read(buff, sizeof(buff));    InputFile->read(buff, sizeof(buff));
196        
# Line 188  int EventReader::UnpackPscuHeader(void) Line 204  int EventReader::UnpackPscuHeader(void)
204    unsigned char FileOffset   = buff[15];    unsigned char FileOffset   = buff[15];
205    
206    if (Counter < prevPckCounter){    if (Counter < prevPckCounter){
207      oss.flush();      oss.str("");
208      oss << "Packet counter is less than before of " << (prevPckCounter - Counter);      oss << "Packet counter is less than before of " << (prevPckCounter - Counter);
209      logger->info(oss.str().c_str());      logger->warn(oss.str().c_str());
210    }    }
211    
212    if (OrbitalTime < prevPckOBT){    if (OrbitalTime < prevPckOBT){
213      oss.flush();      oss.str("");
214      oss << " Orbital Time is less than before of " << (prevPckOBT - OrbitalTime);      oss << " Onboard Time is less than before of " << (prevPckOBT - OrbitalTime);
215      logger->info(oss.str().c_str());      logger->warn(oss.str().c_str());
216    }    }
217    
218    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 215  int EventReader::UnpackPscuHeader(void) Line 231  int EventReader::UnpackPscuHeader(void)
231            
232      //commented out because of the above test code      //commented out because of the above test code
233      InputFile->seekg(Header->GetPscuHeader()->GetPacketLenght(), std::ios::cur);      InputFile->seekg(Header->GetPscuHeader()->GetPacketLenght(), std::ios::cur);
234      FindStart();      if (FindStart()) {
235      finalPos =  (long int)InputFile->tellg() - (1 + initPos + (long int)(Header->GetPscuHeader()->GetPacketLenght()));          finalPos =  (long int)InputFile->tellg() - (initPos + (long int)(Header->GetPscuHeader()->GetPacketLenght()));
236          if(finalPos == 0){          if(finalPos == 0){
237              logger->debug(_T("Correct packet length"));              logger->debug(_T(" Correct packet length"));
238              }              }
239          if (finalPos > 0 && finalPos < 64) {          if (finalPos > 0 && finalPos < 64) {
240              oss.flush();              oss.str("");
241              oss << " Correct packet length: Padded of " << finalPos << " bytes";              oss << " Correct packet length: Padded of " << finalPos << " bytes";
242              logger->warn(oss.str().c_str());              logger->debug(oss.str().c_str());
243          }          }
244          if (finalPos > 64){          if (finalPos > 64){
245              logger->warn(_T(" Wrong packet length? (because of wrong padding?)"));              oss.str("");
246                oss << " The begin of the next packet is far more than 64 byte from the end of the previous."
247                    << Header->GetPscuHeader()->Print();
248                logger->error(oss.str().c_str());
249                //throw LengthException("The begin of the next packet is far more than 64 byte from the end of the previous.");
250          }          }
251        }
252        else {
253            logger->debug(_T(" END OF FILE"));        
254        }
255            
256          InputFile->seekg(initPos, std::ios::beg);          InputFile->seekg(initPos, std::ios::beg);
         response =  true;  
257    } else {    } else {
     logger->warn(_T(" WRONG CRC FOR HEADER "));  
258      InputFile->seekg(-(13), std::ios::cur);      InputFile->seekg(-(13), std::ios::cur);
259      response =  false;      throw WrongCRCHeaderException();
260    }    }
261      char tmpId1[4];  
262    /*    char tmpId1[4];
263      char tmpId2[4];      char tmpId2[4];
264      char tmpLength[12];      char tmpLength[12];
265      char tmpStart[100];      char tmpStart[100];
# Line 253  int EventReader::UnpackPscuHeader(void) Line 277  int EventReader::UnpackPscuHeader(void)
277          <<  "\n CRC                      : "  <<  tmpCRC          <<  "\n CRC                      : "  <<  tmpCRC
278          <<  "\n Header Start Position    : "  <<  tmpStart;          <<  "\n Header Start Position    : "  <<  tmpStart;
279      logger->info(oss.str().c_str());      logger->info(oss.str().c_str());
280    return response;  */
281  }  }
282    
283  /**  /**
# Line 266  void EventReader::UnpackPscuTrailer(void Line 290  void EventReader::UnpackPscuTrailer(void
290  /**  /**
291   * 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
292   */   */
293  int EventReader::FindStart(void) throw (std::exception) {  bool EventReader::FindStart(void) throw (std::exception) {
294  //search an hexadecimal sequence in a file  //search an hexadecimal sequence in a file
295  //subSign    ------> pointer to the sequence buffer  //subSign    ------> pointer to the sequence buffer
296  //subSignDim ------> dimension of the buffer  //subSignDim ------> dimension of the buffer
# Line 274  int EventReader::FindStart(void) throw ( Line 298  int EventReader::FindStart(void) throw (
298  // return true if founds a match (else false)  // return true if founds a match (else false)
299  // subF point rigth after the match, if found. Else EOF.  // subF point rigth after the match, if found. Else EOF.
300  //Maurizio 15/11/2002-----------------------  //Maurizio 15/11/2002-----------------------
301    const unsigned char subSign[3]={0xFA, 0xFE, 0xDE};    const int subSignDim = 3;
302    int subSignDim = 3;    const unsigned char subSign[subSignDim]={0xFA, 0xFE, 0xDE};
303  //------------------------------------------  //------------------------------------------
304    int subIndex = 0;    int subIndex = 0;
305    char dataByte;    char dataByte;
306    
307    int  buffSize = 100;    int  buffSize = 100;
308    int  index = 0;    int  index = 0;
309    int  loop = 0;    int  loop = -1;
310    char buffer[buffSize];    char buffer[buffSize];
311    
   /* original version  
   while (!InputFile->eof()) {  
     InputFile->get(dataByte);  
     if (dataByte == (char)(*(subSign+subIndex))){  
       if (subIndex++ == (subSignDim-1)) {  
          InputFile->seekg(-(subIndex), std::ios::cur);  
         return 1;  
        }  
     } else {  
       if (InputFile->eof()) {  
         throw Exception("Extra bytes over the last packets");  
       } else {  
         subIndex = 0;  
       }  
     }  
   } */  
312    while (!InputFile->eof()) {    while (!InputFile->eof()) {
313      InputFile->read(buffer, sizeof(buffer));      InputFile->read(buffer, sizeof(buffer));
314      index = 0;      index = 0;
315      ++loop;      loop++;
316      while (index < buffSize){      while (index < buffSize){
317          dataByte = buffer[index++];          dataByte = buffer[index++];
318          if (dataByte == (char)(*(subSign+subIndex))){          if (dataByte == (char)(*(subSign+subIndex))){
319              if (subIndex++ == (subSignDim-1)) {              if (subIndex++ == (subSignDim-1)) {
320                  InputFile->seekg( (index - subIndex - (buffSize*loop)), std::ios::cur);                  InputFile->seekg( (index - (subIndex + buffSize)), std::ios::cur);
321              return 1;                  return true;
322              }              }
323          } else {          } else {
324                index = index - (subIndex);
325              subIndex = 0;              subIndex = 0;
326          }          }
327      }      }
328    }      //Needs to guarantee the overap of the buffer(s) in several loop
329    return 0;      InputFile->seekg( (-1)*(subSignDim + 1) , std::ios::cur);
330      }
331      return false;
332  }  }
333    
334  ClassImp(EventReader)  ClassImp(EventReader)

Legend:
Removed from v.2.3  
changed lines
  Added in v.2.7

  ViewVC Help
Powered by ViewVC 1.1.23