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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations) (download)
Thu Feb 11 09:02:11 2010 UTC (14 years, 10 months ago) by mocchiut
Branch: MAIN
CVS Tags: v10RED, v9r00, v9r01, HEAD
Changes since 1.4: +34 -14 lines
Error occurred while calculating annotation data.
9R bugs fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23