/[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.3 - (hide annotations) (download)
Fri Jul 24 13:53:45 2009 UTC (15 years, 4 months ago) by mocchiut
Branch: MAIN
Changes since 1.2: +7 -6 lines
Runtime error with ROOT 5.24 fixed, many small changes and warnings fixing

1 mocchiut 1.1 /** @file
2 mocchiut 1.3 * $Author: mocchiut $
3     * $Date: 2008/11/04 09:44:36 $
4     * $Revision: 1.2 $
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 mocchiut 1.3 // oss << " No way to read events of type " << type->GetName().c_str()<<". The Packet is skipped ";
194     oss << " No way to read events of type " << type->GetName()<<". The Packet is skipped ";
195 mocchiut 1.1 oss << " Return "<<ret;
196     msg=oss.str();
197     PamOffLineSW::mainLogUtil->logWarning(msg);
198     return ret;
199     }
200     return ret;
201     }
202    
203     /**
204     * Unpack the PSCU header from the pkt into the structure.
205     */
206     //fill the header structure,
207     void EventReader::PKT_UnpackPscuHeader(char* buff)
208     {
209     unsigned char PacketId1 = buff[3];
210     unsigned char PacketId2 = buff[4];
211     unsigned int Counter = (((UINT32)buff[5]<<16)&0x00FF0000) + (((UINT32)buff[6]<<8)&0x0000FF00) + (((UINT32)buff[7])&0x000000FF);
212     unsigned int OrbitalTime = (((UINT32)buff[8]<<24)&0xFF000000) + (((UINT32)buff[9]<<16)&0x00FF0000) + (((UINT32)buff[10]<<8)&0x0000FF00) + (((UINT32)buff[11])&0x000000FF);
213     unsigned int PacketLenght = (((UINT32)buff[12]<<16)&0x00FF0000) + (((UINT32)buff[13]<<8)&0x0000FF00) + (((UINT32)buff[14])&0x000000FF);
214     unsigned char CRC = buff[15];
215 mocchiut 1.3 // unsigned char FileOffset = 0;// ??
216 mocchiut 1.1
217     Header->GetPscuHeader()->SetPacketId(PacketId1, PacketId2);
218     Header->GetPscuHeader()->SetCounter(Counter);
219     Header->GetPscuHeader()->SetOrbitalTime(OrbitalTime);
220     //PacketLength is the length of the whole DATApacket starting from the first byte after the header
221     //plus the CRC legth (which varies for each type of packet)
222     Header->GetPscuHeader()->SetPacketLenght(PacketLenght);
223    
224     Header->GetPscuHeader()->SetCRC(CRC);
225     Header->GetPscuHeader()->SetFileOffset(0);//I don't need this !!
226     }
227    
228    
229    
230     /**
231     * Get a string with the version info of the algorithm.
232     */
233     std::string EventReader::GetVersionInfo(void) const {
234     return
235 mocchiut 1.3 "$Header: /afs/ba.infn.it/user/pamela/src/CVS/chewbacca/PamOffLineSW/techmodel/EventReader.cpp,v 1.2 2008/11/04 09:44:36 mocchiut Exp $\n";
236 mocchiut 1.1 }
237    
238    
239     ClassImp(EventReader)

  ViewVC Help
Powered by ViewVC 1.1.23