/[PAMELA software]/chewbacca/PamOffLineSW/techmodel/EventReader.cpp
ViewVC logotype

Annotation of /chewbacca/PamOffLineSW/techmodel/EventReader.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Tue Nov 4 09:44:36 2008 UTC (16 years, 1 month ago) by mocchiut
Branch: MAIN
CVS Tags: v1r02, v1r00, v1r01
Changes since 1.1: +4 -4 lines
chewbacca upgrade, YP upgrade

1 mocchiut 1.1 /** @file
2     * $Author: messineo $
3 mocchiut 1.2 * $Date: 2008-06-13 11:58:58 $
4     * $Revision: 1.22 $
5 mocchiut 1.1 *
6     * Implementation of the functions of a sample Algorithm class.
7     * This file can be used as a templace to develop your own algorithm.
8     */
9    
10     #include "EventReader.h"
11     #include "ReaderAlgorithms.h"
12    
13     extern "C" {
14     #include "CRC.h"
15     }
16    
17     using namespace pamela;
18     using namespace pamela::techmodel;
19    
20     EventReader::~EventReader(){
21     if(Header){delete Header; Header=NULL;}
22     }
23    
24     /**
25     * Constructor.
26     */
27    
28     EventReader::EventReader():
29     TechmodelAlgorithm(0, "TechmodelEventReader"){
30     Header = new EventHeader();
31    
32     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::PhysEndRun, new PhysEndRunReader));
33     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPulse1, new CalibCalPulse1Reader));
34     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPulse2, new CalibCalPulse2Reader));
35     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Physics, new PhysicsReader));
36     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrkBoth, new CalibTrkBothReader));
37     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk1, new CalibTrk1Reader));
38     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrk2, new CalibTrk2Reader));
39     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTof, new CalibTofReader));
40     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibS4, new CalibS4Reader));
41     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCalPed, new CalibCalPedReader));
42     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Calib1_Ac1, new Calib1_Ac1Reader));
43     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Calib2_Ac1, new Calib2_Ac1Reader));
44     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Calib1_Ac2, new Calib1_Ac2Reader));
45     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Calib2_Ac2, new Calib2_Ac2Reader));
46     //TODO: marco maybe a bug?: due volte Calib2_Ac2. ??
47     // TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Calib2_Ac2, new CalibCalReader));
48     //TODO: marco maybe a bug?
49     // questa dovrebbe essere cosi ma poi c'e' un errore in Pamela Run: in WriteHeaders non ho CalibCal
50     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibCal, new CalibCalReader));
51     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunHeader, new RunHeaderReader));
52     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::RunTrailer, new RunTrailerReader));
53     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibHeader, new CalibHeaderReader));
54     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalibTrailer, new CalibTrailerReader));
55     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::InitHeader, new InitHeaderReader));
56     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::InitTrailer, new InitTrailerReader));
57     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::EventTrk, new EventTrkReader));
58     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Log, new LogReader));
59     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::VarDump, new VarDumpReader));
60     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ArrDump, new ArrDumpReader));
61     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TabDump, new TabDumpReader));
62     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Tmtc, new TmtcReader));
63     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Mcmd, new McmdReader));
64     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::ForcedFECmd, new ForcedFECmdReader));
65     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Ac1Init, new Ac1InitReader));
66     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalInit, new CalInitReader));
67     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrkInit, new TrkInitReader));
68     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TofInit, new TofInitReader));
69     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TrgInit, new TrgInitReader));
70     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::NdInit, new NdInitReader));
71     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::S4Init, new S4InitReader));
72     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Ac2Init, new Ac2InitReader));
73     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::CalAlarm, new CalAlarmReader));
74     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Ac1Alarm, new Ac1AlarmReader));
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     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::S4Alarm, new S4AlarmReader));
79     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::Ac2Alarm, new Ac2AlarmReader));
80     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TsbT, new TsbTReader));
81     TechmodelAlgorithmMap.insert(AlgorithmMap::value_type(PacketType::TsbB, new TsbBReader));
82     }
83    
84     /**
85     * Initialize the algorithm with a special run. This will initialize the
86     * event reader routines for all packet types.
87     */
88     void EventReader::Init(PamelaRun *run) {
89     //Create the structure of directories and create xxx.Header.root files
90     run->WriteHeaders(this, &Header);
91     //Create the xxx.root in it's specific directory
92     for (AlgorithmMap::iterator i = TechmodelAlgorithmMap.begin();
93     i != TechmodelAlgorithmMap.end(); i++) {
94     // cout << " Initializing algo " << i->second->GetAlgorithmName()<<endl;
95     i->second->Init(run);
96     }
97    
98     if ( Header ) { delete Header; Header = new EventHeader(); }; // EMILIANO, reset Counter when opening a new file
99    
100     Run=run;
101     }
102    
103    
104     /**
105     * Read the next event header, call the reader algorithms that
106     * correspond to its packet type, and read the event trailer.
107     * if the packet is saved return 0.
108     *
109     * return values: meaning:
110     0 packet good
111     1 exception but used //never happen
112     2 CRC exception but used
113     3 CALIBRATION PACKET with error but used
114     -1 CRC exception packet DISCARDED
115     -2 FATAL exception packet DISCARDED //never happen
116 mocchiut 1.2 -3 No way to read events of this type. packet DISCARDED( es CalibCal --old)
117 mocchiut 1.1 //in PacketUser I will put ret = 10
118     ret = 10 if the packet is good but comes from a cadre with VRL problems
119    
120     *
121     */
122     int EventReader::PKT_RunEvent(char* headerPkt, char* pamPkt, long int length, const PacketType* type){
123     stringstream oss;
124     string msg;
125     int ret=0;
126     PKT_UnpackPscuHeader(headerPkt);
127     AlgorithmMap::iterator i = TechmodelAlgorithmMap.find(type);
128     if (i != TechmodelAlgorithmMap.end())
129     {
130     TechmodelAlgorithm* EventAlgorithm(i->second);
131     try{
132     EventAlgorithm->PKT_RunEvent(pamPkt, length);
133     }
134     catch (WrongCRCException_PKTUsed &exc){
135     //questo tipo di eccezione NON mi preoccupa,
136     //il pacchetto e' stato utilizzato e salvato ugualmente
137     ret=2;
138     oss.str("");
139     oss << exc.print();
140     oss << " Return "<<ret;
141     msg=oss.str();
142     PamOffLineSW::mainLogUtil->logWarning(msg);
143     }
144     catch (CalibException &exc){
145     //questo tipo di eccezione mi preoccupa un pochino,
146     //il pacchetto e' stato utilizzato e salvato ugualmente
147     ret=3;
148     oss.str("");
149     oss << exc.print();
150     oss << " Return "<<ret;
151     msg=oss.str();
152     PamOffLineSW::mainLogUtil->logWarning(msg);
153     }
154     catch (WrongCRCException &exc){
155     //questo tipo di eccezione mi preoccupa,
156     //il pacchetto non e' stato utilizzato ne salvato
157     ret=-1;
158     oss.str("");
159     oss << exc.print();
160     oss << " The Packet is Discarded ";
161     oss << " Return "<<ret;
162     msg=oss.str();
163     PamOffLineSW::mainLogUtil->logError(msg);
164     return ret;
165     }
166     catch (FatalException &exc){
167     ret=-2;
168     oss.str("");
169     oss << exc.print();
170     oss << " The Packet is Discarded ";
171     oss << " Return "<<ret;
172     msg=oss.str();
173     PamOffLineSW::mainLogUtil->logError(msg);
174     return ret;
175     }
176     catch (Exception &exc){
177     ret=1;
178     oss.str("");
179     oss << exc.print();
180     oss << " Return "<<ret;
181     msg=oss.str();
182     PamOffLineSW::mainLogUtil->logWarning(msg);
183     }
184     // catch (NotExistingAlgorithmException exc) {}
185    
186     Run->FillTrees(type);
187     Header->GetCounter()->Increment(type);
188     }
189     else
190     {
191     ret=-3;
192     oss.str("");
193     oss << " No way to read events of type " << type->GetName().c_str()<<". The Packet is skipped ";
194     oss << " Return "<<ret;
195     msg=oss.str();
196     PamOffLineSW::mainLogUtil->logWarning(msg);
197     return ret;
198     }
199     return ret;
200     }
201    
202     /**
203     * Unpack the PSCU header from the pkt into the structure.
204     */
205     //fill the header structure,
206     void EventReader::PKT_UnpackPscuHeader(char* buff)
207     {
208     unsigned char PacketId1 = buff[3];
209     unsigned char PacketId2 = buff[4];
210     unsigned int Counter = (((UINT32)buff[5]<<16)&0x00FF0000) + (((UINT32)buff[6]<<8)&0x0000FF00) + (((UINT32)buff[7])&0x000000FF);
211     unsigned int OrbitalTime = (((UINT32)buff[8]<<24)&0xFF000000) + (((UINT32)buff[9]<<16)&0x00FF0000) + (((UINT32)buff[10]<<8)&0x0000FF00) + (((UINT32)buff[11])&0x000000FF);
212     unsigned int PacketLenght = (((UINT32)buff[12]<<16)&0x00FF0000) + (((UINT32)buff[13]<<8)&0x0000FF00) + (((UINT32)buff[14])&0x000000FF);
213     unsigned char CRC = buff[15];
214     unsigned char FileOffset = 0;// ??
215    
216     Header->GetPscuHeader()->SetPacketId(PacketId1, PacketId2);
217     Header->GetPscuHeader()->SetCounter(Counter);
218     Header->GetPscuHeader()->SetOrbitalTime(OrbitalTime);
219     //PacketLength is the length of the whole DATApacket starting from the first byte after the header
220     //plus the CRC legth (which varies for each type of packet)
221     Header->GetPscuHeader()->SetPacketLenght(PacketLenght);
222    
223     Header->GetPscuHeader()->SetCRC(CRC);
224     Header->GetPscuHeader()->SetFileOffset(0);//I don't need this !!
225     }
226    
227    
228    
229     /**
230     * Get a string with the version info of the algorithm.
231     */
232     std::string EventReader::GetVersionInfo(void) const {
233     return
234 mocchiut 1.2 "$Header: /repository/PamOffLineSW/techmodel/EventReader.cpp,v 1.22 2008-06-13 11:58:58 messineo Exp $\n";
235 mocchiut 1.1 }
236    
237    
238     ClassImp(EventReader)

  ViewVC Help
Powered by ViewVC 1.1.23